Skip to content

Commit

Permalink
Update service type based on the CR spec (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Shiva Krishna, Merla <[email protected]>
  • Loading branch information
shivamerla authored Oct 23, 2024
1 parent e412cbb commit 5eb9270
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions api/apps/v1alpha1/nemo_guardrails_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ func (n *NemoGuardrail) GetServicePort() int32 {
return n.Spec.Expose.Service.Port
}

// GetServiceType returns the service type for the NemoGuardrail deployment
func (n *NemoGuardrail) GetServiceType() string {
return string(n.Spec.Expose.Service.Type)
}

// GetUserID returns the user ID for the NemoGuardrail deployment
func (n *NemoGuardrail) GetUserID() *int64 {
return n.Spec.UserID
Expand Down Expand Up @@ -587,9 +592,13 @@ func (n *NemoGuardrail) GetServiceParams() *rendertypes.ServiceParams {
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetServiceAnnotations()

// Set service selector labels
params.SelectorLabels = n.GetSelectorLabels()

// Set service type
params.Type = n.GetServiceType()

// Set service ports
params.Port = n.GetServicePort()
params.PortName = "service-port"
Expand Down
9 changes: 9 additions & 0 deletions api/apps/v1alpha1/nimservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ func (n *NIMService) GetServicePort() int32 {
return n.Spec.Expose.Service.Port
}

// GetServiceType returns the service type for the NIMService deployment
func (n *NIMService) GetServiceType() string {
return string(n.Spec.Expose.Service.Type)
}

// GetUserID returns the user ID for the NIMService deployment
func (n *NIMService) GetUserID() *int64 {
return n.Spec.UserID
Expand Down Expand Up @@ -629,9 +634,13 @@ func (n *NIMService) GetServiceParams() *rendertypes.ServiceParams {
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetServiceAnnotations()

// Set service selector labels
params.SelectorLabels = n.GetSelectorLabels()

// Set service type
params.Type = n.GetServiceType()

// Set service ports
params.Port = n.GetServicePort()
params.PortName = "service-port"
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/platform/standalone/nimservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
},
},
Expose: appsv1alpha1.Expose{
Service: appsv1alpha1.Service{Type: corev1.ServiceTypeClusterIP, Port: 8123, Annotations: map[string]string{"annotation-key-specific": "service"}},
Service: appsv1alpha1.Service{Type: corev1.ServiceTypeLoadBalancer, Port: 8123, Annotations: map[string]string{"annotation-key-specific": "service"}},
Ingress: appsv1alpha1.Ingress{
Enabled: ptr.To[bool](true),
Annotations: map[string]string{"annotation-key-specific": "ingress"},
Expand Down Expand Up @@ -408,6 +408,7 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
err = client.Get(context.TODO(), namespacedName, service)
Expect(err).NotTo(HaveOccurred())
Expect(service.Name).To(Equal(nimService.GetName()))
Expect(string(service.Spec.Type)).To(Equal(nimService.GetServiceType()))
Expect(service.Namespace).To(Equal(nimService.GetNamespace()))
Expect(service.Annotations["annotation-key"]).To(Equal("annotation-value"))
Expect(service.Annotations["annotation-key-specific"]).To(Equal("service"))
Expand Down

0 comments on commit 5eb9270

Please sign in to comment.