@@ -88,27 +88,33 @@ func (feast *FeastServices) Deploy() error {
8888}
8989
9090func (feast * FeastServices ) deployFeastServiceByType (feastType FeastServiceType ) error {
91- if err := feast .createService (feastType ); err != nil {
92- return feast .setFeastServiceCondition (err , feastType )
93- }
94- if err := feast .createDeployment (feastType ); err != nil {
95- return feast .setFeastServiceCondition (err , feastType )
96- }
9791 if pvcCreate , shouldCreate := shouldCreatePvc (feast .FeatureStore , feastType ); shouldCreate {
9892 if err := feast .createPVC (pvcCreate , feastType ); err != nil {
9993 return feast .setFeastServiceCondition (err , feastType )
10094 }
10195 } else {
10296 _ = feast .deleteOwnedFeastObj (feast .initPVC (feastType ))
10397 }
98+ if err := feast .createServiceAccount (feastType ); err != nil {
99+ return feast .setFeastServiceCondition (err , feastType )
100+ }
101+ if err := feast .createDeployment (feastType ); err != nil {
102+ return feast .setFeastServiceCondition (err , feastType )
103+ }
104+ if err := feast .createService (feastType ); err != nil {
105+ return feast .setFeastServiceCondition (err , feastType )
106+ }
104107 return feast .setFeastServiceCondition (nil , feastType )
105108}
106109
107110func (feast * FeastServices ) removeFeastServiceByType (feastType FeastServiceType ) error {
111+ if err := feast .deleteOwnedFeastObj (feast .initFeastSvc (feastType )); err != nil {
112+ return err
113+ }
108114 if err := feast .deleteOwnedFeastObj (feast .initFeastDeploy (feastType )); err != nil {
109115 return err
110116 }
111- if err := feast .deleteOwnedFeastObj (feast .initFeastSvc (feastType )); err != nil {
117+ if err := feast .deleteOwnedFeastObj (feast .initFeastSA (feastType )); err != nil {
112118 return err
113119 }
114120 if err := feast .deleteOwnedFeastObj (feast .initPVC (feastType )); err != nil {
@@ -131,6 +137,19 @@ func (feast *FeastServices) createService(feastType FeastServiceType) error {
131137 return nil
132138}
133139
140+ func (feast * FeastServices ) createServiceAccount (feastType FeastServiceType ) error {
141+ logger := log .FromContext (feast .Context )
142+ sa := feast .initFeastSA (feastType )
143+ if op , err := controllerutil .CreateOrUpdate (feast .Context , feast .Client , sa , controllerutil .MutateFn (func () error {
144+ return feast .setServiceAccount (sa , feastType )
145+ })); err != nil {
146+ return err
147+ } else if op == controllerutil .OperationResultCreated || op == controllerutil .OperationResultUpdated {
148+ logger .Info ("Successfully reconciled" , "ServiceAccount" , sa .Name , "operation" , op )
149+ }
150+ return nil
151+ }
152+
134153func (feast * FeastServices ) createDeployment (feastType FeastServiceType ) error {
135154 logger := log .FromContext (feast .Context )
136155 deploy := feast .initFeastDeploy (feastType )
@@ -173,6 +192,7 @@ func (feast *FeastServices) setDeployment(deploy *appsv1.Deployment, feastType F
173192 deploySettings := FeastServiceConstants [feastType ]
174193 serviceConfigs := feast .getServiceConfigs (feastType )
175194 defaultServiceConfigs := serviceConfigs .DefaultConfigs
195+ sa := feast .initFeastSA (feastType )
176196
177197 // standard configs are applied here
178198 probeHandler := corev1.ProbeHandler {
@@ -188,6 +208,7 @@ func (feast *FeastServices) setDeployment(deploy *appsv1.Deployment, feastType F
188208 Labels : deploy .GetLabels (),
189209 },
190210 Spec : corev1.PodSpec {
211+ ServiceAccountName : sa .Name ,
191212 Containers : []corev1.Container {
192213 {
193214 Name : string (feastType ),
@@ -252,6 +273,11 @@ func (feast *FeastServices) setService(svc *corev1.Service, feastType FeastServi
252273 return controllerutil .SetControllerReference (feast .FeatureStore , svc , feast .Scheme )
253274}
254275
276+ func (feast * FeastServices ) setServiceAccount (sa * corev1.ServiceAccount , feastType FeastServiceType ) error {
277+ sa .Labels = feast .getLabels (feastType )
278+ return controllerutil .SetControllerReference (feast .FeatureStore , sa , feast .Scheme )
279+ }
280+
255281func (feast * FeastServices ) createNewPVC (pvcCreate * feastdevv1alpha1.PvcCreate , feastType FeastServiceType ) (* corev1.PersistentVolumeClaim , error ) {
256282 pvc := feast .initPVC (feastType )
257283
@@ -426,6 +452,14 @@ func (feast *FeastServices) initFeastSvc(feastType FeastServiceType) *corev1.Ser
426452 return svc
427453}
428454
455+ func (feast * FeastServices ) initFeastSA (feastType FeastServiceType ) * corev1.ServiceAccount {
456+ sa := & corev1.ServiceAccount {
457+ ObjectMeta : feast .GetObjectMeta (feastType ),
458+ }
459+ sa .SetGroupVersionKind (corev1 .SchemeGroupVersion .WithKind ("ServiceAccount" ))
460+ return sa
461+ }
462+
429463func (feast * FeastServices ) initPVC (feastType FeastServiceType ) * corev1.PersistentVolumeClaim {
430464 pvc := & corev1.PersistentVolumeClaim {
431465 ObjectMeta : feast .GetObjectMeta (feastType ),
0 commit comments