Skip to content

Commit 1953906

Browse files
converting to IANA names
1 parent 5d26d07 commit 1953906

File tree

10 files changed

+28
-25
lines changed

10 files changed

+28
-25
lines changed

internal/controller/postgrescluster/cluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/util/intstr"
2727

28+
"github.com/crunchydata/postgres-operator/internal/initialize"
2829
"github.com/crunchydata/postgres-operator/internal/naming"
2930
"github.com/crunchydata/postgres-operator/internal/patroni"
3031
"github.com/crunchydata/postgres-operator/internal/pki"
@@ -142,13 +143,12 @@ func (r *Reconciler) generateClusterPrimaryService(
142143
service.Spec.ClusterIP = corev1.ClusterIPNone
143144
service.Spec.Selector = nil
144145

145-
appProtocol := naming.AppProtocolTCP
146146
service.Spec.Ports = []corev1.ServicePort{{
147147
Name: naming.PortPostgreSQL,
148148
Port: *cluster.Spec.Port,
149149
Protocol: corev1.ProtocolTCP,
150150
TargetPort: intstr.FromString(naming.PortPostgreSQL),
151-
AppProtocol: &appProtocol,
151+
AppProtocol: initialize.String(naming.AppProtocolPOSTGRES),
152152
}}
153153

154154
// Resolve to the ClusterIP for which Patroni has configured the Endpoints.
@@ -163,6 +163,7 @@ func (r *Reconciler) generateClusterPrimaryService(
163163
Name: sp.Name,
164164
Port: sp.Port,
165165
Protocol: sp.Protocol,
166+
AppProtocol: sp.AppProtocol,
166167
})
167168
}
168169

