Skip to content

Commit 3f49517

Browse files
authored
fix: Improve status.applied updates & add offline pvc unit test (feast-dev#4871)
improve status.applied update & add offline pvc unit test Signed-off-by: Tommy Hughes <tohughes@redhat.com>
1 parent 4de187d commit 3f49517

File tree

3 files changed

+60
-38
lines changed

3 files changed

+60
-38
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ func getBaseServiceRepoConfig(
8585
featureStore *feastdevv1alpha1.FeatureStore,
8686
secretExtractionFunc func(storeType string, secretRef string, secretKeyName string) (map[string]interface{}, error)) (RepoConfig, error) {
8787

88-
appliedSpec := featureStore.Status.Applied
8988
repoConfig := defaultRepoConfig(featureStore)
9089
clientRepoConfig, err := getClientRepoConfig(featureStore, secretExtractionFunc)
9190
if err != nil {
9291
return repoConfig, err
9392
}
94-
repoConfig.AuthzConfig = clientRepoConfig.AuthzConfig
9593
if isRemoteRegistry(featureStore) {
9694
repoConfig.Registry = clientRepoConfig.Registry
9795
}
96+
repoConfig.AuthzConfig = clientRepoConfig.AuthzConfig
9897

98+
appliedSpec := featureStore.Status.Applied
9999
if appliedSpec.AuthzConfig != nil && appliedSpec.AuthzConfig.OidcAuthz != nil {
100100
propertiesMap, authSecretErr := secretExtractionFunc("", appliedSpec.AuthzConfig.OidcAuthz.SecretRef.Name, "")
101101
if authSecretErr != nil {

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

+29-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ var _ = Describe("Repo Config", func() {
4646
Path: EphemeralPath + "/" + DefaultOnlineStorePath,
4747
}
4848

49-
var repoConfig RepoConfig
5049
repoConfig, err := getServiceRepoConfig(featureStore, emptyMockExtractConfigFromSecret)
5150
Expect(err).NotTo(HaveOccurred())
5251
Expect(repoConfig.AuthzConfig.Type).To(Equal(NoAuthAuthType))
@@ -100,6 +99,35 @@ var _ = Describe("Repo Config", func() {
10099
Expect(repoConfig.OnlineStore).To(Equal(expectedOnlineConfig))
101100
Expect(repoConfig.Registry).To(Equal(emptyRegistryConfig))
102101

102+
By("Having an offlineStore with PVC")
103+
mountPath := "/testing"
104+
expectedOnlineConfig.Path = mountPath + "/" + DefaultOnlineStorePath
105+
expectedRegistryConfig.Path = mountPath + "/" + DefaultRegistryPath
106+
107+
featureStore = minimalFeatureStore()
108+
featureStore.Spec.Services = &feastdevv1alpha1.FeatureStoreServices{
109+
OfflineStore: &feastdevv1alpha1.OfflineStore{
110+
Persistence: &feastdevv1alpha1.OfflineStorePersistence{
111+
FilePersistence: &feastdevv1alpha1.OfflineStoreFilePersistence{
112+
PvcConfig: &feastdevv1alpha1.PvcConfig{
113+
MountPath: mountPath,
114+
},
115+
},
116+
},
117+
},
118+
}
119+
ApplyDefaultsToStatus(featureStore)
120+
appliedServices := featureStore.Status.Applied.Services
121+
Expect(appliedServices.OnlineStore).To(BeNil())
122+
Expect(appliedServices.Registry.Local.Persistence.FilePersistence.Path).To(Equal(expectedRegistryConfig.Path))
123+
124+
repoConfig, err = getServiceRepoConfig(featureStore, emptyMockExtractConfigFromSecret)
125+
Expect(err).NotTo(HaveOccurred())
126+
Expect(repoConfig.OfflineStore).To(Equal(defaultOfflineStoreConfig))
127+
Expect(repoConfig.AuthzConfig.Type).To(Equal(NoAuthAuthType))
128+
Expect(repoConfig.Registry).To(Equal(expectedRegistryConfig))
129+
Expect(repoConfig.OnlineStore).To(Equal(expectedOnlineConfig))
130+
103131
By("Having the all the file services")
104132
featureStore = minimalFeatureStore()
105133
featureStore.Spec.Services = &feastdevv1alpha1.FeatureStoreServices{

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

+29-35
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ func hasPvcConfig(featureStore *feastdevv1alpha1.FeatureStore, feastType FeastSe
3737
if services != nil {
3838
switch feastType {
3939
case OnlineFeastType:
40-
if services.OnlineStore != nil && services.OnlineStore.Persistence.FilePersistence != nil {
40+
if services.OnlineStore != nil && services.OnlineStore.Persistence != nil &&
41+
services.OnlineStore.Persistence.FilePersistence != nil {
4142
pvcConfig = services.OnlineStore.Persistence.FilePersistence.PvcConfig
4243
}
4344
case OfflineFeastType:
44-
if services.OfflineStore != nil && services.OfflineStore.Persistence.FilePersistence != nil {
45+
if services.OfflineStore != nil && services.OfflineStore.Persistence != nil &&
46+
services.OfflineStore.Persistence.FilePersistence != nil {
4547
pvcConfig = services.OfflineStore.Persistence.FilePersistence.PvcConfig
4648
}
4749
case RegistryFeastType:
48-
if IsLocalRegistry(featureStore) && services.Registry.Local.Persistence.FilePersistence != nil {
50+
if IsLocalRegistry(featureStore) && services.Registry.Local.Persistence != nil &&
51+
services.Registry.Local.Persistence.FilePersistence != nil {
4952
pvcConfig = services.Registry.Local.Persistence.FilePersistence.PvcConfig
5053
}
5154
}
@@ -66,18 +69,18 @@ func shouldMountEmptyDir(featureStore *feastdevv1alpha1.FeatureStore) bool {
6669
}
6770

6871
func getOfflineMountPath(featureStore *feastdevv1alpha1.FeatureStore) string {
69-
if featureStore.Status.Applied.Services != nil {
70-
if pvcConfig, ok := hasPvcConfig(featureStore, OfflineFeastType); ok {
71-
return pvcConfig.MountPath
72-
}
72+
if pvcConfig, ok := hasPvcConfig(featureStore, OfflineFeastType); ok {
73+
return pvcConfig.MountPath
7374
}
7475
return EphemeralPath
7576
}
7677

7778
func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
79+
// overwrite status.applied with every reconcile
80+
cr.Spec.DeepCopyInto(&cr.Status.Applied)
7881
cr.Status.FeastVersion = feastversion.FeastVersion
79-
applied := cr.Spec.DeepCopy()
8082

83+
applied := &cr.Status.Applied
8184
if applied.Services == nil {
8285
applied.Services = &feastdevv1alpha1.FeatureStoreServices{}
8386
}
@@ -106,10 +109,7 @@ func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
106109
services.Registry.Local.Persistence.FilePersistence.Path = defaultRegistryPath(cr)
107110
}
108111

109-
if services.Registry.Local.Persistence.FilePersistence.PvcConfig != nil {
110-
pvc := services.Registry.Local.Persistence.FilePersistence.PvcConfig
111-
ensurePVCDefaults(pvc, RegistryFeastType)
112-
}
112+
ensurePVCDefaults(services.Registry.Local.Persistence.FilePersistence.PvcConfig, RegistryFeastType)
113113
}
114114

115115
setServiceDefaultConfigs(&services.Registry.Local.ServiceConfigs.DefaultConfigs)
@@ -131,10 +131,7 @@ func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
131131
services.OfflineStore.Persistence.FilePersistence.Type = string(OfflineFilePersistenceDaskConfigType)
132132
}
133133

134-
if services.OfflineStore.Persistence.FilePersistence.PvcConfig != nil {
135-
pvc := services.OfflineStore.Persistence.FilePersistence.PvcConfig
136-
ensurePVCDefaults(pvc, OfflineFeastType)
137-
}
134+
ensurePVCDefaults(services.OfflineStore.Persistence.FilePersistence.PvcConfig, OfflineFeastType)
138135
}
139136

140137
setServiceDefaultConfigs(&services.OfflineStore.ServiceConfigs.DefaultConfigs)
@@ -154,16 +151,11 @@ func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
154151
services.OnlineStore.Persistence.FilePersistence.Path = defaultOnlineStorePath(cr)
155152
}
156153

157-
if services.OnlineStore.Persistence.FilePersistence.PvcConfig != nil {
158-
pvc := services.OnlineStore.Persistence.FilePersistence.PvcConfig
159-
ensurePVCDefaults(pvc, OnlineFeastType)
160-
}
154+
ensurePVCDefaults(services.OnlineStore.Persistence.FilePersistence.PvcConfig, OnlineFeastType)
161155
}
162156

163157
setServiceDefaultConfigs(&services.OnlineStore.ServiceConfigs.DefaultConfigs)
164158
}
165-
// overwrite status.applied with every reconcile
166-
applied.DeepCopyInto(&cr.Status.Applied)
167159
}
168160

169161
func setServiceDefaultConfigs(defaultConfigs *feastdevv1alpha1.DefaultConfigs) {
@@ -189,19 +181,21 @@ func ensureRequestedStorage(resources *v1.VolumeResourceRequirements, requestedS
189181
}
190182

191183
func ensurePVCDefaults(pvc *feastdevv1alpha1.PvcConfig, feastType FeastServiceType) {
192-
var storageRequest string
193-
switch feastType {
194-
case OnlineFeastType:
195-
storageRequest = DefaultOnlineStorageRequest
196-
case OfflineFeastType:
197-
storageRequest = DefaultOfflineStorageRequest
198-
case RegistryFeastType:
199-
storageRequest = DefaultRegistryStorageRequest
200-
}
201-
if pvc.Create != nil {
202-
ensureRequestedStorage(&pvc.Create.Resources, storageRequest)
203-
if pvc.Create.AccessModes == nil {
204-
pvc.Create.AccessModes = DefaultPVCAccessModes
184+
if pvc != nil {
185+
var storageRequest string
186+
switch feastType {
187+
case OnlineFeastType:
188+
storageRequest = DefaultOnlineStorageRequest
189+
case OfflineFeastType:
190+
storageRequest = DefaultOfflineStorageRequest
191+
case RegistryFeastType:
192+
storageRequest = DefaultRegistryStorageRequest
193+
}
194+
if pvc.Create != nil {
195+
ensureRequestedStorage(&pvc.Create.Resources, storageRequest)
196+
if pvc.Create.AccessModes == nil {
197+
pvc.Create.AccessModes = DefaultPVCAccessModes
198+
}
205199
}
206200
}
207201
}

0 commit comments

Comments
 (0)