Skip to content

Commit 0ef8f02

Browse files
authored
Merge pull request #550 from oracle/owls-69919-domain-resource-properties
Owls 69919 domain resource properties
2 parents 18185ea + d4e643e commit 0ef8f02

File tree

6 files changed

+124
-9
lines changed

6 files changed

+124
-9
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/DomainConfigurator.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected DomainConfigurator(Domain domain) {
3737
/**
3838
* Sets the home for the domain.
3939
*
40-
* @param home the home of the domain
40+
* @param domainHome the home of the domain
4141
* @return this object
4242
*/
4343
public DomainConfigurator withDomainHome(String domainHome) {
@@ -46,7 +46,7 @@ public DomainConfigurator withDomainHome(String domainHome) {
4646
}
4747

4848
/**
49-
* @param homeInImage
49+
* @param domainHomeInImage
5050
* @return
5151
*/
5252
public DomainConfigurator withDomainHomeInImage(boolean domainHomeInImage) {
@@ -110,6 +110,28 @@ public DomainConfigurator withDefaultImagePullSecrets(
110110
return this;
111111
}
112112

113+
/**
114+
* Sets the log home value
115+
*
116+
* @param logHome the log home value
117+
* @return this object
118+
*/
119+
public DomainConfigurator withLogHome(String logHome) {
120+
getDomainSpec().setLogHome(logHome);
121+
return this;
122+
}
123+
124+
/**
125+
* Sets the log home enabled flag
126+
*
127+
* @param logHomeEnabled true if log home is enabled, false otherwise
128+
* @return this object
129+
*/
130+
public DomainConfigurator withLogHomeEnabled(boolean logHomeEnabled) {
131+
getDomainSpec().setLogHomeEnabled(logHomeEnabled);
132+
return this;
133+
}
134+
113135
/**
114136
* Configures the domain to use a persistent volume claim defined before the domain is created.
115137
*

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class DomainSpec extends BaseConfiguration {
3434
/** The pattern for computing the default persistent volume claim name. */
3535
private static final String PVC_NAME_PATTERN = "%s-weblogic-domain-pvc";
3636

37+
/** The pattern for computing the default shared logs directory. */
38+
private static final String LOG_HOME_DEFAULT_PATTERN = "/shared/logs/%s";
39+
3740
/** Domain unique identifier. Must be unique across the Kubernetes cluster. (Required) */
3841
@SerializedName("domainUID")
3942
@Expose
@@ -95,6 +98,19 @@ public class DomainSpec extends BaseConfiguration {
9598
@Expose
9699
private String logHome;
97100

101+
/**
102+
* Whether the log home is enabled.
103+
*
104+
* @since 2.0
105+
*/
106+
@SerializedName("logHomeEnabled")
107+
@Expose
108+
@Description(
109+
"Specified whether the log home folder is enabled (Not required). "
110+
+ "Defaults to true if domainHomeInImage is false. "
111+
+ "Defaults to false if domainHomeInImage is true. ")
112+
private Boolean logHomeEnabled; // Boolean object, null if unspecified
113+
98114
/** Whether to include the server .out file to the pod's stdout. Default is true. */
99115
@SerializedName("includeServerOutInPodLog")
100116
@Expose
@@ -157,7 +173,9 @@ public class DomainSpec extends BaseConfiguration {
157173
*/
158174
@SerializedName("domainHomeInImage")
159175
@Expose
160-
private boolean domainHomeInImage;
176+
@Description(
177+
"Flag indicating whether the domain home is part of the image. Default value is true. ")
178+
private boolean domainHomeInImage = true;
161179

162180
/** The definition of the storage used for this domain. */
163181
@SerializedName("storage")
@@ -461,7 +479,7 @@ public void setImagePullSecrets(@Nullable List<V1LocalObjectReference> imagePull
461479
* server .out files in.
462480
*/
463481
public String getLogHome() {
464-
return logHome;
482+
return Optional.ofNullable(logHome).orElse(String.format(LOG_HOME_DEFAULT_PATTERN, domainUID));
465483
}
466484

467485
public void setLogHome(String logHome) {
@@ -473,6 +491,29 @@ public DomainSpec withLogHome(String logHome) {
473491
return this;
474492
}
475493

494+
/**
495+
* Log home enabled
496+
*
497+
* @since 2.0
498+
* @return log home enabled
499+
*/
500+
public boolean getLogHomeEnabled() {
501+
if (logHomeEnabled == null) {
502+
return !isDomainHomeInImage();
503+
}
504+
return logHomeEnabled.booleanValue();
505+
}
506+
507+
/**
508+
* Log home enabled
509+
*
510+
* @since 2.0
511+
* @param logHomeEnabled log home enabled
512+
*/
513+
public void setLogHomeEnabled(boolean logHomeEnabled) {
514+
this.logHomeEnabled = new Boolean(logHomeEnabled);
515+
}
516+
476517
/**
477518
* Whether to include server .out to the pod's stdout
478519
*
@@ -641,6 +682,7 @@ public String toString() {
641682
.append("clusters", clusters)
642683
.append("replicas", replicas)
643684
.append("logHome", logHome)
685+
.append("logHomeEnabled", logHomeEnabled)
644686
.append("includeServerOutInPodLog", includeServerOutInPodLog)
645687
.append("configOverrides", configOverrides)
646688
.append("configOverrideSecrets", configOverrideSecrets);
@@ -669,6 +711,7 @@ public int hashCode() {
669711
.append(clusters)
670712
.append(replicas)
671713
.append(logHome)
714+
.append(logHomeEnabled)
672715
.append(includeServerOutInPodLog)
673716
.append(configOverrides)
674717
.append(configOverrideSecrets);
@@ -701,6 +744,7 @@ public boolean equals(Object other) {
701744
.append(clusters, rhs.clusters)
702745
.append(replicas, rhs.replicas)
703746
.append(logHome, rhs.logHome)
747+
.append(logHomeEnabled, rhs.logHomeEnabled)
704748
.append(includeServerOutInPodLog, rhs.includeServerOutInPodLog)
705749
.append(configOverrides, rhs.configOverrides)
706750
.append(configOverrideSecrets, rhs.configOverrideSecrets);

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Test.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,55 @@ public void whenDuplicateVolumeMountsConfiguredOnMultipleLevels_useCombination()
12371237
volumeMount("name3", "/server-test1")));
12381238
}
12391239

1240+
@Test
1241+
public void whenDefaultConfiguration_domainHomeInImage() {
1242+
configureDomain(domain);
1243+
1244+
assertThat(domain.getSpec().isDomainHomeInImage(), is(true));
1245+
}
1246+
1247+
@Test
1248+
public void whenDomainHomeInImageSpecified_useValue() {
1249+
configureDomain(domain).withDomainHomeInImage(false);
1250+
1251+
assertThat(domain.getSpec().isDomainHomeInImage(), is(false));
1252+
}
1253+
1254+
@Test
1255+
public void whenLogHomeNotSet_useDefault() {
1256+
configureDomain(domain);
1257+
1258+
assertThat(domain.getSpec().getLogHome(), equalTo("/shared/logs/uid1"));
1259+
}
1260+
1261+
@Test
1262+
public void whenLogHomeSet_useValue() {
1263+
configureDomain(domain).withLogHome("/custom/logs");
1264+
1265+
assertThat(domain.getSpec().getLogHome(), equalTo("/custom/logs"));
1266+
}
1267+
1268+
@Test
1269+
public void whenDomainHomeInImage_logHomeNotEnabled() {
1270+
configureDomain(domain).withDomainHomeInImage(true);
1271+
1272+
assertThat(domain.getSpec().getLogHomeEnabled(), is(false));
1273+
}
1274+
1275+
@Test
1276+
public void whenDomainHomeNotInImage_logHomeEnabled() {
1277+
configureDomain(domain).withDomainHomeInImage(false);
1278+
1279+
assertThat(domain.getSpec().getLogHomeEnabled(), is(true));
1280+
}
1281+
1282+
@Test
1283+
public void whenLogHomeEnabledSet_useValue() {
1284+
configureDomain(domain).withLogHomeEnabled(true);
1285+
1286+
assertThat(domain.getSpec().getLogHomeEnabled(), is(true));
1287+
}
1288+
12401289
@Test
12411290
public void domainHomeTest_standardHome2() {
12421291
configureDomain(domain).withDomainHomeInImage(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void whenDomainHasEnvironmentItemsWithVariables_createAdminPodStartupWith
254254
assertThat(
255255
getCreatedPodSpecContainer().getEnv(),
256256
allOf(
257-
hasEnvVar("item1", "find uid1 at /shared/domains/uid1"),
257+
hasEnvVar("item1", "find uid1 at /shared/domain"),
258258
hasEnvVar("item2", "ADMIN_SERVER is ADMIN_SERVER:7001")));
259259
}
260260

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ManagedPodHelperTest extends PodHelperTestBase {
4646
private static final String VALUE1 = "value1";
4747
private static final String VALUE2 = "value2";
4848
private static final String RAW_VALUE_1 = "find uid1 at $(DOMAIN_HOME)";
49-
private static final String END_VALUE_1 = "find uid1 at /shared/domains/uid1";
49+
private static final String END_VALUE_1 = "find uid1 at /shared/domain";
5050
private static final String RAW_VALUE_2 = "$(SERVER_NAME) is not $(ADMIN_NAME):$(ADMIN_PORT)";
5151
private static final String END_VALUE_2 = "ms1 is not ADMIN_SERVER:7001";
5252
private static final String CLUSTER_NAME = "test-cluster";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void whenPodCreated_hasPredefinedEnvVariables() {
348348
getCreatedPodSpecContainer().getEnv(),
349349
allOf(
350350
hasEnvVar("DOMAIN_NAME", DOMAIN_NAME),
351-
hasEnvVar("DOMAIN_HOME", "/shared/domains/" + UID),
351+
hasEnvVar("DOMAIN_HOME", "/shared/domain"),
352352
hasEnvVar("ADMIN_NAME", ADMIN_SERVER),
353353
hasEnvVar("ADMIN_PORT", Integer.toString(ADMIN_PORT)),
354354
hasEnvVar("SERVER_NAME", getServerName()),
@@ -586,7 +586,7 @@ V1ObjectMeta createPodMetadata() {
586586
.putLabelsItem(RESOURCE_VERSION_LABEL, VersionConstants.DEFAULT_DOMAIN_VERSION)
587587
.putLabelsItem(LabelConstants.DOMAINUID_LABEL, UID)
588588
.putLabelsItem(LabelConstants.DOMAINNAME_LABEL, DOMAIN_NAME)
589-
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/shared/domains/" + UID)
589+
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/shared/domain")
590590
.putLabelsItem(LabelConstants.SERVERNAME_LABEL, getServerName())
591591
.putLabelsItem(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
592592
}
@@ -612,7 +612,7 @@ V1Container createPodSpecContainer() {
612612
.readOnly(true))
613613
.command(createStartCommand())
614614
.addEnvItem(envItem("DOMAIN_NAME", DOMAIN_NAME))
615-
.addEnvItem(envItem("DOMAIN_HOME", "/shared/domains/" + UID))
615+
.addEnvItem(envItem("DOMAIN_HOME", "/shared/domain"))
616616
.addEnvItem(envItem("ADMIN_NAME", ADMIN_SERVER))
617617
.addEnvItem(envItem("ADMIN_PORT", Integer.toString(ADMIN_PORT)))
618618
.addEnvItem(envItem("SERVER_NAME", getServerName()))

0 commit comments

Comments
 (0)