Test:KO-481 remove global storage validation#494
Test:KO-481 remove global storage validation#494rpandey-stack wants to merge 13 commits intoenhancement/KO-481-remove-global-storage-validationfrom
Conversation
Modified .PHONY: env-test with --keep-going to continue execution even after failure
…rom cluster_webhook_test.go to rack_revision_webhook_test.go
…paced name for aerospikeCluster
| env-test-cluster: fmt vet setup-envtest ## Run tests. | ||
| export KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)"; cd $(shell pwd)/test/envtests/cluster && mkdir -p ../../test-results && go run github.com/onsi/ginkgo/v2/ginkgo -r --focus "$(FOCUS)" -coverprofile envcover.out -v -show-node-events -timeout=1h0m0s --junit-report=../../test-results/junit-envtests-cluster.xml -- . ${ARGS} | ||
| export KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)"; cd $(shell pwd)/test/envtests/cluster && mkdir -p ../../test-results && go run github.com/onsi/ginkgo/v2/ginkgo -r --focus "$(FOCUS)" -coverprofile envcover.out -timeout=1h0m0s --junit-report=../../test-results/junit-envtests-cluster.xml -- . ${ARGS} | ||
|
|
||
| .PHONY: env-test-eviction # Run test/envtests/eviction | ||
| env-test-eviction: fmt vet setup-envtest ## Run tests. | ||
| export KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)"; cd $(shell pwd)/test/envtests/eviction && mkdir -p ../../test-results && go run github.com/onsi/ginkgo/v2/ginkgo -r --focus "$(FOCUS)" -coverprofile envcover.out -v -show-node-events -timeout=1h0m0s --junit-report=../../test-results/junit-envtests-eviction.xml -- . ${ARGS} |
There was a problem hiding this comment.
These changes seem inconsistent like we didn't remove -show-node-events param here whereas removed in above 2
| func uniqueNamespacedName(suffix string) types.NamespacedName { | ||
| name := fmt.Sprintf("envtests-%s", suffix) | ||
|
|
||
| return test.GetNamespacedName(name, testutil.DefaultNamespace) | ||
| } |
There was a problem hiding this comment.
What's the use of this func?
We are only adding a envtests- prefix for all, so uniqueness only depends on suffix passed.
|
|
||
| BeforeEach(func() { | ||
| nsName = uniqueNamespacedName("rackcfg-neg") | ||
| }) | ||
|
|
||
| AfterEach(func() { | ||
| deleteCluster(ctx, nsName) | ||
| }) |
There was a problem hiding this comment.
Any reason for not moving these Before and After at the top level to keep it common for all?
We'll loose diff naming convention for each context but that fine IMO.
| fullRack := getStorageSpecForDevice("/test/dev/xvdf") | ||
| policies := aero.Spec.Storage | ||
| aero.Spec.Storage = asdbv1.AerospikeStorageSpec{ | ||
| BlockVolumePolicy: policies.BlockVolumePolicy, | ||
| FileSystemVolumePolicy: policies.FileSystemVolumePolicy, | ||
| Volumes: nil, | ||
| } |
There was a problem hiding this comment.
We can test with complete removal of spec storage
| fullRack := getStorageSpecForDevice("/test/dev/xvdf") | |
| policies := aero.Spec.Storage | |
| aero.Spec.Storage = asdbv1.AerospikeStorageSpec{ | |
| BlockVolumePolicy: policies.BlockVolumePolicy, | |
| FileSystemVolumePolicy: policies.FileSystemVolumePolicy, | |
| Volumes: nil, | |
| } | |
| rackStorage := getStorageSpecForDevice("/test/dev/xvdf") | |
| aero.Spec.Storage = asdbv1.AerospikeStorageSpec{} |
| Context("Update validation", func() { | ||
| Context("spec.storage", func() { | ||
| Context("negative", func() { | ||
| var nsName types.NamespacedName | ||
|
|
||
| BeforeEach(func() { | ||
| nsName = uniqueNamespacedName("updstor-neg") | ||
| }) | ||
|
|
||
| AfterEach(func() { | ||
| deleteCluster(ctx, nsName) | ||
| }) | ||
|
|
||
| It("rejects update that only mutates top-level spec.storage when there is no rackConfig", func() { | ||
| aero := testCluster.CreateDummyAerospikeCluster(nsName, 2) | ||
| Expect(envtests.K8sClient.Create(ctx, aero)).To(Succeed()) | ||
|
|
||
| current, err := testCluster.GetCluster(envtests.K8sClient, ctx, nsName) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| patchFirstPVStorageClassSpec(¤t.Spec.Storage) | ||
|
|
||
| err = envtests.K8sClient.Update(ctx, current) | ||
| Expect(err).To(HaveOccurred()) | ||
|
|
||
| // Webhook response validation | ||
| envtests.NewStatusErrorMatcher(). | ||
| WithMessageSubstrings("\"vaerospikecluster.kb.io\"", | ||
| "rack storage config cannot be updated", | ||
| "cannot change volumes old"). | ||
| Validate(err) | ||
| }) |
There was a problem hiding this comment.
We have similar context in cluster_webhook_test.go with similar test-case. Check once
|
|
||
| // validateActualPodNames finds the longest pod name across all racks. | ||
| // Even if only one rack's pod name overflows, the whole UPDATE is rejected. | ||
| It("rejects UPDATE when only one rack's pod name exceeds the DNS label limit (multi-rack)", func() { |
There was a problem hiding this comment.
| It("rejects UPDATE when only one rack's pod name exceeds the DNS label limit (multi-rack)", func() { | |
| It("rejects UPDATE when only one rack's pod name exceeds the DNS label limit due to rack revision change(multi-rack)", func() { |
| It("allows UPDATE without re-checking CREATE-only length bounds", func() { | ||
| // Create a valid cluster then update an unrelated field (size). | ||
| // The webhook must not surface any CREATE-only naming error on UPDATE. | ||
| aeroCluster := testCluster.CreateDummyAerospikeCluster(clusterNamespacedName, 2) | ||
| err := envtests.K8sClient.Create(ctx, aeroCluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| current, err := testCluster.GetCluster(envtests.K8sClient, ctx, clusterNamespacedName) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| // Change size — an otherwise valid update. | ||
| current.Spec.Size = 2 | ||
| err = envtests.K8sClient.Update(ctx, current) | ||
| // The webhook must not surface any CREATE-only naming error on UPDATE. | ||
| if err != nil { | ||
| Expect(err).NotTo(MatchError(ContainSubstring("computed at max rack ID")), | ||
| "CREATE-only pod name length check must not be re-run on UPDATE") | ||
| } | ||
| }) | ||
|
|
||
| // validateActualPodNames returns nil immediately when no user-defined | ||
| // racks are present (the controller manages a default rack internally). | ||
| It("allows UPDATE when cluster has no user-defined racks", func() { | ||
| aeroCluster := testCluster.CreateDummyAerospikeCluster(clusterNamespacedName, 2) | ||
| // No explicit RackConfig — controller will create a default rack. | ||
| err := envtests.K8sClient.Create(ctx, aeroCluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| current, err := testCluster.GetCluster(envtests.K8sClient, ctx, clusterNamespacedName) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| current.Spec.Size = 2 | ||
| err = envtests.K8sClient.Update(ctx, current) | ||
| Expect(err).ToNot(HaveOccurred(), | ||
| "UPDATE with no user-defined racks must not fail on actual pod name check") | ||
| }) |
There was a problem hiding this comment.
Didn't understand these test-cases. What are we exactly testing here? The size is still 2 in update
|
|
||
| It("allows UPDATE when one rack has zero pods under DistributeItems"+ | ||
| "(validateActualPodNames skips rackSize 0)", func() { | ||
| cName := uniqueNamespacedName("actpod-zero-rack") |
There was a problem hiding this comment.
| cName := uniqueNamespacedName("actpod-zero-rack") | |
| cName = uniqueNamespacedName("actpod-zero-rack") |
| }) | ||
|
|
||
| It("allows UPDATE when max pod ordinal is greater than zero (validateActualPodNames uses rackSize-1)", func() { | ||
| cName := uniqueNamespacedName("actpod-ord-gt0") |
There was a problem hiding this comment.
| cName := uniqueNamespacedName("actpod-ord-gt0") | |
| cName = uniqueNamespacedName("actpod-ord-gt0") |
| Expect(envtests.K8sClient.Update(ctx, current)).To(Succeed()) | ||
| }) | ||
|
|
||
| It("allows UPDATE when max pod ordinal is greater than zero (validateActualPodNames uses rackSize-1)", func() { |
There was a problem hiding this comment.
This seems redundant as this "allows UPDATE when max pod ordinal is greater than zero" is already getting checked in above positive test-cases.
| aero.Spec.Storage = asdbv1.AerospikeStorageSpec{ | ||
| BlockVolumePolicy: policies.BlockVolumePolicy, | ||
| FileSystemVolumePolicy: policies.FileSystemVolumePolicy, | ||
| Volumes: nil, | ||
| } |
There was a problem hiding this comment.
We can simply set it empty. Check wherver possible
| Expect(envtests.K8sClient.Create(ctx, aero)).To(Succeed()) | ||
| }) | ||
|
|
||
| It("allows multiple racks each using distinct InputStorage paths consistent "+ |
There was a problem hiding this comment.
How is this test-case different from above? We have diff storage paths for each rack in both the cases
Added TCs for enhancement/KO-481-remove-global-storage-validation and for enhancement/KO-480-K8-Objects-name-validation