Skip to content

Commit b0ae15c

Browse files
committed
Version the last of the artifacts, remove the old format annotations and use the version labels instead to determine when resources are obsolete
1 parent 7b9e00a commit b0ae15c

File tree

8 files changed

+49
-44
lines changed

8 files changed

+49
-44
lines changed

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,13 @@
33

44
package oracle.kubernetes.operator.helpers;
55

6-
import java.util.Objects;
7-
86
import io.kubernetes.client.models.V1ObjectMeta;
97

108
/**
119
* Annotates pods, services with details about the Domain instance and checks these annotations.
1210
*
1311
*/
1412
public class AnnotationHelper {
15-
// Make these public so that the tests can use them:
16-
public static final String FORMAT_ANNOTATION = "weblogic.oracle/operator-formatVersion";
17-
public static final String FORMAT_VERSION = "1";
18-
19-
/**
20-
* Marks metadata object with an annotation saying that it was created for this format version
21-
* @param meta Metadata object that will be included in a newly created resource, e.g. pod or service
22-
*/
23-
public static void annotateWithFormat(V1ObjectMeta meta) {
24-
meta.putAnnotationsItem(FORMAT_ANNOTATION, FORMAT_VERSION);
25-
}
26-
27-
2813
/**
2914
* Marks metadata with annotations that let Prometheus know how to retrieve metrics from
3015
* the wls-exporter web-app. The specified httpPort should be the listen port of the WebLogic server
@@ -37,14 +22,4 @@ public static void annotateForPrometheus(V1ObjectMeta meta, int httpPort) {
3722
meta.putAnnotationsItem("prometheus.io/path", "/wls-exporter/metrics");
3823
meta.putAnnotationsItem("prometheus.io/scrape", "true");
3924
}
40-
41-
/**
42-
* Check the metadata object for the presence of an annotation matching the expected format version.
43-
* @param meta The metadata object
44-
* @return true, if the metadata includes an annotation matching the expected format version
45-
*/
46-
public static boolean checkFormatAnnotation(V1ObjectMeta meta) {
47-
String metaResourceVersion = meta.getAnnotations().get(FORMAT_ANNOTATION);
48-
return Objects.equals(FORMAT_VERSION, metaResourceVersion);
49-
}
5025
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
9999
}
100100
});
101101
return doNext(create, packet);
102-
} else if (AnnotationHelper.checkFormatAnnotation(result.getMetadata()) && result.getData().entrySet().containsAll(cm.getData().entrySet())) {
102+
} else if (VersionHelper.matchesResourceVersion(result.getMetadata(), LabelConstants.RESOURCE_VERSION_LABEL) &&
103+
result.getData().entrySet().containsAll(cm.getData().entrySet())) {
103104
// existing config map has correct data
104105
LOGGER.fine(MessageKeys.CM_EXISTS, domainNamespace);
105106
packet.put(ProcessingConstants.SCRIPT_CONFIG_MAP, result);
@@ -142,9 +143,7 @@ protected V1ConfigMap computeDomainConfigMap() {
142143
V1ObjectMeta metadata = new V1ObjectMeta();
143144
metadata.setName(name);
144145
metadata.setNamespace(domainNamespace);
145-
146-
AnnotationHelper.annotateWithFormat(metadata);
147-
146+
148147
Map<String, String> labels = new HashMap<>();
149148
labels.put(LabelConstants.RESOURCE_VERSION_LABEL, VersionConstants.DOMAIN_V1);
150149
labels.put(LabelConstants.OPERATORNAME_LABEL, operatorNamespace);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import oracle.kubernetes.operator.KubernetesConstants;
2121
import oracle.kubernetes.operator.LabelConstants;
2222
import oracle.kubernetes.operator.ProcessingConstants;
23+
import oracle.kubernetes.operator.VersionConstants;
2324
import oracle.kubernetes.weblogic.domain.v1.Domain;
2425
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
2526
import oracle.kubernetes.operator.work.ContainerResolver;
@@ -78,9 +79,9 @@ public NextAction apply(Packet packet) {
7879
v1ObjectMeta.setNamespace(namespace);
7980

8081
v1ObjectMeta.putAnnotationsItem(KubernetesConstants.CLASS_INGRESS, KubernetesConstants.CLASS_INGRESS_VALUE);
81-
AnnotationHelper.annotateWithFormat(v1ObjectMeta);
8282

8383
Map<String, String> labels = new HashMap<>();
84+
labels.put(LabelConstants.RESOURCE_VERSION_LABEL, VersionConstants.DOMAIN_V1);
8485
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
8586
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
8687
labels.put(LabelConstants.CLUSTERNAME_LABEL, clusterName);
@@ -141,7 +142,7 @@ public NextAction onSuccess(Packet packet, V1beta1Ingress result, int statusCode
141142
}
142143
}), packet);
143144
} else {
144-
if (AnnotationHelper.checkFormatAnnotation(result.getMetadata()) && v1beta1Ingress.getSpec().equals(result.getSpec())) {
145+
if (VersionHelper.matchesResourceVersion(result.getMetadata(), VersionConstants.DOMAIN_V1) && v1beta1Ingress.getSpec().equals(result.getSpec())) {
145146
return doNext(packet);
146147
}
147148
return doNext(factory.create().replaceIngressAsync(ingressName, meta.getNamespace(),

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ protected V1Pod computeAdminPodConfig(TuningParameters configMapHelper, Packet p
184184
metadata.setName(podName);
185185
metadata.setNamespace(namespace);
186186
adminPod.setMetadata(metadata);
187-
188-
AnnotationHelper.annotateWithFormat(metadata);
187+
189188
AnnotationHelper.annotateForPrometheus(metadata, spec.getAsPort());
190189

191190
Map<String, String> labels = new HashMap<>();
@@ -408,7 +407,7 @@ private static boolean validateCurrentPod(V1Pod build, V1Pod current) {
408407
// returns fields, such as nodeName, even when export=true is specified.
409408
// Therefore, we'll just compare specific fields
410409

411-
if (!AnnotationHelper.checkFormatAnnotation(current.getMetadata())) {
410+
if (!VersionHelper.matchesResourceVersion(current.getMetadata(), LabelConstants.RESOURCE_VERSION_LABEL)) {
412411
return false;
413412
}
414413

@@ -613,7 +612,6 @@ protected V1Pod computeManagedPodConfig(TuningParameters configMapHelper, Packet
613612
metadata.setNamespace(namespace);
614613
pod.setMetadata(metadata);
615614

616-
AnnotationHelper.annotateWithFormat(metadata);
617615
AnnotationHelper.annotateForPrometheus(metadata, scan.getListenPort());
618616

619617
Map<String, String> labels = new HashMap<>();

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.kubernetes.client.models.*;
88
import oracle.kubernetes.operator.LabelConstants;
99
import oracle.kubernetes.operator.ProcessingConstants;
10+
import oracle.kubernetes.operator.VersionConstants;
1011
import oracle.kubernetes.weblogic.domain.v1.Domain;
1112
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
1213
import oracle.kubernetes.operator.helpers.HealthCheckHelper.KubernetesVersion;
@@ -72,10 +73,10 @@ public NextAction apply(Packet packet) {
7273
metadata.setName(name);
7374
metadata.setNamespace(namespace);
7475

75-
AnnotationHelper.annotateWithFormat(metadata);
7676
metadata.putAnnotationsItem("service.alpha.kubernetes.io/tolerate-unready-endpoints", "true");
7777

7878
Map<String, String> labels = new HashMap<>();
79+
labels.put(LabelConstants.RESOURCE_VERSION_LABEL, VersionConstants.DOMAIN_V1);
7980
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
8081
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
8182
labels.put(LabelConstants.SERVERNAME_LABEL, serverName);
@@ -252,9 +253,8 @@ public NextAction apply(Packet packet) {
252253
metadata.setName(name);
253254
metadata.setNamespace(namespace);
254255

255-
AnnotationHelper.annotateWithFormat(metadata);
256-
257256
Map<String, String> labels = new HashMap<>();
257+
labels.put(LabelConstants.RESOURCE_VERSION_LABEL, VersionConstants.DOMAIN_V1);
258258
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
259259
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
260260
labels.put(LabelConstants.CLUSTERNAME_LABEL, clusterName);
@@ -368,7 +368,7 @@ private static boolean validateCurrentService(V1Service build, V1Service current
368368
V1ServiceSpec buildSpec = build.getSpec();
369369
V1ServiceSpec currentSpec = current.getSpec();
370370

371-
if (!AnnotationHelper.checkFormatAnnotation(current.getMetadata())) {
371+
if (!VersionHelper.matchesResourceVersion(current.getMetadata(), LabelConstants.RESOURCE_VERSION_LABEL)) {
372372
return false;
373373
}
374374

@@ -520,10 +520,9 @@ public NextAction apply(Packet packet) {
520520
V1ObjectMeta metadata = new V1ObjectMeta();
521521
metadata.setName(name);
522522
metadata.setNamespace(namespace);
523-
524-
AnnotationHelper.annotateWithFormat(metadata);
525523

526524
Map<String, String> labels = new HashMap<>();
525+
labels.put(LabelConstants.RESOURCE_VERSION_LABEL, VersionConstants.DOMAIN_V1);
527526
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
528527
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
529528
labels.put(LabelConstants.SERVERNAME_LABEL, serverName);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator.helpers;
5+
6+
import java.util.Map;
7+
8+
import io.kubernetes.client.models.V1ObjectMeta;
9+
import oracle.kubernetes.operator.LabelConstants;
10+
11+
/**
12+
* Helper methods for managing versions.
13+
*
14+
*/
15+
public class VersionHelper {
16+
/**
17+
* Determines whether a resource matches a version
18+
* @param meta Metadata
19+
* @param resourceVersion resource version
20+
*/
21+
public static boolean matchesResourceVersion(V1ObjectMeta meta, String resourceVersion) {
22+
if (meta == null) {
23+
return false;
24+
}
25+
Map<String,String> labels = meta.getLabels();
26+
if (labels == null) {
27+
return false;
28+
}
29+
String val = labels.get(LabelConstants.RESOURCE_VERSION_LABEL);
30+
if (val == null) {
31+
return false;
32+
}
33+
return val.equals(resourceVersion);
34+
}
35+
}

operator/src/test/java/oracle/kubernetes/operator/create/ConfigMapHelperConfigTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ private V1ConfigMap getDesiredDomainConfigMap() {
5858
.namespace(DOMAIN_NAMESPACE)
5959
.putLabelsItem(RESOURCE_VERSION_LABEL, DOMAIN_V1)
6060
.putLabelsItem(OPERATORNAME_LABEL, OPERATOR_NAMESPACE)
61-
.putLabelsItem(CREATEDBYOPERATOR_LABEL, "true")
62-
.putAnnotationsItem(FORMAT_ANNOTATION, FORMAT_VERSION))
61+
.putLabelsItem(CREATEDBYOPERATOR_LABEL, "true"))
6362
.putDataItem(PROPERTY_LIVENESS_PROBE_SH, "")
6463
.putDataItem(PROPERTY_READINESS_PROBE_SH, "")
6564
.putDataItem(PROPERTY_READ_STATE_SH, "")

operator/src/test/java/oracle/kubernetes/operator/create/PodHelperConfigTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ private V1Pod getDesiredBaseServerPodConfigForDefaults(String image, String imag
426426
.putAnnotationsItem("prometheus.io/path", "/wls-exporter/metrics")
427427
.putAnnotationsItem("prometheus.io/port", "" + port)
428428
.putAnnotationsItem("prometheus.io/scrape", "true")
429-
.putAnnotationsItem("weblogic.oracle/operator-formatVersion", "1")
430429
.putLabelsItem(RESOURCE_VERSION_LABEL, DOMAIN_V1)
431430
.putLabelsItem(CREATEDBYOPERATOR_LABEL, "true")
432431
.putLabelsItem(DOMAINNAME_LABEL, DOMAIN_NAME)

0 commit comments

Comments
 (0)