|
1 | 1 | /* |
2 | | - * Copyright (c) 2023, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. |
3 | 3 | * Licensed under the Universal Permissive License v 1.0 as shown at |
4 | 4 | * http://oss.oracle.com/licenses/upl. |
5 | 5 | */ |
@@ -198,6 +198,123 @@ func TestCreateWKAServiceForJobWithClusterName(t *testing.T) { |
198 | 198 | assertWKAServiceForJob(t, deployment, expected) |
199 | 199 | } |
200 | 200 |
|
| 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 | + |
201 | 318 | func assertWKAServiceForJob(t *testing.T, deployment *coh.CoherenceJob, expected *corev1.Service) { |
202 | 319 | g := NewGomegaWithT(t) |
203 | 320 |
|
|
0 commit comments