Skip to content

Commit b7a5e44

Browse files
committed
Add TCP protocol to fix equals check
1 parent c279996 commit b7a5e44

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,31 @@ protected List<V1ContainerPort> getContainerPorts() {
168168
V1ContainerPort port =
169169
new V1ContainerPort()
170170
.name(LegalNames.toDNS1123LegalName(nap.getName()))
171-
.containerPort(nap.getListenPort());
171+
.containerPort(nap.getListenPort())
172+
.protocol("TCP");
172173
ports.add(port);
173174
}
174175
}
175176
if (scan.getListenPort() != null) {
176-
ports.add(new V1ContainerPort().name("default").containerPort(scan.getListenPort()));
177+
ports.add(
178+
new V1ContainerPort()
179+
.name("default")
180+
.containerPort(scan.getListenPort())
181+
.protocol("TCP"));
177182
}
178183
if (scan.getSslListenPort() != null) {
179184
ports.add(
180-
new V1ContainerPort().name("default-secure").containerPort(scan.getSslListenPort()));
185+
new V1ContainerPort()
186+
.name("default-secure")
187+
.containerPort(scan.getSslListenPort())
188+
.protocol("TCP"));
181189
}
182190
if (scan.getAdminPort() != null) {
183-
ports.add(new V1ContainerPort().name("default-admin").containerPort(scan.getAdminPort()));
191+
ports.add(
192+
new V1ContainerPort()
193+
.name("default-admin")
194+
.containerPort(scan.getAdminPort())
195+
.protocol("TCP"));
184196
}
185197
return ports;
186198
}

