Skip to content

Commit 1115d96

Browse files
authored
fix: Operator envVar positioning & tls.SecretRef.Name (#4806)
* fix envVar positioning Signed-off-by: Tommy Hughes <tohughes@redhat.com> * tls.SecretRef.Name Signed-off-by: Tommy Hughes <tohughes@redhat.com> --------- Signed-off-by: Tommy Hughes <tohughes@redhat.com>
1 parent eb111d6 commit 1115d96

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

infra/feast-operator/internal/controller/services/repo_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
. "github.com/onsi/gomega"
2424
"gopkg.in/yaml.v3"
2525
corev1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627

2728
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
2829
)
@@ -468,6 +469,7 @@ func emptyRegistryConfig() RegistryConfig {
468469

469470
func minimalFeatureStore() *feastdevv1alpha1.FeatureStore {
470471
return &feastdevv1alpha1.FeatureStore{
472+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
471473
Spec: feastdevv1alpha1.FeatureStoreSpec{
472474
FeastProject: projectName,
473475
},

infra/feast-operator/internal/controller/services/services.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ func (feast *FeastServices) initPVC(feastType FeastServiceType) *corev1.Persiste
659659

660660
func applyOptionalContainerConfigs(container *corev1.Container, optionalConfigs feastdevv1alpha1.OptionalConfigs) {
661661
if optionalConfigs.Env != nil {
662-
container.Env = mergeEnvVarsArrays(container.Env, optionalConfigs.Env)
662+
container.Env = envOverride(container.Env, *optionalConfigs.Env)
663663
}
664664
if optionalConfigs.ImagePullPolicy != nil {
665665
container.ImagePullPolicy = *optionalConfigs.ImagePullPolicy
@@ -669,28 +669,6 @@ func applyOptionalContainerConfigs(container *corev1.Container, optionalConfigs
669669
}
670670
}
671671

672-
func mergeEnvVarsArrays(envVars1 []corev1.EnvVar, envVars2 *[]corev1.EnvVar) []corev1.EnvVar {
673-
merged := make(map[string]corev1.EnvVar)
674-
675-
// Add all env vars from the first array
676-
for _, envVar := range envVars1 {
677-
merged[envVar.Name] = envVar
678-
}
679-
680-
// Add all env vars from the second array, overriding duplicates
681-
for _, envVar := range *envVars2 {
682-
merged[envVar.Name] = envVar
683-
}
684-
685-
// Convert the map back to an array
686-
result := make([]corev1.EnvVar, 0, len(merged))
687-
for _, envVar := range merged {
688-
result = append(result, envVar)
689-
}
690-
691-
return result
692-
}
693-
694672
func mountPvcConfig(podSpec *corev1.PodSpec, pvcConfig *feastdevv1alpha1.PvcConfig, deployName string) {
695673
if podSpec != nil && pvcConfig != nil {
696674
container := &podSpec.Containers[0]

infra/feast-operator/internal/controller/services/tls.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,28 @@ func (feast *FeastServices) setTlsDefaults() error {
4242

4343
func (feast *FeastServices) setOpenshiftTls() error {
4444
appliedServices := feast.Handler.FeatureStore.Status.Applied.Services
45-
tlsConfigs := &feastdevv1alpha1.TlsConfigs{
46-
SecretRef: &corev1.LocalObjectReference{},
47-
}
4845
if feast.offlineOpenshiftTls() {
4946
appliedServices.OfflineStore.TLS = &feastdevv1alpha1.OfflineTlsConfigs{
50-
TlsConfigs: *tlsConfigs,
47+
TlsConfigs: feastdevv1alpha1.TlsConfigs{
48+
SecretRef: &corev1.LocalObjectReference{
49+
Name: feast.initFeastSvc(OfflineFeastType).Name + tlsNameSuffix,
50+
},
51+
},
5152
}
52-
appliedServices.OfflineStore.TLS.TlsConfigs.SecretRef.Name = feast.initFeastSvc(OfflineFeastType).Name + tlsNameSuffix
5353
}
5454
if feast.onlineOpenshiftTls() {
55-
appliedServices.OnlineStore.TLS = tlsConfigs
56-
appliedServices.OnlineStore.TLS.SecretRef.Name = feast.initFeastSvc(OnlineFeastType).Name + tlsNameSuffix
55+
appliedServices.OnlineStore.TLS = &feastdevv1alpha1.TlsConfigs{
56+
SecretRef: &corev1.LocalObjectReference{
57+
Name: feast.initFeastSvc(OnlineFeastType).Name + tlsNameSuffix,
58+
},
59+
}
5760
}
5861
if feast.localRegistryOpenshiftTls() {
59-
appliedServices.Registry.Local.TLS = tlsConfigs
60-
appliedServices.Registry.Local.TLS.SecretRef.Name = feast.initFeastSvc(RegistryFeastType).Name + tlsNameSuffix
62+
appliedServices.Registry.Local.TLS = &feastdevv1alpha1.TlsConfigs{
63+
SecretRef: &corev1.LocalObjectReference{
64+
Name: feast.initFeastSvc(RegistryFeastType).Name + tlsNameSuffix,
65+
},
66+
}
6167
} else if remote, err := feast.remoteRegistryOpenshiftTls(); remote {
6268
// if the remote registry reference is using openshift's service serving certificates, we can use the injected service CA bundle configMap
6369
if appliedServices.Registry.Remote.TLS == nil {

infra/feast-operator/internal/controller/services/tls_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ var _ = Describe("TLS Config", func() {
113113
tls = feast.getTlsConfigs(OfflineFeastType)
114114
Expect(tls).NotTo(BeNil())
115115
Expect(tls.IsTLS()).To(BeTrue())
116+
Expect(tls.SecretRef).NotTo(BeNil())
117+
Expect(tls.SecretRef.Name).To(Equal("feast-test-offline-tls"))
116118
tls = feast.getTlsConfigs(OnlineFeastType)
117119
Expect(tls).NotTo(BeNil())
118120
Expect(tls.IsTLS()).To(BeTrue())
121+
Expect(tls.SecretRef).NotTo(BeNil())
122+
Expect(tls.SecretRef.Name).To(Equal("feast-test-online-tls"))
119123
tls = feast.getTlsConfigs(RegistryFeastType)
120124
Expect(tls).NotTo(BeNil())
125+
Expect(tls.SecretRef).NotTo(BeNil())
126+
Expect(tls.SecretRef.Name).To(Equal("feast-test-registry-tls"))
121127
Expect(tls.SecretKeyNames).To(Equal(secretKeyNames))
122128
Expect(tls.IsTLS()).To(BeTrue())
123129

infra/feast-operator/internal/controller/services/util.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,26 @@ func SetIsOpenShift(cfg *rest.Config) {
315315
func missingOidcSecretProperty(property OidcPropertyType) error {
316316
return fmt.Errorf(OidcMissingSecretError, property)
317317
}
318+
319+
// getEnvVar returns the position of the EnvVar found by name
320+
func getEnvVar(envName string, env []corev1.EnvVar) int {
321+
for pos, v := range env {
322+
if v.Name == envName {
323+
return pos
324+
}
325+
}
326+
return -1
327+
}
328+
329+
// envOverride replaces or appends the provided EnvVar to the collection
330+
func envOverride(dst, src []corev1.EnvVar) []corev1.EnvVar {
331+
for _, cre := range src {
332+
pos := getEnvVar(cre.Name, dst)
333+
if pos != -1 {
334+
dst[pos] = cre
335+
} else {
336+
dst = append(dst, cre)
337+
}
338+
}
339+
return dst
340+
}

0 commit comments

Comments
 (0)