Skip to content

Commit c026181

Browse files
authored
Support clusterService.sessionAffinity (#2383)
* Support clusterService.sessionAffinity
1 parent 7bd2a00 commit c026181

File tree

15 files changed

+212
-31
lines changed

15 files changed

+212
-31
lines changed

documentation/domains/Domain.json

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
},
122122
"clusterService": {
123123
"description": "Customization affecting Kubernetes Service generated for this WebLogic cluster.",
124-
"$ref": "#/definitions/KubernetesResource"
124+
"$ref": "#/definitions/ClusterService"
125125
},
126126
"maxConcurrentShutdown": {
127127
"description": "The maximum number of WebLogic Server instances that will shut down in parallel for this cluster when it is being partially shut down by lowering its replica count. A value of 0 means there is no limit. Defaults to `spec.maxClusterConcurrentShutdown`, which defaults to 1.",
@@ -150,6 +150,33 @@
150150
"clusterName"
151151
]
152152
},
153+
"ClusterService": {
154+
"type": "object",
155+
"properties": {
156+
"sessionAffinity": {
157+
"description": "Supports \"ClientIP\" and \"None\". Used to maintain session affinity. Enable client IP based session affinity. Must be ClientIP or None. Defaults to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies",
158+
"type": "string",
159+
"enum": [
160+
"ClientIP",
161+
"None"
162+
]
163+
},
164+
"annotations": {
165+
"description": "The annotations to be added to generated resources.",
166+
"additionalProperties": {
167+
"type": "string"
168+
},
169+
"$ref": "#/definitions/Map"
170+
},
171+
"labels": {
172+
"description": "The labels to be added to generated resources. The label names must not start with \"weblogic.\".",
173+
"additionalProperties": {
174+
"type": "string"
175+
},
176+
"$ref": "#/definitions/Map"
177+
}
178+
}
179+
},
153180
"ClusterStatus": {
154181
"type": "object",
155182
"properties": {
@@ -493,25 +520,6 @@
493520
}
494521
}
495522
},
496-
"KubernetesResource": {
497-
"type": "object",
498-
"properties": {
499-
"annotations": {
500-
"description": "The annotations to be added to generated resources.",
501-
"additionalProperties": {
502-
"type": "string"
503-
},
504-
"$ref": "#/definitions/Map"
505-
},
506-
"labels": {
507-
"description": "The labels to be added to generated resources. The label names must not start with \"weblogic.\".",
508-
"additionalProperties": {
509-
"type": "string"
510-
},
511-
"$ref": "#/definitions/Map"
512-
}
513-
}
514-
},
515523
"ManagedServer": {
516524
"type": "object",
517525
"properties": {

documentation/domains/Domain.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The current status of the operation of the WebLogic domain. Updated automaticall
7878
| --- | --- | --- |
7979
| `allowReplicasBelowMinDynClusterSize` | Boolean | Specifies whether the number of running cluster members is allowed to drop below the minimum dynamic cluster size configured in the WebLogic domain configuration. Otherwise, the operator will ensure that the number of running cluster members is not less than the minimum dynamic cluster setting. This setting applies to dynamic clusters only. Defaults to true. |
8080
| `clusterName` | string | The name of the cluster. This value must match the name of a WebLogic cluster already defined in the WebLogic domain configuration. Required. |
81-
| `clusterService` | [Kubernetes Resource](#kubernetes-resource) | Customization affecting Kubernetes Service generated for this WebLogic cluster. |
81+
| `clusterService` | [Cluster Service](#cluster-service) | Customization affecting Kubernetes Service generated for this WebLogic cluster. |
8282
| `maxConcurrentShutdown` | number | The maximum number of WebLogic Server instances that will shut down in parallel for this cluster when it is being partially shut down by lowering its replica count. A value of 0 means there is no limit. Defaults to `spec.maxClusterConcurrentShutdown`, which defaults to 1. |
8383
| `maxConcurrentStartup` | number | The maximum number of Managed Servers instances that the operator will start in parallel for this cluster in response to a change in the `replicas` count. If more Managed Server instances must be started, the operator will wait until a Managed Server Pod is in the `Ready` state before starting the next Managed Server instance. A value of 0 means all Managed Server instances will start in parallel. Defaults to 0. |
8484
| `maxUnavailable` | number | The maximum number of cluster members that can be temporarily unavailable. Defaults to 1. |
@@ -197,12 +197,13 @@ The current status of the operation of the WebLogic domain. Updated automaticall
197197
| `channels` | array of [Channel](#channel) | Specifies which of the Administration Server's WebLogic channels should be exposed outside the Kubernetes cluster via a NodePort Service, along with the port for each channel. If not specified, the Administration Server's NodePort Service will not be created. |
198198
| `labels` | Map | Labels to associate with the Administration Server's NodePort Service, if it is created. |
199199

200-
### Kubernetes Resource
200+
### Cluster Service
201201

202202
| Name | Type | Description |
203203
| --- | --- | --- |
204204
| `annotations` | Map | The annotations to be added to generated resources. |
205205
| `labels` | Map | The labels to be added to generated resources. The label names must not start with "weblogic.". |
206+
| `sessionAffinity` | string | Supports "ClientIP" and "None". Used to maintain session affinity. Enable client IP based session affinity. Must be ClientIP or None. Defaults to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies |
206207

207208
### Istio
208209

integration-tests/src/test/java/oracle/weblogic/domain/ClusterService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public class ClusterService {
2121
@ApiModelProperty("The annotations to be attached to generated resources.")
2222
private Map<String, String> annotations = new HashMap<>();
2323

24+
@ApiModelProperty(
25+
"Supports \"ClientIP\" and \"None\". Used to maintain session affinity. Enable client IP based session affinity. "
26+
+ "Must be ClientIP or None. Defaults to None. More info: "
27+
+ "https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies")
28+
private String sessionAffinity;
29+
2430
public ClusterService labels(Map<String, String> labels) {
2531
this.labels = labels;
2632
return this;
@@ -83,11 +89,20 @@ public void setAnnotations(Map<String, String> annotations) {
8389
this.annotations = annotations;
8490
}
8591

92+
public String getSessionAffinity() {
93+
return sessionAffinity;
94+
}
95+
96+
public void setSessionAffinity(String sessionAffinity) {
97+
this.sessionAffinity = sessionAffinity;
98+
}
99+
86100
@Override
87101
public String toString() {
88102
return new ToStringBuilder(this)
89103
.append("labels", labels)
90104
.append("annotations", annotations)
105+
.append("sessionAffinity", sessionAffinity)
91106
.toString();
92107
}
93108

@@ -104,11 +119,13 @@ public boolean equals(Object other) {
104119
return new EqualsBuilder()
105120
.append(labels, rhs.labels)
106121
.append(annotations, rhs.annotations)
122+
.append(sessionAffinity, rhs.sessionAffinity)
107123
.isEquals();
108124
}
109125

110126
@Override
111127
public int hashCode() {
112-
return new HashCodeBuilder(17, 37).append(labels).append(annotations).toHashCode();
128+
return new HashCodeBuilder(17, 37)
129+
.append(labels).append(annotations).append(sessionAffinity).toHashCode();
113130
}
114131
}

kubernetes/crd/domain-crd.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: apiextensions.k8s.io/v1
55
kind: CustomResourceDefinition
66
metadata:
77
annotations:
8-
weblogic.sha256: 3e2981c2a3c6057a30a7d22c0a969b992f3a36051a133b6ba4e9fe20121d3088
8+
weblogic.sha256: e091b25f525f2d1a6b90729dcee23d63ead5beb23660912acebf921d1c0499a7
99
name: domains.weblogic.oracle
1010
spec:
1111
group: weblogic.oracle
@@ -5590,6 +5590,15 @@ spec:
55905590
for this WebLogic cluster.
55915591
type: object
55925592
properties:
5593+
sessionAffinity:
5594+
description: 'Supports "ClientIP" and "None". Used to maintain
5595+
session affinity. Enable client IP based session affinity.
5596+
Must be ClientIP or None. Defaults to None. More info:
5597+
https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies'
5598+
type: string
5599+
enum:
5600+
- ClientIP
5601+
- None
55935602
annotations:
55945603
description: The annotations to be added to generated resources.
55955604
additionalProperties:

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,13 @@ V1Service createRecipe() {
401401
}
402402

403403
protected V1ServiceSpec createServiceSpec() {
404-
return new V1ServiceSpec()
404+
V1ServiceSpec spec = new V1ServiceSpec()
405405
.type(getSpecType())
406406
.putSelectorItem(LabelConstants.DOMAINUID_LABEL, getDomainUid())
407407
.putSelectorItem(LabelConstants.CREATEDBYOPERATOR_LABEL, "true")
408408
.ports(createServicePorts());
409+
Optional.ofNullable(getSessionAffinity()).ifPresent(spec::setSessionAffinity);
410+
return spec;
409411
}
410412

411413
void addServicePorts(List<V1ServicePort> ports, WlsServerConfig serverConfig) {
@@ -527,6 +529,10 @@ boolean isIstioEnabled() {
527529

528530
abstract Map<String, String> getServiceAnnotations();
529531

532+
String getSessionAffinity() {
533+
return null;
534+
}
535+
530536
protected abstract void logServiceCreated(String messageKey);
531537

532538
protected abstract String getSpecType();
@@ -839,6 +845,11 @@ Map<String, String> getServiceLabels() {
839845
Map<String, String> getServiceAnnotations() {
840846
return getClusterSpec().getClusterAnnotations();
841847
}
848+
849+
@Override
850+
String getSessionAffinity() {
851+
return getClusterSpec().getClusterSessionAffinity();
852+
}
842853
}
843854

844855
private static class ForExternalServiceStep extends ServiceHelperStep {

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/Cluster.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Cluster extends BaseConfiguration implements Comparable<Cluster> {
6868
@Description("Customization affecting Kubernetes Service generated for this WebLogic cluster.")
6969
@SerializedName("clusterService")
7070
@Expose
71-
private KubernetesResource clusterService = new KubernetesResource();
71+
private ClusterService clusterService = new ClusterService();
7272

7373
@Description("Specifies whether the number of running cluster members is allowed to drop below the "
7474
+ "minimum dynamic cluster size configured in the WebLogic domain configuration. "
@@ -112,7 +112,7 @@ public void setClusterName(@Nonnull String clusterName) {
112112
this.clusterName = clusterName;
113113
}
114114

115-
Cluster withClusterName(@Nonnull String clusterName) {
115+
public Cluster withClusterName(@Nonnull String clusterName) {
116116
setClusterName(clusterName);
117117
return this;
118118
}
@@ -167,14 +167,19 @@ public void setServerStartPolicy(String serverStartPolicy) {
167167
this.serverStartPolicy = serverStartPolicy;
168168
}
169169

170-
public KubernetesResource getClusterService() {
170+
public ClusterService getClusterService() {
171171
return clusterService;
172172
}
173173

174-
public void setClusterService(KubernetesResource clusterService) {
174+
public void setClusterService(ClusterService clusterService) {
175175
this.clusterService = clusterService;
176176
}
177177

178+
public Cluster withClusterService(ClusterService clusterService) {
179+
this.setClusterService(clusterService);
180+
return this;
181+
}
182+
178183
public Map<String, String> getClusterLabels() {
179184
return clusterService.getLabels();
180185
}
@@ -191,6 +196,10 @@ void addClusterAnnotation(String name, String value) {
191196
clusterService.addAnnotations(name, value);
192197
}
193198

199+
public String getClusterSessionAffinity() {
200+
return clusterService.getSessionAffinity();
201+
}
202+
194203
Integer getMaxUnavailable() {
195204
return maxUnavailable;
196205
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2021, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.weblogic.domain.model;
5+
6+
import java.util.Optional;
7+
8+
import oracle.kubernetes.json.Description;
9+
import oracle.kubernetes.json.EnumClass;
10+
import org.apache.commons.lang3.builder.EqualsBuilder;
11+
import org.apache.commons.lang3.builder.HashCodeBuilder;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
13+
14+
public class ClusterService extends KubernetesResource {
15+
16+
@EnumClass(SessionAffinity.class)
17+
@Description(
18+
"Supports \"ClientIP\" and \"None\". Used to maintain session affinity. Enable client IP based session affinity. "
19+
+ "Must be ClientIP or None. Defaults to None. More info: "
20+
+ "https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies")
21+
private String sessionAffinity;
22+
23+
void fillInFrom(ClusterService clusterService1) {
24+
super.fillInFrom(clusterService1);
25+
this.sessionAffinity =
26+
Optional.ofNullable(sessionAffinity).orElse(clusterService1.sessionAffinity);
27+
}
28+
29+
public String getSessionAffinity() {
30+
return sessionAffinity;
31+
}
32+
33+
public void setSessionAffinity(String sessionAffinity) {
34+
this.sessionAffinity = sessionAffinity;
35+
}
36+
37+
public ClusterService withSessionAffinity(String sessionAffinity) {
38+
this.sessionAffinity = sessionAffinity;
39+
return this;
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return new ToStringBuilder(this)
45+
.appendSuper(super.toString())
46+
.append("sessionAffinity", sessionAffinity)
47+
.toString();
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) {
53+
return true;
54+
}
55+
56+
if (o == null || getClass() != o.getClass()) {
57+
return false;
58+
}
59+
60+
ClusterService that = (ClusterService) o;
61+
62+
return new EqualsBuilder()
63+
.appendSuper(super.equals(o))
64+
.append(sessionAffinity, that.sessionAffinity)
65+
.isEquals();
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
return new HashCodeBuilder(17, 37)
71+
.appendSuper(super.hashCode())
72+
.append(sessionAffinity)
73+
.toHashCode();
74+
}
75+
}

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/ClusterSpec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public abstract class ClusterSpec {
2828
@Nonnull
2929
public abstract Map<String, String> getClusterAnnotations();
3030

31+
public abstract String getClusterSessionAffinity();
32+
3133
/**
3234
* Returns the list of initContainers.
3335
*

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/ClusterSpecCommonImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public Map<String, String> getClusterAnnotations() {
3030
return cluster.getClusterAnnotations();
3131
}
3232

33+
@Override
34+
public String getClusterSessionAffinity() {
35+
return cluster.getClusterSessionAffinity();
36+
}
37+
3338
@Override
3439
public List<V1Container> getInitContainers() {
3540
return cluster.getInitContainers();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2021, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.weblogic.domain.model;
5+
6+
public enum SessionAffinity {
7+
ClientIP,
8+
None
9+
}

0 commit comments

Comments
 (0)