Skip to content

Test:KO-481 remove global storage validation#494

Open
rpandey-stack wants to merge 13 commits intoenhancement/KO-481-remove-global-storage-validationfrom
test/KO-481-remove-global-storage-validation
Open

Test:KO-481 remove global storage validation#494
rpandey-stack wants to merge 13 commits intoenhancement/KO-481-remove-global-storage-validationfrom
test/KO-481-remove-global-storage-validation

Conversation

@rpandey-stack
Copy link
Copy Markdown
Contributor

@rpandey-stack rpandey-stack commented Apr 2, 2026

Added TCs for enhancement/KO-481-remove-global-storage-validation and for enhancement/KO-480-K8-Objects-name-validation

@rpandey-stack rpandey-stack changed the base branch from master to enhancement/KO-481-remove-global-storage-validation April 2, 2026 05:48
Richa Pandey added 4 commits April 2, 2026 15:57
Modified .PHONY: env-test with --keep-going to continue execution even after failure
…rom cluster_webhook_test.go to rack_revision_webhook_test.go
@rpandey-stack rpandey-stack requested a review from tanmayja April 6, 2026 06:23
@rpandey-stack rpandey-stack requested a review from tanmayja April 7, 2026 01:57
Comment on lines 178 to -183
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}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem inconsistent like we didn't remove -show-node-events param here whereas removed in above 2

Comment on lines +28 to +32
func uniqueNamespacedName(suffix string) types.NamespacedName {
name := fmt.Sprintf("envtests-%s", suffix)

return test.GetNamespacedName(name, testutil.DefaultNamespace)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use of this func?
We are only adding a envtests- prefix for all, so uniqueness only depends on suffix passed.

Comment on lines +40 to +47

BeforeEach(func() {
nsName = uniqueNamespacedName("rackcfg-neg")
})

AfterEach(func() {
deleteCluster(ctx, nsName)
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +83 to +89
fullRack := getStorageSpecForDevice("/test/dev/xvdf")
policies := aero.Spec.Storage
aero.Spec.Storage = asdbv1.AerospikeStorageSpec{
BlockVolumePolicy: policies.BlockVolumePolicy,
FileSystemVolumePolicy: policies.FileSystemVolumePolicy,
Volumes: nil,
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can test with complete removal of spec storage

Suggested change
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{}

Comment on lines +103 to +134
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(&current.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)
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() {

Comment on lines +590 to +625
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")
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant as this "allows UPDATE when max pod ordinal is greater than zero" is already getting checked in above positive test-cases.

Comment on lines +53 to +57
aero.Spec.Storage = asdbv1.AerospikeStorageSpec{
BlockVolumePolicy: policies.BlockVolumePolicy,
FileSystemVolumePolicy: policies.FileSystemVolumePolicy,
Volumes: nil,
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 "+
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this test-case different from above? We have diff storage paths for each rack in both the cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants