@@ -26,14 +26,64 @@ const (
2626 FeastPrefix = "feast-"
2727 FeatureStoreName = "simple-feast-setup"
2828 FeastResourceName = FeastPrefix + FeatureStoreName
29+ APIVersionV1Alpha1 = "v1alpha1"
30+ APIVersionV1 = "v1"
2931)
3032
33+ // cachedAPIVersion stores the detected API version to avoid repeated lookups
34+ var cachedAPIVersion string
35+
36+ // getFeatureStoreAPIVersion detects the available API version from the CRD
37+ // Returns "v1" or "v1alpha1" depending on what's available
38+ func getFeatureStoreAPIVersion () string {
39+ if cachedAPIVersion != "" {
40+ return cachedAPIVersion
41+ }
42+
43+ // Query the CRD to get available versions
44+ cmd := exec .Command ("kubectl" , "get" , "crd" , "featurestores.feast.dev" , "-o" , "jsonpath={.spec.versions[*].name}" )
45+ output , err := cmd .Output ()
46+ if err != nil {
47+ // Default to v1alpha1 for compatibility with older versions
48+ fmt .Printf ("Warning: Could not detect CRD versions, defaulting to %s: %v\n " , APIVersionV1Alpha1 , err )
49+ cachedAPIVersion = APIVersionV1Alpha1
50+ return cachedAPIVersion
51+ }
52+
53+ versions := strings .TrimSpace (string (output ))
54+ fmt .Printf ("Available CRD versions: %s\n " , versions )
55+
56+ // Prefer v1 if available, otherwise use v1alpha1
57+ if strings .Contains (versions , APIVersionV1 + " " ) || strings .HasSuffix (versions , APIVersionV1 ) || versions == APIVersionV1 {
58+ cachedAPIVersion = APIVersionV1
59+ } else if strings .Contains (versions , APIVersionV1Alpha1 ) {
60+ cachedAPIVersion = APIVersionV1Alpha1
61+ } else {
62+ // Default fallback
63+ cachedAPIVersion = APIVersionV1Alpha1
64+ }
65+
66+ fmt .Printf ("Using API version: %s\n " , cachedAPIVersion )
67+ return cachedAPIVersion
68+ }
69+
70+ // getFeatureStoreResource returns the kubectl resource name with the correct API version
71+ // e.g., "featurestores.v1.feast.dev" or "featurestores.v1alpha1.feast.dev"
72+ func getFeatureStoreResource () string {
73+ return fmt .Sprintf ("featurestores.%s.feast.dev" , getFeatureStoreAPIVersion ())
74+ }
75+
76+ // resetCachedAPIVersion resets the cached API version (useful when switching between operator versions)
77+ func resetCachedAPIVersion () {
78+ cachedAPIVersion = ""
79+ }
80+
3181// dynamically checks if all conditions of custom resource featurestore are in "Ready" state.
3282func checkIfFeatureStoreCustomResourceConditionsInReady (featureStoreName , namespace string ) error {
3383 // Wait 10 seconds to lets the feature store status update
3484 time .Sleep (1 * time .Minute )
3585
36- cmd := exec .Command ("kubectl" , "get" , "featurestore" , featureStoreName , "-n" , namespace , "-o" , "json" )
86+ cmd := exec .Command ("kubectl" , "get" , getFeatureStoreResource () , featureStoreName , "-n" , namespace , "-o" , "json" )
3787
3888 var out bytes.Buffer
3989 var stderr bytes.Buffer
@@ -180,15 +230,15 @@ func isFeatureStoreHavingRemoteRegistry(namespace, featureStoreName string) (boo
180230
181231 for time .Since (startTime ) < timeout {
182232 // First check if the resource exists
183- checkCmd := exec .Command ("kubectl" , "get" , "featurestore" , featureStoreName , "-n" , namespace )
233+ checkCmd := exec .Command ("kubectl" , "get" , getFeatureStoreResource () , featureStoreName , "-n" , namespace )
184234 if err := checkCmd .Run (); err != nil {
185235 // Resource doesn't exist yet, retry
186236 fmt .Printf ("FeatureStore %s/%s does not exist yet, waiting...\n " , namespace , featureStoreName )
187237 time .Sleep (interval )
188238 continue
189239 }
190240
191- cmd := exec .Command ("kubectl" , "get" , "featurestore" , featureStoreName , "-n" , namespace ,
241+ cmd := exec .Command ("kubectl" , "get" , getFeatureStoreResource () , featureStoreName , "-n" , namespace ,
192242 "-o=jsonpath='{.status.applied.services.registry}'" )
193243
194244 output , err := cmd .Output ()
@@ -520,6 +570,9 @@ func DeployPreviousVersionOperator() {
520570 _ , err = Run (cmd , "/test/upgrade" )
521571 ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
522572
573+ // Reset cached API version since we deployed a new operator with potentially different CRD version
574+ resetCachedAPIVersion ()
575+
523576 err = CheckIfDeploymentExistsAndAvailable (FeastControllerNamespace , ControllerDeploymentName , Timeout )
524577 Expect (err ).ToNot (HaveOccurred (), fmt .Sprintf (
525578 "Deployment %s is not available but expected to be available. \n Error: %v\n " ,
0 commit comments