Skip to content

Support configurable model home #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/domains/Domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@
"configMap": {
"description": "Name of a ConfigMap containing the WebLogic Deploy Tooling model.",
"type": "string"
},
"modelHome": {
"description": "Location of the WebLogic Deploy Tooling model home. Defaults to /u01/wdt/models.",
"type": "string"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions docs/domains/Domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ The current status of the operation of the WebLogic domain. Updated automaticall
| --- | --- | --- |
| `configMap` | string | Name of a ConfigMap containing the WebLogic Deploy Tooling model. |
| `domainType` | string | WebLogic Deploy Tooling domain type. Legal values: WLS, RestrictedJRF, JRF. Defaults to WLS. |
| `modelHome` | string | Location of the WebLogic Deploy Tooling model home. Defaults to /u01/wdt/models. |
| `runtimeEncryptionSecret` | string | Runtime encryption secret. Required when `domainHomeSourceType` is set to FromModel. |

### Opss
Expand Down
4 changes: 4 additions & 0 deletions docs/domains/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,10 @@
"configMap": {
"description": "Name of a ConfigMap containing the WebLogic Deploy Tooling model.",
"type": "string"
},
"modelHome": {
"description": "Location of the WebLogic Deploy Tooling model home. Defaults to /u01/wdt/models.",
"type": "string"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions kubernetes/crd/domain-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ spec:
type: string
description: Name of a ConfigMap containing the WebLogic Deploy
Tooling model.
modelHome:
type: string
description: Location of the WebLogic Deploy Tooling model
home. Defaults to /u01/wdt/models.
secrets:
type: array
description: A list of names of the Secrets for WebLogic configuration
Expand Down
4 changes: 4 additions & 0 deletions kubernetes/crd/domain-v1beta1-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ spec:
type: string
description: Name of a ConfigMap containing the WebLogic Deploy
Tooling model.
modelHome:
type: string
description: Location of the WebLogic Deploy Tooling model home.
Defaults to /u01/wdt/models.
secrets:
type: array
description: A list of names of the Secrets for WebLogic configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ List<V1EnvVar> getConfiguredEnvVars(TuningParameters tuningParameters) {
addEnvVar(vars, "AS_SERVICE_NAME", getAsServiceName());
}

String modelHome = getModelHome();
if (modelHome != null && !modelHome.isEmpty()) {
addEnvVar(vars, IntrospectorJobEnvVars.WDT_MODEL_HOME, modelHome);
}
return vars;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ protected String getDataHome() {
return dataHome != null && !dataHome.isEmpty() ? dataHome + File.separator + getDomainUid() : null;
}

protected String getModelHome() {
return getDomain().getModelHome();
}

protected String getWdtDomainType() {
return getDomain().getWdtDomainType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public void setModel(Model model) {
this.model = model;
}

public Configuration withModel(Model model) {
this.model = model;
return this;
}

public Opss getOpss() {
return this.opss;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ public List<String> getConfigOverrideSecrets() {
.map(Configuration::getSecrets).orElse(spec.getConfigOverrideSecrets());
}

/**
* Returns the model home directory of the domain.
*
* @return model home directory
*/
public String getModelHome() {
return spec.getModelHome();
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static oracle.kubernetes.operator.KubernetesConstants.DEFAULT_IMAGE;
import static oracle.kubernetes.operator.KubernetesConstants.DEFAULT_MAX_CLUSTER_CONCURRENT_START_UP;
import static oracle.kubernetes.operator.KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY;
import static oracle.kubernetes.weblogic.domain.model.Model.DEFAULT_WDT_MODEL_HOME;

/** DomainSpec is a description of a domain. */
@Description("The specification of the operation of the WebLogic domain. Required.")
Expand Down Expand Up @@ -780,6 +781,16 @@ public String getWdtConfigMap() {
.orElse(null);
}

/**
* Returns the model home directory of the domain.
*
* @return model home directory
*/
public String getModelHome() {
return Optional.ofNullable(configuration)
.map(Configuration::getModel).map(Model::getModelHome).orElse(DEFAULT_WDT_MODEL_HOME);
}

@Override
public String toString() {
ToStringBuilder builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class IntrospectorJobEnvVars {
* Istio pod namespace.
*/
public static final String ISTIO_POD_NAMESPACE = "ISTIO_POD_NAMESPACE";
public static final String WDT_MODEL_HOME = "WDT_MODEL_HOME";

/**
* Returns true if the specified environment variable name is reserved by the operator for communication with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;

public class Model {
static final String DEFAULT_WDT_MODEL_HOME = "/u01/wdt/models";

@EnumClass(value = ModelInImageDomainType.class)
@Description("WebLogic Deploy Tooling domain type. Legal values: WLS, RestrictedJRF, JRF. Defaults to WLS.")
Expand All @@ -22,6 +23,9 @@ public class Model {
@Description("Name of a ConfigMap containing the WebLogic Deploy Tooling model.")
private String configMap;

@Description("Location of the WebLogic Deploy Tooling model home. Defaults to /u01/wdt/models.")
private String modelHome;

@Valid
@Nullable
@Description("Runtime encryption secret. Required when `domainHomeSourceType` is set to FromModel.")
Expand Down Expand Up @@ -68,12 +72,26 @@ public Model withRuntimeEncryptionSecret(String runtimeEncryptionSecret) {
return this;
}

String getModelHome() {
return modelHome;
}

void setModelHome(String modelHome) {
this.modelHome = modelHome;
}

public Model withModelHome(String modelHome) {
this.modelHome = modelHome;
return this;
}

@Override
public String toString() {
ToStringBuilder builder =
new ToStringBuilder(this)
.append("domainType", domainType)
.append("configMap", configMap)
.append("modelHome", modelHome)
.append("runtimeEncryptionSecret", runtimeEncryptionSecret);

return builder.toString();
Expand All @@ -84,6 +102,7 @@ public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder()
.append(domainType)
.append(configMap)
.append(modelHome)
.append(runtimeEncryptionSecret);

return builder.toHashCode();
Expand All @@ -103,6 +122,7 @@ public boolean equals(Object other) {
new EqualsBuilder()
.append(domainType, rhs.domainType)
.append(configMap,rhs.configMap)
.append(modelHome,rhs.modelHome)
.append(runtimeEncryptionSecret, rhs.runtimeEncryptionSecret);

return builder.isEquals();
Expand Down
4 changes: 2 additions & 2 deletions operator/src/main/resources/scripts/modelInImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WDT_CONFIGMAP_ROOT="/weblogic-operator/wdt-config-map"
RUNTIME_ENCRYPTION_SECRET_PASSWORD="/weblogic-operator/model-runtime-secret/password"
OPSS_KEY_PASSPHRASE="/weblogic-operator/opss-walletkey-secret/walletPassword"
OPSS_KEY_B64EWALLET="/weblogic-operator/opss-walletfile-secret/walletFile"
IMG_MODELS_HOME="/u01/wdt/models"
IMG_MODELS_HOME="${WDT_MODEL_HOME:-/u01/wdt/models}"
IMG_MODELS_ROOTDIR="${IMG_MODELS_HOME}"
IMG_ARCHIVES_ROOTDIR="${IMG_MODELS_HOME}"
IMG_VARIABLE_FILES_ROOTDIR="${IMG_MODELS_HOME}"
Expand Down Expand Up @@ -279,7 +279,7 @@ function createWLDomain() {
"in your domain resource and deploying this secret with a 'password' key, but the secret does not have this key."
exitOrLoop
fi
# Check if /u01/wdt/models and /u01/wdt/weblogic-deploy exists
# Check if modelHome (default /u01/wdt/models) and /u01/wdt/weblogic-deploy exists

checkDirNotExistsOrEmpty ${IMG_MODELS_HOME}
checkDirNotExistsOrEmpty ${WDT_BINDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import oracle.kubernetes.operator.work.TerminalStep;
import oracle.kubernetes.utils.TestUtils;
import oracle.kubernetes.weblogic.domain.model.Cluster;
import oracle.kubernetes.weblogic.domain.model.Configuration;
import oracle.kubernetes.weblogic.domain.model.ConfigurationConstants;
import oracle.kubernetes.weblogic.domain.model.Domain;
import oracle.kubernetes.weblogic.domain.model.DomainSpec;
import oracle.kubernetes.weblogic.domain.model.Model;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -67,6 +69,7 @@ public class DomainIntrospectorJobTest {
private static final String OVERRIDE_SECRET_2 = "override-secret-2";
private static final String LOG_HOME = "/shared/logs/" + UID;
private static final String CREDENTIALS_SECRET_NAME = "webLogicCredentialsSecretName";
private static final String WDT_MODEL_HOME = "/u01/wdt/my-models";
private static final String LATEST_IMAGE = "image:latest";
private static final String ADMIN_NAME = "admin";
private static final int MAX_SERVERS = 2;
Expand Down Expand Up @@ -258,6 +261,20 @@ public void whenJobCreated_hasPredefinedEnvVariables() {
hasEnvVar("CREDENTIALS_SECRET_NAME", CREDENTIALS_SECRET_NAME)));
}

@Test
public void whenJobCreatedWithModelHomeDefined_hasModelHomeEnvVariable() {
getDomain().getSpec()
.setConfiguration(new Configuration().withModel(new Model().withModelHome(WDT_MODEL_HOME)));
testSupport.runSteps(getStepFactory(), terminalStep);
logRecords.clear();

List<V1Job> jobs = testSupport.getResources(KubernetesTestSupport.JOB);
List<V1Container> podTemplateContainers = getPodTemplateContainers(jobs.get(0));
assertThat(
podTemplateContainers.get(0).getEnv(),
hasEnvVar("WDT_MODEL_HOME", WDT_MODEL_HOME));
}

@Test
public void whenPodCreationFailsDueToUnprocessableEntityFailure_reportInDomainStatus() {
testSupport.failOnResource(JOB, getJobName(), NS, new UnrecoverableErrorBuilderImpl()
Expand Down