Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional labels and annotations to be specified for the WKA Service #667

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/k8s-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,32 @@ jobs:
fail-fast: false
matrix:
matrixName:
- v1.31
- v1.30
- v1.29
- v1.28
- v1.27
- v1.26
- v1.25
include:
- matrixName: v1.31
k8s: kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865
kindCommand: kind-calico
runNetTests: true
- matrixName: v1.30
k8s: kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e
k8s: kindest/node:v1.30.4@sha256:976ea815844d5fa93be213437e3ff5754cd599b040946b5cca43ca45c2047114
kindCommand: kind-calico
runNetTests: true
- matrixName: v1.29
k8s: kindest/node:v1.29.4@sha256:3abb816a5b1061fb15c6e9e60856ec40d56b7b52bcea5f5f1350bc6e2320b6f8
k8s: kindest/node:v1.29.8@sha256:d46b7aa29567e93b27f7531d258c372e829d7224b25e3fc6ffdefed12476d3aa
kindCommand: kind-calico
runNetTests: true
- matrixName: v1.28
k8s: kindest/node:v1.28.9@sha256:dca54bc6a6079dd34699d53d7d4ffa2e853e46a20cd12d619a09207e35300bd0
k8s: kindest/node:v1.28.13@sha256:45d319897776e11167e4698f6b14938eb4d52eb381d9e3d7a9086c16c69a8110
kindCommand: kind-calico
runNetTests: true
- matrixName: v1.27
k8s: kindest/node:v1.27.13@sha256:17439fa5b32290e3ead39ead1250dca1d822d94a10d26f1981756cd51b24b9d8
k8s: kindest/node:v1.27.17@sha256:3fd82731af34efe19cd54ea5c25e882985bafa2c9baefe14f8deab1737d9fabe
kindCommand: kind-calico
runNetTests: true
- matrixName: v1.26
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COMPATIBLE_SELECTOR ?= control-plane=coherence
# The GitHub project URL
PROJECT_URL = https://github.com/oracle/coherence-operator

KUBERNETES_DOC_VERSION=v1.29
KUBERNETES_DOC_VERSION=v1.30

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

KIND_CLUSTER ?= operator
KIND_IMAGE ?= "kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e"
KIND_IMAGE ?= "kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865"
CALICO_TIMEOUT ?= 300s

# ----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1829,7 +1829,7 @@ tanzu-install: ## Install the Coherence Operator package into Tanzu
# ======================================================================================================================
##@ Miscellaneous

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

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

# ----------------------------------------------------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions api/v1/coherence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,16 @@ type CoherenceWKASpec struct {
// +listType=atomic
// +optional
Addresses []string `json:"addresses,omitempty"`

// 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/
// +optional
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"`

// 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/
// +optional
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"`
}

// ----- CoherenceTracingSpec struct ----------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,20 @@ func (in *CoherenceResourceSpec) CreateWKAService(deployment CoherenceResource)
}
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"

if in != nil {
cohSpec := in.Coherence
if cohSpec != nil {
if cohSpec.WKA != nil {
for k, v := range cohSpec.WKA.Labels {
labels[k] = v
}
for k, v := range cohSpec.WKA.Annotations {
ann[k] = v
}
}
}
}

svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: deployment.GetNamespace(),
Expand Down
119 changes: 118 additions & 1 deletion api/v1/create_job_wka_services_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -198,6 +198,123 @@ func TestCreateWKAServiceForJobWithClusterName(t *testing.T) {
assertWKAServiceForJob(t, deployment, expected)
}

func TestCreateWKAServiceForJobWithAdditionalLabels(t *testing.T) {
extraLabels := make(map[string]string)
extraLabels["one"] = "label-one"
extraLabels["two"] = "label-two"

// Create the test deployment
deployment := &coh.CoherenceJob{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test",
},
Spec: coh.CoherenceJobResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Coherence: &coh.CoherenceSpec{
WKA: &coh.CoherenceWKASpec{
Labels: extraLabels,
},
},
},
Cluster: "test-cluster",
},
}

// create the expected WKA service
labels := deployment.CreateCommonLabels()
labels[coh.LabelCoherenceCluster] = "test-cluster"
labels[coh.LabelComponent] = coh.LabelComponentWKA
labels["one"] = "label-one"
labels["two"] = "label-two"

// The selector for the service (match all Pods with the same cluster label)
selector := make(map[string]string)
selector[coh.LabelCoherenceCluster] = "test-cluster"
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
selector[coh.LabelCoherenceWKAMember] = "true"

expected := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test-wka",
Labels: labels,
Annotations: map[string]string{
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: corev1.ClusterIPNone,
// Pods must be part of the WKA service even if not ready
PublishNotReadyAddresses: true,
Ports: getDefaultServicePorts(),
Selector: selector,
},
}

// assert that the Services are as expected
assertWKAServiceForJob(t, deployment, expected)
}

func TestCreateWKAServiceForJobWithAdditionalAnnotations(t *testing.T) {
extraAnnotations := make(map[string]string)
extraAnnotations["one"] = "label-one"
extraAnnotations["two"] = "label-two"

// Create the test deployment
deployment := &coh.CoherenceJob{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test",
},
Spec: coh.CoherenceJobResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Coherence: &coh.CoherenceSpec{
WKA: &coh.CoherenceWKASpec{
Annotations: extraAnnotations,
},
},
},
Cluster: "test-cluster",
},
}

