-
Couldn't load subscription status.
- Fork 12
CFE-1108: Use upstream e2e to run using downstream images #11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,8 +160,12 @@ test-e2e-teardown: $(KIND) | |
| $(e2e_targets):: test-e2e-setup | ||
| test-e2e:: $(e2e_tests) ## Run e2e tests | ||
|
|
||
| test-e2e-ansible:: image/ansible-operator ## Run Ansible e2e tests | ||
| test-e2e-ansible:: image/ansible-operator test-e2e-ansible-run ## Run Ansible e2e tests | ||
|
|
||
| .PHONY: test-e2e-ansible-run | ||
| test-e2e-ansible-run: | ||
| go test ./test/e2e/ansible -v -ginkgo.v | ||
|
Comment on lines
+165
to
167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to move this target above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought adding the |
||
|
|
||
| test-e2e-ansible-molecule:: install dev-install image/ansible-operator ## Run molecule-based Ansible e2e tests | ||
| go run ./hack/generate/samples/molecule/generate.go | ||
| ./hack/tests/e2e-ansible-molecule.sh | ||
|
Comment on lines
169
to
171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also try adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can take a look at it. |
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,8 @@ var memcachedGVK = schema.GroupVersionKind{ | |||||
| Kind: "Memcached", | ||||||
| } | ||||||
|
|
||||||
| var skipSecretGeneration = "" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to make it a global variable? If this variable is getting used only in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to make changes to the existing function definitions. That's why I used the global variable. |
||||||
|
|
||||||
| func getCli() *cli.CLI { | ||||||
| ansibleBundle, _ := plugin.NewBundleWithOptions( | ||||||
| plugin.WithName(golang.DefaultNameQualifier), | ||||||
|
|
@@ -127,21 +129,26 @@ func GenerateMoleculeSample(samplesPath string) []sample.Sample { | |||||
| ) | ||||||
| pkg.CheckError("attempting to create sample cli", err) | ||||||
|
|
||||||
| addIgnore, err := samplecli.NewCliSample( | ||||||
| samplecli.WithCLI(getCli()), | ||||||
| samplecli.WithCommandContext(ansibleMoleculeMemcached.CommandContext()), | ||||||
| samplecli.WithGvk( | ||||||
| schema.GroupVersionKind{ | ||||||
| Group: "ignore", | ||||||
| Version: "v1", | ||||||
| Kind: "Secret", | ||||||
| }, | ||||||
| ), | ||||||
| samplecli.WithPlugins("ansible"), | ||||||
| samplecli.WithExtraApiOptions("--generate-role"), | ||||||
| samplecli.WithName(ansibleMoleculeMemcached.Name()), | ||||||
| ) | ||||||
| pkg.CheckError("creating ignore samples", err) | ||||||
| skipSecretGeneration = os.Getenv("SKIP_SECRET_GENERATION") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// env returns an environment variable or a default value if not specified.
func env(key string, defaultValue string) string {
val := os.Getenv(key)
if len(val) == 0 {
return defaultValue
}
return val
}
func isTrue(s string) bool {
v, _ := strconv.ParseBool(s)
return v
}
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usage of |
||||||
| var addIgnore sample.Sample | ||||||
|
|
||||||
| if skipSecretGeneration == "" { | ||||||
| addIgnore, err = samplecli.NewCliSample( | ||||||
| samplecli.WithCLI(getCli()), | ||||||
| samplecli.WithCommandContext(ansibleMoleculeMemcached.CommandContext()), | ||||||
| samplecli.WithGvk( | ||||||
| schema.GroupVersionKind{ | ||||||
| Group: "ignore", | ||||||
| Version: "v1", | ||||||
| Kind: "Secret", | ||||||
| }, | ||||||
| ), | ||||||
| samplecli.WithPlugins("ansible"), | ||||||
| samplecli.WithExtraApiOptions("--generate-role"), | ||||||
| samplecli.WithName(ansibleMoleculeMemcached.Name()), | ||||||
| ) | ||||||
| pkg.CheckError("creating ignore samples", err) | ||||||
| } | ||||||
|
|
||||||
| // remove sample directory if it already exists | ||||||
| err = os.RemoveAll(ansibleMoleculeMemcached.Dir()) | ||||||
|
|
@@ -158,9 +165,11 @@ func GenerateMoleculeSample(samplesPath string) []sample.Sample { | |||||
| err = e2e.AllowProjectBeMultiGroup(ansibleMoleculeMemcached) | ||||||
| pkg.CheckError("updating PROJECT file", err) | ||||||
|
|
||||||
| ignoreGen := sample.NewGenerator(sample.WithNoInit(), sample.WithNoWebhook()) | ||||||
| err = ignoreGen.GenerateSamples(addIgnore) | ||||||
| pkg.CheckError("generating ansible molecule sample - ignore", err) | ||||||
| if skipSecretGeneration == "" { | ||||||
| ignoreGen := sample.NewGenerator(sample.WithNoInit(), sample.WithNoWebhook()) | ||||||
| err = ignoreGen.GenerateSamples(addIgnore) | ||||||
| pkg.CheckError("generating ansible molecule sample - ignore", err) | ||||||
| } | ||||||
|
|
||||||
| ImplementMemcached(ansibleMoleculeMemcached, bundleImage) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #11 (comment). |
||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,12 +41,14 @@ func ImplementMemcachedMolecule(sample sample.Sample, image string) { | |
| err := kbutil.InsertCode(moleculeTaskPath, targetMoleculeCheckDeployment, molecuTaskToCheckConfigMap) | ||
| pkg.CheckError("replacing memcached task to add config map check", err) | ||
|
|
||
| log.Info("insert molecule task to ensure to check secret") | ||
| err = kbutil.InsertCode(moleculeTaskPath, memcachedCustomStatusMoleculeTarget, testSecretMoleculeCheck) | ||
| pkg.CheckError("replacing memcached task to add secret check", err) | ||
| if skipSecretGeneration == "" { | ||
| log.Info("insert molecule task to ensure to check secret") | ||
| err = kbutil.InsertCode(moleculeTaskPath, memcachedCustomStatusMoleculeTarget, testSecretMoleculeCheck) | ||
| pkg.CheckError("replacing memcached task to add secret check", err) | ||
| } | ||
|
|
||
| log.Info("insert molecule task to ensure to foo ") | ||
| err = kbutil.InsertCode(moleculeTaskPath, testSecretMoleculeCheck, testFooMoleculeCheck) | ||
| err = kbutil.InsertCode(moleculeTaskPath, memcachedCustomStatusMoleculeTarget, testFooMoleculeCheck) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the sequence of the tasks matter? If yes, then this might change the sequence of the code insertion for regular flow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task related to secret is independent of the other tasks. The secrets will get reconciled by default whenever the operator starts, and it will create the corresponding service. This is independent of the tasks related to the reconciliation of the Memcached CR, which will have it's own set of reconciliation related logic. |
||
| pkg.CheckError("replacing memcached task to add foo check", err) | ||
|
|
||
| log.Info("insert molecule task to check custom metrics") | ||
|
|
@@ -58,6 +60,11 @@ func ImplementMemcachedMolecule(sample sample.Sample, image string) { | |
| err = kbutil.InsertCode(filepath.Join(sample.Dir(), "roles", strings.ToLower(gvk.Kind), "tasks", "main.yml"), | ||
| roleFragment, memcachedWithBlackListTask) | ||
| pkg.CheckError("replacing in tasks/main.yml", err) | ||
|
|
||
| log.Info("adding RBAC permissions for project.openshift.io") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "config", "rbac", "role.yaml"), | ||
| "#+kubebuilder:scaffold:rules", rolesForProject) | ||
| pkg.CheckError("replacing in role.yml", err) | ||
| } | ||
|
|
||
| if gvk.Kind != "Memcached" { | ||
|
|
@@ -95,34 +102,36 @@ func ImplementMemcachedMolecule(sample sample.Sample, image string) { | |
| "playbook: playbooks/memcached.yml", memcachedWatchCustomizations) | ||
| pkg.CheckError("replacing in watches", err) | ||
|
|
||
| log.Info("removing ignore group for the secret from watches as an workaround to work with core types") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "watches.yaml"), | ||
| "ignore.example.com", "\"\"") | ||
| pkg.CheckError("replacing the watches file", err) | ||
|
|
||
| log.Info("removing molecule test for the Secret since it is a core type") | ||
| cmd := exec.Command("rm", "-rf", filepath.Join(sample.Dir(), "molecule", "default", "tasks", "secret_test.yml")) | ||
| _, err = sample.CommandContext().Run(cmd) | ||
| pkg.CheckError("removing secret test file", err) | ||
|
|
||
| log.Info("adding Secret task to the role") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "roles", "secret", "tasks", "main.yml"), | ||
| originalTaskSecret, taskForSecret) | ||
| pkg.CheckError("replacing in secret/tasks/main.yml file", err) | ||
|
|
||
| log.Info("adding ManageStatus == false for role secret") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "watches.yaml"), | ||
| "role: secret", manageStatusFalseForRoleSecret) | ||
| pkg.CheckError("replacing in watches.yaml", err) | ||
|
|
||
| // prevent high load of controller caused by watching all the secrets in the cluster | ||
| watchNamespacePatchFileName := "watch_namespace_patch.yaml" | ||
| log.Info("adding WATCH_NAMESPACE env patch to watch own namespace") | ||
| err = os.WriteFile(filepath.Join(sample.Dir(), "config", "testing", watchNamespacePatchFileName), []byte(watchNamespacePatch), 0644) | ||
| pkg.CheckError("adding watch_namespace_patch.yaml", err) | ||
|
|
||
| log.Info("adding WATCH_NAMESPACE env patch to patch list to be applied") | ||
| err = kbutil.InsertCode(filepath.Join(sample.Dir(), "config", "testing", "kustomization.yaml"), "patchesStrategicMerge:", | ||
| fmt.Sprintf("\n- %s", watchNamespacePatchFileName)) | ||
| pkg.CheckError("inserting in kustomization.yaml", err) | ||
| if skipSecretGeneration == "" { | ||
| log.Info("removing ignore group for the secret from watches as an workaround to work with core types") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "watches.yaml"), | ||
| "ignore.example.com", "\"\"") | ||
| pkg.CheckError("replacing the watches file", err) | ||
|
|
||
| log.Info("removing molecule test for the Secret since it is a core type") | ||
| cmd := exec.Command("rm", "-rf", filepath.Join(sample.Dir(), "molecule", "default", "tasks", "secret_test.yml")) | ||
| _, err = sample.CommandContext().Run(cmd) | ||
| pkg.CheckError("removing secret test file", err) | ||
|
|
||
| log.Info("adding Secret task to the role") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "roles", "secret", "tasks", "main.yml"), | ||
| originalTaskSecret, taskForSecret) | ||
| pkg.CheckError("replacing in secret/tasks/main.yml file", err) | ||
|
|
||
| log.Info("adding ManageStatus == false for role secret") | ||
| err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "watches.yaml"), | ||
| "role: secret", manageStatusFalseForRoleSecret) | ||
| pkg.CheckError("replacing in watches.yaml", err) | ||
|
|
||
| // prevent high load of controller caused by watching all the secrets in the cluster | ||
| watchNamespacePatchFileName := "watch_namespace_patch.yaml" | ||
| log.Info("adding WATCH_NAMESPACE env patch to watch own namespace") | ||
| err = os.WriteFile(filepath.Join(sample.Dir(), "config", "testing", watchNamespacePatchFileName), []byte(watchNamespacePatch), 0644) | ||
| pkg.CheckError("adding watch_namespace_patch.yaml", err) | ||
|
Comment on lines
+127
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear to me why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operator will reconcile secrets from all namespaces and this will overburden the operator with continuous events related to all the secrets in the cluster. To reduce this reconciliation burden, a watch is added to a specific namespace. That's why this is part of the code generation related to secret. |
||
|
|
||
| log.Info("adding WATCH_NAMESPACE env patch to patch list to be applied") | ||
| err = kbutil.InsertCode(filepath.Join(sample.Dir(), "config", "testing", "kustomization.yaml"), "patchesStrategicMerge:", | ||
| fmt.Sprintf("\n- %s", watchNamespacePatchFileName)) | ||
| pkg.CheckError("inserting in kustomization.yaml", err) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| FROM basebuilder AS builder | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we directly use the image tag to avoid overwriting in release config? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems easier to maintain it like this. We won't have to update it on every branch cut and it will minimize the effort going forward. Also we just need the |
||
|
|
||
| COPY . /go/src/github.com/openshift/ansible-operator-plugins | ||
|
|
||
| ENV SKIP_SECRET_GENERATION=true | ||
|
|
||
| RUN cd /go/src/github.com/openshift/ansible-operator-plugins && \ | ||
| make generate | ||
|
|
||
| FROM openshift-ansible-operator-plugins | ||
|
|
||
| COPY --from=builder /go/src/github.com/openshift/ansible-operator-plugins/testdata/memcached-molecule-operator/requirements.yml ${HOME}/requirements.yml | ||
|
|
||
| RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \ | ||
| && chmod -R ug+rwx ${HOME}/.ansible | ||
|
|
||
| COPY --from=builder /go/src/github.com/openshift/ansible-operator-plugins/testdata/memcached-molecule-operator/watches.yaml ${HOME}/watches.yaml | ||
| COPY --from=builder /go/src/github.com/openshift/ansible-operator-plugins/testdata/memcached-molecule-operator/roles/ ${HOME}/roles/ | ||
| COPY --from=builder /go/src/github.com/openshift/ansible-operator-plugins/testdata/memcached-molecule-operator/playbooks/ ${HOME}/playbooks/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ var _ = Describe("Running ansible projects", func() { | |
| Expect(metrics.CleanUpMetrics(kctl, metricsClusterRoleBindingName)).To(Succeed()) | ||
|
|
||
| By("cleaning up created API objects during test process") | ||
| Expect(operator.UndeployOperator(ansibleSample)).To(Succeed()) | ||
| testutils.WrapWarnOutput("", operator.UndeployOperator(ansibleSample)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Undeploy causing some issues? Currently, there is only one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I think it's okay to not fail a test if the cleanup fails. It's not related to the actual e2e test anyway. |
||
|
|
||
| By("ensuring that the namespace was deleted") | ||
| testutils.WrapWarnOutput(kctl.Wait(false, "namespace", "foo", "--for", "delete", "--timeout", "2m")) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes should happen in runtime inside the container, do we need to commit the changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is updated as a result of running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if we don't run |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,23 @@ rules: | |
| - update | ||
| - watch | ||
|
|
||
| ## | ||
| ## Apply customize roles related to project.openshift.io | ||
| ## | ||
| - apiGroups: | ||
| - project.openshift.io | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the api groups installed via a CR on kind cluster? |
||
| resources: | ||
| - projectrequests | ||
| - projects | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
|
|
||
| ## | ||
| ## Apply customize roles for base operator | ||
| ## | ||
|
|
@@ -124,3 +141,4 @@ rules: | |
| - watch | ||
| #+kubebuilder:scaffold:rules | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this is updated as a result of running |
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.
SKIP_SECRET_GENERATIONENV can be exported withfalseThere 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.
Explained in #11 (comment).