Skip to content

Commit bf4e0cb

Browse files
committed
refactoring types with FeastHandler
Signed-off-by: Daniele Martinoli <[email protected]>
1 parent 3f7e80c commit bf4e0cb

16 files changed

+353
-178
lines changed

infra/feast-operator/api/v1alpha1/featurestore_types.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ const (
2828
FailedPhase = "Failed"
2929

3030
// Feast condition types:
31-
ClientReadyType = "Client"
32-
OfflineStoreReadyType = "OfflineStore"
33-
OnlineStoreReadyType = "OnlineStore"
34-
RegistryReadyType = "Registry"
35-
ReadyType = "FeatureStore"
31+
ClientReadyType = "Client"
32+
OfflineStoreReadyType = "OfflineStore"
33+
OnlineStoreReadyType = "OnlineStore"
34+
RegistryReadyType = "Registry"
35+
ReadyType = "FeatureStore"
36+
KubernetesAuthReadyType = "KubernetesAuth"
3637

3738
// Feast condition reasons:
38-
ReadyReason = "Ready"
39-
FailedReason = "FeatureStoreFailed"
40-
OfflineStoreFailedReason = "OfflineStoreDeploymentFailed"
41-
OnlineStoreFailedReason = "OnlineStoreDeploymentFailed"
42-
RegistryFailedReason = "RegistryDeploymentFailed"
43-
ClientFailedReason = "ClientDeploymentFailed"
39+
ReadyReason = "Ready"
40+
FailedReason = "FeatureStoreFailed"
41+
OfflineStoreFailedReason = "OfflineStoreDeploymentFailed"
42+
OnlineStoreFailedReason = "OnlineStoreDeploymentFailed"
43+
RegistryFailedReason = "RegistryDeploymentFailed"
44+
ClientFailedReason = "ClientDeploymentFailed"
45+
KubernetesAuthFailedReason = "KubernetesAuthorizationDeploymentFailed"
4446

4547
// Feast condition messages:
46-
ReadyMessage = "FeatureStore installation complete"
47-
OfflineStoreReadyMessage = "Offline Store installation complete"
48-
OnlineStoreReadyMessage = "Online Store installation complete"
49-
RegistryReadyMessage = "Registry installation complete"
50-
ClientReadyMessage = "Client installation complete"
48+
ReadyMessage = "FeatureStore installation complete"
49+
OfflineStoreReadyMessage = "Offline Store installation complete"
50+
OnlineStoreReadyMessage = "Online Store installation complete"
51+
RegistryReadyMessage = "Registry installation complete"
52+
ClientReadyMessage = "Client installation complete"
53+
KubernetesAuthReadyMessage = "Kubernetes authorization installation complete"
5154

5255
// entity_key_serialization_version
5356
SerializationVersion = 3

infra/feast-operator/config/rbac/role.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@ rules:
5555
- get
5656
- patch
5757
- update
58+
- apiGroups:
59+
- rbac.authorization.k8s.io
60+
resources:
61+
- roles
62+
verbs:
63+
- create
64+
- delete
65+
- get
66+
- list
67+
- update
68+
- watch

infra/feast-operator/dist/install.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,17 @@ rules:
21302130
- get
21312131
- patch
21322132
- update
2133+
- apiGroups:
2134+
- rbac.authorization.k8s.io
2135+
resources:
2136+
- roles
2137+
verbs:
2138+
- create
2139+
- delete
2140+
- get
2141+
- list
2142+
- update
2143+
- watch
21332144
---
21342145
apiVersion: rbac.authorization.k8s.io/v1
21352146
kind: ClusterRole

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ import (
2323

2424
appsv1 "k8s.io/api/apps/v1"
2525
corev1 "k8s.io/api/core/v1"
26+
rbacv1 "k8s.io/api/rbac/v1"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
apimeta "k8s.io/apimachinery/pkg/api/meta"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/types"
3132
ctrl "sigs.k8s.io/controller-runtime"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
33-
"sigs.k8s.io/controller-runtime/pkg/handler"
34+
handler "sigs.k8s.io/controller-runtime/pkg/handler"
3435
"sigs.k8s.io/controller-runtime/pkg/log"
3536
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3637

3738
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
39+
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/auth"
40+
feasthandler "github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler"
3841
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/services"
3942
)
4043

@@ -107,20 +110,39 @@ func (r *FeatureStoreReconciler) deployFeast(ctx context.Context, cr *feastdevv1
107110
Message: feastdevv1alpha1.ReadyMessage,
108111
}
109112

110-
feast := services.FeastServices{
111-
Client: r.Client,
112-
Context: ctx,
113-
FeatureStore: cr,
114-
Scheme: r.Scheme,
113+
auth := auth.FeastAuth{
114+
Handler: feasthandler.FeastHandler{
115+
Client: r.Client,
116+
Context: ctx,
117+
FeatureStore: cr,
118+
Scheme: r.Scheme,
119+
},
115120
}
116-
if err = feast.Deploy(); err != nil {
121+
if err = auth.Deploy(); err != nil {
117122
condition = metav1.Condition{
118123
Type: feastdevv1alpha1.ReadyType,
119124
Status: metav1.ConditionFalse,
120125
Reason: feastdevv1alpha1.FailedReason,
121126
Message: "Error: " + err.Error(),
122127
}
123128
result = ctrl.Result{Requeue: true, RequeueAfter: RequeueDelayError}
129+
} else {
130+
feast := services.FeastServices{
131+
Handler: feasthandler.FeastHandler{
132+
Client: r.Client,
133+
Context: ctx,
134+
FeatureStore: cr,
135+
Scheme: r.Scheme,
136+
}}
137+
if err = feast.Deploy(); err != nil {
138+
condition = metav1.Condition{
139+
Type: feastdevv1alpha1.ReadyType,
140+
Status: metav1.ConditionFalse,
141+
Reason: feastdevv1alpha1.FailedReason,
142+
Message: "Error: " + err.Error(),
143+
}
144+
result = ctrl.Result{Requeue: true, RequeueAfter: RequeueDelayError}
145+
}
124146
}
125147

126148
logger.Info(condition.Message)
@@ -145,6 +167,8 @@ func (r *FeatureStoreReconciler) SetupWithManager(mgr ctrl.Manager) error {
145167
Owns(&corev1.Service{}).
146168
Owns(&corev1.PersistentVolumeClaim{}).
147169
Owns(&corev1.ServiceAccount{}).
170+
Owns(&rbacv1.RoleBinding{}).
171+
Owns(&rbacv1.Role{}).
148172
Watches(&feastdevv1alpha1.FeatureStore{}, handler.EnqueueRequestsFromMapFunc(r.mapFeastRefsToFeastRequests)).
149173
Complete(r)
150174
}
@@ -169,11 +193,12 @@ func (r *FeatureStoreReconciler) mapFeastRefsToFeastRequests(ctx context.Context
169193
// this if statement is extra protection against any potential infinite reconcile loops
170194
if feastRefNsName != objNsName {
171195
feast := services.FeastServices{
172-
Client: r.Client,
173-
Context: ctx,
174-
FeatureStore: &obj,
175-
Scheme: r.Scheme,
176-
}
196+
Handler: feasthandler.FeastHandler{
197+
Client: r.Client,
198+
Context: ctx,
199+
FeatureStore: &obj,
200+
Scheme: r.Scheme,
201+
}}
177202
if feast.IsRemoteRefRegistry() {
178203
remoteRef := obj.Status.Applied.Services.Registry.Remote.FeastRef
179204
remoteRefNsName := types.NamespacedName{Name: remoteRef.Name, Namespace: remoteRef.Namespace}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939

4040
"github.com/feast-dev/feast/infra/feast-operator/api/feastversion"
4141
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
42+
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler"
4243
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/services"
4344
)
4445

@@ -115,15 +116,18 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
115116
Expect(err).NotTo(HaveOccurred())
116117

117118
feast := services.FeastServices{
118-
Client: controllerReconciler.Client,
119-
Context: ctx,
120-
Scheme: controllerReconciler.Scheme,
121-
FeatureStore: resource,
119+
Handler: handler.FeastHandler{
120+
Client: controllerReconciler.Client,
121+
Context: ctx,
122+
Scheme: controllerReconciler.Scheme,
123+
FeatureStore: resource,
124+
},
122125
}
123126
Expect(resource.Status).NotTo(BeNil())
124127
Expect(resource.Status.FeastVersion).To(Equal(feastversion.FeastVersion))
125128
Expect(resource.Status.ClientConfigMap).To(Equal(feast.GetFeastServiceName(services.ClientFeastType)))
126129
Expect(resource.Status.Applied.FeastProject).To(Equal(resource.Spec.FeastProject))
130+
Expect(resource.Status.Applied.AuthConfig).To(Equal(&feastdevv1alpha1.AuthConfig{}))
127131
Expect(resource.Status.Applied.Services).NotTo(BeNil())
128132
Expect(resource.Status.Applied.Services.OfflineStore).NotTo(BeNil())
129133
Expect(resource.Status.Applied.Services.OfflineStore.Persistence).NotTo(BeNil())
@@ -161,6 +165,9 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
161165
Expect(cond.Type).To(Equal(feastdevv1alpha1.ReadyType))
162166
Expect(cond.Message).To(Equal(feastdevv1alpha1.ReadyMessage))
163167

168+
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.KubernetesAuthReadyType)
169+
Expect(cond).To(BeNil())
170+
164171
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.RegistryReadyType)
165172
Expect(cond).ToNot(BeNil())
166173
Expect(cond.Status).To(Equal(metav1.ConditionTrue))
@@ -249,10 +256,12 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
249256
Expect(cmList.Items).To(HaveLen(1))
250257

251258
feast := services.FeastServices{
252-
Client: controllerReconciler.Client,
253-
Context: ctx,
254-
Scheme: controllerReconciler.Scheme,
255-
FeatureStore: resource,
259+
Handler: handler.FeastHandler{
260+
Client: controllerReconciler.Client,
261+
Context: ctx,
262+
Scheme: controllerReconciler.Scheme,
263+
FeatureStore: resource,
264+
},
256265
}
257266

258267
// check registry config
@@ -412,7 +421,7 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
412421
resource = &feastdevv1alpha1.FeatureStore{}
413422
err = k8sClient.Get(ctx, typeNamespacedName, resource)
414423
Expect(err).NotTo(HaveOccurred())
415-
feast.FeatureStore = resource
424+
feast.Handler.FeatureStore = resource
416425

417426
// check registry config
418427
deploy = &appsv1.Deployment{}

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838

3939
"github.com/feast-dev/feast/infra/feast-operator/api/feastversion"
4040
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
41+
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler"
4142
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/services"
4243
)
4344

@@ -110,15 +111,18 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
110111
Expect(err).NotTo(HaveOccurred())
111112

112113
feast := services.FeastServices{
113-
Client: controllerReconciler.Client,
114-
Context: ctx,
115-
Scheme: controllerReconciler.Scheme,
116-
FeatureStore: resource,
114+
Handler: handler.FeastHandler{
115+
Client: controllerReconciler.Client,
116+
Context: ctx,
117+
Scheme: controllerReconciler.Scheme,
118+
FeatureStore: resource,
119+
},
117120
}
118121
Expect(resource.Status).NotTo(BeNil())
119122
Expect(resource.Status.FeastVersion).To(Equal(feastversion.FeastVersion))
120123
Expect(resource.Status.ClientConfigMap).To(Equal(feast.GetFeastServiceName(services.ClientFeastType)))
121124
Expect(resource.Status.Applied.FeastProject).To(Equal(resource.Spec.FeastProject))
125+
Expect(resource.Status.Applied.AuthConfig).To(Equal(&feastdevv1alpha1.AuthConfig{}))
122126
Expect(resource.Status.Applied.Services).NotTo(BeNil())
123127
Expect(resource.Status.Applied.Services.OfflineStore).To(BeNil())
124128
Expect(resource.Status.Applied.Services.OnlineStore).To(BeNil())
@@ -146,6 +150,9 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
146150
Expect(cond.Type).To(Equal(feastdevv1alpha1.ReadyType))
147151
Expect(cond.Message).To(Equal(feastdevv1alpha1.ReadyMessage))
148152

153+
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.KubernetesAuthReadyType)
154+
Expect(cond).To(BeNil())
155+
149156
cond = apimeta.FindStatusCondition(resource.Status.Conditions, feastdevv1alpha1.RegistryReadyType)
150157
Expect(cond).ToNot(BeNil())
151158
Expect(cond.Status).To(Equal(metav1.ConditionTrue))
@@ -220,7 +227,7 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
220227
resource = &feastdevv1alpha1.FeatureStore{}
221228
err = k8sClient.Get(ctx, typeNamespacedName, resource)
222229
Expect(err).NotTo(HaveOccurred())
223-
feast.FeatureStore = resource
230+
feast.Handler.FeatureStore = resource
224231
Expect(resource.Status.Applied.Services.Registry.Local.Persistence.FilePersistence.S3AdditionalKwargs).NotTo(BeNil())
225232
Expect(resource.Status.Applied.Services.Registry.Local.Persistence.FilePersistence.S3AdditionalKwargs).NotTo(Equal(&s3AdditionalKwargs))
226233
Expect(resource.Status.Applied.Services.Registry.Local.Persistence.FilePersistence.S3AdditionalKwargs).To(Equal(&newS3AdditionalKwargs))
@@ -274,10 +281,12 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
274281
Expect(cmList.Items).To(HaveLen(1))
275282

276283
feast := services.FeastServices{
277-
Client: controllerReconciler.Client,
278-
Context: ctx,
279-
Scheme: controllerReconciler.Scheme,
280-
FeatureStore: resource,
284+
Handler: handler.FeastHandler{
285+
Client: controllerReconciler.Client,
286+
Context: ctx,
287+
Scheme: controllerReconciler.Scheme,
288+
FeatureStore: resource,
289+
},
281290
}
282291

283292
// check registry deployment
@@ -373,7 +382,7 @@ var _ = Describe("FeatureStore Controller-Ephemeral services", func() {
373382
resource = &feastdevv1alpha1.FeatureStore{}
374383
err = k8sClient.Get(ctx, typeNamespacedName, resource)
375384
Expect(err).NotTo(HaveOccurred())
376-
feast.FeatureStore = resource
385+
feast.Handler.FeatureStore = resource
377386

378387
// check registry config
379388
deploy = &appsv1.Deployment{}

0 commit comments

Comments
 (0)