forked from openshift/compliance-operator
-
Notifications
You must be signed in to change notification settings - Fork 48
CMP-3883: Create an e2e suite for operator deployment tests #1110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
77596e5
Created deployment suite and copied related test cases there
taimurhafeez 8af3bcd
Addressed minor comments
taimurhafeez 56ecbbc
Merge branch 'master' into CMP-3883
taimurhafeez 1bc6fe0
Merge branch 'master' into CMP-3883
taimurhafeez de6c667
Removed a typo
taimurhafeez 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| package deployment_e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| compv1alpha1 "github.com/ComplianceAsCode/compliance-operator/pkg/apis/compliance/v1alpha1" | ||
| "github.com/ComplianceAsCode/compliance-operator/tests/e2e/framework" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| var brokenContentImagePath string | ||
| var contentImagePath string | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| f := framework.NewFramework() | ||
| err := f.SetUp() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| contentImagePath = os.Getenv("CONTENT_IMAGE") | ||
| if contentImagePath == "" { | ||
| fmt.Println("Please set the 'CONTENT_IMAGE' environment variable") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| brokenContentImagePath = os.Getenv("BROKEN_CONTENT_IMAGE") | ||
|
|
||
| if brokenContentImagePath == "" { | ||
| fmt.Println("Please set the 'BROKEN_CONTENT_IMAGE' environment variable") | ||
| os.Exit(1) | ||
| } | ||
| exitCode := m.Run() | ||
| if exitCode == 0 || (exitCode > 0 && f.CleanUpOnError()) { | ||
| if err = f.TearDown(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| func TestServiceMonitoringMetricsTarget(t *testing.T) { | ||
| t.Parallel() | ||
| f := framework.Global | ||
|
|
||
| err := f.SetupRBACForMetricsTest() | ||
| if err != nil { | ||
| t.Fatalf("failed to create service account: %s", err) | ||
| } | ||
| defer f.CleanUpRBACForMetricsTest() | ||
|
|
||
| metricsTargets, err := f.WaitForPrometheusMetricTargets() | ||
| if err != nil { | ||
| t.Fatalf("failed to get prometheus metric targets: %s", err) | ||
| } | ||
|
|
||
| expectedMetricsCount := 2 | ||
|
|
||
| err = f.AssertServiceMonitoringMetricsTarget(metricsTargets, expectedMetricsCount) | ||
| if err != nil { | ||
| t.Fatalf("failed to assert metrics target: %s", err) | ||
| } | ||
| } | ||
|
|
||
| func TestResultServerHTTPVersion(t *testing.T) { | ||
| t.Parallel() | ||
| f := framework.Global | ||
| endpoints := []string{ | ||
| fmt.Sprintf("https://metrics.%s.svc:8585/metrics-co", f.OperatorNamespace), | ||
| fmt.Sprintf("http://metrics.%s.svc:8383/metrics", f.OperatorNamespace), | ||
| } | ||
|
|
||
| expectedHTTPVersion := "HTTP/1.1" | ||
| for _, endpoint := range endpoints { | ||
| err := f.AssertMetricsEndpointUsesHTTPVersion(endpoint, expectedHTTPVersion) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestProfileBundleDefaultIsKept(t *testing.T) { | ||
| f := framework.Global | ||
| var ( | ||
| otherImage = fmt.Sprintf("%s:%s", brokenContentImagePath, "proff_diff_baseline") | ||
| bctx = context.Background() | ||
| ) | ||
|
|
||
| ocpPb, err := f.GetReadyProfileBundle("ocp4", f.OperatorNamespace) | ||
| if err != nil { | ||
| t.Fatalf("failed to get ocp4 ProfileBundle: %s", err) | ||
| } | ||
|
|
||
| origImage := ocpPb.Spec.ContentImage | ||
|
|
||
| ocpPbCopy := ocpPb.DeepCopy() | ||
| ocpPbCopy.Spec.ContentImage = otherImage | ||
| ocpPbCopy.Spec.ContentFile = framework.RhcosContentFile | ||
| if updateErr := f.Client.Update(bctx, ocpPbCopy); updateErr != nil { | ||
| t.Fatalf("failed to update default ocp4 profile: %s", err) | ||
| } | ||
|
|
||
| if err := f.WaitForProfileBundleStatus("ocp4", compv1alpha1.DataStreamPending); err != nil { | ||
| t.Fatalf("ocp4 update didn't trigger a PENDING state: %s", err) | ||
| } | ||
|
|
||
| // Now wait for the processing to finish | ||
| if err := f.WaitForProfileBundleStatus("ocp4", compv1alpha1.DataStreamValid); err != nil { | ||
| t.Fatalf("ocp4 update didn't trigger a VALID state: %s", err) | ||
| } | ||
|
|
||
| // Delete compliance operator pods | ||
| // This will trigger a reconciliation of the profile bundle | ||
| // This is what would happen on an operator update. | ||
|
|
||
| inNs := client.InNamespace(f.OperatorNamespace) | ||
| withLabel := client.MatchingLabels{ | ||
| "name": "compliance-operator", | ||
| } | ||
| if err := f.Client.DeleteAllOf(bctx, &corev1.Pod{}, inNs, withLabel); err != nil { | ||
| t.Fatalf("failed to delete compliance-operator pods: %s", err) | ||
| } | ||
|
|
||
| // Wait for the operator deletion to happen | ||
| time.Sleep(framework.RetryInterval) | ||
|
|
||
| err = f.WaitForDeployment("compliance-operator", 1, framework.RetryInterval, framework.Timeout) | ||
| if err != nil { | ||
| t.Fatalf("failed waiting for compliance-operator to come back up: %s", err) | ||
| } | ||
|
|
||
| var lastErr error | ||
| pbkey := types.NamespacedName{Name: "ocp4", Namespace: f.OperatorNamespace} | ||
| timeouterr := wait.Poll(framework.RetryInterval, framework.Timeout, func() (bool, error) { | ||
| pb := &compv1alpha1.ProfileBundle{} | ||
| if lastErr := f.Client.Get(bctx, pbkey, pb); lastErr != nil { | ||
| log.Printf("error getting ocp4 PB. Retrying: %s\n", lastErr) | ||
| return false, nil | ||
| } | ||
| if pb.Spec.ContentImage != origImage { | ||
| log.Printf("ProfileBundle ContentImage not updated yet: Got %s - Expected %s\n", pb.Spec.ContentImage, origImage) | ||
| return false, nil | ||
| } | ||
| log.Printf("ProfileBundle ContentImage up-to-date\n") | ||
| return true, nil | ||
| }) | ||
| if lastErr != nil { | ||
| t.Fatalf("failed waiting for ProfileBundle to update: %s", lastErr) | ||
| } | ||
| if timeouterr != nil { | ||
| t.Fatalf("timed out waiting for ProfileBundle to update: %s", timeouterr) | ||
| } | ||
|
|
||
| _, err = f.GetReadyProfileBundle("ocp4", f.OperatorNamespace) | ||
| if err != nil { | ||
| t.Fatalf("error getting valid and up-to-date PB: %s", err) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good deal - this is being wired up in https://github.com/openshift/release/pull/76333/changes#diff-b82cf05db3d6825e537d43e7630499543f1897657729631dcc60a5765989f3aeR131