Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added IsValidOfflineStoreFilePersistenceType to the API definitions
Signed-off-by: Daniele Martinoli <dmartino@redhat.com>
  • Loading branch information
dmartinol committed Nov 7, 2024
commit bce16ca48f656a9ec6ed95115777c4fe3f098a5f
17 changes: 17 additions & 0 deletions infra/feast-operator/api/v1alpha1/featurestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -85,6 +87,21 @@ type OfflineStoreFilePersistence struct {
Type string `json:"type,omitempty"`
}
Comment thread
dmartinol marked this conversation as resolved.

var validOfflineStoreFilePersistenceType = []string{
Comment thread
dmartinol marked this conversation as resolved.
Outdated
"dask",
"duckdb",
}

// A function to validate the file persistence types for offline stores
func IsValidOfflineStoreFilePersistenceType(value string) (bool, error) {
Comment thread
dmartinol marked this conversation as resolved.
Outdated
for _, v := range validOfflineStoreFilePersistenceType {
if v == value {
return true, nil
}
}
return false, fmt.Errorf("invalid file type %s for offline store", value)
}

// OnlineStore configures the deployed online store service
type OnlineStore struct {
ServiceConfigs `json:",inline"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ func (r *FeatureStoreReconciler) Reconcile(ctx context.Context, req ctrl.Request
currentStatus := cr.Status.DeepCopy()

// initial status defaults must occur before feast deployment
services.ApplyDefaultsToStatus(cr)
if err := services.ApplyDefaultsToStatus(cr); err != nil {
logger.Error(err, "Error updating the FeatureStore status")
result = ctrl.Result{Requeue: true, RequeueAfter: RequeueDelayError}
return result, err
}
Comment thread
dmartinol marked this conversation as resolved.
Outdated
result, recErr = r.deployFeast(ctx, cr)
if cr.DeletionTimestamp == nil && !reflect.DeepEqual(currentStatus, cr.Status) {
if err := r.Client.Status().Update(ctx, cr); err != nil {
if err = r.Client.Status().Update(ctx, cr); err != nil {
if apierrors.IsConflict(err) {
logger.Info("FeatureStore object modified, retry syncing status")
// Re-queue and preserve existing recErr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func getServiceRepoConfig(feastType FeastServiceType, featureStore *feastdevv1al
// Offline server has an `offline_store` section and a remote `registry`
if feastType == OfflineFeastType && appliedSpec.Services.OfflineStore != nil {
fileType := string(OfflineDaskConfigType)
if appliedSpec.Services.OfflineStore.Persistence != nil && appliedSpec.Services.OfflineStore.Persistence.FilePersistence != nil {
if appliedSpec.Services.OfflineStore.Persistence != nil &&
appliedSpec.Services.OfflineStore.Persistence.FilePersistence != nil &&
len(appliedSpec.Services.OfflineStore.Persistence.FilePersistence.Type) > 0 {
fileType = appliedSpec.Services.OfflineStore.Persistence.FilePersistence.Type
}

repoConfig.OfflineStore = OfflineStoreConfig{}
var err error
repoConfig.OfflineStore.Type, err = ParseOfflineConfigType(fileType)
if err != nil {
return repoConfig, err
repoConfig.OfflineStore = OfflineStoreConfig{
Type: OfflineConfigType(fileType),
}
repoConfig.OnlineStore = OnlineStoreConfig{}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ var _ = Describe("Repo Config", func() {
It("should successfully create the repo configs", func() {
By("Having the minimal created resource")
featureStore := minimalFeatureStore()
ApplyDefaultsToStatus(featureStore)
repoConfig, err := getServiceRepoConfig(OfflineFeastType, featureStore)
err := ApplyDefaultsToStatus(featureStore)
Expect(err).NotTo(HaveOccurred())
var repoConfig RepoConfig
repoConfig, err = getServiceRepoConfig(OfflineFeastType, featureStore)
Expect(err).NotTo(HaveOccurred())
Expect(repoConfig.OfflineStore).To(Equal(emptyOfflineStoreConfig()))
Expect(repoConfig.OnlineStore).To(Equal(emptyOnlineStoreConfig()))
Expand Down Expand Up @@ -67,7 +69,8 @@ var _ = Describe("Repo Config", func() {
},
},
}
ApplyDefaultsToStatus(featureStore)
err = ApplyDefaultsToStatus(featureStore)
Expect(err).NotTo(HaveOccurred())
repoConfig, err = getServiceRepoConfig(OfflineFeastType, featureStore)
Expect(err).NotTo(HaveOccurred())
Expect(repoConfig.OfflineStore).To(Equal(emptyOfflineStoreConfig()))
Expand Down Expand Up @@ -102,7 +105,8 @@ var _ = Describe("Repo Config", func() {
},
},
}
ApplyDefaultsToStatus(featureStore)
err = ApplyDefaultsToStatus(featureStore)
Expect(err).NotTo(HaveOccurred())
repoConfig, err = getServiceRepoConfig(OfflineFeastType, featureStore)
Expect(err).NotTo(HaveOccurred())
Expect(repoConfig.OfflineStore).To(Equal(emptyOfflineStoreConfig()))
Expand Down Expand Up @@ -148,7 +152,8 @@ var _ = Describe("Repo Config", func() {
},
},
}
ApplyDefaultsToStatus(featureStore)
err = ApplyDefaultsToStatus(featureStore)
Expect(err).NotTo(HaveOccurred())
repoConfig, err = getServiceRepoConfig(OfflineFeastType, featureStore)
Expect(err).NotTo(HaveOccurred())
expectedOfflineConfig := OfflineStoreConfig{
Expand Down Expand Up @@ -191,8 +196,7 @@ var _ = Describe("Repo Config", func() {
},
},
}
ApplyDefaultsToStatus(featureStore)
_, err := getServiceRepoConfig(OfflineFeastType, featureStore)
err := ApplyDefaultsToStatus(featureStore)
Expect(err).To(HaveOccurred())
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package services

import (
"context"
"fmt"

"github.com/feast-dev/feast/infra/feast-operator/api/feastversion"
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
Expand Down Expand Up @@ -137,17 +136,6 @@ type FeastServiceType string
// OfflineConfigType provider name or a class name that implements Offline Store
type OfflineConfigType string

func ParseOfflineConfigType(value string) (OfflineConfigType, error) {
switch value {
case string(OfflineDaskConfigType):
return OfflineDaskConfigType, nil
case string(OfflineDuckDbConfigType):
return OfflineDuckDbConfigType, nil
default:
return "", fmt.Errorf("invalid OfflineConfigType value %s", value)
}
}

// RegistryConfigType provider name or a class name that implements Registry
type RegistryConfigType string

Expand Down
8 changes: 7 additions & 1 deletion infra/feast-operator/internal/controller/services/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func IsLocalRegistry(featureStore *feastdevv1alpha1.FeatureStore) bool {
return appliedServices != nil && appliedServices.Registry != nil && appliedServices.Registry.Local != nil
}

func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) error {
cr.Status.FeastVersion = feastversion.FeastVersion
applied := cr.Spec.DeepCopy()
if applied.Services == nil {
Expand Down Expand Up @@ -48,6 +48,11 @@ func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
}
if len(applied.Services.OfflineStore.Persistence.FilePersistence.Type) == 0 {
applied.Services.OfflineStore.Persistence.FilePersistence.Type = string(OfflineDaskConfigType)
} else {
_, err := feastdevv1alpha1.IsValidOfflineStoreFilePersistenceType(applied.Services.OfflineStore.Persistence.FilePersistence.Type)
if err != nil {
return err
}
}
}
Comment thread
dmartinol marked this conversation as resolved.
if applied.Services.OnlineStore != nil {
Expand All @@ -64,6 +69,7 @@ func ApplyDefaultsToStatus(cr *feastdevv1alpha1.FeatureStore) {
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would be good to have unit tests ensuring that proper defaults are being set in status when varying pointers around service persistence are set in the spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

would be good to have unit tests ensuring that proper defaults are being set in status when varying pointers around service persistence are set in the spec.

This was the idea of repo_config_test.go, which verifies the repo config created after applying the defaults.

Copy link
Copy Markdown
Contributor

@tchughesiv tchughesiv Nov 7, 2024

Choose a reason for hiding this comment

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

that's a great addition, and necessary, but its different from ensuring the status defaults are properly being reconciled in the CR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean, I'll add it in the next PR for PVC so there will be more cases to cover

// overwrite status.applied with every reconcile
applied.DeepCopyInto(&cr.Status.Applied)
return nil
}

func setServiceDefaultConfigs(defaultConfigs *feastdevv1alpha1.DefaultConfigs) {
Expand Down