Skip to content

Commit 32e3c3e

Browse files
committed
Add schema to CRD
1 parent b5d5846 commit 32e3c3e

File tree

10 files changed

+125
-170
lines changed

10 files changed

+125
-170
lines changed

model/src/main/java/oracle/kubernetes/operator/KubernetesConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface KubernetesConstants {
2525
String DOMAIN_SINGULAR = "domain";
2626
String DOMAIN_SHORT = "dom";
2727

28-
String DEFAULT_INCLUDE_SERVER_OUT_IN_POD_LOG = "true";
28+
boolean DEFAULT_INCLUDE_SERVER_OUT_IN_POD_LOG = true;
2929

3030
String CONTAINER_NAME = "weblogic-server";
3131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public String getLogHome() {
314314
return spec.getLogHome();
315315
}
316316

317-
public String getIncludeServerOutInPodLog() {
317+
public boolean isIncludeServerOutInPodLog() {
318318
return spec.getIncludeServerOutInPodLog();
319319
}
320320

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

Lines changed: 23 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,19 @@
1010
import com.google.gson.annotations.SerializedName;
1111
import io.kubernetes.client.models.V1LocalObjectReference;
1212
import io.kubernetes.client.models.V1SecretReference;
13-
import java.util.Collections;
14-
import java.util.HashMap;
15-
import java.util.List;
16-
import java.util.Map;
17-
import java.util.Optional;
13+
import java.util.*;
1814
import javax.annotation.Nonnull;
1915
import javax.annotation.Nullable;
2016
import javax.validation.Valid;
2117
import javax.validation.constraints.NotNull;
2218
import oracle.kubernetes.json.Description;
2319
import oracle.kubernetes.operator.KubernetesConstants;
24-
import oracle.kubernetes.operator.VersionConstants;
2520
import oracle.kubernetes.weblogic.domain.EffectiveConfigurationFactory;
2621
import org.apache.commons.lang3.builder.EqualsBuilder;
2722
import org.apache.commons.lang3.builder.HashCodeBuilder;
2823
import org.apache.commons.lang3.builder.ToStringBuilder;
2924

3025
/** DomainSpec is a description of a domain. */
31-
@SuppressWarnings("NullableProblems")
3226
public class DomainSpec extends BaseConfiguration {
3327

3428
/** The pattern for computing the default persistent volume claim name. */
@@ -114,7 +108,8 @@ public class DomainSpec extends BaseConfiguration {
114108
/** Whether to include the server .out file to the pod's stdout. Default is true. */
115109
@SerializedName("includeServerOutInPodLog")
116110
@Expose
117-
private String includeServerOutInPodLog;
111+
@Description("If true (the default), the server .out file will be included in the pod's stdout")
112+
private Boolean includeServerOutInPodLog;
118113

119114
/**
120115
* The WebLogic Docker image.
@@ -175,7 +170,7 @@ public class DomainSpec extends BaseConfiguration {
175170
@Expose
176171
@Description(
177172
"Flag indicating whether the domain home is part of the image. Default value is true. ")
178-
private boolean domainHomeInImage = true;
173+
private Boolean domainHomeInImage;
179174

180175
/** The definition of the storage used for this domain. */
181176
@SerializedName("storage")
@@ -236,7 +231,7 @@ public class DomainSpec extends BaseConfiguration {
236231
@Description("Configuration for the clusters")
237232
protected Map<String, Cluster> clusters = new HashMap<>();
238233

239-
public AdminServer getOrCreateAdminServer(String adminServerName) {
234+
AdminServer getOrCreateAdminServer(String adminServerName) {
240235
if (adminServer != null) return adminServer;
241236

242237
return createAdminServer(adminServerName);
@@ -249,14 +244,11 @@ private AdminServer createAdminServer(String adminServerName) {
249244
return adminServer;
250245
}
251246

247+
@SuppressWarnings("unused")
252248
EffectiveConfigurationFactory getEffectiveConfigurationFactory(String resourceVersionLabel) {
253249
return new V2EffectiveConfigurationFactory();
254250
}
255251

256-
private boolean isVersion2Specified(String resourceVersionLabel) {
257-
return VersionConstants.DOMAIN_V2.equals(resourceVersionLabel);
258-
}
259-
260252
/**
261253
* Domain unique identifier. Must be unique across the Kubernetes cluster. (Required)
262254
*
@@ -321,7 +313,7 @@ public DomainSpec withDomainName(String domainName) {
321313
* @since 2.0
322314
* @return domain home
323315
*/
324-
public String getDomainHome() {
316+
String getDomainHome() {
325317
return domainHome;
326318
}
327319

@@ -346,33 +338,6 @@ public DomainSpec withImage(String image) {
346338
return this;
347339
}
348340

349-
/**
350-
* The image pull policy for the WebLogic Docker image. Legal values are Always, Never and
351-
* IfNotPresent.
352-
*
353-
* <p>Defaults to Always if image ends in :latest, IfNotPresent otherwise.
354-
*
355-
* <p>More info: https://kubernetes.io/docs/concepts/containers/images#updating-images
356-
*
357-
* @param imagePullPolicy image pull policy
358-
* @return this
359-
*/
360-
public DomainSpec withImagePullPolicy(String imagePullPolicy) {
361-
setImagePullPolicy(imagePullPolicy);
362-
return this;
363-
}
364-
365-
/**
366-
* The name of the secret used to authenticate a request for an image pull.
367-
*
368-
* <p>More info:
369-
* https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
370-
*/
371-
public DomainSpec withImagePullSecretName(String imagePullSecretName) {
372-
setImagePullSecret(new V1LocalObjectReference().name(imagePullSecretName));
373-
return this;
374-
}
375-
376341
public V1SecretReference getAdminSecret() {
377342
return adminSecret;
378343
}
@@ -398,7 +363,7 @@ public String getAsName() {
398363
return asName;
399364
}
400365

401-
public void setAsName(String asName) {
366+
private void setAsName(String asName) {
402367
this.asName = asName;
403368
}
404369

@@ -486,11 +451,6 @@ public void setLogHome(String logHome) {
486451
this.logHome = logHome;
487452
}
488453

489-
public DomainSpec withLogHome(String logHome) {
490-
this.logHome = logHome;
491-
return this;
492-
}
493-
494454
/**
495455
* Log home enabled
496456
*
@@ -520,20 +480,12 @@ public void setLogHomeEnabled(boolean logHomeEnabled) {
520480
* @return whether server .out should be included in pod's stdout.
521481
* @since 2.0
522482
*/
523-
public String getIncludeServerOutInPodLog() {
524-
return Optional.ofNullable(getConfiguredIncludeServerOutInPodLog())
483+
boolean getIncludeServerOutInPodLog() {
484+
return Optional.ofNullable(includeServerOutInPodLog)
525485
.orElse(KubernetesConstants.DEFAULT_INCLUDE_SERVER_OUT_IN_POD_LOG);
526486
}
527487

528-
String getConfiguredIncludeServerOutInPodLog() {
529-
return includeServerOutInPodLog;
530-
}
531-
532-
public void setIncludeServerOutInPodLog(String includeServerOutInPodLog) {
533-
this.includeServerOutInPodLog = includeServerOutInPodLog;
534-
}
535-
536-
public DomainSpec withIncludeServerOutInPodLog(String includeServerOutInPodLog) {
488+
public DomainSpec withIncludeServerOutInPodLog(boolean includeServerOutInPodLog) {
537489
this.includeServerOutInPodLog = includeServerOutInPodLog;
538490
return this;
539491
}
@@ -544,26 +496,17 @@ public DomainSpec withIncludeServerOutInPodLog(String includeServerOutInPodLog)
544496
* @return true or false
545497
* @since 2.0
546498
*/
547-
public boolean isDomainHomeInImage() {
548-
return domainHomeInImage;
549-
}
550-
551-
/** @param domainHomeInImage */
552-
public void setDomainHomeInImage(boolean domainHomeInImage) {
553-
this.domainHomeInImage = domainHomeInImage;
499+
boolean isDomainHomeInImage() {
500+
return Optional.ofNullable(domainHomeInImage).orElse(true);
554501
}
555502

556503
/**
557-
* Replicas is the desired number of managed servers running in each WebLogic cluster that is not
558-
* configured in clusters. Provided so that administrators can scale the Domain resource.
504+
* Specifies whether the domain home is stored in the image
559505
*
560-
* @deprecated use {@link Domain#getReplicaCount(String)} to obtain the effective setting.
561-
* @return replicas
506+
* @param domainHomeInImage true if the domain home is in the image
562507
*/
563-
@SuppressWarnings("DeprecatedIsStillUsed")
564-
@Deprecated
565-
public Integer getReplicas() {
566-
return replicas != null ? replicas : 0;
508+
public void setDomainHomeInImage(boolean domainHomeInImage) {
509+
this.domainHomeInImage = domainHomeInImage;
567510
}
568511

569512
/**
@@ -572,7 +515,6 @@ public Integer getReplicas() {
572515
*
573516
* @param replicas replicas
574517
*/
575-
@SuppressWarnings("deprecation")
576518
public void setReplicas(Integer replicas) {
577519
this.replicas = replicas;
578520
}
@@ -584,7 +526,6 @@ public void setReplicas(Integer replicas) {
584526
* @param replicas replicas
585527
* @return this
586528
*/
587-
@SuppressWarnings("deprecation")
588529
public DomainSpec withReplicas(Integer replicas) {
589530
this.replicas = replicas;
590531
return this;
@@ -609,11 +550,11 @@ public DomainStorage getStorage() {
609550
}
610551

611552
@Nullable
612-
public String getConfigOverrides() {
553+
String getConfigOverrides() {
613554
return configOverrides;
614555
}
615556

616-
public void setConfigOverrides(@Nullable String overridess) {
557+
void setConfigOverrides(@Nullable String overridess) {
617558
this.configOverrides = overridess;
618559
}
619560

@@ -627,7 +568,7 @@ private boolean hasConfigOverrideSecrets() {
627568
}
628569

629570
@Nullable
630-
public List<String> getConfigOverrideSecrets() {
571+
List<String> getConfigOverrideSecrets() {
631572
if (hasConfigOverrideSecrets()) return configOverrideSecrets;
632573
else return Collections.emptyList();
633574
}
@@ -636,11 +577,6 @@ public void setConfigOverrideSecrets(@Nullable List<String> overridesSecretNames
636577
this.configOverrideSecrets = overridesSecretNames;
637578
}
638579

639-
public DomainSpec withConfigOverrideSecrets(@Nullable List<String> overridesSecretNames) {
640-
this.configOverrideSecrets = overridesSecretNames;
641-
return this;
642-
}
643-
644580
/**
645581
* Returns the name of the persistent volume claim for the logs and PV-based domain.
646582
*
@@ -770,15 +706,15 @@ private boolean hasReplicaCount(Cluster cluster) {
770706
return cluster != null && cluster.getReplicas() != null;
771707
}
772708

773-
public AdminServer getAdminServer() {
709+
private AdminServer getAdminServer() {
774710
return Optional.ofNullable(adminServer).orElse(AdminServer.NULL_ADMIN_SERVER);
775711
}
776712

777-
public void setAdminServer(AdminServer adminServer) {
713+
private void setAdminServer(AdminServer adminServer) {
778714
this.adminServer = adminServer;
779715
}
780716

781-
public Map<String, ManagedServer> getManagedServers() {
717+
Map<String, ManagedServer> getManagedServers() {
782718
return managedServers;
783719
}
784720

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,13 @@
99
import static oracle.kubernetes.operator.KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY;
1010
import static oracle.kubernetes.weblogic.domain.v2.ConfigurationConstants.START_ALWAYS;
1111
import static oracle.kubernetes.weblogic.domain.v2.ConfigurationConstants.START_NEVER;
12-
import static org.hamcrest.Matchers.contains;
13-
import static org.hamcrest.Matchers.containsInAnyOrder;
14-
import static org.hamcrest.Matchers.empty;
15-
import static org.hamcrest.Matchers.equalTo;
16-
import static org.hamcrest.Matchers.hasEntry;
17-
import static org.hamcrest.Matchers.hasItem;
18-
import static org.hamcrest.Matchers.not;
19-
import static org.hamcrest.Matchers.nullValue;
12+
import static org.hamcrest.Matchers.*;
2013
import static org.hamcrest.core.Is.is;
2114
import static org.junit.Assert.assertThat;
2215

2316
import com.google.gson.GsonBuilder;
2417
import io.kubernetes.client.custom.Quantity;
25-
import io.kubernetes.client.models.V1Capabilities;
26-
import io.kubernetes.client.models.V1EnvVar;
27-
import io.kubernetes.client.models.V1HostPathVolumeSource;
28-
import io.kubernetes.client.models.V1PodSecurityContext;
29-
import io.kubernetes.client.models.V1ResourceRequirements;
30-
import io.kubernetes.client.models.V1SELinuxOptions;
31-
import io.kubernetes.client.models.V1SecurityContext;
32-
import io.kubernetes.client.models.V1Sysctl;
33-
import io.kubernetes.client.models.V1Volume;
34-
import io.kubernetes.client.models.V1VolumeMount;
18+
import io.kubernetes.client.models.*;
3519
import java.io.IOException;
3620
import java.util.Map;
3721
import oracle.kubernetes.weblogic.domain.AdminServerConfigurator;
@@ -805,6 +789,34 @@ public void whenDomainReadFromYaml_unconfiguredServerHasDomainDefaults() throws
805789
assertThat(serverSpec.shouldStart(1), is(true));
806790
}
807791

792+
@Test
793+
public void whenDomainReadFromYamlWithNoSetting_defaultsToDomainHomeInImage() throws IOException {
794+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML);
795+
796+
assertThat(domain.isDomainHomeInImage(), is(true));
797+
}
798+
799+
@Test
800+
public void whenDomainReadFromYaml_domainHomeInImageIsDisabled() throws IOException {
801+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML_2);
802+
803+
assertThat(domain.isDomainHomeInImage(), is(false));
804+
}
805+
806+
@Test
807+
public void whenDomainReadFromYamlWithNoSetting_defaultsToServerOutInPodLog() throws IOException {
808+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML);
809+
810+
assertThat(domain.isIncludeServerOutInPodLog(), is(true));
811+
}
812+
813+
@Test
814+
public void whenDomainReadFromYaml_serverOutInPodLogIsSet() throws IOException {
815+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML_2);
816+
817+
assertThat(domain.isIncludeServerOutInPodLog(), is(false));
818+
}
819+
808820
@Test
809821
public void whenDomainReadFromYaml_unconfiguredClusteredServerHasDomainDefaults()
810822
throws IOException {
@@ -1238,7 +1250,7 @@ public void whenDuplicateVolumeMountsConfiguredOnMultipleLevels_useCombination()
12381250
}
12391251

12401252
@Test
1241-
public void whenDefaultConfiguration_domainHomeInImage() {
1253+
public void whenDefaultConfiguration_domainHomeInImageIsTrue() {
12421254
configureDomain(domain);
12431255

12441256
assertThat(domain.getSpec().isDomainHomeInImage(), is(true));

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample-2.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ spec:
3030
# to be started to get to the cluster's replica count..
3131
serverStartPolicy: NEVER
3232

33+
domainHomeInImage: false
34+
includeServerOutInPodLog: false
35+
3336
# Specifies the number of replicas for any clusters which do not specify their own count:
3437
replicas: 3
3538

0 commit comments

Comments
 (0)