operator/src/main/java/oracle/kubernetes/operator/helpers/ServiceHelper.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,24 @@ protected List<V1ServicePort> createServicePorts() {
121121
V1ServicePort port =
122122
new V1ServicePort()
123123
.name(LegalNames.toDNS1123LegalName(nap.getName()))
124-
.port(nap.getListenPort());
124+
.port(nap.getListenPort())
125+
.protocol("TCP");
125126
ports.add(port);
126127
}
127128
}
128129
if (scan.getListenPort() != null) {
129-
ports.add(new V1ServicePort().name("default").port(scan.getListenPort()));
130+
ports.add(new V1ServicePort().name("default").port(scan.getListenPort()).protocol("TCP"));
130131
}
131132
if (scan.getSslListenPort() != null) {
132-
ports.add(new V1ServicePort().name("default-secure").port(scan.getSslListenPort()));
133+
ports.add(
134+
new V1ServicePort()
135+
.name("default-secure")
136+
.port(scan.getSslListenPort())
137+
.protocol("TCP"));
133138
}
134139
if (scan.getAdminPort() != null) {
135-
ports.add(new V1ServicePort().name("default-admin").port(scan.getAdminPort()));
140+
ports.add(
141+
new V1ServicePort().name("default-admin").port(scan.getAdminPort()).protocol("TCP"));
136142
}
137143
return ports;
138144
}
@@ -619,23 +625,31 @@ protected List<V1ServicePort> createServicePorts() {
619625
V1ServicePort port =
620626
new V1ServicePort()
621627
.name(LegalNames.toDNS1123LegalName(nap.getName()))
622-
.port(nap.getListenPort());
628+
.port(nap.getListenPort())
629+
.protocol("TCP");
623630
ports.putIfAbsent(nap.getName(), port);
624631
}
625632
}
626633
if (server.getListenPort() != null) {
627634
ports.putIfAbsent(
628-
"default", new V1ServicePort().name("default").port(server.getListenPort()));
635+
"default",
636+
new V1ServicePort().name("default").port(server.getListenPort()).protocol("TCP"));
629637
}
630638
if (server.getSslListenPort() != null) {
631639
ports.putIfAbsent(
632640
"defaultSecure",
633-
new V1ServicePort().name("default-secure").port(server.getSslListenPort()));
641+
new V1ServicePort()
642+
.name("default-secure")
643+
.port(server.getSslListenPort())
644+
.protocol("TCP"));
634645
}
635646
if (server.getAdminPort() != null) {
636647
ports.putIfAbsent(
637648
"defaultAdmin",
638-
new V1ServicePort().name("default-admin").port(server.getAdminPort()));
649+
new V1ServicePort()
650+
.name("default-admin")
651+
.port(server.getAdminPort())
652+
.protocol("TCP"));
639653
}
640654
}
641655
if (!ports.isEmpty()) {
@@ -831,7 +845,8 @@ protected List<V1ServicePort> createServicePorts() {
831845
new V1ServicePort()
832846
.name(LegalNames.toDNS1123LegalName(nap.getName()))
833847
.port(nap.getListenPort())
834-
.nodePort(nodePort);
848+
.nodePort(nodePort)
849+
.protocol("TCP");
835850
ports.add(port);
836851
}
837852
}
@@ -841,7 +856,11 @@ protected List<V1ServicePort> createServicePorts() {
841856
if (c != null) {
842857
Integer nodePort = Optional.ofNullable(c.getNodePort()).orElse(scan.getListenPort());
843858
ports.add(
844-
new V1ServicePort().name("default").port(scan.getListenPort()).nodePort(nodePort));
859+
new V1ServicePort()
860+
.name("default")
861+
.port(scan.getListenPort())
862+
.nodePort(nodePort)
863+
.protocol("TCP"));
845864
}
846865
}
847866
if (scan.getSslListenPort() != null) {
@@ -852,7 +871,8 @@ protected List<V1ServicePort> createServicePorts() {
852871
new V1ServicePort()
853872
.name("default-secure")
854873
.port(scan.getSslListenPort())
855-
.nodePort(nodePort));
874+
.nodePort(nodePort)
875+
.protocol("TCP"));
856876
}
857877
}
858878
if (scan.getAdminPort() != null) {
@@ -863,7 +883,8 @@ protected List<V1ServicePort> createServicePorts() {
863883
new V1ServicePort()
864884
.name("default-admin")
865885
.port(scan.getAdminPort())
866-
.nodePort(nodePort));
886+
.nodePort(nodePort)
887+
.protocol("TCP"));
867888
}
868889
}
869890
return ports;

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ V1Container createPodSpecContainer() {
611611
.image(LATEST_IMAGE)
612612
.imagePullPolicy(ALWAYS_IMAGEPULLPOLICY)
613613
.securityContext(new V1SecurityContext())
614-
.addPortsItem(new V1ContainerPort().name("default").containerPort(listenPort))
614+
.addPortsItem(
615+
new V1ContainerPort().name("default").containerPort(listenPort).protocol("TCP"))
615616
.lifecycle(createLifecycle())
616617
.volumeMounts(PodDefaults.getStandardVolumeMounts(UID))
617618
.command(createStartCommand())

operator/src/test/java/oracle/kubernetes/operator/helpers/ServiceHelperTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ private V1ServiceSpec createUntypedClusterServiceSpec() {
347347
.putSelectorItem(DOMAINUID_LABEL, UID)
348348
.putSelectorItem(CLUSTERNAME_LABEL, TEST_CLUSTER)
349349
.putSelectorItem(CREATEDBYOPERATOR_LABEL, "true")
350-
.ports(Collections.singletonList(new V1ServicePort().port(TEST_PORT).name("default")));
350+
.ports(
351+
Collections.singletonList(
352+
new V1ServicePort().port(TEST_PORT).name("default").protocol("TCP")));
351353
}
352354

353355
private void expectSuccessfulCreateClusterService() {
@@ -501,7 +503,9 @@ private V1ServiceSpec createUntypedServerServiceSpec() {
501503
.putSelectorItem(DOMAINUID_LABEL, UID)
502504
.putSelectorItem(SERVERNAME_LABEL, TEST_SERVER_NAME)
503505
.putSelectorItem(CREATEDBYOPERATOR_LABEL, "true")
504-
.ports(Collections.singletonList(new V1ServicePort().port(TEST_PORT).name("default")));
506+
.ports(
507+
Collections.singletonList(
508+
new V1ServicePort().port(TEST_PORT).name("default").protocol("TCP")));
505509
}
506510

507511
private void initializeServiceFromRecord(V1Service service) {

0 commit comments

Comments
 (0)