Skip to content

Commit ab4783d

Browse files
resources: determine Service type from common config
Use the common config's network publish field to determine what type of Service we will create - either the default of ClusterIP or LoadBalancer if this share is to be published externally. Signed-off-by: John Mulligan <jmulligan@redhat.com>
1 parent 3486870 commit ab4783d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

internal/resources/planner.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,11 @@ func (sp *sharePlanner) dnsRegisterArgs() []string {
325325
}
326326
args = append(args, sp.serviceWatchJSONPath())
327327
return args
328+
}
328329

330+
func (sp *sharePlanner) serviceType() string {
331+
if sp.CommonConfig != nil && sp.CommonConfig.Spec.Network.Publish == "external" {
332+
return "LoadBalancer"
333+
}
334+
return "ClusterIP"
329335
}

internal/resources/services.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func newServiceForSmb(planner *sharePlanner, ns string) *corev1.Service {
3232
Labels: labels,
3333
},
3434
Spec: corev1.ServiceSpec{
35-
Type: "ClusterIP",
35+
Type: toServiceType(planner.serviceType()),
3636
Ports: []corev1.ServicePort{{
3737
Name: "smb",
3838
Protocol: corev1.ProtocolTCP,
@@ -44,3 +44,15 @@ func newServiceForSmb(planner *sharePlanner, ns string) *corev1.Service {
4444
},
4545
}
4646
}
47+
48+
func toServiceType(s string) corev1.ServiceType {
49+
svcType := corev1.ServiceType(s)
50+
switch svcType {
51+
case corev1.ServiceTypeClusterIP:
52+
case corev1.ServiceTypeNodePort:
53+
case corev1.ServiceTypeLoadBalancer:
54+
default:
55+
panic("invalid value for service type")
56+
}
57+
return svcType
58+
}

0 commit comments

Comments
 (0)