-
Notifications
You must be signed in to change notification settings - Fork 32
🧪 Add e2e tests for cluster-level export filtering: mta868,869,870 #646
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
RanWurmbrand
wants to merge
5
commits into
migtools:main
Choose a base branch
from
RanWurmbrand:test/ca7-ca8-ca10
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
5 commits
Select commit
Hold shift + click to select a range
2fe28f5
added ca8 with utils helper function, its unit testing and adjustment…
RanWurmbrand bcba1cb
added ca7 test
RanWurmbrand 6857756
added test with the utils, and test data needed
RanWurmbrand a277b10
addressed coderabbit comments and added function for assertions that …
RanWurmbrand f5b0e48
Rename ca7/ca8/ca10 tests to mta_868/869/870
RanWurmbrand 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,7 @@ | ||
| apiVersion: crane-e2e.openshift.io/v1 | ||
| kind: Gadget | ||
| metadata: | ||
| name: test-gadget | ||
| spec: | ||
| color: red | ||
| size: 3 | ||
|
Comment on lines
+1
to
+7
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. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Rename the new YAML fixtures consistently with the repository convention.
As per coding guidelines, YAML resource names should follow 📍 Affects 3 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
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,27 @@ | ||
| apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| name: gadgets.crane-e2e.openshift.io | ||
| spec: | ||
| group: crane-e2e.openshift.io | ||
| names: | ||
| kind: Gadget | ||
| listKind: GadgetList | ||
| plural: gadgets | ||
| singular: gadget | ||
| scope: Namespaced | ||
| versions: | ||
| - name: v1 | ||
| served: true | ||
| storage: true | ||
| schema: | ||
| openAPIV3Schema: | ||
| type: object | ||
| properties: | ||
| spec: | ||
| type: object | ||
| properties: | ||
| color: | ||
| type: string | ||
| size: | ||
| type: integer |
110 changes: 110 additions & 0 deletions
110
e2e-tests/tests/tier0/mta_868_label_scoped_export_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,110 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| "github.com/konveyor/crane/e2e-tests/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("Cluster-level export filtering", func() { | ||
| It("[CA-8] Should export only labeled workload and its RBAC with --label-selector", Label("tier0"), func() { | ||
| appName := "simple-nginx-nopv" | ||
| namespace := "simple-nginx-nopv" | ||
| serviceName := "my-" + appName | ||
|
|
||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
| paths, err := NewScenarioPaths("crane-ca8-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir, | ||
| LabelSelector: "app=" + appName} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| inScopeSA := ServiceAccount{Name: "nginx-sa", Namespace: namespace, Label: "app=simple-nginx-nopv"} | ||
| outOfScopeSA := ServiceAccount{Name: "out-of-scope-sa", Namespace: namespace, Label: "app=outScopedApp"} | ||
|
|
||
| inScopeCR := ClusterRole{Name: "in-scope-cr", Verb: "get,list,watch", Resource: "pods", Label: "app=" + appName} | ||
| outOfScopeCR := ClusterRole{Name: "out-scope-cr", Verb: "get,list,watch,create,update,delete", Resource: "pods", Label: "app=outScopedApp"} | ||
|
|
||
| inScopeSubject := "--serviceaccount=" + namespace + ":" + inScopeSA.Name | ||
| outScopeSubject := "--serviceaccount=" + namespace + ":" + outOfScopeSA.Name | ||
|
|
||
| inScopeBinding := ClusterRoleBinding{Name: "in-scope-crb", ClusterRoleName: inScopeCR.Name, Subject: inScopeSubject, Label: "app=" + appName} | ||
| outOfScopeBinding := ClusterRoleBinding{Name: "out-scope-crb", ClusterRoleName: outOfScopeCR.Name, Subject: outScopeSubject, Label: "app=outScopedApp"} | ||
|
|
||
| outOfScopeResources := []utils.ResourceMatch{ | ||
| {Kind: "ClusterRoleBinding", Name: outOfScopeBinding.Name}, | ||
| {Kind: "ClusterRole", Name: outOfScopeCR.Name}, | ||
| } | ||
| inScopeResources := []utils.ResourceMatch{ | ||
| {Kind: "ClusterRoleBinding", Name: inScopeBinding.Name}, | ||
| {Kind: "ClusterRole", Name: inScopeCR.Name}, | ||
| } | ||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{ | ||
| inScopeBinding, outOfScopeBinding, inScopeCR, outOfScopeCR, inScopeSA, outOfScopeSA}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating in-scope ServiceAccount with matching label") | ||
| Expect(inScopeSA.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating out-of-scope ServiceAccount with different label") | ||
| Expect(outOfScopeSA.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating in-scope ClusterRole with matching label") | ||
| Expect(inScopeCR.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating out-of-scope ClusterRole with different label") | ||
| Expect(outOfScopeCR.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating in-scope ClusterRoleBinding with matching label") | ||
| Expect(inScopeBinding.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating out-of-scope ClusterRoleBinding with different label") | ||
| Expect(outOfScopeBinding.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export with label-selector, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying out-of-scope resources are not in export _cluster directory") | ||
| exportClusterPath := filepath.Join(paths.ExportDir, "resources", namespace, "_cluster") | ||
| allExcluded, err := utils.AssertResourcesDontExist(exportClusterPath, outOfScopeResources) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(allExcluded).To(BeTrue()) | ||
|
|
||
| By("Verifying in-scope ClusterRole and ClusterRoleBinding exist in export, transform, and output") | ||
| allFound, err := utils.AssertResourcesExist(exportClusterPath, inScopeResources) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(allFound).To(BeTrue()) | ||
| }) | ||
| }) |
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,217 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| "github.com/konveyor/crane/e2e-tests/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("CRD group filtering during export", func() { | ||
| appName := "simple-nginx-nopv" | ||
| namespace := "simple-nginx-nopv" | ||
| serviceName := "my-" + appName | ||
| It("[CA-10a] Should skip CRD when --crd-skip-group matches", Label("tier0"), func() { | ||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
|
|
||
| paths, err := NewScenarioPaths("crane-ca10a-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| crdYAML, err := utils.ReadTestdataFile("widget_crd.yaml") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| crYAML, err := utils.ReadTestdataFile("widget_cr.yaml") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| crd := CustomResourceDefinition{ | ||
| Name: "widgets.crane-e2e.example.com", | ||
| YAML: crdYAML, | ||
| } | ||
|
|
||
| cr := CustomResource{ | ||
| Name: "test-widget", | ||
| Namespace: namespace, | ||
| Kind: "Widget", | ||
| YAML: crYAML, | ||
| Resource: "widgets", | ||
| } | ||
| excludedResource := []utils.ResourceMatch{ | ||
| {Kind: "CustomResourceDefinition", Name: crd.Name}, | ||
| } | ||
| includedResource := []utils.ResourceMatch{ | ||
| {Kind: cr.Kind, Name: cr.Name, Scope: namespace}, | ||
| } | ||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir, | ||
| CRDSkipGroups: []string{"crane-e2e.example.com"}} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{cr, crd}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Widget CRD on source") | ||
| Expect(crd.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for CRD to be established") | ||
| Expect(crd.WaitForEstablished(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Widget custom resource in namespace") | ||
| Expect(cr.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export with --crd-skip-group, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying CRD is excluded from export") | ||
| found, err := utils.AssertResourcesExist(paths.ExportDir, excludedResource) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(found).To(BeFalse()) | ||
|
|
||
| By("Verifying Widget CR exists in namespace export directory") | ||
| nameSpaceDir := filepath.Join(paths.ExportDir, "resources", namespace) | ||
| found, err = utils.AssertResourcesExist(nameSpaceDir, includedResource) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(found).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("[CA-10b] Should include CRD when --crd-include-group matches", Label("tier0"), func() { | ||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
|
|
||
| paths, err := NewScenarioPaths("crane-ca10b-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| crdYAML, err := utils.ReadTestdataFile("gadget_crd.yaml") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| crYAML, err := utils.ReadTestdataFile("gadget_cr.yaml") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| crd := CustomResourceDefinition{ | ||
| Name: "gadgets.crane-e2e.openshift.io", | ||
| YAML: crdYAML, | ||
| } | ||
| cr := CustomResource{ | ||
| Name: "test-gadget", | ||
| Namespace: namespace, | ||
| Kind: "Gadget", | ||
| YAML: crYAML, | ||
| Resource: "gadgets", | ||
| } | ||
| tgtNameSpace := Namespace{Name: namespace} | ||
|
|
||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir, | ||
| CRDIncludeGroups: []string{"crane-e2e.openshift.io"}} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{cr, crd, tgtNameSpace}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Gadget CRD on source") | ||
| Expect(crd.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for CRD to be established") | ||
| Expect(crd.WaitForEstablished(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Gadget custom resource in namespace") | ||
| Expect(cr.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export with --crd-include-group, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying CRD exists in export _cluster directory") | ||
| exportClusterPath := filepath.Join(paths.ExportDir, "resources", namespace, "_cluster") | ||
| found, err := utils.AssertResourcesExist(exportClusterPath, []utils.ResourceMatch{ | ||
| {Kind: "CustomResourceDefinition", Name: crd.Name}}) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(found).To(BeTrue()) | ||
|
|
||
| By("Verifying Gadget CR exists in namespace export directory") | ||
| namespaceDir := filepath.Join(paths.ExportDir, "resources", namespace) | ||
| found, err = utils.AssertResourcesExist(namespaceDir, []utils.ResourceMatch{ | ||
| {Kind: cr.Kind, Name: cr.Name, Scope: namespace}}) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(found).To(BeTrue()) | ||
|
|
||
| // By("Verifying CRD exists in output _cluster directory") | ||
| // outputClusterPath := filepath.Join(paths.OutputDir, "resources", "_cluster") | ||
| // Expect(ValidateDirResources(outputClusterPath, crdPatterns)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating namespace on target cluster") | ||
| Expect(tgtNameSpace.Create(kubectlTgt)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Applying cluster resources to target") | ||
| Expect(kubectlTgt.ApplyDir(filepath.Join(paths.OutputDir, "resources", "_cluster"))).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for CRD to be established on target") | ||
| Expect(crd.WaitForEstablished(kubectlTgt)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Applying namespace resources to target") | ||
| Expect(kubectlTgt.ApplyDir(filepath.Join(paths.OutputDir, "resources", namespace))).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying Gadget CR exists on target") | ||
| _, err = kubectlTgt.Run("get", "gadget", cr.Name, "-n", namespace) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying Gadget CR has correct spec values on target") | ||
| color, err := kubectlTgt.Run("get", "gadget", cr.Name, "-n", namespace, | ||
| "-o", "jsonpath={.spec.color}") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(color).To(Equal("red")) | ||
|
|
||
| By("Scaling target deployment and validating app") | ||
| Expect(kubectlTgt.ScaleDeployment(namespace, appName, 1)).NotTo(HaveOccurred()) | ||
| Eventually(tgtApp.Validate, "5m", "10s").Should(Succeed()) | ||
|
|
||
| }) | ||
|
|
||
| }) |
Oops, something went wrong.
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add tests for optional ServiceAccount labeling.
Cover the empty-label path, successful label invocation, and propagated label failure. As per coding guidelines, all new features require tests.
🤖 Prompt for AI Agents
Source: Coding guidelines