Skip to content

Commit

Permalink
feat: Adding EnvFrom support for the OptionalConfigs type to the Go O…
Browse files Browse the repository at this point in the history
…perator (feast-dev#4909)

* Adding EnvFrom support for the OptionalConfigs type to the feast go operator

Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com>

* * Refactored the code to avoid the redundent code. moved common code to util.go
* Incorporated code review comments. Added assertion for environment variables at the container level.

Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com>

---------

Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com>
  • Loading branch information
lokeshrangineni authored Jan 13, 2025
1 parent e5527ad commit e01e510
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 37 deletions.
1 change: 1 addition & 0 deletions infra/feast-operator/api/v1alpha1/featurestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type DefaultConfigs struct {
// OptionalConfigs k8s container settings that are optional
type OptionalConfigs struct {
Env *[]corev1.EnvVar `json:"env,omitempty"`
EnvFrom *[]corev1.EnvFromSource `json:"envFrom,omitempty"`
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
}
Expand Down
11 changes: 11 additions & 0 deletions infra/feast-operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

246 changes: 246 additions & 0 deletions infra/feast-operator/config/crd/bases/feast.dev_featurestores.yaml

Large diffs are not rendered by default.

246 changes: 246 additions & 0 deletions infra/feast-operator/dist/install.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ var _ = Describe("FeatureStore Controller - db storage services", func() {
Expect(k8sClient.Create(ctx, secret)).To(Succeed())
}

createEnvFromSecretAndConfigMap()

By("creating the custom resource for the Kind FeatureStore")
err = k8sClient.Get(ctx, typeNamespacedName, featurestore)
if err != nil && errors.IsNotFound(err) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{})
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{}, withEnvFrom())
resource.Spec.Services.OfflineStore.Persistence = &feastdevv1alpha1.OfflineStorePersistence{
DBPersistence: &feastdevv1alpha1.OfflineStoreDBStorePersistence{
Type: string(offlineType),
Expand Down Expand Up @@ -256,6 +258,8 @@ var _ = Describe("FeatureStore Controller - db storage services", func() {
err = k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

deleteEnvFromSecretAndConfigMap()

By("Cleanup the secrets")
Expect(k8sClient.Delete(ctx, onlineSecret)).To(Succeed())
Expect(k8sClient.Delete(ctx, offlineSecret)).To(Succeed())
Expand Down Expand Up @@ -598,6 +602,7 @@ var _ = Describe("FeatureStore Controller - db storage services", func() {

offlineContainer := services.GetOfflineContainer(deploy.Spec.Template.Spec.Containers)
Expect(offlineContainer.Env).To(HaveLen(1))
assertEnvFrom(*offlineContainer)
env = getFeatureStoreYamlEnvVar(offlineContainer.Env)
Expect(env).NotTo(BeNil())

Expand All @@ -615,6 +620,7 @@ var _ = Describe("FeatureStore Controller - db storage services", func() {
onlineContainer := services.GetOnlineContainer(deploy.Spec.Template.Spec.Containers)
Expect(onlineContainer.VolumeMounts).To(HaveLen(1))
Expect(onlineContainer.Env).To(HaveLen(1))
assertEnvFrom(*onlineContainer)
Expect(onlineContainer.ImagePullPolicy).To(Equal(corev1.PullAlways))
env = getFeatureStoreYamlEnvVar(onlineContainer.Env)
Expect(env).NotTo(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", 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) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{{Name: testEnvVarName, Value: testEnvVarValue},
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}})
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}, withEnvFrom())
resource.Spec.Services.OfflineStore.Persistence = &feastdevv1alpha1.OfflineStorePersistence{
FilePersistence: &feastdevv1alpha1.OfflineStoreFilePersistence{
Type: offlineType,
Expand Down Expand Up @@ -97,6 +98,8 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {

By("Cleanup the specific resource instance FeatureStore")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())

deleteEnvFromSecretAndConfigMap()
})

It("should successfully reconcile the resource", func() {
Expand Down Expand Up @@ -141,6 +144,7 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
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.Env).To(Equal(&[]corev1.EnvVar{{Name: testEnvVarName, Value: testEnvVarValue}, {Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}))
Expect(resource.Status.Applied.Services.OnlineStore.EnvFrom).To(Equal(withEnvFrom()))
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))
Expand Down Expand Up @@ -309,9 +313,13 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {

offlineContainer := services.GetOfflineContainer(deploy.Spec.Template.Spec.Containers)
Expect(offlineContainer.Env).To(HaveLen(1))
assertEnvFrom(*offlineContainer)
env = getFeatureStoreYamlEnvVar(offlineContainer.Env)
Expect(env).NotTo(BeNil())

//check envFrom for offlineContainer
assertEnvFrom(*offlineContainer)

fsYamlStr, err = feast.GetServiceFeatureStoreYamlBase64()
Expect(err).NotTo(HaveOccurred())
Expect(fsYamlStr).To(Equal(env.Value))
Expand Down Expand Up @@ -434,6 +442,10 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
env = getFeatureStoreYamlEnvVar(onlineContainer.Env)
Expect(env).NotTo(BeNil())

//check envFrom
// Validate `envFrom` for ConfigMap and Secret
assertEnvFrom(*onlineContainer)

fsYamlStr, err = feast.GetServiceFeatureStoreYamlBase64()
Expect(err).NotTo(HaveOccurred())
Expect(fsYamlStr).To(Equal(env.Value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ var _ = Describe("FeatureStore Controller-Kubernetes authorization", func() {
roles := []string{"reader", "writer"}

BeforeEach(func() {
createEnvFromSecretAndConfigMap()

By("creating the custom resource for the Kind FeatureStore")
err := k8sClient.Get(ctx, typeNamespacedName, featurestore)
if err != nil && errors.IsNotFound(err) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{})
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{}, withEnvFrom())
resource.Spec.AuthzConfig = &feastdevv1alpha1.AuthzConfig{KubernetesAuthz: &feastdevv1alpha1.KubernetesAuthz{
Roles: roles,
}}
Expand All @@ -75,6 +77,8 @@ var _ = Describe("FeatureStore Controller-Kubernetes authorization", func() {
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

deleteEnvFromSecretAndConfigMap()

By("Cleanup the specific resource instance FeatureStore")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
})
Expand Down Expand Up @@ -126,6 +130,7 @@ var _ = Describe("FeatureStore Controller-Kubernetes authorization", func() {
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence).NotTo(BeNil())
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence.Path).To(Equal(services.EphemeralPath + "/" + services.DefaultOnlineStorePath))
Expect(resource.Status.Applied.Services.OnlineStore.Env).To(Equal(&[]corev1.EnvVar{}))
Expect(resource.Status.Applied.Services.OnlineStore.EnvFrom).To(Equal(withEnvFrom()))
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))
Expand Down Expand Up @@ -416,9 +421,12 @@ var _ = Describe("FeatureStore Controller-Kubernetes authorization", func() {
Expect(repoConfig).To(Equal(&testConfig))

// check offline
env = getFeatureStoreYamlEnvVar(services.GetOfflineContainer(deploy.Spec.Template.Spec.Containers).Env)
offlineContainer := services.GetOfflineContainer(deploy.Spec.Template.Spec.Containers)
env = getFeatureStoreYamlEnvVar(offlineContainer.Env)
Expect(env).NotTo(BeNil())

assertEnvFrom(*offlineContainer)

// check offline config
fsYamlStr, err = feast.GetServiceFeatureStoreYamlBase64()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -432,9 +440,12 @@ var _ = Describe("FeatureStore Controller-Kubernetes authorization", func() {
Expect(repoConfig).To(Equal(&testConfig))

// check online
env = getFeatureStoreYamlEnvVar(services.GetOnlineContainer(deploy.Spec.Template.Spec.Containers).Env)
onlineContainer := services.GetOnlineContainer(deploy.Spec.Template.Spec.Containers)
env = getFeatureStoreYamlEnvVar(onlineContainer.Env)
Expect(env).NotTo(BeNil())

assertEnvFrom(*onlineContainer)

// check online config
fsYamlStr, err = feast.GetServiceFeatureStoreYamlBase64()
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
}

BeforeEach(func() {
createEnvFromSecretAndConfigMap()

By("creating the custom resource for the Kind FeatureStore")
err := k8sClient.Get(ctx, typeNamespacedName, featurestore)
if err != nil && errors.IsNotFound(err) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{{Name: testEnvVarName, Value: testEnvVarValue},
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}})
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}, withEnvFrom())
resource.Spec.Services.OnlineStore = nil
resource.Spec.Services.OfflineStore = nil
resource.Spec.Services.Registry = &feastdevv1alpha1.Registry{
Expand All @@ -81,7 +83,6 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
},
},
}

Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}
})
Expand All @@ -90,6 +91,8 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

deleteEnvFromSecretAndConfigMap()

By("Cleanup the specific resource instance FeatureStore")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ var _ = Describe("FeatureStore Controller-OIDC authorization", func() {
Expect(k8sClient.Create(ctx, oidcSecret)).To(Succeed())
}

createEnvFromSecretAndConfigMap()

By("creating the custom resource for the Kind FeatureStore")
err = k8sClient.Get(ctx, typeNamespacedName, featurestore)
if err != nil && errors.IsNotFound(err) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{})
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{}, withEnvFrom())
resource.Spec.AuthzConfig = &feastdevv1alpha1.AuthzConfig{OidcAuthz: &feastdevv1alpha1.OidcAuthz{
SecretRef: corev1.LocalObjectReference{
Name: oidcSecretName,
Expand All @@ -82,6 +84,7 @@ var _ = Describe("FeatureStore Controller-OIDC authorization", func() {

Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}

})
AfterEach(func() {
resource := &feastdevv1alpha1.FeatureStore{}
Expand All @@ -97,6 +100,8 @@ var _ = Describe("FeatureStore Controller-OIDC authorization", func() {

By("Cleanup the specific resource instance FeatureStore")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())

deleteEnvFromSecretAndConfigMap()
})

It("should successfully reconcile the resource", func() {
Expand Down Expand Up @@ -148,6 +153,7 @@ var _ = Describe("FeatureStore Controller-OIDC authorization", func() {
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence).NotTo(BeNil())
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence.Path).To(Equal(services.EphemeralPath + "/" + services.DefaultOnlineStorePath))
Expect(resource.Status.Applied.Services.OnlineStore.Env).To(Equal(&[]corev1.EnvVar{}))
Expect(resource.Status.Applied.Services.OnlineStore.EnvFrom).To(Equal(withEnvFrom()))
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))
Expand Down Expand Up @@ -222,6 +228,9 @@ var _ = Describe("FeatureStore Controller-OIDC authorization", func() {
Expect(services.GetOnlineContainer(deploy.Spec.Template.Spec.Containers).VolumeMounts).To(HaveLen(1))
Expect(services.GetRegistryContainer(deploy.Spec.Template.Spec.Containers).VolumeMounts).To(HaveLen(1))

assertEnvFrom(*services.GetOnlineContainer(deploy.Spec.Template.Spec.Containers))
assertEnvFrom(*services.GetOfflineContainer(deploy.Spec.Template.Spec.Containers))

// check Feast Role
feastRole := &rbacv1.Role{}
err = k8sClient.Get(ctx, types.NamespacedName{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
registryMountedPath := path.Join(registryMountPath, registryPath)

BeforeEach(func() {
createEnvFromSecretAndConfigMap()

By("creating the custom resource for the Kind FeatureStore")
err := k8sClient.Get(ctx, typeNamespacedName, featurestore)
if err != nil && errors.IsNotFound(err) {
resource := createFeatureStoreResource(resourceName, image, pullPolicy, &[]corev1.EnvVar{{Name: testEnvVarName, Value: testEnvVarValue},
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}})
{Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}, withEnvFrom())
resource.Spec.Services.OfflineStore.Persistence = &feastdevv1alpha1.OfflineStorePersistence{
FilePersistence: &feastdevv1alpha1.OfflineStoreFilePersistence{
Type: offlineType,
Expand Down Expand Up @@ -125,6 +127,8 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {

By("Cleanup the specific resource instance FeatureStore")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())

deleteEnvFromSecretAndConfigMap()
})

It("should successfully reconcile the resource", func() {
Expand Down Expand Up @@ -191,6 +195,7 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence.PvcConfig.Create.Resources).NotTo(BeNil())
Expect(resource.Status.Applied.Services.OnlineStore.Persistence.FilePersistence.PvcConfig.Create.Resources).To(Equal(expectedResources))
Expect(resource.Status.Applied.Services.OnlineStore.Env).To(Equal(&[]corev1.EnvVar{{Name: testEnvVarName, Value: testEnvVarValue}, {Name: "fieldRefName", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}))
Expect(resource.Status.Applied.Services.OnlineStore.EnvFrom).To(Equal(withEnvFrom()))
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))
Expand Down Expand Up @@ -283,6 +288,8 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
offlinePvcName := feast.GetFeastServiceName(services.OfflineFeastType)
Expect(offlineVolMount.Name).To(Equal(offlinePvcName))

assertEnvFrom(*offlineContainer)

// check offline pvc
pvc := &corev1.PersistentVolumeClaim{}
err = k8sClient.Get(ctx, types.NamespacedName{
Expand All @@ -307,6 +314,8 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
Expect(onlineVolMount.MountPath).To(Equal(onlineStoreMountPath))
Expect(onlineVolMount.Name).To(Equal(onlinePvcName))

assertEnvFrom(*onlineContainer)

// check online pvc
pvc = &corev1.PersistentVolumeClaim{}
err = k8sClient.Get(ctx, types.NamespacedName{
Expand Down
Loading

0 comments on commit e01e510

Please sign in to comment.