@@ -18,6 +18,10 @@ import (
1818 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1919)
2020
21+ func boolPtr (b bool ) * bool {
22+ return & b
23+ }
24+
2125func createFeatureStore () * feastdevv1alpha1.FeatureStore {
2226 return & feastdevv1alpha1.FeatureStore {
2327 ObjectMeta : metav1.ObjectMeta {
@@ -336,6 +340,90 @@ func registryStoreWithDBPersistenceType(dbPersistenceType string, featureStore *
336340 return fsCopy
337341}
338342
343+ func registryWithOnlyRestAPI (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
344+ fsCopy := featureStore .DeepCopy ()
345+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
346+ Registry : & feastdevv1alpha1.Registry {
347+ Local : & feastdevv1alpha1.LocalRegistryConfig {
348+ Server : & feastdevv1alpha1.RegistryServerConfigs {
349+ RestAPI : boolPtr (false ),
350+ },
351+ },
352+ },
353+ }
354+ return fsCopy
355+ }
356+
357+ func registryWithOnlyGRPC (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
358+ fsCopy := featureStore .DeepCopy ()
359+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
360+ Registry : & feastdevv1alpha1.Registry {
361+ Local : & feastdevv1alpha1.LocalRegistryConfig {
362+ Server : & feastdevv1alpha1.RegistryServerConfigs {
363+ GRPC : boolPtr (true ),
364+ },
365+ },
366+ },
367+ }
368+ return fsCopy
369+ }
370+
371+ func registryWithBothAPIs (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
372+ fsCopy := featureStore .DeepCopy ()
373+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
374+ Registry : & feastdevv1alpha1.Registry {
375+ Local : & feastdevv1alpha1.LocalRegistryConfig {
376+ Server : & feastdevv1alpha1.RegistryServerConfigs {
377+ RestAPI : boolPtr (true ),
378+ GRPC : boolPtr (true ),
379+ },
380+ },
381+ },
382+ }
383+ return fsCopy
384+ }
385+
386+ func registryWithNoAPIs (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
387+ fsCopy := featureStore .DeepCopy ()
388+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
389+ Registry : & feastdevv1alpha1.Registry {
390+ Local : & feastdevv1alpha1.LocalRegistryConfig {
391+ Server : & feastdevv1alpha1.RegistryServerConfigs {},
392+ },
393+ },
394+ }
395+ return fsCopy
396+ }
397+
398+ func registryWithBothFalse (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
399+ fsCopy := featureStore .DeepCopy ()
400+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
401+ Registry : & feastdevv1alpha1.Registry {
402+ Local : & feastdevv1alpha1.LocalRegistryConfig {
403+ Server : & feastdevv1alpha1.RegistryServerConfigs {
404+ RestAPI : boolPtr (false ),
405+ GRPC : boolPtr (false ),
406+ },
407+ },
408+ },
409+ }
410+ return fsCopy
411+ }
412+
413+ func registryWithGRPCFalse (featureStore * feastdevv1alpha1.FeatureStore ) * feastdevv1alpha1.FeatureStore {
414+ fsCopy := featureStore .DeepCopy ()
415+ fsCopy .Spec .Services = & feastdevv1alpha1.FeatureStoreServices {
416+ Registry : & feastdevv1alpha1.Registry {
417+ Local : & feastdevv1alpha1.LocalRegistryConfig {
418+ Server : & feastdevv1alpha1.RegistryServerConfigs {
419+ GRPC : boolPtr (false ),
420+ },
421+ },
422+ },
423+ }
424+ return fsCopy
425+ }
426+
339427func quotedSlice (stringSlice []string ) string {
340428 quotedSlice := make ([]string , len (stringSlice ))
341429
@@ -476,4 +564,65 @@ var _ = Describe("FeatureStore API", func() {
476564 attemptInvalidCreationAndAsserts (ctx , authzConfigWithOidc (authzConfigWithKubernetes (featurestore )), "One selection required between kubernetes or oidc" )
477565 })
478566 })
567+
568+ Context ("When creating a Registry" , func () {
569+ ctx := context .Background ()
570+
571+ BeforeEach (func () {
572+ By ("verifying the custom resource FeatureStore is not there" )
573+ resource := & feastdevv1alpha1.FeatureStore {}
574+ err := k8sClient .Get (ctx , typeNamespacedName , resource )
575+ Expect (err != nil && errors .IsNotFound (err )).To (BeTrue ())
576+ })
577+ AfterEach (func () {
578+ By ("Cleaning up the test resource" )
579+ resource := & feastdevv1alpha1.FeatureStore {}
580+ err := k8sClient .Get (ctx , typeNamespacedName , resource )
581+ if err == nil {
582+ Expect (k8sClient .Delete (ctx , resource )).To (Succeed ())
583+ }
584+ err = k8sClient .Get (ctx , typeNamespacedName , resource )
585+ Expect (err != nil && errors .IsNotFound (err )).To (BeTrue ())
586+ })
587+
588+ Context ("with valid API configurations" , func () {
589+ It ("should succeed when restAPI is false and grpc is not specified (defaults to true)" , func () {
590+ featurestore := createFeatureStore ()
591+ resource := registryWithOnlyRestAPI (featurestore )
592+ Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
593+ })
594+
595+ It ("should succeed when only grpc is true" , func () {
596+ featurestore := createFeatureStore ()
597+ resource := registryWithOnlyGRPC (featurestore )
598+ Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
599+ })
600+
601+ It ("should succeed when both APIs are true" , func () {
602+ featurestore := createFeatureStore ()
603+ resource := registryWithBothAPIs (featurestore )
604+ Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
605+ })
606+
607+ It ("should succeed when no APIs are specified (grpc defaults to true)" , func () {
608+ featurestore := createFeatureStore ()
609+ resource := registryWithNoAPIs (featurestore )
610+ Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
611+ })
612+ })
613+
614+ Context ("with invalid API configurations" , func () {
615+ It ("should fail when both APIs are explicitly false" , func () {
616+ featurestore := createFeatureStore ()
617+ resource := registryWithBothFalse (featurestore )
618+ attemptInvalidCreationAndAsserts (ctx , resource , "At least one of restAPI or grpc must be true" )
619+ })
620+
621+ It ("should fail when grpc is false and restAPI is not specified" , func () {
622+ featurestore := createFeatureStore ()
623+ resource := registryWithGRPCFalse (featurestore )
624+ attemptInvalidCreationAndAsserts (ctx , resource , "At least one of restAPI or grpc must be true" )
625+ })
626+ })
627+ })
479628})
0 commit comments