@@ -157,40 +157,53 @@ func checkIfKubernetesServiceExists(namespace, serviceName string) error {
157157}
158158
159159func isFeatureStoreHavingRemoteRegistry (namespace , featureStoreName string ) (bool , error ) {
160- cmd := exec .Command ("kubectl" , "get" , "featurestore" , featureStoreName , "-n" , namespace ,
161- "-o=jsonpath='{.status.applied.services.registry}'" )
160+ timeout := time .Second * 30
161+ interval := time .Second * 2 // Poll every 2 seconds
162+ startTime := time .Now ()
163+
164+ for time .Since (startTime ) < timeout {
165+ cmd := exec .Command ("kubectl" , "get" , "featurestore" , featureStoreName , "-n" , namespace ,
166+ "-o=jsonpath='{.status.applied.services.registry}'" )
167+
168+ output , err := cmd .Output ()
169+ if err != nil {
170+ // Retry only on transient errors
171+ if _ , ok := err .(* exec.ExitError ); ok {
172+ time .Sleep (interval )
173+ continue
174+ }
175+ return false , err // Return immediately on non-transient errors
176+ }
162177
163- // Capture the output
164- output , err := cmd .Output ()
165- if err != nil {
166- return false , err // Return false on command execution failure
167- }
178+ // Convert output to string and trim any extra spaces
179+ result := strings .TrimSpace (string (output ))
168180
169- // Convert output to string and trim any extra spaces
170- result := strings .TrimSpace (string (output ))
181+ // Remove single quotes if present
182+ if strings .HasPrefix (result , "'" ) && strings .HasSuffix (result , "'" ) {
183+ result = strings .Trim (result , "'" )
184+ }
171185
172- // Remove single quotes if present
173- if strings . HasPrefix ( result , "'" ) && strings . HasSuffix ( result , "'" ) {
174- result = strings . Trim ( result , "'" )
175- }
186+ if result == "" {
187+ time . Sleep ( interval ) // Retry if result is empty
188+ continue
189+ }
176190
177- if result == "" {
178- return false , errors .New ("kubectl get featurestore command returned empty output" )
179- }
191+ // Parse the JSON into a map
192+ var registryConfig v1alpha1.Registry
193+ if err := json .Unmarshal ([]byte (result ), & registryConfig ); err != nil {
194+ return false , err // Return false on JSON parsing failure
195+ }
180196
181- // Parse the JSON into a map
182- var registryConfig v1alpha1.Registry
183- if err := json .Unmarshal ([]byte (result ), & registryConfig ); err != nil {
184- return false , err // Return false on JSON parsing failure
185- }
197+ if registryConfig .Remote == nil {
198+ return false , nil
199+ }
186200
187- if registryConfig .Remote == nil {
188- return false , nil
189- }
201+ hasHostname := registryConfig .Remote . Hostname != nil
202+ hasValidFeastRef := registryConfig . Remote . FeastRef != nil &&
203+ registryConfig . Remote . FeastRef . Name != ""
190204
191- hasHostname := registryConfig .Remote .Hostname != nil
192- hasValidFeastRef := registryConfig .Remote .FeastRef != nil &&
193- registryConfig .Remote .FeastRef .Name != ""
205+ return hasHostname || hasValidFeastRef , nil
206+ }
194207
195- return hasHostname || hasValidFeastRef , nil
208+ return false , errors . New ( "timeout waiting for featurestore registry status to be ready" )
196209}
0 commit comments