// create the expected WKA service
labels := deployment.CreateCommonLabels()
labels[coh.LabelCoherenceCluster] = "test-cluster"
labels[coh.LabelComponent] = coh.LabelComponentWKA

ann := make(map[string]string)
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"
ann["one"] = "label-one"
ann["two"] = "label-two"

// The selector for the service (match all Pods with the same cluster label)
selector := make(map[string]string)
selector[coh.LabelCoherenceCluster] = "test-cluster"
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
selector[coh.LabelCoherenceWKAMember] = "true"

expected := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test-wka",
Labels: labels,
Annotations: ann,
},
Spec: corev1.ServiceSpec{
ClusterIP: corev1.ClusterIPNone,
// Pods must be part of the WKA service even if not ready
PublishNotReadyAddresses: true,
Ports: getDefaultServicePorts(),
Selector: selector,
},
}

// assert that the Services are as expected
assertWKAServiceForJob(t, deployment, expected)
}

func assertWKAServiceForJob(t *testing.T, deployment *coh.CoherenceJob, expected *corev1.Service) {
g := NewGomegaWithT(t)

Expand Down
117 changes: 117 additions & 0 deletions api/v1/create_wka_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,123 @@ func TestCreateWKAServiceForDeploymentWithClusterName(t *testing.T) {
assertWKAService(t, deployment, expected)
}

func TestCreateWKAServiceForDeploymentWithAdditionalLabels(t *testing.T) {
extraLabels := make(map[string]string)
extraLabels["one"] = "label-one"
extraLabels["two"] = "label-two"

// Create the test deployment
deployment := &coh.Coherence{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test",
},
Spec: coh.CoherenceStatefulSetResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Coherence: &coh.CoherenceSpec{
WKA: &coh.CoherenceWKASpec{
Labels: extraLabels,
},
},
},
Cluster: ptr.To("test-cluster"),
},
}

// create the expected WKA service
labels := deployment.CreateCommonLabels()
labels[coh.LabelCoherenceCluster] = "test-cluster"
labels[coh.LabelComponent] = coh.LabelComponentWKA
labels["one"] = "label-one"
labels["two"] = "label-two"

// The selector for the service (match all Pods with the same cluster label)
selector := make(map[string]string)
selector[coh.LabelCoherenceCluster] = "test-cluster"
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
selector[coh.LabelCoherenceWKAMember] = "true"

expected := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test-wka",
Labels: labels,
Annotations: map[string]string{
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: corev1.ClusterIPNone,
// Pods must be part of the WKA service even if not ready
PublishNotReadyAddresses: true,
Ports: getDefaultServicePorts(),
Selector: selector,
},
}

// assert that the Services are as expected
assertWKAService(t, deployment, expected)
}

func TestCreateWKAServiceForDeploymentWithAdditionalAnnotations(t *testing.T) {
extraAnnotations := make(map[string]string)
extraAnnotations["one"] = "label-one"
extraAnnotations["two"] = "label-two"

// Create the test deployment
deployment := &coh.Coherence{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test",
},
Spec: coh.CoherenceStatefulSetResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Coherence: &coh.CoherenceSpec{
WKA: &coh.CoherenceWKASpec{
Annotations: extraAnnotations,
},
},
},
Cluster: ptr.To("test-cluster"),
},
}

// create the expected WKA service
labels := deployment.CreateCommonLabels()
labels[coh.LabelCoherenceCluster] = "test-cluster"
labels[coh.LabelComponent] = coh.LabelComponentWKA

ann := make(map[string]string)
ann["service.alpha.kubernetes.io/tolerate-unready-endpoints"] = "true"
ann["one"] = "label-one"
ann["two"] = "label-two"

// The selector for the service (match all Pods with the same cluster label)
selector := make(map[string]string)
selector[coh.LabelCoherenceCluster] = "test-cluster"
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
selector[coh.LabelCoherenceWKAMember] = "true"

expected := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test-wka",
Labels: labels,
Annotations: ann,
},
Spec: corev1.ServiceSpec{
ClusterIP: corev1.ClusterIPNone,
// Pods must be part of the WKA service even if not ready
PublishNotReadyAddresses: true,
Ports: getDefaultServicePorts(),
Selector: selector,
},
}

// assert that the Services are as expected
assertWKAService(t, deployment, expected)
}

func assertWKAService(t *testing.T, deployment *coh.Coherence, expected *corev1.Service) {
g := NewGomegaWithT(t)

Expand Down
14 changes: 14 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/about/04_coherence_spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ CoherenceWKASpec configures Coherence well-known-addressing to use an existing C
m| deployment | The name of the existing Coherence deployment to use for WKA. m| string | true
m| namespace | The optional namespace of the existing Coherence deployment to use for WKA if different from this deployment's namespace. m| string | false
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
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
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
|===

<<Table of Contents,Back to TOC>>
Expand Down
Loading
Loading