Skip to content

Commit

Permalink
Setting appProtocol for service objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenmat committed May 2, 2024
1 parent c030956 commit ce90c23
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ metadata:
name: some-name
spec:
ports:
- name: mongodb
- appProtocol: mongo
name: mongodb
port: 27017
protocol: TCP
targetPort: 27017
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ metadata:
name: some-name
spec:
ports:
- name: mongodb
- appProtocol: mongo
name: mongodb
port: 27017
protocol: TCP
targetPort: 27017
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ metadata:
name: some-name
spec:
ports:
- name: mongodb
- appProtocol: mongo
name: mongodb
port: 27017
protocol: TCP
targetPort: 27017
Expand Down
23 changes: 16 additions & 7 deletions pkg/psmdb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Service(cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec) *corev1.Ser
"app.kubernetes.io/managed-by": "percona-server-mongodb-operator",
"app.kubernetes.io/part-of": "percona-server-mongodb",
}
appProtocol := "mongo"

svc := &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -42,10 +42,9 @@ func Service(cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec) *corev1.Ser
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: mongodPortName,
Port: api.DefaultMongodPort,
TargetPort: intstr.FromInt(int(api.DefaultMongodPort)),
AppProtocol: &appProtocol,
Name: mongodPortName,
Port: api.DefaultMongodPort,
TargetPort: intstr.FromInt(int(api.DefaultMongodPort)),
},
},
ClusterIP: "None",
Expand All @@ -64,7 +63,12 @@ func Service(cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec) *corev1.Ser
}
}
}

if cr.CompareVersion("1.16.0") >= 0 {
appProtocol := "mongo"
for _, v := range svc.Spec.Ports {
v.AppProtocol = &appProtocol
}
}
return svc
}

Expand Down Expand Up @@ -119,7 +123,12 @@ func ExternalService(cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec, pod
default:
svc.Spec.Type = corev1.ServiceTypeClusterIP
}

if cr.CompareVersion("1.16.0") >= 0 {
appProtocol := "mongo"
for _, v := range svc.Spec.Ports {
v.AppProtocol = &appProtocol
}
}
return svc
}

Expand Down

0 comments on commit ce90c23

Please sign in to comment.