From 155641277aa7665b6e44c7592e5091d8b85ab89c Mon Sep 17 00:00:00 2001 From: lrangine <19699092+lokeshrangineni@users.noreply.github.com> Date: Thu, 30 Jan 2025 22:59:06 -0500 Subject: [PATCH] Keeping only the relevant tests related to volume and volumeMounts. rest all are not needed for this test. Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com> --- ...tore_controller_volume_volumemount_test.go | 147 +++++------------- 1 file changed, 37 insertions(+), 110 deletions(-) diff --git a/infra/feast-operator/internal/controller/featurestore_controller_volume_volumemount_test.go b/infra/feast-operator/internal/controller/featurestore_controller_volume_volumemount_test.go index 502d0b33ad..e90d0bddb3 100644 --- a/infra/feast-operator/internal/controller/featurestore_controller_volume_volumemount_test.go +++ b/infra/feast-operator/internal/controller/featurestore_controller_volume_volumemount_test.go @@ -19,25 +19,20 @@ package controller import ( "context" + "github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler" + "github.com/feast-dev/feast/infra/feast-operator/internal/controller/services" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" - apimeta "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "github.com/feast-dev/feast/infra/feast-operator/api/feastversion" - feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1" - "github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler" - "github.com/feast-dev/feast/infra/feast-operator/internal/controller/services" ) -var _ = Describe("FeatureStore Controller-Volume and VolumeMount test", func() { +var _ = Describe("FeatureStore Controller - Deployment Volumes and VolumeMounts", func() { Context("When deploying featureStore Spec we should have an option do Volumes and VolumeMounts", func() { const resourceName = "services-ephemeral" const offlineType = "duckdb" @@ -54,7 +49,6 @@ var _ = Describe("FeatureStore Controller-Volume and VolumeMount test", func() { registryPath := "/data/registry.db" BeforeEach(func() { - createEnvFromSecretAndConfigMap() By("creating the custom resource for the Kind FeatureStore") err := k8sClient.Get(ctx, typeNamespacedName, featurestore) if err != nil && errors.IsNotFound(err) { @@ -78,7 +72,6 @@ var _ = Describe("FeatureStore Controller-Volume and VolumeMount test", func() { }, }, } - Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } }) @@ -90,10 +83,9 @@ var _ = Describe("FeatureStore Controller-Volume and VolumeMount test", func() { By("Cleanup the specific resource instance FeatureStore") Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) - deleteEnvFromSecretAndConfigMap() }) - It("should successfully reconcile the resource", func() { + It("should successfully reconcile the resource and volumes and volumeMounts should be available", func() { By("Reconciling the created resource") controllerReconciler := &FeatureStoreReconciler{ Client: k8sClient, @@ -117,113 +109,48 @@ var _ = Describe("FeatureStore Controller-Volume and VolumeMount test", func() { FeatureStore: resource, }, } - Expect(resource.Status).NotTo(BeNil()) - Expect(resource.Status.FeastVersion).To(Equal(feastversion.FeastVersion)) - Expect(resource.Status.ClientConfigMap).To(Equal(feast.GetFeastServiceName(services.ClientFeastType))) - Expect(resource.Status.Applied.FeastProject).To(Equal(resource.Spec.FeastProject)) - Expect(resource.Status.Applied.AuthzConfig).To(BeNil()) - Expect(resource.Status.Applied.Services).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore.Persistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore.Persistence.FilePersistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore.Persistence.FilePersistence.Type).To(Equal(offlineType)) - Expect(resource.Status.Applied.Services.OfflineStore.ImagePullPolicy).To(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore.Resources).To(BeNil()) - Expect(resource.Status.Applied.Services.OfflineStore.Image).To(Equal(&services.DefaultImage)) - Expect(resource.Status.Applied.Services.OnlineStore).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OnlineStore.Persistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence.Path).To(Equal(onlineStorePath)) - Expect(resource.Status.Applied.Services.OnlineStore.ImagePullPolicy).To(Equal(&pullPolicy)) - Expect(resource.Status.Applied.Services.OnlineStore.Resources).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.OnlineStore.Image).To(Equal(&image)) - Expect(resource.Status.Applied.Services.Registry).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local.Persistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local.Persistence.FilePersistence).NotTo(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local.Persistence.FilePersistence.Path).To(Equal(registryPath)) - Expect(resource.Status.Applied.Services.Registry.Local.ImagePullPolicy).To(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local.Resources).To(BeNil()) - Expect(resource.Status.Applied.Services.Registry.Local.Image).To(Equal(&services.DefaultImage)) - - Expect(resource.Status.ServiceHostnames.OfflineStore).To(Equal(feast.GetFeastServiceName(services.OfflineFeastType) + "." + resource.Namespace + domain)) - Expect(resource.Status.ServiceHostnames.OnlineStore).To(Equal(feast.GetFeastServiceName(services.OnlineFeastType) + "." + resource.Namespace + domain)) - Expect(resource.Status.ServiceHostnames.Registry).To(Equal(feast.GetFeastServiceName(services.RegistryFeastType) + "." + resource.Namespace + domain)) - - Expect(resource.Status.Conditions).NotTo(BeEmpty()) - cond := apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.ReadyType) - Expect(cond).ToNot(BeNil()) - Expect(cond.Status).To(Equal(metav1.ConditionTrue)) - Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) - Expect(cond.Type).To(Equal(feastdevv1alpha1.ReadyType)) - Expect(cond.Message).To(Equal(feastdevv1alpha1.ReadyMessage)) - - cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.AuthorizationReadyType) - Expect(cond).To(BeNil()) - - cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.RegistryReadyType) - Expect(cond).ToNot(BeNil()) - Expect(cond.Status).To(Equal(metav1.ConditionTrue)) - Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) - Expect(cond.Type).To(Equal(feastdevv1alpha1.RegistryReadyType)) - Expect(cond.Message).To(Equal(feastdevv1alpha1.RegistryReadyMessage)) - - cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.ClientReadyType) - Expect(cond).ToNot(BeNil()) - Expect(cond.Status).To(Equal(metav1.ConditionTrue)) - Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) - Expect(cond.Type).To(Equal(feastdevv1alpha1.ClientReadyType)) - Expect(cond.Message).To(Equal(feastdevv1alpha1.ClientReadyMessage)) - - cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.OfflineStoreReadyType) - Expect(cond).ToNot(BeNil()) - Expect(cond.Status).To(Equal(metav1.ConditionTrue)) - Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) - Expect(cond.Type).To(Equal(feastdevv1alpha1.OfflineStoreReadyType)) - Expect(cond.Message).To(Equal(feastdevv1alpha1.OfflineStoreReadyMessage)) - - cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.OnlineStoreReadyType) - Expect(cond).ToNot(BeNil()) - Expect(cond.Status).To(Equal(metav1.ConditionTrue)) - Expect(cond.Reason).To(Equal(feastdevv1alpha1.ReadyReason)) - Expect(cond.Type).To(Equal(feastdevv1alpha1.OnlineStoreReadyType)) - Expect(cond.Message).To(Equal(feastdevv1alpha1.OnlineStoreReadyMessage)) - - Expect(resource.Status.Phase).To(Equal(feastdevv1alpha1.ReadyPhase)) - - // check deployment + deploy := &appsv1.Deployment{} objMeta := feast.GetObjectMeta() err = k8sClient.Get(ctx, types.NamespacedName{ Name: objMeta.Name, Namespace: objMeta.Namespace, }, deploy) + Expect(err).NotTo(HaveOccurred()) - Expect(deploy.Spec.Replicas).To(Equal(&services.DefaultReplicas)) - Expect(controllerutil.HasControllerReference(deploy)).To(BeTrue()) - Expect(deploy.Spec.Template.Spec.Containers).To(HaveLen(4)) - svc := &corev1.Service{} - err = k8sClient.Get(ctx, types.NamespacedName{ - Name: feast.GetFeastServiceName(services.RegistryFeastType), - Namespace: resource.Namespace, - }, - svc) - Expect(err).NotTo(HaveOccurred()) - Expect(controllerutil.HasControllerReference(svc)).To(BeTrue()) - Expect(svc.Spec.Ports[0].TargetPort).To(Equal(intstr.FromInt(int(services.FeastServiceConstants[services.RegistryFeastType].TargetHttpPort)))) // Extract the PodSpec from DeploymentSpec podSpec := deploy.Spec.Template.Spec // Validate Volumes - Expect(podSpec.Volumes).To(HaveLen(1), "Expected one volume to be added") - Expect(podSpec.Volumes[0].Name).To(Equal("test-volume"), "Volume name mismatch") - - // Validate VolumeMounts in the first container - Expect(podSpec.Containers).ToNot(BeEmpty(), "Expected at least one container") - Expect(podSpec.Containers[0].VolumeMounts).To(HaveLen(1), "Expected one volume mount to be added") - Expect(podSpec.Containers[0].VolumeMounts[0].Name).To(Equal("test-volume"), "VolumeMount name mismatch") - Expect(podSpec.Containers[0].VolumeMounts[0].MountPath).To(Equal("/data"), "VolumeMount path mismatch") + // Validate Volumes - Check if our test volume exists among multiple + Expect(podSpec.Volumes).To(ContainElement(WithTransform(func(v corev1.Volume) string { + return v.Name + }, Equal("test-volume"))), "Expected volume 'test-volume' to be present") + + // Ensure 'online' container has the test volume mount + var onlineContainer *corev1.Container + for i, container := range podSpec.Containers { + if container.Name == "online" { + onlineContainer = &podSpec.Containers[i] + break + } + } + Expect(onlineContainer).ToNot(BeNil(), "Expected to find container 'online'") + + // Validate that 'online' container has the test-volume mount + Expect(onlineContainer.VolumeMounts).To(ContainElement(WithTransform(func(vm corev1.VolumeMount) string { + return vm.Name + }, Equal("test-volume"))), "Expected 'online' container to have volume mount 'test-volume'") + + // Ensure all other containers do NOT have the test volume mount + for _, container := range podSpec.Containers { + if container.Name != "online" { + Expect(container.VolumeMounts).ToNot(ContainElement(WithTransform(func(vm corev1.VolumeMount) string { + return vm.Name + }, Equal("test-volume"))), "Unexpected volume mount 'test-volume' found in container "+container.Name) + } + } }) })