-
Notifications
You must be signed in to change notification settings - Fork 32
🧪 Add e2e test for migrate namespace with multiple secret types #635
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
Tamar-Dinavetsky
wants to merge
2
commits into
migtools:main
Choose a base branch
from
Tamar-Dinavetsky:Automate-MTA-842
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
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
104 changes: 104 additions & 0 deletions
104
e2e-tests/tests/tier1/mta_842_secrets_migration_test.go
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,104 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("Migrate namespace with multiple secret types", func() { | ||
| It("[MTA-842] all secret types are exported, transformed, and applied to target cluster", Label("tier1"), func() { | ||
| namespace := "crane-secrets-test" | ||
|
|
||
| scenario := NewMigrationScenario( | ||
| namespace, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
|
|
||
| paths, err := NewScenarioPaths("crane-export-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| exportOpts := ExportOptions{Namespace: namespace, ExportDir: paths.ExportDir} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
| DeferCleanup(func() { | ||
| By("Cleanup temp directory") | ||
| if paths.TempDir != "" { | ||
| log.Printf("Removing temp dir: %s\n", paths.TempDir) | ||
| if err := os.RemoveAll(paths.TempDir); err != nil { | ||
| log.Printf("cleanup: failed to remove temp dir %q: %v", paths.TempDir, err) | ||
| } | ||
| } | ||
| By("Cleanup source namespace and temp dir") | ||
| if _, err := kubectlSrc.Run("delete", "namespace", namespace, "--ignore-not-found=true"); err != nil { | ||
| log.Printf("cleanup: failed to delete source namespace: %v", err) | ||
| } | ||
| By("Cleanup target namespace and temp dir") | ||
| if _, err := kubectlTgt.Run("delete", "namespace", namespace, "--ignore-not-found=true"); err != nil { | ||
| log.Printf("cleanup: failed to delete target namespace: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Create namespace on source") | ||
| Expect(kubectlSrc.CreateNamespace(namespace)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Create Opaque secret on source") | ||
| Expect(kubectlSrc.Run("create", "secret", "generic", "opaque-secret", "--from-literal=key=value", "-n", namespace)).Error().NotTo(HaveOccurred()) | ||
|
|
||
| By("Generate TLS certificate and key") | ||
| certFile := filepath.Join(paths.TempDir, "tls.crt") | ||
| keyFile := filepath.Join(paths.TempDir, "tls.key") | ||
| cmd := exec.Command("openssl", "req", "-x509", "-newkey", "rsa:2048", "-keyout", keyFile, "-out", certFile, "-days", "1", "-nodes", "-subj", "/CN=test") | ||
| out, err := cmd.CombinedOutput() | ||
| Expect(err).NotTo(HaveOccurred(), "openssl output: %s", out) | ||
|
|
||
| By("Create TLS secret on source") | ||
| Expect(kubectlSrc.Run("create", "secret", "tls", "tls-secret", "--cert="+certFile, "--key="+keyFile, "-n", namespace)).Error().NotTo(HaveOccurred()) | ||
|
|
||
| By("Create docker-registry secret on source") | ||
| Expect(kubectlSrc.Run("create", "secret", "docker-registry", "docker-secret", "--docker-server=quay.io", "--docker-username=user", "--docker-password=pass", "-n", namespace)).Error().NotTo(HaveOccurred()) | ||
|
|
||
| runner := scenario.Crane | ||
| runner.WorkDir = paths.TempDir | ||
|
|
||
| By("Run crane export/transform/apply pipeline") | ||
| log.Printf("Running crane pipeline for namespace %s\n", namespace) | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
| log.Printf("Crane pipeline completed for namespace %s\n", namespace) | ||
|
|
||
| By("Verify all secret manifests are present in output directory") | ||
| for _, secretName := range []string{"opaque-secret", "tls-secret", "docker-secret"} { | ||
| glob := filepath.Join(paths.OutputDir, "resources", namespace, "Secret__*_"+secretName+".yaml") | ||
| matches, err := filepath.Glob(glob) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(matches).NotTo(BeEmpty(), "expected manifest for secret "+secretName+" in output directory") | ||
| log.Printf("Secret manifest found in output: %s\n", matches) | ||
| } | ||
|
|
||
| By("Apply rendered manifests to target") | ||
| log.Printf("Applying rendered manifests on target namespace %s from %s\n", namespace, paths.OutputDir) | ||
| Expect(ApplyOutputToTarget(kubectlTgt, namespace, paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verify Opaque secret is present on target with correct type") | ||
| Expect(VerifySecret(kubectlTgt, namespace, "opaque-secret", "Opaque")).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verify tls secret is present on target with correct type") | ||
| Expect(VerifySecret(kubectlTgt, namespace, "tls-secret", "kubernetes.io/tls")).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verify docker secret is present on target with correct type") | ||
| Expect(VerifySecret(kubectlTgt, namespace, "docker-secret", "kubernetes.io/dockerconfigjson")).NotTo(HaveOccurred()) | ||
|
|
||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.