Skip to content

Commit e86d42b

Browse files
authored
OWLS-99679 - Fix ItKubernetesDomainEvents.testDomainK8sEventsProcessingFailed test failure (#3158)
* restart introspector job if existing job is for a different introspectVersion
1 parent 69afc34 commit e86d42b

File tree

11 files changed

+127
-9
lines changed

11 files changed

+127
-9
lines changed

documentation/domains/Cluster.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@
485485
"type": "string"
486486
},
487487
"introspectVersion": {
488-
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. See also `domains.spec.configuration.overrideDistributionStrategy`.",
488+
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. The introspectVersion value must be a valid label value in Kubernetes. See also `domains.spec.configuration.overrideDistributionStrategy`.",
489489
"type": "string"
490490
},
491491
"dataHome": {

documentation/domains/Domain.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@
485485
"type": "string"
486486
},
487487
"introspectVersion": {
488-
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. See also `domains.spec.configuration.overrideDistributionStrategy`.",
488+
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. The introspectVersion value must be a valid label value in Kubernetes. See also `domains.spec.configuration.overrideDistributionStrategy`.",
489489
"type": "string"
490490
},
491491
"dataHome": {

documentation/domains/Domain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The specification of the operation of the WebLogic domain. Required.
3030
| `imagePullPolicy` | string | The image pull policy for the WebLogic Server image. Legal values are Always, Never, and IfNotPresent. Defaults to Always if image ends in :latest; IfNotPresent, otherwise. |
3131
| `imagePullSecrets` | Array of [Local Object Reference](k8s1.13.5.md#local-object-reference) | A list of image pull Secrets for the WebLogic Server image. |
3232
| `includeServerOutInPodLog` | Boolean | Specifies whether the server .out file will be included in the Pod's log. Defaults to true. |
33-
| `introspectVersion` | string | Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. See also `domains.spec.configuration.overrideDistributionStrategy`. |
33+
| `introspectVersion` | string | Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. The introspectVersion value must be a valid label value in Kubernetes. See also `domains.spec.configuration.overrideDistributionStrategy`. |
3434
| `livenessProbeCustomScript` | string | Full path of an optional liveness probe custom script for WebLogic Server instance pods. The existing liveness probe script `livenessProbe.sh` will invoke this custom script after the existing script performs its own checks. This element is optional and is for advanced usage only. Its value is not set by default. If the custom script fails with non-zero exit status, then pod will fail the liveness probe and Kubernetes will restart the container. If the script specified by this element value is not found, then it is ignored. |
3535
| `logHome` | string | The directory in a server's container in which to store the domain, Node Manager, server logs, server *.out, introspector .out, and optionally HTTP access log files if `httpAccessLogInLogHome` is true. Default is `/shared/logs/DOMAIN-UID`. Ignored if `logHomeEnabled` is false.See also `domains.spec.logHomeLayout`. |
3636
| `logHomeEnabled` | Boolean | Specifies whether the log home folder is enabled. Defaults to true if `domainHomeSourceType` is PersistentVolume; false, otherwise. |

documentation/domains/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@
14061406
"type": "string"
14071407
},
14081408
"introspectVersion": {
1409-
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. See also `domains.spec.configuration.overrideDistributionStrategy`.",
1409+
"description": "Changes to this field cause the operator to repeat its introspection of the WebLogic domain configuration. Repeating introspection is required for the operator to recognize changes to the domain configuration, such as adding a new WebLogic cluster or Managed Server instance, to regenerate configuration overrides, or to regenerate the WebLogic domain home when the `domainHomeSourceType` is FromModel. Introspection occurs automatically, without requiring change to this field, when servers are first started or restarted after a full domain shut down. For the FromModel `domainHomeSourceType`, introspection also occurs when a running server must be restarted because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. The introspectVersion value must be a valid label value in Kubernetes. See also `domains.spec.configuration.overrideDistributionStrategy`.",
14101410
"type": "string"
14111411
},
14121412
"dataHome": {

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIntrospectVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void testDedicatedModeSameNamespaceScale() {
851851
* Update the introspectVersion of the domain resource using lifecycle script.
852852
* Refer to kubernetes/samples/scripts/domain-lifecycle/introspectDomain.sh
853853
* The usecase update the introspectVersion by passing differnt value to -i
854-
* option (non-numeic, non-numeric with space, no value) and make sure that
854+
* option (non-numeic, non-numeric with underscore and dash, no value) and make sure that
855855
* the introspectVersion is updated accrodingly in both domain sepc level
856856
* and server pod level.
857857
* It also verifies the intospector job is started/stoped and none of the
@@ -914,8 +914,8 @@ void testIntrospectDomainScript() {
914914
verifyIntrospectVersionLabelInPod();
915915

916916
// use introspectDomain.sh to initiate introspection
917-
logger.info("Initiate introspection with non numeric string with space");
918-
introspectVersion = "My Version";
917+
logger.info("Initiate introspection with non numeric string with underscore and dash");
918+
introspectVersion = "My_Version-1";
919919
String extraParam2 = " -i " + "\"" + introspectVersion + "\"";
920920
assertDoesNotThrow(() -> executeLifecycleScript(INTROSPECT_DOMAIN_SCRIPT, extraParam2),
921921
String.format("Failed to run %s", INTROSPECT_DOMAIN_SCRIPT));

kubernetes/crd/domain-crd.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: apiextensions.k8s.io/v1
55
kind: CustomResourceDefinition
66
metadata:
77
annotations:
8-
weblogic.sha256: eb697282e8cf67ddf56fa6cc35cf7deb6c572ab1df40e4a4598eaedc1b57c7c3
8+
weblogic.sha256: 9d0b4712b81ed3816329476fb3b035019bed06d60d095b82f2f92de1e417f083
99
name: domains.weblogic.oracle
1010
spec:
1111
group: weblogic.oracle
@@ -6688,6 +6688,7 @@ spec:
66886688
full domain shut down. For the FromModel `domainHomeSourceType`,
66896689
introspection also occurs when a running server must be restarted
66906690
because of changes to any of the fields listed here: https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted.
6691+
The introspectVersion value must be a valid label value in Kubernetes.
66916692
See also `domains.spec.configuration.overrideDistributionStrategy`.'
66926693
type: string
66936694
dataHome:

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ private String jobDescription(@Nonnull V1Job job) {
246246
}
247247

248248
private boolean isInProgressJobOutdated(V1Job job) {
249-
return hasNotCompleted(job) && hasAnyImageChanged(job);
249+
return Optional.ofNullable(job)
250+
.map(j -> hasNotCompleted(j) && (hasAnyImageChanged(j) || hasIntrospectVersionChanged(j)))
251+
.orElse(false);
250252
}
251253

252254
private boolean hasNotCompleted(V1Job job) {
@@ -265,6 +267,11 @@ private boolean hasAuxiliaryImageChanged(@Nonnull V1Job job) {
265267
return ! getSortedJobModelPodSpecAuxiliaryImages().equals(getSortedAuxiliaryImagesFromJob(job));
266268
}
267269

270+
private boolean hasIntrospectVersionChanged(@Nonnull V1Job job) {
271+
return !Objects.equals(getIntrospectVersionLabelFromJob(job),
272+
getIntrospectVersionLabelFromJob(getJobModel()));
273+
}
274+
268275
String getImageFromJob(V1Job job) {
269276
return getPodSpecFromJob(job).map(this::getImageFromPodSpec).orElse(null);
270277
}
@@ -311,6 +318,15 @@ Stream<String> getJobModelPodSpecAuxiliaryImages() {
311318
.orElse(Stream.empty());
312319
}
313320

321+
@Nullable
322+
String getIntrospectVersionLabelFromJob(V1Job job) {
323+
return Optional.ofNullable(job)
324+
.map(V1Job::getMetadata)
325+
.map(V1ObjectMeta::getLabels)
326+
.map(m -> m.get(INTROSPECTION_STATE_LABEL))
327+
.orElse(null);
328+
}
329+
314330
private boolean isKnownFailedJob(V1Job job) {
315331
return getUid(job).equals(getLastFailedUid());
316332
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ private V1ObjectMeta createMetadata() {
326326
new V1ObjectMeta()
327327
.name(getJobName())
328328
.namespace(getNamespace())
329+
.putLabelsItem(LabelConstants.INTROSPECTION_STATE_LABEL, getIntrospectVersionLabel())
329330
.putLabelsItem(LabelConstants.DOMAINUID_LABEL, getDomainUid())
330331
.putLabelsItem(LabelConstants.CREATEDBYOPERATOR_LABEL, "true"));
331332
}
@@ -664,6 +665,10 @@ private String getAsServiceName() {
664665
return LegalNames.toServerServiceName(getDomainUid(), getAsName());
665666
}
666667

668+
private String getIntrospectVersionLabel() {
669+
return Optional.ofNullable(getDomain().getIntrospectVersion()).orElse(null);
670+
}
671+
667672
@Override
668673
List<V1EnvVar> getConfiguredEnvVars() {
669674
// Pod for introspector job would use same environment variables as for admin server

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/DomainSpec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public class DomainSpec extends BaseConfiguration {
292292
+ "server must be restarted because of changes to any of the fields listed here: "
293293
+ "https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/"
294294
+ "domain-lifecycle/startup/#properties-that-cause-servers-to-be-restarted. "
295+
+ "The introspectVersion value must be a valid label value in Kubernetes. "
295296
+ "See also `domains.spec.configuration.overrideDistributionStrategy`.")
296297
private String introspectVersion;
297298

operator/src/test/java/oracle/kubernetes/operator/helpers/DomainIntrospectorJobTest.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ private void definePreviousFailedIntrospectionWithoutPodLog() {
781781
getDomain().getOrCreateStatus().setFailedIntrospectionUid(JOB_UID);
782782
}
783783

784+
private void defineIntrospectionWithIntrospectVersionLabel(String introspectVersion) {
785+
testSupport.defineResources(createIntrospectorJobWithIntrospectVersionLabel(introspectVersion));
786+
}
787+
784788
@Test
785789
void whenPreviousFailedJobExists_deleteIt() {
786790
ignoreJobCreatedAndDeletedLogs();
@@ -989,6 +993,69 @@ void whenJobInProgressWithNonAuxImageInitContainer_doNotCreateNewJob() {
989993
assertThat(affectedJob, nullValue());
990994
}
991995

996+
@Test
997+
void whenJobInProgressAndIntrospectVersionAdded_createNewJob() {
998+
ignoreIntrospectorFailureLogs();
999+
ignoreJobCreatedAndDeletedLogs();
1000+
1001+
getConfigurator().withIntrospectVersion("v2");
1002+
1003+
testSupport.addToPacket(DOMAIN_TOPOLOGY, createDomainConfig("cluster-1"));
1004+
defineIntrospection();
1005+
testSupport.doOnCreate(JOB, this::recordJob);
1006+
1007+
testSupport.runSteps(JobHelper.createIntrospectionStartStep(null));
1008+
1009+
assertThat(affectedJob, notNullValue());
1010+
}
1011+
1012+
@Test
1013+
void whenJobInProgressAndIntrospectVersionChanged_createNewJob() {
1014+
ignoreIntrospectorFailureLogs();
1015+
ignoreJobCreatedAndDeletedLogs();
1016+
1017+
getConfigurator().withIntrospectVersion("v2");
1018+
1019+
testSupport.addToPacket(DOMAIN_TOPOLOGY, createDomainConfig("cluster-1"));
1020+
defineIntrospectionWithIntrospectVersionLabel("v1");
1021+
testSupport.doOnCreate(JOB, this::recordJob);
1022+
1023+
testSupport.runSteps(JobHelper.createIntrospectionStartStep(null));
1024+
1025+
assertThat(affectedJob, notNullValue());
1026+
}
1027+
1028+
@Test
1029+
void whenJobInProgressAndIntrospectVersionUnchanged_doNotCreateNewJob() {
1030+
ignoreIntrospectorFailureLogs();
1031+
ignoreJobCreatedAndDeletedLogs();
1032+
1033+
getConfigurator().withIntrospectVersion("v2");
1034+
1035+
testSupport.addToPacket(DOMAIN_TOPOLOGY, createDomainConfig("cluster-1"));
1036+
defineIntrospectionWithIntrospectVersionLabel("v2");
1037+
testSupport.doOnCreate(JOB, this::recordJob);
1038+
1039+
testSupport.runSteps(JobHelper.createIntrospectionStartStep(null));
1040+
1041+
assertThat(affectedJob, nullValue());
1042+
}
1043+
1044+
@Test
1045+
void whenJobInProgressAndNullIntrospectVersionUnchanged_doNotCreateNewJob() {
1046+
ignoreIntrospectorFailureLogs();
1047+
ignoreJobCreatedAndDeletedLogs();
1048+
1049+
getConfigurator().withIntrospectVersion(null);
1050+
1051+
testSupport.addToPacket(DOMAIN_TOPOLOGY, createDomainConfig("cluster-1"));
1052+
defineIntrospectionWithIntrospectVersionLabel(null);
1053+
testSupport.doOnCreate(JOB, this::recordJob);
1054+
1055+
testSupport.runSteps(JobHelper.createIntrospectionStartStep(null));
1056+
1057+
assertThat(affectedJob, nullValue());
1058+
}
9921059

9931060
private void replaceFailedJobPodWithSuccess() {
9941061
testSupport.deleteResources(createIntrospectorJobPod());
@@ -1186,6 +1253,12 @@ private V1JobSpec createJobSpecWithImage(String image) {
11861253
return new V1JobSpec().template(podTemplateSpec);
11871254
}
11881255

1256+
private V1Job createIntrospectorJobWithIntrospectVersionLabel(String introspectVersion) {
1257+
V1Job job = createIntrospectorJob(UID);
1258+
job.getMetadata().putLabelsItem(LabelConstants.INTROSPECTION_STATE_LABEL, introspectVersion);
1259+
return job;
1260+
}
1261+
11891262
private V1ObjectMeta createJobMetadata(String uid) {
11901263
return new V1ObjectMeta().name(getJobName()).namespace(NS).creationTimestamp(SystemClock.now()).uid(uid);
11911264
}

0 commit comments

Comments
 (0)