Skip to content

Commit 9b16718

Browse files
authored
Merge pull request #544 from oracle/service_label_and_annotation
OWLS-68701 -- Support for additional service labels and annotations
2 parents e28aef7 + de07935 commit 9b16718

File tree

14 files changed

+241
-1
lines changed

14 files changed

+241
-1
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/AdminServerConfigurator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public interface AdminServerConfigurator extends ServerConfigurator {
1616
AdminServerConfigurator withExportedNetworkAccessPoints(String... names);
1717

1818
ExportedNetworkAccessPoint configureExportedNetworkAccessPoint(String channelName);
19+
20+
AdminServerConfigurator withNodePortLabel(String name, String value);
21+
22+
AdminServerConfigurator withNodePortAnnotation(String name, String value);
1923
}

model/src/main/java/oracle/kubernetes/weblogic/domain/ClusterConfigurator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ ClusterConfigurator withLivenessProbeSettings(
4343
ClusterConfigurator withPodLabel(String name, String value);
4444

4545
ClusterConfigurator withPodAnnotation(String name, String value);
46+
47+
ClusterConfigurator withServiceLabel(String name, String value);
48+
49+
ClusterConfigurator withServiceAnnotation(String name, String value);
4650
}

model/src/main/java/oracle/kubernetes/weblogic/domain/ServerConfigurator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ ServerConfigurator withReadinessProbeSettings(
4141
ServerConfigurator withPodLabel(String name, String value);
4242

4343
ServerConfigurator withPodAnnotation(String name, String value);
44+
45+
ServerConfigurator withServiceLabel(String name, String value);
46+
47+
ServerConfigurator withServiceAnnotation(String name, String value);
4448
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/AdminServer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public String toString() {
5252
return new ToStringBuilder(this)
5353
.appendSuper(super.toString())
5454
.append("exportedNetworkAccessPoints", exportedNetworkAccessPoints)
55+
.append("nodePortLabels", nodePortLabels)
56+
.append("nodePortAnnotations", nodePortAnnotations)
5557
.toString();
5658
}
5759

@@ -66,6 +68,8 @@ public boolean equals(Object o) {
6668
return new EqualsBuilder()
6769
.appendSuper(super.equals(o))
6870
.append(exportedNetworkAccessPoints, that.exportedNetworkAccessPoints)
71+
.append(nodePortLabels, that.nodePortLabels)
72+
.append(nodePortAnnotations, that.nodePortAnnotations)
6973
.isEquals();
7074
}
7175

@@ -74,6 +78,20 @@ public int hashCode() {
7478
return new HashCodeBuilder(17, 37)
7579
.appendSuper(super.hashCode())
7680
.append(exportedNetworkAccessPoints)
81+
.append(nodePortLabels)
82+
.append(nodePortAnnotations)
7783
.toHashCode();
7884
}
85+
86+
private Map<String, String> nodePortLabels = new HashMap<>();
87+
88+
private Map<String, String> nodePortAnnotations = new HashMap<>();
89+
90+
void addNodePortLabels(String name, String value) {
91+
nodePortLabels.put(name, value);
92+
}
93+
94+
void addNodePortAnnotations(String name, String value) {
95+
nodePortAnnotations.put(name, value);
96+
}
7997
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/BaseConfiguration.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ void addPodAnnotations(String name, String value) {
194194
serverPod.addPodAnnotations(name, value);
195195
}
196196

197+
public Map<String, String> getServiceLabels() {
198+
return serverPod.getServiceLabels();
199+
}
200+
201+
void addServiceLabels(String name, String value) {
202+
serverPod.addServiceLabel(name, value);
203+
}
204+
205+
public Map<String, String> getServiceAnnotations() {
206+
return serverPod.getServiceAnnotations();
207+
}
208+
209+
void addServiceAnnotations(String name, String value) {
210+
serverPod.addServiceAnnotations(name, value);
211+
}
212+
197213
@Override
198214
public String toString() {
199215
return new ToStringBuilder(this)

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Configurator.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ public AdminServerConfigurator withNodePort(int nodePort) {
136136
return this;
137137
}
138138

139+
@Override
140+
public AdminServerConfigurator withNodePortLabel(String name, String value) {
141+
adminServer.addNodePortLabels(name, value);
142+
return this;
143+
}
144+
145+
@Override
146+
public AdminServerConfigurator withNodePortAnnotation(String name, String value) {
147+
adminServer.addNodePortAnnotations(name, value);
148+
return this;
149+
}
150+
139151
@Override
140152
public AdminServerConfigurator withExportedNetworkAccessPoints(String... names) {
141153
for (String name : names) {
@@ -304,6 +316,18 @@ public ServerConfigurator withPodAnnotation(String name, String value) {
304316
server.addPodAnnotations(name, value);
305317
return this;
306318
}
319+
320+
@Override
321+
public ServerConfigurator withServiceLabel(String name, String value) {
322+
server.addServiceLabels(name, value);
323+
return this;
324+
}
325+
326+
@Override
327+
public ServerConfigurator withServiceAnnotation(String name, String value) {
328+
server.addServiceAnnotations(name, value);
329+
return this;
330+
}
307331
}
308332

309333
@Override
@@ -436,5 +460,17 @@ public ClusterConfigurator withPodAnnotation(String name, String value) {
436460
cluster.addPodAnnotations(name, value);
437461
return this;
438462
}
463+
464+
@Override
465+
public ClusterConfigurator withServiceLabel(String name, String value) {
466+
cluster.addServiceLabels(name, value);
467+
return this;
468+
}
469+
470+
@Override
471+
public ClusterConfigurator withServiceAnnotation(String name, String value) {
472+
cluster.addServiceAnnotations(name, value);
473+
return this;
474+
}
439475
}
440476
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/ServerPod.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ class ServerPod {
155155
@Description("Annotations applied to pods")
156156
private Map<String, String> podAnnotations = new HashMap<String, String>();
157157

158+
/**
159+
* The labels to be attached to Service.
160+
*
161+
* @since 2.0
162+
*/
163+
@SerializedName("serviceLabels")
164+
@Expose
165+
@Description("Labels applied to services")
166+
private Map<String, String> serviceLabels = new HashMap<String, String>();
167+
168+
/**
169+
* The annotations to be attached to Service.
170+
*
171+
* @since 2.0
172+
*/
173+
@SerializedName("serviceAnnotations")
174+
@Expose
175+
@Description("Annotations applied to services")
176+
private Map<String, String> serviceAnnotations = new HashMap<String, String>();
177+
158178
ProbeTuning getReadinessProbeTuning() {
159179
return this.readinessProbeTuning;
160180
}
@@ -185,6 +205,8 @@ void fillInFrom(ServerPod serverPod1) {
185205
for (V1VolumeMount var : serverPod1.getAdditionalVolumeMounts()) addIfMissing(var);
186206
serverPod1.getPodLabels().forEach((k, v) -> addPodLabelIfMissing(k, v));
187207
serverPod1.getPodAnnotations().forEach((k, v) -> addPodAnnotationIfMissing(k, v));
208+
serverPod1.getServiceAnnotations().forEach((k, v) -> addServiceAnnotationIfMissing(k, v));
209+
serverPod1.getServiceLabels().forEach((k, v) -> addServiceLabelIfMissing(k, v));
188210
serverPod1.nodeSelectorMap.forEach(nodeSelectorMap::putIfAbsent);
189211
copyValues(resourceRequirements, serverPod1.resourceRequirements);
190212
copyValues(podSecurityContext, serverPod1.podSecurityContext);
@@ -293,6 +315,14 @@ private void addPodAnnotationIfMissing(String name, String value) {
293315
if (!podAnnotations.containsKey(name)) podAnnotations.put(name, value);
294316
}
295317

318+
private void addServiceLabelIfMissing(String name, String value) {
319+
if (!serviceLabels.containsKey(name)) serviceLabels.put(name, value);
320+
}
321+
322+
private void addServiceAnnotationIfMissing(String name, String value) {
323+
if (!serviceAnnotations.containsKey(name)) serviceAnnotations.put(name, value);
324+
}
325+
296326
List<V1EnvVar> getEnv() {
297327
return this.env;
298328
}
@@ -391,6 +421,22 @@ public Map<String, String> getPodAnnotations() {
391421
return podAnnotations;
392422
}
393423

424+
void addServiceLabel(String name, String value) {
425+
serviceLabels.put(name, value);
426+
}
427+
428+
void addServiceAnnotations(String name, String value) {
429+
serviceAnnotations.put(name, value);
430+
}
431+
432+
public Map<String, String> getServiceLabels() {
433+
return serviceLabels;
434+
}
435+
436+
public Map<String, String> getServiceAnnotations() {
437+
return serviceAnnotations;
438+
}
439+
394440
@Override
395441
public String toString() {
396442
return new ToStringBuilder(this)
@@ -401,6 +447,8 @@ public String toString() {
401447
.append("additionalVolumeMounts", additionalVolumeMounts)
402448
.append("podLabels", podLabels)
403449
.append("podAnnotations", podAnnotations)
450+
.append("serviceLabels", serviceLabels)
451+
.append("serviceAnnotations", serviceAnnotations)
404452
.append("nodeSelector", nodeSelectorMap)
405453
.append("resourceRequirements", resourceRequirements)
406454
.append("podSecurityContext", podSecurityContext)
@@ -424,6 +472,8 @@ public boolean equals(Object o) {
424472
.append(additionalVolumeMounts, that.additionalVolumeMounts)
425473
.append(podLabels, that.podLabels)
426474
.append(podAnnotations, that.podAnnotations)
475+
.append(serviceLabels, that.serviceLabels)
476+
.append(serviceAnnotations, that.serviceAnnotations)
427477
.append(nodeSelectorMap, that.nodeSelectorMap)
428478
.append(resourceRequirements, that.resourceRequirements)
429479
.append(podSecurityContext, that.podSecurityContext)
@@ -441,6 +491,8 @@ public int hashCode() {
441491
.append(additionalVolumeMounts)
442492
.append(podLabels)
443493
.append(podAnnotations)
494+
.append(serviceLabels)
495+
.append(serviceAnnotations)
444496
.append(nodeSelectorMap)
445497
.append(resourceRequirements)
446498
.append(podSecurityContext)

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/ServerSpec.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ public ProbeTuning getReadinessProbe() {
179179
@Nonnull
180180
public abstract Map<String, String> getPodAnnotations();
181181

182+
/**
183+
* Returns the labels applied to the service.
184+
*
185+
* @return a map of labels
186+
*/
187+
@Nonnull
188+
public abstract Map<String, String> getServiceLabels();
189+
190+
/**
191+
* Returns the annotations applied to the service.
192+
*
193+
* @return a map of annotations
194+
*/
195+
@Nonnull
196+
public abstract Map<String, String> getServiceAnnotations();
197+
182198
@Nonnull
183199
public Map<String, String> getListenAddressServiceLabels() {
184200
return Collections.emptyMap();

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/ServerSpecV2Impl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public Map<String, String> getPodAnnotations() {
7373
return server.getPodAnnotations();
7474
}
7575

76+
@Override
77+
public Map<String, String> getServiceLabels() {
78+
return server.getServiceLabels();
79+
}
80+
81+
@Override
82+
public Map<String, String> getServiceAnnotations() {
83+
return server.getServiceAnnotations();
84+
}
85+
7686
@Override
7787
public String getDesiredState() {
7888
return Optional.ofNullable(getConfiguredDesiredState()).orElse("RUNNING");

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/AdminServerTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void whenExportedAccessPointsAreTheSame_objectsAreEqual() {
3333
.addAnnotation("annotation1", "value2")
3434
.addLabel("label1", "value1");
3535

36-
assertThat(server1, equalTo(server1));
36+
assertThat(server1, equalTo(server2));
3737
}
3838

3939
@Test
@@ -59,4 +59,30 @@ public void whenExportedAccessPointsDifferByAnnotation_objectsAreNotEqual() {
5959

6060
assertThat(server1, not(equalTo(server2)));
6161
}
62+
63+
@Test
64+
public void whenNodePortAnnotationsDiffer_objectsAreNotEqual() {
65+
server1.addNodePortAnnotations("key", "value");
66+
assertThat(server1, not(equalTo(server2)));
67+
}
68+
69+
@Test
70+
public void whenNodePortAnnotationsAreSame_objectsAreEqual() {
71+
server1.addNodePortAnnotations("key", "value");
72+
server2.addNodePortAnnotations("key", "value");
73+
assertThat(server1, equalTo(server2));
74+
}
75+
76+
@Test
77+
public void whenNodePortLabelsDiffer_hashCodesAreNotEqual() {
78+
server1.addNodePortLabels("key", "value");
79+
assertThat(server1.hashCode(), not(equalTo(server2.hashCode())));
80+
}
81+
82+
@Test
83+
public void whenNodePortLabelsAreSame_hashCodesAreEqual() {
84+
server1.addNodePortLabels("key", "value");
85+
server2.addNodePortLabels("key", "value");
86+
assertThat(server1.hashCode(), equalTo(server2.hashCode()));
87+
}
6288
}

0 commit comments

Comments
 (0)