Skip to content

Commit 9f1f60a

Browse files
authored
Allow additional labels and annotations to be specified for the WKA service. (#667)
1 parent 3073bdc commit 9f1f60a

File tree

13 files changed

+426
-40
lines changed

13 files changed

+426
-40
lines changed

.github/workflows/k8s-matrix.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,32 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
matrixName:
43+
- v1.31
4344
- v1.30
4445
- v1.29
4546
- v1.28
4647
- v1.27
4748
- v1.26
4849
- v1.25
4950
include:
51+
- matrixName: v1.31
52+
k8s: kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865
53+
kindCommand: kind-calico
54+
runNetTests: true
5055
- matrixName: v1.30
51-
k8s: kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e
56+
k8s: kindest/node:v1.30.4@sha256:976ea815844d5fa93be213437e3ff5754cd599b040946b5cca43ca45c2047114
5257
kindCommand: kind-calico
5358
runNetTests: true
5459
- matrixName: v1.29
55-
k8s: kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8
60+
k8s: kindest/node:v1.29.8@sha256:d46b7aa29567e93b27f7531d258c372e829d7224b25e3fc6ffdefed12476d3aa
5661
kindCommand: kind-calico
5762
runNetTests: true
5863
- matrixName: v1.28
59-
k8s: kindest/node:v1.28.9@sha256:dca54bc6a6079dd34699d53d7d4ffa2e853e46a20cd12d619a09207e35300bd0
64+
k8s: kindest/node:v1.28.13@sha256:45d319897776e11167e4698f6b14938eb4d52eb381d9e3d7a9086c16c69a8110
6065
kindCommand: kind-calico
6166
runNetTests: true
6267
- matrixName: v1.27
63-
k8s: kindest/node:v1.27.13@sha256:17439fa5b32290e3ead39ead1250dca1d822d94a10d26f1981756cd51b24b9d8
68+
k8s: kindest/node:v1.27.17@sha256:3fd82731af34efe19cd54ea5c25e882985bafa2c9baefe14f8deab1737d9fabe
6469
kindCommand: kind-calico
6570
runNetTests: true
6671
- matrixName: v1.26

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ COMPATIBLE_SELECTOR ?= control-plane=coherence
3232
# The GitHub project URL
3333
PROJECT_URL = https://github.com/oracle/coherence-operator
3434

35-
KUBERNETES_DOC_VERSION=v1.29
35+
KUBERNETES_DOC_VERSION=v1.30
3636

3737
# ----------------------------------------------------------------------------------------------------------------------
3838
# The Coherence image to use for deployments that do not specify an image
@@ -1569,7 +1569,7 @@ create-ssl-secrets: $(BUILD_OUTPUT)/certs
15691569
##@ KinD
15701570

15711571
KIND_CLUSTER ?= operator
1572-
KIND_IMAGE ?= "kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e"
1572+
KIND_IMAGE ?= "kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865"
15731573
CALICO_TIMEOUT ?= 300s
15741574

15751575
# ----------------------------------------------------------------------------------------------------------------------
@@ -1829,7 +1829,7 @@ tanzu-install: ## Install the Coherence Operator package into Tanzu
18291829
# ======================================================================================================================
18301830
##@ Miscellaneous
18311831

1832-
TRIVY_IMAGE=ghcr.io/aquasecurity/trivy:0.51.2
1832+
TRIVY_IMAGE=ghcr.io/aquasecurity/trivy:0.54.1
18331833
.PHONY: trivy-scan
18341834
trivy-scan: $(BUILD_TARGETS)/build-operator ## Scan the Operator image using Trivy
18351835
docker pull $(TRIVY_IMAGE)
@@ -1848,7 +1848,7 @@ controller-gen: $(TOOLS_BIN)/controller-gen ## Download controller-gen locally i
18481848

18491849
$(TOOLS_BIN)/controller-gen:
18501850
@echo "Downloading controller-gen"
1851-
test -s $(TOOLS_BIN)/controller-gen || GOBIN=$(TOOLS_BIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0
1851+
test -s $(TOOLS_BIN)/controller-gen || GOBIN=$(TOOLS_BIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.2
18521852
ls -al $(TOOLS_BIN)
18531853

18541854
# ----------------------------------------------------------------------------------------------------------------------

api/v1/coherence_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,16 @@ type CoherenceWKASpec struct {
589589
// +listType=atomic
590590
// +optional
591591
Addresses []string `json:"addresses,omitempty"`
592+
593+
// Labels is a map of optional additional labels to apply to the WKA Service.
594+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
595+
// +optional
596+
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"`
597+
598+
// Annotations is a map of optional additional labels to apply to the WKA Service.
599+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
600+
// +optional
601+
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"`
592602
}
593603

594604
// ----- CoherenceTracingSpec struct ----------------------------------------

api/v1/coherenceresourcespec_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,20 @@ func (in *CoherenceResourceSpec) CreateWKAService(deployment CoherenceResource)
523523
}
524524
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"
525525

526+
if in != nil {
527+
cohSpec := in.Coherence
528+
if cohSpec != nil {
529+
if cohSpec.WKA != nil {
530+
for k, v := range cohSpec.WKA.Labels {
531+
labels[k] = v
532+
}
533+
for k, v := range cohSpec.WKA.Annotations {
534+
ann[k] = v
535+
}
536+
}
537+
}
538+
}
539+
526540
svc := &corev1.Service{
527541
ObjectMeta: metav1.ObjectMeta{
528542
Namespace: deployment.GetNamespace(),

api/v1/create_job_wka_services_test.go

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/
@@ -198,6 +198,123 @@ func TestCreateWKAServiceForJobWithClusterName(t *testing.T) {
198198
assertWKAServiceForJob(t, deployment, expected)
199199
}
200200

201+
func TestCreateWKAServiceForJobWithAdditionalLabels(t *testing.T) {
202+
extraLabels := make(map[string]string)
203+
extraLabels["one"] = "label-one"
204+
extraLabels["two"] = "label-two"
205+
206+
// Create the test deployment
207+
deployment := &coh.CoherenceJob{
208+
ObjectMeta: metav1.ObjectMeta{
209+
Namespace: "test-ns",
210+
Name: "test",
211+
},
212+
Spec: coh.CoherenceJobResourceSpec{
213+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
214+
Coherence: &coh.CoherenceSpec{
215+
WKA: &coh.CoherenceWKASpec{
216+
Labels: extraLabels,
217+
},
218+
},
219+
},
220+
Cluster: "test-cluster",
221+
},
222+
}
223+
224+
// create the expected WKA service
225+
labels := deployment.CreateCommonLabels()
226+
labels[coh.LabelCoherenceCluster] = "test-cluster"
227+
labels[coh.LabelComponent] = coh.LabelComponentWKA
228+
labels["one"] = "label-one"
229+
labels["two"] = "label-two"
230+
231+
// The selector for the service (match all Pods with the same cluster label)
232+
selector := make(map[string]string)
233+
selector[coh.LabelCoherenceCluster] = "test-cluster"
234+
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
235+
selector[coh.LabelCoherenceWKAMember] = "true"
236+
237+
expected := &corev1.Service{
238+
ObjectMeta: metav1.ObjectMeta{
239+
Namespace: "test-ns",
240+
Name: "test-wka",
241+
Labels: labels,
242+
Annotations: map[string]string{
243+
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
244+
},
245+
},
246+
Spec: corev1.ServiceSpec{
247+
ClusterIP: corev1.ClusterIPNone,
248+
// Pods must be part of the WKA service even if not ready
249+
PublishNotReadyAddresses: true,
250+
Ports: getDefaultServicePorts(),
251+
Selector: selector,
252+
},
253+
}
254+
255+
// assert that the Services are as expected
256+
assertWKAServiceForJob(t, deployment, expected)
257+
}
258+
259+
func TestCreateWKAServiceForJobWithAdditionalAnnotations(t *testing.T) {
260+
extraAnnotations := make(map[string]string)
261+
extraAnnotations["one"] = "label-one"
262+
extraAnnotations["two"] = "label-two"
263+
264+
// Create the test deployment
265+
deployment := &coh.CoherenceJob{
266+
ObjectMeta: metav1.ObjectMeta{
267+
Namespace: "test-ns",
268+
Name: "test",
269+
},
270+
Spec: coh.CoherenceJobResourceSpec{
271+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
272+
Coherence: &coh.CoherenceSpec{
273+
WKA: &coh.CoherenceWKASpec{
274+
Annotations: extraAnnotations,
275+
},
276+
},
277+
},
278+
Cluster: "test-cluster",
279+
},
280+
}
281+
282+
// create the expected WKA service
283+
labels := deployment.CreateCommonLabels()
284+
labels[coh.LabelCoherenceCluster] = "test-cluster"
285+
labels[coh.LabelComponent] = coh.LabelComponentWKA
286+
287+
ann := make(map[string]string)
288+
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"
289+
ann["one"] = "label-one"
290+
ann["two"] = "label-two"
291+
292+
// The selector for the service (match all Pods with the same cluster label)
293+
selector := make(map[string]string)
294+
selector[coh.LabelCoherenceCluster] = "test-cluster"
295+
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
296+
selector[coh.LabelCoherenceWKAMember] = "true"
297+
298+
expected := &corev1.Service{
299+
ObjectMeta: metav1.ObjectMeta{
300+
Namespace: "test-ns",
301+
Name: "test-wka",
302+
Labels: labels,
303+
Annotations: ann,
304+
},
305+
Spec: corev1.ServiceSpec{
306+
ClusterIP: corev1.ClusterIPNone,
307+
// Pods must be part of the WKA service even if not ready
308+
PublishNotReadyAddresses: true,
309+
Ports: getDefaultServicePorts(),
310+
Selector: selector,
311+
},
312+
}
313+
314+
// assert that the Services are as expected
315+
assertWKAServiceForJob(t, deployment, expected)
316+
}
317+
201318
func assertWKAServiceForJob(t *testing.T, deployment *coh.CoherenceJob, expected *corev1.Service) {
202319
g := NewGomegaWithT(t)
203320

api/v1/create_wka_services_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,123 @@ func TestCreateWKAServiceForDeploymentWithClusterName(t *testing.T) {
200200
assertWKAService(t, deployment, expected)
201201
}
202202

203+
func TestCreateWKAServiceForDeploymentWithAdditionalLabels(t *testing.T) {
204+
extraLabels := make(map[string]string)
205+
extraLabels["one"] = "label-one"
206+
extraLabels["two"] = "label-two"
207+
208+
// Create the test deployment
209+
deployment := &coh.Coherence{
210+
ObjectMeta: metav1.ObjectMeta{
211+
Namespace: "test-ns",
212+
Name: "test",
213+
},
214+
Spec: coh.CoherenceStatefulSetResourceSpec{
215+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
216+
Coherence: &coh.CoherenceSpec{
217+
WKA: &coh.CoherenceWKASpec{
218+
Labels: extraLabels,
219+
},
220+
},
221+
},
222+
Cluster: ptr.To("test-cluster"),
223+
},
224+
}
225+
226+
// create the expected WKA service
227+
labels := deployment.CreateCommonLabels()
228+
labels[coh.LabelCoherenceCluster] = "test-cluster"
229+
labels[coh.LabelComponent] = coh.LabelComponentWKA
230+
labels["one"] = "label-one"
231+
labels["two"] = "label-two"
232+
233+
// The selector for the service (match all Pods with the same cluster label)
234+
selector := make(map[string]string)
235+
selector[coh.LabelCoherenceCluster] = "test-cluster"
236+
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
237+
selector[coh.LabelCoherenceWKAMember] = "true"
238+
239+
expected := &corev1.Service{
240+
ObjectMeta: metav1.ObjectMeta{
241+
Namespace: "test-ns",
242+
Name: "test-wka",
243+
Labels: labels,
244+
Annotations: map[string]string{
245+
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
246+
},
247+
},
248+
Spec: corev1.ServiceSpec{
249+
ClusterIP: corev1.ClusterIPNone,
250+
// Pods must be part of the WKA service even if not ready
251+
PublishNotReadyAddresses: true,
252+
Ports: getDefaultServicePorts(),
253+
Selector: selector,
254+
},
255+
}
256+
257+
// assert that the Services are as expected
258+
assertWKAService(t, deployment, expected)
259+
}
260+
261+
func TestCreateWKAServiceForDeploymentWithAdditionalAnnotations(t *testing.T) {
262+
extraAnnotations := make(map[string]string)
263+
extraAnnotations["one"] = "label-one"
264+
extraAnnotations["two"] = "label-two"
265+
266+
// Create the test deployment
267+
deployment := &coh.Coherence{
268+
ObjectMeta: metav1.ObjectMeta{
269+
Namespace: "test-ns",
270+
Name: "test",
271+
},
272+
Spec: coh.CoherenceStatefulSetResourceSpec{
273+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
274+
Coherence: &coh.CoherenceSpec{
275+
WKA: &coh.CoherenceWKASpec{
276+
Annotations: extraAnnotations,
277+
},
278+
},
279+
},
280+
Cluster: ptr.To("test-cluster"),
281+
},
282+
}
283+
284+
// create the expected WKA service
285+
labels := deployment.CreateCommonLabels()
286+
labels[coh.LabelCoherenceCluster] = "test-cluster"
287+
labels[coh.LabelComponent] = coh.LabelComponentWKA
288+
289+
ann := make(map[string]string)
290+
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"
291+
ann["one"] = "label-one"
292+
ann["two"] = "label-two"
293+
294+
// The selector for the service (match all Pods with the same cluster label)
295+
selector := make(map[string]string)
296+
selector[coh.LabelCoherenceCluster] = "test-cluster"
297+
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
298+
selector[coh.LabelCoherenceWKAMember] = "true"
299+
300+
expected := &corev1.Service{
301+
ObjectMeta: metav1.ObjectMeta{
302+
Namespace: "test-ns",
303+
Name: "test-wka",
304+
Labels: labels,
305+
Annotations: ann,
306+
},
307+
Spec: corev1.ServiceSpec{
308+
ClusterIP: corev1.ClusterIPNone,
309+
// Pods must be part of the WKA service even if not ready
310+
PublishNotReadyAddresses: true,
311+
Ports: getDefaultServicePorts(),
312+
Selector: selector,
313+
},
314+
}
315+
316+
// assert that the Services are as expected
317+
assertWKAService(t, deployment, expected)
318+
}
319+
203320
func assertWKAService(t *testing.T, deployment *coh.Coherence, expected *corev1.Service) {
204321
g := NewGomegaWithT(t)
205322

api/v1/zz_generated.deepcopy.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/about/04_coherence_spec.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ CoherenceWKASpec configures Coherence well-known-addressing to use an existing C
275275
m| deployment | The name of the existing Coherence deployment to use for WKA. m| string | true
276276
m| namespace | The optional namespace of the existing Coherence deployment to use for WKA if different from this deployment's namespace. m| string | false
277277
m| addresses | A list of addresses to be used for WKA. If this field is set, the WKA property for the Coherence cluster will be set using this value and the other WKA fields will be ignored. m| []string | false
278+
m| labels | Labels is a map of optional additional labels to apply to the WKA Service. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ m| map[string]string | false
279+
m| annotations | Annotations is a map of optional additional labels to apply to the WKA Service. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ m| map[string]string | false
278280
|===
279281
280282
<<Table of Contents,Back to TOC>>

0 commit comments

Comments
 (0)