Skip to content

adding checks to ensure only the code needed for the target domain location is generated #30

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 1 commit into from
Nov 10, 2021
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
41 changes: 22 additions & 19 deletions webui/src/js/utils/k8s-domain-script-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ define(['models/wkt-project', 'utils/script-generator-base', 'utils/k8s-domain-c
this.adapter.addVariableDefinition('PULL_SECRET_PASS', this.credentialMask);
this.adapter.addEmptyLine();

this.adapter.addVariableDefinition('TARGET_DOMAIN_LOCATION', this.project.settings.targetDomainLocation.value);
this.adapter.addVariableDefinition('RUNTIME_SECRET_NAME', this.project.k8sDomain.runtimeSecretName.value);
this.adapter.addVariableDefinition('RUNTIME_SECRET_PASS', this.project.k8sDomain.runtimeSecretValue.value);
this.adapter.addEmptyLine();
if (this.isModelInImage()) {
this.adapter.addVariableDefinition('RUNTIME_SECRET_NAME', this.project.k8sDomain.runtimeSecretName.value);
this.adapter.addVariableDefinition('RUNTIME_SECRET_PASS', this.project.k8sDomain.runtimeSecretValue.value);
this.adapter.addEmptyLine();
}

this.adapter.addVariableDefinition('DOMAIN_SECRET_NAME', this.project.k8sDomain.credentialsSecretName.value);
this.adapter.addVariableDefinition('DOMAIN_SECRET_USER', this.credentialMask);
this.adapter.addVariableDefinition('DOMAIN_SECRET_PASS', this.credentialMask);
this.adapter.addEmptyLine();

if (this.project.k8sDomain.secrets.value && this.project.k8sDomain.secrets.value.length > 0) {
if (this.isModelInImage() && this.project.k8sDomain.secrets.value && this.project.k8sDomain.secrets.value.length > 0) {
for (const secretEntry of this.project.k8sDomain.secrets.value) {
const name = secretEntry.name;
const user = this.credentialMask;
Expand All @@ -86,7 +87,7 @@ define(['models/wkt-project', 'utils/script-generator-base', 'utils/k8s-domain-c
}
}

if (this.configMapGenerator.shouldCreateConfigMap()) {
if (this.isModelInImage() && this.configMapGenerator.shouldCreateConfigMap()) {
this.adapter.addVariableDefinition('DOMAIN_CONFIG_MAP_YAML', this.fillInFileNameMask);
}
this.adapter.addVariableDefinition('DOMAIN_RESOURCE_YAML', this.fillInFileNameMask);
Expand Down Expand Up @@ -144,17 +145,19 @@ define(['models/wkt-project', 'utils/script-generator-base', 'utils/k8s-domain-c
this.adapter.addCreatePullSecretBlock(comment, kubectlExe, pullSecretName, k8sDomainNamespace, pullSecretData,
createErrorMessage, deleteErrorMessage, replaceMessage, pullRequiresAuthentication, useExistingPullSecret);

comment = [ 'Create runtime encryption secret, if needed.' ];
const targetDomainLocation = this.adapter.getVariableReference('TARGET_DOMAIN_LOCATION');
const runtimeSecretName = this.adapter.getVariableReference('RUNTIME_SECRET_NAME');
const runtimeSecretData = {
password: this.adapter.getVariableReference('RUNTIME_SECRET_PASS')
};
createErrorMessage = `Failed to create runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
replaceMessage = `Replacing existing runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
deleteErrorMessage = `Failed to delete runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
this.adapter.addCreateRuntimeSecretBlock(comment, kubectlExe, targetDomainLocation, runtimeSecretName,
k8sDomainNamespace, runtimeSecretData, createErrorMessage, deleteErrorMessage, replaceMessage);
if (this.isModelInImage()) {
comment = ['Create runtime encryption secret, if needed.'];
const targetDomainLocation = this.adapter.getVariableReference('TARGET_DOMAIN_LOCATION');
const runtimeSecretName = this.adapter.getVariableReference('RUNTIME_SECRET_NAME');
const runtimeSecretData = {
password: this.adapter.getVariableReference('RUNTIME_SECRET_PASS')
};
createErrorMessage = `Failed to create runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
replaceMessage = `Replacing existing runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
deleteErrorMessage = `Failed to delete runtime encryption secret ${runtimeSecretName} in namespace ${k8sDomainNamespace}`;
this.adapter.addCreateRuntimeSecretBlock(comment, kubectlExe, targetDomainLocation, runtimeSecretName,
k8sDomainNamespace, runtimeSecretData, createErrorMessage, deleteErrorMessage, replaceMessage);
}

comment = [ 'Create WebLogic domain credentials secret.' ];
const domainSecretName = this.adapter.getVariableReference('DOMAIN_SECRET_NAME');
Expand All @@ -168,7 +171,7 @@ define(['models/wkt-project', 'utils/script-generator-base', 'utils/k8s-domain-c
this.adapter.addCreateGenericSecretBlock(comment, kubectlExe, domainSecretName, k8sDomainNamespace,
domainSecretData, createErrorMessage, deleteErrorMessage, replaceMessage);

if (this.project.k8sDomain.secrets.value && this.project.k8sDomain.secrets.value.length > 0) {
if (this.isModelInImage() && this.project.k8sDomain.secrets.value && this.project.k8sDomain.secrets.value.length > 0) {
for (const secretEntry of this.project.k8sDomain.secrets.value) {
const name = this.adapter.getVariableReference(getSecretVariableName(secretEntry.name, 'NAME'));
const data = {
Expand All @@ -184,7 +187,7 @@ define(['models/wkt-project', 'utils/script-generator-base', 'utils/k8s-domain-c
}
}

if (this.configMapGenerator.shouldCreateConfigMap()) {
if (this.isModelInImage() && this.configMapGenerator.shouldCreateConfigMap()) {
const configMapName = this.project.k8sDomain.modelConfigMapName.value;
const yamlFile = this.adapter.getVariableReference('DOMAIN_CONFIG_MAP_YAML');
const errorMessage = `Failed to create domain ConfigMap ${configMapName}`;
Expand Down
8 changes: 8 additions & 0 deletions webui/src/js/utils/script-generator-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ define(['models/wkt-project', 'utils/sh-script-adapter', 'utils/powershell-scrip
return this.adapter.getEnvironmentVariableReference(tempDirVariableName);
}

isModelInImage() {
return this.project.settings.targetDomainLocation.value === 'mii';
}

isDomainInPV() {
return this.project.settings.targetDomainLocation.value === 'pv';
}

_getAdapter(scriptType) {
switch (scriptType) {
case 'sh':
Expand Down