forked from rh-ecosystem-edge/eco-gotests
-
Notifications
You must be signed in to change notification settings - Fork 11
mdr-operator: add MDRT negative validation test (RHWA-1249) #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gamado
wants to merge
4
commits into
medik8s:main
Choose a base branch
from
gamado:feat/mdr-negative-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
585a111
mdr-operator: add MDRT negative validation test (OCP-60889)
gamado d2f6041
mdr-operator: address razo7 review comments on PR #88
gamado 8630dac
mdr-operator: address ugreener review comments on PR #88
gamado db5759e
mdr-operator: replace remaining context.TODO() in negative test
gamado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package tests | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/rh-ecosystem-edge/eco-goinfra/pkg/deployment" | ||
| "github.com/rh-ecosystem-edge/eco-goinfra/pkg/pod" | ||
| "github.com/rh-ecosystem-edge/eco-goinfra/pkg/reportxml" | ||
|
|
||
| "github.com/medik8s/system-tests/tests/internal/helpers" | ||
| "github.com/medik8s/system-tests/tests/internal/labels" | ||
| . "github.com/medik8s/system-tests/tests/internal/medik8sinittools" | ||
| "github.com/medik8s/system-tests/tests/internal/medik8sparams" | ||
| "github.com/medik8s/system-tests/tests/mdr-operator/internal/mdrparams" | ||
|
|
||
| k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| var _ = Describe( | ||
| "MDR Negative Validation tests", | ||
| Ordered, | ||
| ContinueOnFailure, | ||
| Label(labels.OperatorMDR, mdrparams.Label), func() { | ||
| BeforeAll(func() { | ||
| By("Verify MDR deployment is ready") | ||
|
|
||
| mdrDeployment, err := deployment.Pull( | ||
| APIClient, mdrparams.OperatorDeploymentName, medik8sparams.OperatorNs) | ||
| Expect(err).ToNot(HaveOccurred(), "Failed to get MDR deployment") | ||
| Expect(mdrDeployment.IsReady(medik8sparams.DefaultTimeout)).To(BeTrue(), | ||
|
gamado marked this conversation as resolved.
|
||
| "MDR deployment is not Ready") | ||
|
|
||
| By("Pre-cleaning stale test resources from previous runs") | ||
|
|
||
| cleanupMDRT(mdrparams.MDRTNegativeTestName) | ||
| cleanupMDRT(mdrparams.MDRTInvalidTestName) | ||
| }) | ||
|
|
||
| AfterAll(func() { | ||
| By("Cleaning up test MDRTs if unexpectedly created") | ||
|
|
||
| cleanupMDRT(mdrparams.MDRTNegativeTestName) | ||
| cleanupMDRT(mdrparams.MDRTInvalidTestName) | ||
|
|
||
| By("Verifying MDR controller pod is running") | ||
|
|
||
| Eventually(verifyMDRControllerRunning, | ||
| medik8sparams.DefaultTimeout, mdrparams.DefaultPollInterval).Should(Succeed(), | ||
| "MDR controller pod should be running after negative tests") | ||
| }) | ||
|
|
||
| It("Verify MDRT with invalid values is rejected by API server", | ||
| reportxml.ID("60889"), | ||
| Label(labels.TierAcceptance, | ||
| labels.DisruptionNonDestructive, labels.PlatformAny, | ||
| labels.FrequencyPresubmit), func() { | ||
| var validationErrors []string | ||
|
|
||
| By("Creating MDRT with non-existent namespace") | ||
|
|
||
| mdrtInvalidNs := buildMDRT(mdrparams.MDRTNegativeTestName) | ||
| mdrtInvalidNs.SetNamespace(mdrparams.MDRTInvalidTestNamespace) | ||
|
|
||
| err := APIClient.Create(context.Background(), mdrtInvalidNs) | ||
| if err == nil { | ||
| DeferCleanup(func() { | ||
| By("Cleaning up unexpectedly created MDRT in non-existent namespace") | ||
| if delErr := APIClient.Delete(context.Background(), mdrtInvalidNs); delErr != nil && !k8serrors.IsNotFound(delErr) { | ||
| GinkgoWriter.Printf("Warning: failed to delete MDRT %s/%s: %v\n", | ||
| mdrtInvalidNs.GetNamespace(), mdrtInvalidNs.GetName(), delErr) | ||
| } | ||
| }) | ||
|
gamado marked this conversation as resolved.
|
||
|
|
||
| validationErrors = append(validationErrors, | ||
| fmt.Sprintf("MDRT with namespace %q was unexpectedly created", | ||
| mdrparams.MDRTInvalidTestNamespace)) | ||
| } else if !k8serrors.IsNotFound(err) { | ||
| validationErrors = append(validationErrors, | ||
| fmt.Sprintf("MDRT with namespace %q: expected NotFound error, got: %v", | ||
| mdrparams.MDRTInvalidTestNamespace, err)) | ||
| } | ||
|
|
||
| By("Creating MDRT with name violating RFC 1123") | ||
|
|
||
| mdrtInvalidName := buildMDRT(mdrparams.MDRTInvalidTestName) | ||
|
|
||
| err = APIClient.Create(context.Background(), mdrtInvalidName) | ||
| if err == nil { | ||
| DeferCleanup(func() { cleanupMDRT(mdrtInvalidName.GetName()) }) | ||
|
|
||
| validationErrors = append(validationErrors, | ||
|
gamado marked this conversation as resolved.
|
||
| fmt.Sprintf("MDRT with name %q was unexpectedly created", | ||
| mdrparams.MDRTInvalidTestName)) | ||
| } else if !k8serrors.IsInvalid(err) { | ||
| validationErrors = append(validationErrors, | ||
| fmt.Sprintf("MDRT with name %q: expected Invalid error, got: %v", | ||
| mdrparams.MDRTInvalidTestName, err)) | ||
| } | ||
|
|
||
| if len(validationErrors) > 0 { | ||
| Fail("MDRT negative validation failures:\n- " + | ||
| strings.Join(validationErrors, "\n- ")) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| func verifyMDRControllerRunning() error { | ||
| listOptions := metav1.ListOptions{ | ||
| LabelSelector: mdrparams.OperatorControllerPodLabelSelector, | ||
| } | ||
|
|
||
| allPods, listErr := pod.List(APIClient, medik8sparams.OperatorNs, listOptions) | ||
| if listErr != nil { | ||
| return fmt.Errorf("failed to list MDR pods: %w", listErr) | ||
| } | ||
|
|
||
| mdrPods := helpers.FilterPodsByDeployment(allPods, mdrparams.OperatorDeploymentName) | ||
| runningCount := int32(len(helpers.FilterRunningPods(mdrPods))) | ||
|
|
||
| if runningCount != mdrparams.ExpectedReplicas { | ||
| return fmt.Errorf("expected %d running MDR pod(s), found %d", | ||
| mdrparams.ExpectedReplicas, runningCount) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.