@@ -222,13 +223,12 @@ func (r *Reconciler) generateClusterReplicaService(
222223
// The TargetPort must be the name (not the number) of the PostgreSQL
223224
// ContainerPort. This name allows the port number to differ between Pods,
224225
// which can happen during a rolling update.
225-
appProtocol := naming.AppProtocolTCP
226226
service.Spec.Ports = []corev1.ServicePort{{
227227
Name: naming.PortPostgreSQL,
228228
Port: *cluster.Spec.Port,
229229
Protocol: corev1.ProtocolTCP,
230230
TargetPort: intstr.FromString(naming.PortPostgreSQL),
231-
AppProtocol: &appProtocol,
231+
AppProtocol: initialize.String(naming.AppProtocolPOSTGRES),
232232
}}
233233

234234
err := errors.WithStack(r.setControllerReference(cluster, service))

internal/controller/postgrescluster/cluster_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ ownerReferences:
634634
uid: ""
635635
`))
636636
assert.Assert(t, marshalMatches(service.Spec.Ports, `
637-
- appProtocol: tcp
637+
- appProtocol: postgresql
638638
name: postgres
639639
port: 2600
640640
protocol: TCP
@@ -666,7 +666,8 @@ subsets:
666666
- addresses:
667667
- ip: 1.9.8.3
668668
ports:
669-
- name: postgres
669+
- appProtocol: postgresql
670+
name: postgres
670671
port: 2600
671672
protocol: TCP
672673
`))
@@ -754,7 +755,7 @@ ownerReferences:
754755
`))
755756
assert.Assert(t, marshalMatches(service.Spec, `
756757
ports:
757-
- appProtocol: tcp
758+
- appProtocol: postgresql
758759
name: postgres
759760
port: 9876
760761
protocol: TCP

internal/controller/postgrescluster/patroni.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,12 @@ func (r *Reconciler) generatePatroniLeaderLeaseService(
261261
// The TargetPort must be the name (not the number) of the PostgreSQL
262262
// ContainerPort. This name allows the port number to differ between
263263
// instances, which can happen during a rolling update.
264-
appProtocol := naming.AppProtocolTCP
265264
servicePort := corev1.ServicePort{
266265
Name: naming.PortPostgreSQL,
267266
Port: *cluster.Spec.Port,
268267
Protocol: corev1.ProtocolTCP,
269268
TargetPort: intstr.FromString(naming.PortPostgreSQL),
270-
AppProtocol: &appProtocol,
269+
AppProtocol: initialize.String(naming.AppProtocolPOSTGRES),
271270
}
272271

273272
if spec := cluster.Spec.Service; spec == nil {

internal/controller/postgrescluster/patroni_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ownerReferences:
9393
// Defaults to ClusterIP.
9494
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeClusterIP)
9595
assert.Assert(t, marshalMatches(service.Spec.Ports, `
96-
- appProtocol: tcp
96+
- appProtocol: postgresql
9797
name: postgres
9898
port: 9876
9999
protocol: TCP
@@ -183,7 +183,7 @@ ownerReferences:
183183
alwaysExpect(t, service)
184184
test.Expect(t, service)
185185
assert.Assert(t, marshalMatches(service.Spec.Ports, `
186-
- appProtocol: tcp
186+
- appProtocol: postgresql
187187
name: postgres
188188
port: 9876
189189
protocol: TCP
@@ -209,7 +209,7 @@ ownerReferences:
209209
alwaysExpect(t, service)
210210
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeNodePort)
211211
assert.Assert(t, marshalMatches(service.Spec.Ports, `
212-
- appProtocol: tcp
212+
- appProtocol: postgresql
213213
name: postgres
214214
nodePort: 32001
215215
port: 9876
@@ -223,7 +223,7 @@ ownerReferences:
223223
assert.NilError(t, err)
224224
alwaysExpect(t, service)
225225
assert.Assert(t, marshalMatches(service.Spec.Ports, `
226-
- appProtocol: tcp
226+
- appProtocol: postgresql
227227
name: postgres
228228
nodePort: 32002
229229
port: 9876

internal/controller/postgrescluster/pgadmin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,12 @@ func (r *Reconciler) generatePGAdminService(
166166
//
167167
// TODO(tjmoore4): A custom service port is not currently supported as this
168168
// requires updates to the pgAdmin service configuration.
169-
appProtocol := naming.AppProtocolTCP
170169
servicePort := corev1.ServicePort{
171170
Name: naming.PortPGAdmin,
172171
Port: *initialize.Int32(5050),
173172
Protocol: corev1.ProtocolTCP,
174173
TargetPort: intstr.FromString(naming.PortPGAdmin),
175-
AppProtocol: &appProtocol,
174+
AppProtocol: initialize.String(naming.AppProtocolHTTP),
176175
}
177176

178177
if spec := cluster.Spec.UserInterface.PGAdmin.Service; spec == nil {

internal/controller/postgrescluster/pgadmin_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ ownerReferences:
266266
// Defaults to ClusterIP.
267267
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeClusterIP)
268268
assert.Assert(t, marshalMatches(service.Spec.Ports, `
269-
- appProtocol: tcp
269+
- appProtocol: http
270270
name: pgadmin
271271
port: 5050
272272
protocol: TCP
@@ -300,7 +300,7 @@ ownerReferences:
300300
alwaysExpect(t, service)
301301
test.Expect(t, service)
302302
assert.Assert(t, marshalMatches(service.Spec.Ports, `
303-
- appProtocol: tcp
303+
- appProtocol: http
304304
name: pgadmin
305305
port: 5050
306306
protocol: TCP
@@ -326,7 +326,7 @@ ownerReferences:
326326
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeNodePort)
327327
alwaysExpect(t, service)
328328
assert.Assert(t, marshalMatches(service.Spec.Ports, `
329-
- appProtocol: tcp
329+
- appProtocol: http
330330
name: pgadmin
331331
nodePort: 32001
332332
port: 5050
@@ -340,7 +340,7 @@ ownerReferences:
340340
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeLoadBalancer)
341341
alwaysExpect(t, service)
342342
assert.Assert(t, marshalMatches(service.Spec.Ports, `
343-
- appProtocol: tcp
343+
- appProtocol: http
344344
name: pgadmin
345345
nodePort: 32002
346346
port: 5050

internal/controller/postgrescluster/pgbouncer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ func (r *Reconciler) generatePGBouncerService(
290290
// The TargetPort must be the name (not the number) of the PgBouncer
291291
// ContainerPort. This name allows the port number to differ between Pods,
292292
// which can happen during a rolling update.
293-
appProtocol := naming.AppProtocolTCP
294293
servicePort := corev1.ServicePort{
295294
Name: naming.PortPGBouncer,
296295
Port: *cluster.Spec.Proxy.PGBouncer.Port,
297296
Protocol: corev1.ProtocolTCP,
298297
TargetPort: intstr.FromString(naming.PortPGBouncer),
299-
AppProtocol: &appProtocol,
298+
AppProtocol: initialize.String(naming.AppProtocolPOSTGRES),
300299
}
301300

302301
if spec := cluster.Spec.Proxy.PGBouncer.Service; spec == nil {

internal/controller/postgrescluster/pgbouncer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ownerReferences:
175175
// Defaults to ClusterIP.
176176
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeClusterIP)
177177
assert.Assert(t, marshalMatches(service.Spec.Ports, `
178-
- appProtocol: tcp
178+
- appProtocol: postgresql
179179
name: pgbouncer
180180
port: 9651
181181
protocol: TCP
@@ -209,7 +209,7 @@ ownerReferences:
209209
alwaysExpect(t, service)
210210
test.Expect(t, service)
211211
assert.Assert(t, marshalMatches(service.Spec.Ports, `
212-
- appProtocol: tcp
212+
- appProtocol: postgresql
213213
name: pgbouncer
214214
port: 9651
215215
protocol: TCP
@@ -235,7 +235,7 @@ ownerReferences:
235235
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeNodePort)
236236
alwaysExpect(t, service)
237237
assert.Assert(t, marshalMatches(service.Spec.Ports, `
238-
- appProtocol: tcp
238+
- appProtocol: postgresql
239239
name: pgbouncer
240240
nodePort: 32001
241241
port: 9651
@@ -249,7 +249,7 @@ ownerReferences:
249249
assert.Equal(t, service.Spec.Type, corev1.ServiceTypeLoadBalancer)
250250
alwaysExpect(t, service)
251251
assert.Assert(t, marshalMatches(service.Spec.Ports, `
252-
- appProtocol: tcp
252+
- appProtocol: postgresql
253253
name: pgbouncer
254254
nodePort: 32002
255255
port: 9651

internal/naming/names.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ const (
189189
const (
190190
// AppProtocolTCP is the name of the appProtocol for the Service which use the tcp protocol
191191
AppProtocolTCP = "tcp"
192+
// AppProtocolTCP is the name of the appProtocol for the Service which use the http protocol
193+
AppProtocolHTTP = "http"
194+
// AppProtocolTCP is the name of the appProtocol for the Service which use the PostgreSQL protocol
195+
AppProtocolPOSTGRES = "postgresql"
192196
)
193197

194198
// AsObjectKey converts the ObjectMeta API type to a client.ObjectKey.

internal/patroni/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ func instanceEnvironment(
337337
Name: sp.Name,
338338
Port: cp.ContainerPort,
339339
Protocol: cp.Protocol,
340+
AppProtocol: sp.AppProtocol,
340341
})
341342
}
342343
}

0 commit comments

Comments
 (0)