Skip to content

Commit 6ee4147

Browse files
authored
OWLS-103645 - Add domain and cluster 4.0 'observedGeneration' to pod labels. (#3648)
* OWLS-103645 - Add domain and cluster 4.0 'observedGeneration' to pod labels.
1 parent 493c7f8 commit 6ee4147

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

operator/src/main/java/oracle/kubernetes/operator/LabelConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface LabelConstants {
2525
String MII_UPDATED_RESTART_REQUIRED_LABEL = "weblogic.configChangesPendingRestart";
2626
String INTROSPECTION_DOMAIN_SPEC_GENERATION = "weblogic.domainSpecGeneration";
2727
String TO_BE_ROLLED_LABEL = "weblogic.awaitingPodRoll";
28+
String DOMAIN_OBSERVED_GENERATION_LABEL = "weblogic.domainObservedGeneration";
29+
String CLUSTER_OBSERVED_GENERATION_LABEL = "weblogic.clusterObservedGeneration";
2830

2931
static String forDomainUidSelector(String uid) {
3032
return String.format("%s=%s", DOMAINUID_LABEL, uid);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import oracle.kubernetes.operator.work.Packet;
7474
import oracle.kubernetes.operator.work.Step;
7575
import oracle.kubernetes.weblogic.domain.model.AuxiliaryImage;
76+
import oracle.kubernetes.weblogic.domain.model.ClusterResource;
7677
import oracle.kubernetes.weblogic.domain.model.DomainResource;
7778
import oracle.kubernetes.weblogic.domain.model.IntrospectorJobEnvVars;
7879
import oracle.kubernetes.weblogic.domain.model.MonitoringExporterSpecification;
@@ -90,6 +91,8 @@
9091
import static oracle.kubernetes.operator.KubernetesConstants.DEFAULT_EXPORTER_SIDECAR_PORT;
9192
import static oracle.kubernetes.operator.KubernetesConstants.EXPORTER_CONTAINER_NAME;
9293
import static oracle.kubernetes.operator.KubernetesConstants.HTTP_NOT_FOUND;
94+
import static oracle.kubernetes.operator.LabelConstants.CLUSTER_OBSERVED_GENERATION_LABEL;
95+
import static oracle.kubernetes.operator.LabelConstants.DOMAIN_OBSERVED_GENERATION_LABEL;
9396
import static oracle.kubernetes.operator.LabelConstants.INTROSPECTION_STATE_LABEL;
9497
import static oracle.kubernetes.operator.LabelConstants.MII_UPDATED_RESTART_REQUIRED_LABEL;
9598
import static oracle.kubernetes.operator.LabelConstants.MODEL_IN_IMAGE_DOMAINZIP_HASH;
@@ -147,8 +150,9 @@ private static boolean isPatchableItem(Map.Entry<String, String> entry) {
147150
return isCustomerItem(entry) || PATCHABLE_OPERATOR_KEYS.contains(entry.getKey());
148151
}
149152

150-
private static final Set<String> PATCHABLE_OPERATOR_KEYS
151-
= Set.of(INTROSPECTION_STATE_LABEL, OPERATOR_VERSION, MODEL_IN_IMAGE_DOMAINZIP_HASH, SHA256_ANNOTATION);
153+
private static final Set<String> PATCHABLE_OPERATOR_KEYS = Set.of(INTROSPECTION_STATE_LABEL, OPERATOR_VERSION,
154+
MODEL_IN_IMAGE_DOMAINZIP_HASH, SHA256_ANNOTATION, DOMAIN_OBSERVED_GENERATION_LABEL,
155+
CLUSTER_OBSERVED_GENERATION_LABEL);
152156

153157
private static boolean isCustomerItem(Map.Entry<String, String> entry) {
154158
return !entry.getKey().startsWith("weblogic.");
@@ -214,6 +218,10 @@ DomainResource getDomain() {
214218
return info.getDomain();
215219
}
216220

221+
ClusterResource getCluster(String clusterName) {
222+
return info.getClusterResource(clusterName);
223+
}
224+
217225
private String getDomainName() {
218226
return domainTopology.getName();
219227
}
@@ -443,6 +451,10 @@ private Map<String, String> getNonHashedPodLabels() {
443451
.ifPresent(version -> result.put(INTROSPECTION_STATE_LABEL, version));
444452
Optional.ofNullable(productVersion)
445453
.ifPresent(pv -> result.put(LabelConstants.OPERATOR_VERSION, pv));
454+
Optional.ofNullable(getDomain().getMetadata()).map(V1ObjectMeta::getGeneration)
455+
.ifPresent(generation -> result.put(DOMAIN_OBSERVED_GENERATION_LABEL, String.valueOf(generation)));
456+
Optional.ofNullable(getCluster(getClusterName())).map(ClusterResource::getMetadata).map(V1ObjectMeta::getGeneration)
457+
.ifPresent(generation -> result.put(CLUSTER_OBSERVED_GENERATION_LABEL, String.valueOf(generation)));
446458

447459
if (addRestartRequiredLabel) {
448460
result.put(MII_UPDATED_RESTART_REQUIRED_LABEL, "true");

operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@
119119
import static oracle.kubernetes.operator.KubernetesConstants.HTTP_NOT_FOUND;
120120
import static oracle.kubernetes.operator.KubernetesConstants.HTTP_OK;
121121
import static oracle.kubernetes.operator.LabelConstants.CLUSTERNAME_LABEL;
122+
import static oracle.kubernetes.operator.LabelConstants.CLUSTER_OBSERVED_GENERATION_LABEL;
122123
import static oracle.kubernetes.operator.LabelConstants.CREATEDBYOPERATOR_LABEL;
123124
import static oracle.kubernetes.operator.LabelConstants.DOMAINNAME_LABEL;
124125
import static oracle.kubernetes.operator.LabelConstants.DOMAINUID_LABEL;
126+
import static oracle.kubernetes.operator.LabelConstants.DOMAIN_OBSERVED_GENERATION_LABEL;
125127
import static oracle.kubernetes.operator.LabelConstants.INTROSPECTION_STATE_LABEL;
126128
import static oracle.kubernetes.operator.LabelConstants.SERVERNAME_LABEL;
127129
import static oracle.kubernetes.operator.ProcessingConstants.DOMAIN_INTROSPECTION_COMPLETE;
@@ -486,7 +488,7 @@ void whenDomainConfiguredForMaxServers_establishMatchingPresence() {
486488
}
487489

488490
@Test
489-
void whenMakeRightRun_updateDomainStatus() {
491+
void whenMakeRightRun_updateDomainStatusAndDomainObservedGeneration() {
490492
domainConfigurator.configureCluster(newInfo, CLUSTER).withReplicas(MIN_REPLICAS);
491493
newInfo.getReferencedClusters().forEach(testSupport::defineResources);
492494

@@ -501,10 +503,26 @@ void whenMakeRightRun_updateDomainStatus() {
501503
assertThat(getStateGoal(updatedDomain, MANAGED_SERVER_NAMES[4]), equalTo(SHUTDOWN_STATE));
502504
assertThat(getResourceVersion(updatedDomain), not(getResourceVersion(domain)));
503505
assertThat(updatedDomain.getStatus().getObservedGeneration(), equalTo(2L));
506+
assertThat(getDomainObservedGeneration(ADMIN_NAME), is("2"));
507+
assertThat(getDomainObservedGeneration(getManagedServerName(1)), is("2"));
508+
assertThat(getDomainObservedGeneration(getManagedServerName(2)), is("2"));
509+
}
510+
511+
private String getDomainObservedGeneration(String name) {
512+
return getObservedGeneration(name, "DOMAIN");
513+
}
514+
515+
private String getObservedGeneration(String name, String generationType) {
516+
return generationType.equals("DOMAIN") ? getPodLabels(name).get(DOMAIN_OBSERVED_GENERATION_LABEL)
517+
: getPodLabels(name).get(CLUSTER_OBSERVED_GENERATION_LABEL);
518+
}
519+
520+
private Map<String, String> getPodLabels(String name) {
521+
return testSupport.<V1Pod>getResourceWithName(POD, UID + "-" + name).getMetadata().getLabels();
504522
}
505523

506524
@Test
507-
void whenMakeRightRun_updateClusterResourceStatus() {
525+
void whenMakeRightRun_updateClusterResourceStatusAndClusterObservedGeneration() {
508526
ClusterResource clusterResource = createClusterResource(NS, CLUSTER);
509527
clusterResource.getMetadata().generation(2L);
510528
testSupport.defineResources(clusterResource);
@@ -515,10 +533,12 @@ void whenMakeRightRun_updateClusterResourceStatus() {
515533

516534
ClusterResource updatedClusterResource = testSupport
517535
.getResourceWithName(KubernetesTestSupport.CLUSTER, CLUSTER);
536+
518537
assertThat(updatedClusterResource.getStatus(), notNullValue());
519538
assertThat(updatedClusterResource.getStatus().getMinimumReplicas(), equalTo(0));
520539
assertThat(updatedClusterResource.getStatus().getMaximumReplicas(), equalTo(5));
521540
assertThat(updatedClusterResource.getStatus().getObservedGeneration(), equalTo(2L));
541+
assertThat(getObservedGeneration(getManagedServerName(1), "CLUSTER"), is("2"));
522542
}
523543

524544
@Test

0 commit comments

Comments
 (0)