Skip to content

Commit 8c649c2

Browse files
committed
test: Added tests for svc probe, container port and registry validations
Signed-off-by: ntkathole <nikhilkathole2683@gmail.com>
1 parent 6ace5ec commit 8c649c2

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
Copyright 2024 Feast Community.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package services
18+
19+
import (
20+
"context"
21+
22+
feastdevv1alpha1 "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
23+
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler"
24+
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/types"
28+
"k8s.io/apimachinery/pkg/util/intstr"
29+
)
30+
31+
func ptr[T any](v T) *T {
32+
return &v
33+
}
34+
35+
func (feast *FeastServices) refreshFeatureStore(ctx context.Context, key types.NamespacedName) {
36+
fs := &feastdevv1alpha1.FeatureStore{}
37+
Expect(k8sClient.Get(ctx, key, fs)).To(Succeed())
38+
feast.Handler.FeatureStore = fs
39+
}
40+
41+
func applySpecToStatus(fs *feastdevv1alpha1.FeatureStore) {
42+
fs.Status.Applied.Services = fs.Spec.Services.DeepCopy()
43+
fs.Status.Applied.FeastProject = fs.Spec.FeastProject
44+
Expect(k8sClient.Status().Update(context.Background(), fs)).To(Succeed())
45+
}
46+
47+
var _ = Describe("Registry Service", func() {
48+
var (
49+
featureStore *feastdevv1alpha1.FeatureStore
50+
feast *FeastServices
51+
typeNamespacedName types.NamespacedName
52+
ctx context.Context
53+
)
54+
55+
var setFeatureStoreServerConfig = func(grpcEnabled, restEnabled bool) {
56+
featureStore.Spec.Services.Registry.Local.Server.GRPC = ptr(grpcEnabled)
57+
featureStore.Spec.Services.Registry.Local.Server.RestAPI = ptr(restEnabled)
58+
Expect(k8sClient.Update(ctx, featureStore)).To(Succeed())
59+
Expect(feast.ApplyDefaults()).To(Succeed())
60+
applySpecToStatus(featureStore)
61+
feast.refreshFeatureStore(ctx, typeNamespacedName)
62+
}
63+
64+
BeforeEach(func() {
65+
ctx = context.Background()
66+
typeNamespacedName = types.NamespacedName{
67+
Name: "testfeaturestore",
68+
Namespace: "default",
69+
}
70+
71+
featureStore = &feastdevv1alpha1.FeatureStore{
72+
ObjectMeta: metav1.ObjectMeta{
73+
Name: typeNamespacedName.Name,
74+
Namespace: typeNamespacedName.Namespace,
75+
},
76+
Spec: feastdevv1alpha1.FeatureStoreSpec{
77+
FeastProject: "testproject",
78+
Services: &feastdevv1alpha1.FeatureStoreServices{
79+
Registry: &feastdevv1alpha1.Registry{
80+
Local: &feastdevv1alpha1.LocalRegistryConfig{
81+
Server: &feastdevv1alpha1.RegistryServerConfigs{
82+
ServerConfigs: feastdevv1alpha1.ServerConfigs{
83+
ContainerConfigs: feastdevv1alpha1.ContainerConfigs{
84+
DefaultCtrConfigs: feastdevv1alpha1.DefaultCtrConfigs{
85+
Image: ptr("test-image"),
86+
},
87+
},
88+
},
89+
GRPC: ptr(true),
90+
RestAPI: ptr(false),
91+
},
92+
},
93+
},
94+
},
95+
},
96+
}
97+
98+
Expect(k8sClient.Create(ctx, featureStore)).To(Succeed())
99+
applySpecToStatus(featureStore)
100+
101+
feast = &FeastServices{
102+
Handler: handler.FeastHandler{
103+
Client: k8sClient,
104+
Context: ctx,
105+
Scheme: k8sClient.Scheme(),
106+
FeatureStore: featureStore,
107+
},
108+
}
109+
})
110+
111+
AfterEach(func() {
112+
Expect(k8sClient.Delete(ctx, featureStore)).To(Succeed())
113+
})
114+
115+
Describe("Probe Handler Configuration", func() {
116+
It("should configure TCP socket probe when gRPC is enabled", func() {
117+
setFeatureStoreServerConfig(true, false)
118+
probeHandler := feast.getProbeHandler(RegistryFeastType, featureStore.Spec.Services.Registry.Local.Server.TLS)
119+
Expect(probeHandler.TCPSocket).NotTo(BeNil())
120+
Expect(probeHandler.TCPSocket.Port).To(Equal(intstr.FromInt(int(FeastServiceConstants[RegistryFeastType].TargetHttpPort))))
121+
})
122+
123+
It("should configure HTTP GET probe when REST is enabled", func() {
124+
setFeatureStoreServerConfig(false, true)
125+
probeHandler := feast.getProbeHandler(RegistryFeastType, featureStore.Spec.Services.Registry.Local.Server.TLS)
126+
Expect(probeHandler.HTTPGet).NotTo(BeNil())
127+
Expect(probeHandler.HTTPGet.Port).To(Equal(intstr.FromInt(int(FeastServiceConstants[RegistryFeastType].TargetRestHttpPort))))
128+
})
129+
})
130+
131+
Describe("Registry Server Configuration", func() {
132+
It("should enable both gRPC and REST", func() {
133+
setFeatureStoreServerConfig(true, true)
134+
Expect(feast.isRegistryGrpcEnabled()).To(BeTrue())
135+
Expect(feast.isRegistryRestEnabled()).To(BeTrue())
136+
})
137+
138+
It("should create both gRPC and REST services", func() {
139+
setFeatureStoreServerConfig(true, true)
140+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
141+
Expect(feast.initFeastSvc(RegistryFeastType)).NotTo(BeNil())
142+
Expect(feast.initFeastRestSvc(RegistryFeastType)).NotTo(BeNil())
143+
})
144+
145+
It("should enable only gRPC", func() {
146+
setFeatureStoreServerConfig(true, false)
147+
Expect(feast.isRegistryGrpcEnabled()).To(BeTrue())
148+
Expect(feast.isRegistryRestEnabled()).To(BeFalse())
149+
})
150+
151+
It("should create only gRPC service and not REST service", func() {
152+
setFeatureStoreServerConfig(true, false)
153+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
154+
Expect(feast.initFeastSvc(RegistryFeastType)).NotTo(BeNil())
155+
})
156+
})
157+
158+
Describe("Container Ports Configuration", func() {
159+
It("should configure correct gRPC container ports", func() {
160+
setFeatureStoreServerConfig(true, false)
161+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
162+
deployment := feast.initFeastDeploy()
163+
Expect(deployment).NotTo(BeNil())
164+
Expect(feast.setDeployment(deployment)).To(Succeed())
165+
166+
ports := deployment.Spec.Template.Spec.Containers[0].Ports
167+
Expect(ports).To(HaveLen(1))
168+
Expect(ports[0].ContainerPort).To(Equal(FeastServiceConstants[RegistryFeastType].TargetHttpPort))
169+
Expect(ports[0].Name).To(Equal(string(RegistryFeastType)))
170+
})
171+
172+
It("should configure correct REST container ports", func() {
173+
setFeatureStoreServerConfig(false, true)
174+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
175+
deployment := feast.initFeastDeploy()
176+
Expect(deployment).NotTo(BeNil())
177+
Expect(feast.setDeployment(deployment)).To(Succeed())
178+
179+
ports := deployment.Spec.Template.Spec.Containers[0].Ports
180+
Expect(ports).To(HaveLen(1))
181+
Expect(ports[0].ContainerPort).To(Equal(FeastServiceConstants[RegistryFeastType].TargetRestHttpPort))
182+
Expect(ports[0].Name).To(Equal(string(RegistryFeastType) + "-rest"))
183+
184+
Expect(deployment.Spec.Template.Spec.Containers).To(HaveLen(1))
185+
Expect(deployment.Spec.Template.Spec.Containers[0].Ports).To(HaveLen(1))
186+
Expect(deployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort).To(Equal(FeastServiceConstants[RegistryFeastType].TargetRestHttpPort))
187+
Expect(deployment.Spec.Template.Spec.Containers[0].Ports[0].Name).To(Equal(string(RegistryFeastType) + "-rest"))
188+
})
189+
190+
It("should configure correct ports for both services", func() {
191+
setFeatureStoreServerConfig(true, true)
192+
Expect(feast.deployFeastServiceByType(RegistryFeastType)).To(Succeed())
193+
194+
deployment := feast.initFeastDeploy()
195+
Expect(deployment).NotTo(BeNil())
196+
Expect(feast.setDeployment(deployment)).To(Succeed())
197+
198+
ports := deployment.Spec.Template.Spec.Containers[0].Ports
199+
Expect(ports).To(HaveLen(2))
200+
Expect(ports[0].ContainerPort).To(Equal(FeastServiceConstants[RegistryFeastType].TargetHttpPort))
201+
Expect(ports[0].Name).To(Equal(string(RegistryFeastType)))
202+
Expect(ports[1].ContainerPort).To(Equal(FeastServiceConstants[RegistryFeastType].TargetRestHttpPort))
203+
Expect(ports[1].Name).To(Equal(string(RegistryFeastType) + "-rest"))
204+
})
205+
})
206+
})

0 commit comments

Comments
 (0)