Skip to content

Commit e68542d

Browse files
committed
test(operator): add unit tests for getServiceAppProtocol
Signed-off-by: Igor Kvachenok <igor.kvachenok@prokube.ai>
1 parent 49aeda2 commit e68542d

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

infra/feast-operator/internal/controller/services/services_test.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,118 @@ var _ = Describe("Registry Service", func() {
632632
})
633633
})
634634

635+
var _ = Describe("Service AppProtocol Configuration", func() {
636+
var (
637+
featureStore *feastdevv1.FeatureStore
638+
feast *FeastServices
639+
ctx context.Context
640+
)
641+
642+
BeforeEach(func() {
643+
ctx = context.Background()
644+
featureStore = &feastdevv1.FeatureStore{
645+
ObjectMeta: metav1.ObjectMeta{
646+
Name: "testfeaturestore-approtocol",
647+
Namespace: "default",
648+
},
649+
Spec: feastdevv1.FeatureStoreSpec{
650+
FeastProject: "testproject",
651+
Services: &feastdevv1.FeatureStoreServices{
652+
Registry: &feastdevv1.Registry{
653+
Local: &feastdevv1.LocalRegistryConfig{
654+
Server: &feastdevv1.RegistryServerConfigs{
655+
ServerConfigs: feastdevv1.ServerConfigs{
656+
ContainerConfigs: feastdevv1.ContainerConfigs{
657+
DefaultCtrConfigs: feastdevv1.DefaultCtrConfigs{
658+
Image: ptr.To("test-image"),
659+
},
660+
},
661+
},
662+
GRPC: ptr.To(true),
663+
RestAPI: ptr.To(false),
664+
},
665+
},
666+
},
667+
},
668+
},
669+
}
670+
Expect(k8sClient.Create(ctx, featureStore)).To(Succeed())
671+
applySpecToStatus(featureStore)
672+
feast = &FeastServices{
673+
Handler: handler.FeastHandler{
674+
Client: k8sClient,
675+
Context: ctx,
676+
Scheme: k8sClient.Scheme(),
677+
FeatureStore: featureStore,
678+
},
679+
}
680+
Expect(feast.ApplyDefaults()).To(Succeed())
681+
applySpecToStatus(featureStore)
682+
})
683+
684+
AfterEach(func() {
685+
Expect(k8sClient.Delete(ctx, featureStore)).To(Succeed())
686+
})
687+
688+
It("should return grpc appProtocol for the registry gRPC service", func() {
689+
Expect(feast.isRegistryGrpcEnabled()).To(BeTrue())
690+
Expect(feast.getServiceAppProtocol(RegistryFeastType, false)).To(Equal(ptr.To("grpc")))
691+
})
692+
693+
It("should return nil appProtocol for the registry REST service", func() {
694+
featureStore.Spec.Services.Registry.Local.Server.RestAPI = ptr.To(true)
695+
Expect(k8sClient.Update(ctx, featureStore)).To(Succeed())
696+
Expect(feast.ApplyDefaults()).To(Succeed())
697+
applySpecToStatus(featureStore)
698+
699+
Expect(feast.getServiceAppProtocol(RegistryFeastType, true)).To(BeNil())
700+
})
701+
702+
It("should return nil appProtocol for the online store service", func() {
703+
Expect(feast.getServiceAppProtocol(OnlineFeastType, false)).To(BeNil())
704+
})
705+
706+
It("should return nil appProtocol for the offline store service", func() {
707+
Expect(feast.getServiceAppProtocol(OfflineFeastType, false)).To(BeNil())
708+
})
709+
710+
It("should return nil appProtocol when registry gRPC is disabled", func() {
711+
featureStore.Spec.Services.Registry.Local.Server.GRPC = ptr.To(false)
712+
featureStore.Spec.Services.Registry.Local.Server.RestAPI = ptr.To(true)
713+
Expect(k8sClient.Update(ctx, featureStore)).To(Succeed())
714+
Expect(feast.ApplyDefaults()).To(Succeed())
715+
applySpecToStatus(featureStore)
716+
717+
Expect(feast.isRegistryGrpcEnabled()).To(BeFalse())
718+
Expect(feast.getServiceAppProtocol(RegistryFeastType, false)).To(BeNil())
719+
})
720+
721+
It("should set grpc appProtocol on the registry gRPC Service port", func() {
722+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
723+
svc := feast.initFeastSvc(RegistryFeastType)
724+
Expect(svc).NotTo(BeNil())
725+
Expect(feast.setService(svc, RegistryFeastType, false)).To(Succeed())
726+
727+
Expect(svc.Spec.Ports).To(HaveLen(1))
728+
Expect(svc.Spec.Ports[0].AppProtocol).To(Equal(ptr.To("grpc")))
729+
})
730+
731+
It("should not set appProtocol on the registry REST Service port", func() {
732+
featureStore.Spec.Services.Registry.Local.Server.RestAPI = ptr.To(true)
733+
Expect(k8sClient.Update(ctx, featureStore)).To(Succeed())
734+
Expect(feast.ApplyDefaults()).To(Succeed())
735+
applySpecToStatus(featureStore)
736+
737+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
738+
restSvc := feast.initFeastRestSvc(RegistryFeastType)
739+
Expect(restSvc).NotTo(BeNil())
740+
Expect(feast.setService(restSvc, RegistryFeastType, true)).To(Succeed())
741+
742+
Expect(restSvc.Spec.Ports).To(HaveLen(1))
743+
Expect(restSvc.Spec.Ports[0].AppProtocol).To(BeNil())
744+
})
745+
})
746+
635747
var _ = Describe("Pod Container Failure Messages", func() {
636748
It("should detect init container in CrashLoopBackOff", func() {
637749
pod := &corev1.Pod{

0 commit comments

Comments
 (0)