From 19f9fe42e1f39868d6ede865013d57352b742f4b Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 26 Sep 2018 14:47:40 -0700 Subject: [PATCH 1/9] Make sure run.sh has execute permission Signed-off-by: doxiao --- src/integration-tests/bash/run.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/integration-tests/bash/run.sh diff --git a/src/integration-tests/bash/run.sh b/src/integration-tests/bash/run.sh old mode 100644 new mode 100755 From 8d8a3379a7a0647c5888cfa0b796793333415c84 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 28 Sep 2018 07:29:59 -0700 Subject: [PATCH 2/9] Add customization for creating WebLogic domain home Signed-off-by: doxiao --- .../create-weblogic-sample-domain-inputs.yaml | 15 +- ...e-weblogic-sample-domain-job-template.yaml | 263 +----------------- .../create-weblogic-sample-domain.sh | 59 +++- .../wlst/create-domain-job.sh | 40 +++ .../wlst/create-domain-script.sh | 14 + .../domain-home-on-pv/wlst/create-domain.py | 150 ++++++++++ .../wlst/read-domain-secret.py | 15 + .../domain-home-on-pv/wlst/utility.sh | 31 +++ 8 files changed, 323 insertions(+), 264 deletions(-) create mode 100644 kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh create mode 100644 kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh create mode 100644 kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py create mode 100644 kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py create mode 100644 kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml index b95c7c67fc6..8df0b421713 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml @@ -85,7 +85,20 @@ javaOptions: -Dweblogic.StdoutDebugEnabled=false # Name of the persistent volume claim persistentVolumeClaimName: domain1-weblogic-domain-pvc -# Pod domain root dir +# Pod domain root directory # This should match the directory in the WebLogic Server pod's file system that # the domain's persistent volume is mounted on. podDomainRootDir: /shared + +# Pod script root directory +# This should match the directory in the WebLogic Server pod's file system that +# the create domain scripts are located +createDomainScriptDir: /u01/weblogic + +# Script that creates the domain +createDomainScript: create-domain-job.sh + +# Directory that contains the files/scripts that are needed to create the domain. +# This directory should contain all the files that are required for creating a domain, including +# the script that is specified by createDomainScript. +createDomainFilesDir: diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml index c91568c79ed..e633bf3df2e 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml @@ -1,264 +1,5 @@ # Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. -apiVersion: v1 -kind: ConfigMap -metadata: - name: %DOMAIN_UID%-create-weblogic-sample-domain-job-cm - namespace: %NAMESPACE% - labels: - weblogic.resourceVersion: domain-v1 - weblogic.domainUID: %DOMAIN_UID% - weblogic.domainName: %DOMAIN_NAME% -data: - utility.sh: |- - #!/bin/bash - # - - # - # Report an error and fail the job - # $1 - text of error - function fail { - echo ERROR: $1 - exit 1 - } - - # - # Create a folder - # $1 - path of folder to create - function createFolder { - mkdir -m 777 -p $1 - if [ ! -d $1 ]; then - fail "Unable to create folder $1" - fi - } - - # - # Check a file exists - # $1 - path of file to check - function checkFileExists { - if [ ! -f $1 ]; then - fail "The file $1 does not exist" - fi - } - - create-domain-job.sh: |- - #!/bin/bash - # - - # Include common utility functions - source /u01/weblogic/utility.sh - - # Verify the script to create the domain exists - script='/u01/weblogic/create-domain-script.sh' - if [ -f $script ]; then - echo The domain will be created using the script $script - else - fail "Could not locate the domain creation script ${script}" - fi - - # Validate the domain secrets exist before proceeding. - if [ ! -f /weblogic-operator/secrets/username ]; then - fail "The domain secret /weblogic-operator/secrets/username was not found" - fi - if [ ! -f /weblogic-operator/secrets/password ]; then - fail "The domain secret /weblogic-operator/secrets/password was not found" - fi - - # Do not proceed if the domain already exists - domainFolder=${DOMAIN_HOME_DIR} - if [ -d ${domainFolder} ]; then - fail "The create domain job will not overwrite an existing domain. The domain folder ${domainFolder} already exists" - fi - - # Create the base folders - createFolder ${DOMAIN_ROOT_DIR}/domain - createFolder ${DOMAIN_LOGS_DIR} - createFolder ${DOMAIN_ROOT_DIR}/applications - createFolder ${DOMAIN_ROOT_DIR}/stores - - # Execute the script to create the domain - source $script - - read-domain-secret.py: |- - # - # +++ Start of common code for reading domain secrets - - # Read username secret - file = open('/weblogic-operator/secrets/username', 'r') - admin_username = file.read() - file.close() - - # Read password secret - file = open('/weblogic-operator/secrets/password', 'r') - admin_password = file.read() - file.close() - - # +++ End of common code for reading domain secrets - # - - create-domain-script.sh: |- - #!/bin/bash - # - - # Include common utility functions - source /u01/weblogic/utility.sh - - export DOMAIN_HOME=${DOMAIN_HOME_DIR} - - # Create the domain - wlst.sh -skipWLSModuleScanning /u01/weblogic/create-domain.py - - echo "Successfully Completed" - - create-domain.py: |- - # This python script is used to create a WebLogic domain - - # Read the domain secrets from the common python file - execfile("/u01/weblogic/read-domain-secret.py") - - server_port = %MANAGED_SERVER_PORT% - domain_path = os.environ.get("DOMAIN_HOME") - cluster_name = "%CLUSTER_NAME%" - number_of_ms = %CONFIGURED_MANAGED_SERVER_COUNT% - cluster_type = "%CLUSTER_TYPE%" - - print('domain_path : [%s]' % domain_path); - print('domain_name : [%DOMAIN_NAME%]'); - print('admin_username : [%s]' % admin_username); - print('admin_port : [%ADMIN_PORT%]'); - print('cluster_name : [%s]' % cluster_name); - print('server_port : [%s]' % server_port); - print('cluster_type : [%s]' % cluster_type); - - # Open default domain template - # ============================ - readTemplate("/u01/oracle/wlserver/common/templates/wls/wls.jar") - - set('Name', '%DOMAIN_NAME%') - setOption('DomainName', '%DOMAIN_NAME%') - create('%DOMAIN_NAME%','Log') - cd('/Log/%DOMAIN_NAME%'); - set('FileName', '%DOMAIN_LOGS_DIR%/%DOMAIN_NAME%.log') - - # Configure the Administration Server - # =================================== - cd('/Servers/AdminServer') - set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') - set('ListenPort', %ADMIN_PORT%) - set('Name', '%ADMIN_SERVER_NAME%') - - create('T3Channel', 'NetworkAccessPoint') - cd('/Servers/%ADMIN_SERVER_NAME%/NetworkAccessPoints/T3Channel') - set('PublicPort', %T3_CHANNEL_PORT%) - set('PublicAddress', '%T3_PUBLIC_ADDRESS%') - set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') - set('ListenPort', %T3_CHANNEL_PORT%) - - cd('/Servers/%ADMIN_SERVER_NAME%') - create('%ADMIN_SERVER_NAME%', 'Log') - cd('/Servers/%ADMIN_SERVER_NAME%/Log/%ADMIN_SERVER_NAME%') - set('FileName', '%DOMAIN_LOGS_DIR%/%ADMIN_SERVER_NAME%.log') - - # Set the admin user's username and password - # ========================================== - cd('/Security/%DOMAIN_NAME%/User/weblogic') - cmo.setName(admin_username) - cmo.setPassword(admin_password) - - # Write the domain and close the domain template - # ============================================== - setOption('OverwriteDomain', 'true') - - # Configure the node manager - # ========================== - cd('/NMProperties') - set('ListenAddress','0.0.0.0') - set('ListenPort',5556) - set('CrashRecoveryEnabled', 'true') - set('NativeVersionEnabled', 'true') - set('StartScriptEnabled', 'false') - set('SecureListener', 'false') - set('LogLevel', 'FINEST') - set('DomainsDirRemoteSharingEnabled', 'true') - - # Set the Node Manager user name and password (domain name will change after writeDomain) - cd('/SecurityConfiguration/base_domain') - set('NodeManagerUsername', admin_username) - set('NodeManagerPasswordEncrypted', admin_password) - - # Create a cluster - # ====================== - cd('/') - cl=create(cluster_name, 'Cluster') - - if cluster_type == "CONFIGURED": - - # Create managed servers - for index in range(0, number_of_ms): - cd('/') - - msIndex = index+1 - name = '%MANAGED_SERVER_NAME_BASE%%s' % msIndex - name_svc = '%MANAGED_SERVER_NAME_BASE_SVC%%s' % msIndex - - create(name, 'Server') - cd('/Servers/%s/' % name ) - print('managed server name is %s' % name); - set('ListenAddress', '%DOMAIN_UID%-%s' % name_svc) - set('ListenPort', server_port) - set('NumOfRetriesBeforeMSIMode', 0) - set('RetryIntervalBeforeMSIMode', 1) - set('Cluster', cluster_name) - - create(name,'Log') - cd('/Servers/%s/Log/%s' % (name, name)) - set('FileName', '%DOMAIN_LOGS_DIR%/%s.log' % name) - else: - print('Configuring Dynamic Cluster %s' % cluster_name) - - templateName = cluster_name + "-template" - print('Creating Server Template: %s' % templateName) - st1=create(templateName, 'ServerTemplate') - print('Done creating Server Template: %s' % templateName) - cd('/ServerTemplates/%s' % templateName) - cmo.setListenPort(server_port) - cmo.setListenAddress('%DOMAIN_UID%-%MANAGED_SERVER_NAME_BASE_SVC%${id}') - cmo.setCluster(cl) - print('Done setting attributes for Server Template: %s' % templateName); - - - cd('/Clusters/%s' % cluster_name) - create(cluster_name, 'DynamicServers') - cd('DynamicServers/%s' % cluster_name) - set('ServerTemplate', st1) - set('ServerNamePrefix', "%MANAGED_SERVER_NAME_BASE%") - set('DynamicClusterSize', number_of_ms) - set('MaxDynamicClusterSize', number_of_ms) - set('CalculatedListenPorts', false) - set('Id', 1) - - print('Done setting attributes for Dynamic Cluster: %s' % cluster_name); - - # Write Domain - # ============ - writeDomain(domain_path) - closeTemplate() - print 'Domain Created' - - # Update Domain - readDomain(domain_path) - cd('/') - cmo.setProductionModeEnabled(%PRODUCTION_MODE_ENABLED%) - updateDomain() - closeDomain() - print 'Domain Updated' - print 'Done' - - # Exit WLST - # ========= - exit() - ---- apiVersion: batch/v1 kind: Job metadata: @@ -281,14 +22,14 @@ spec: ports: - containerPort: 7001 volumeMounts: - - mountPath: /u01/weblogic + - mountPath: %CREATE_DOMAIN_SCRIPT_DIR% name: create-weblogic-sample-domain-job-cm-volume - mountPath: %DOMAIN_ROOT_DIR% name: weblogic-domain-storage-volume - mountPath: /weblogic-operator/secrets name: weblogic-credentials-volume command: ["/bin/sh"] - args: ["/u01/weblogic/create-domain-job.sh"] + args: ["%CREATE_DOMAIN_SCRIPT_DIR%/%CREATE_DOMAIN_SCRIPT%"] env: - name: DOMAIN_ROOT_DIR value: %DOMAIN_ROOT_DIR% diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh index 8c29cb9bb98..272fd7b9296 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh @@ -215,7 +215,9 @@ function initialize { t3PublicAddress \ version \ persistentVolumeClaimName \ - podDomainRootDir + podDomainRootDir \ + createDomainScriptDir \ + createDomainScript validateIntegerInputParamsSpecified \ adminPort \ @@ -302,6 +304,8 @@ function createYamlFiles { sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${createJobOutput} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptDir}:g" ${createJobOutput} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScript}:g" ${createJobOutput} # Generate the yaml to create the kubernetes job that will delete the weblogic domain_home folder echo Generating ${deleteJobOutput} @@ -316,6 +320,7 @@ function createYamlFiles { sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${deleteJobOutput} + sed -i -e "s:%DOMAIN_LOGS_DIR%:${podDomainRootDir}/logs:g" ${outputFile} # Generate the yaml to create the domain custom resource echo Generating ${dcrOutput} @@ -348,16 +353,66 @@ function createYamlFiles { sed -i -e "s:%ADMIN_NODE_PORT%:${adminNodePort}:g" ${dcrOutput} sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${dcrOutput} sed -i -e "s:%STARTUP_CONTROL%:${startupControl}:g" ${dcrOutput} - + # Remove any "...yaml-e" files left over from running sed rm -f ${domainOutputDir}/*.yaml-e } +# create domain configmap using what is in the createDomainFilesDir +function create_domain_configmap { + # Use the default files if createDomainFilesDir is not specified + if [ -z "${createDomainFilesDir}" ]; then + createDomainFilesDir=${scriptDir}/wlst + fi + + # customize the files with domain information + local externalFilesTmpDir=$domainOutputDir/tmp + mkdir -p $externalFilesTmpDir + cp ${createDomainFilesDir}/* ${externalFilesTmpDir}/ + + for fname in ${externalFilesTmpDir}/* + do + local outputFile=$fname + sed -i -e "s:%NAMESPACE%:$namespace:g" ${outputFile} + sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${outputFile} + sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${outputFile} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${outputFile} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${weblogicImagePullSecretPrefix}:g" ${outputFile} + sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${outputFile} + sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${outputFile} + sed -i -e "s:%PRODUCTION_MODE_ENABLED%:${productionModeEnabled}:g" ${outputFile} + sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${outputFile} + sed -i -e "s:%ADMIN_SERVER_NAME_SVC%:${adminServerNameSVC}:g" ${outputFile} + sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${outputFile} + sed -i -e "s:%CONFIGURED_MANAGED_SERVER_COUNT%:${configuredManagedServerCount}:g" ${outputFile} + sed -i -e "s:%MANAGED_SERVER_NAME_BASE%:${managedServerNameBase}:g" ${outputFile} + sed -i -e "s:%MANAGED_SERVER_NAME_BASE_SVC%:${managedServerNameBaseSVC}:g" ${outputFile} + sed -i -e "s:%MANAGED_SERVER_PORT%:${managedServerPort}:g" ${outputFile} + sed -i -e "s:%T3_CHANNEL_PORT%:${t3ChannelPort}:g" ${outputFile} + sed -i -e "s:%T3_PUBLIC_ADDRESS%:${t3PublicAddress}:g" ${outputFile} + sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${outputFile} + sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${outputFile} + sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${outputFile} + sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${outputFile} + sed -i -e "s:%DOMAIN_LOGS_DIR%:${podDomainRootDir}/logs:g" ${outputFile} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptDir}:g" ${outputFile} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScript}:g" ${outputFile} + + done + + # create the configmap and label it properly + kubectl create configmap ${domainUID}-create-weblogic-sample-domain-job-cm -n $namespace --from-file $externalFilesTmpDir + kubectl label configmap ${domainUID}-create-weblogic-sample-domain-job-cm -n $namespace weblogic.resourceVersion=domain-v1 weblogic.domainUID=$domainUID weblogic.domainName=$domainName +} + # # Function to run the job that creates the domain # function createDomainHome { + # create the config map for the job + create_domain_configmap + # There is no way to re-run a kubernetes job, so first delete any prior job JOB_NAME="${domainUID}-create-weblogic-sample-domain-job" deleteK8sObj job $JOB_NAME ${createJobOutput} diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh new file mode 100644 index 00000000000..badbb714780 --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +#!/bin/bash +# + +# Include common utility functions +source %CREATE_DOMAIN_SCRIPT_DIR%/utility.sh + +# Verify the script to create the domain exists +script=%CREATE_DOMAIN_SCRIPT_DIR%/create-domain-script.sh +if [ -f $script ]; then + echo The domain will be created using the script $script +else + fail "Could not locate the domain creation script ${script}" +fi + +# Validate the domain secrets exist before proceeding. +if [ ! -f /weblogic-operator/secrets/username ]; then + fail "The domain secret /weblogic-operator/secrets/username was not found" +fi +if [ ! -f /weblogic-operator/secrets/password ]; then + fail "The domain secret /weblogic-operator/secrets/password was not found" +fi + +# Do not proceed if the domain already exists +domainFolder=${DOMAIN_HOME_DIR} +if [ -d ${domainFolder} ]; then + fail "The create domain job will not overwrite an existing domain. The domain folder ${domainFolder} already exists" +fi + +# Create the base folders +createFolder ${DOMAIN_ROOT_DIR}/domain +createFolder ${DOMAIN_LOGS_DIR} +createFolder ${DOMAIN_ROOT_DIR}/applications +createFolder ${DOMAIN_ROOT_DIR}/stores + +# Execute the script to create the domain +source $script + diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh new file mode 100644 index 00000000000..3e7222a600c --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. + +# Include common utility functions +source %CREATE_DOMAIN_SCRIPT_DIR%/utility.sh + +export DOMAIN_HOME=${DOMAIN_HOME_DIR} + +# Create the domain +wlst.sh -skipWLSModuleScanning %CREATE_DOMAIN_SCRIPT_DIR%/create-domain.py + +echo "Successfully Completed" + diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py new file mode 100644 index 00000000000..d53156201a4 --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py @@ -0,0 +1,150 @@ +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. + +# This python script is used to create a WebLogic domain + +# Read the domain secrets from the common python file +execfile("%CREATE_DOMAIN_SCRIPT_DIR%/read-domain-secret.py") + +server_port = %MANAGED_SERVER_PORT% +domain_path = os.environ.get("DOMAIN_HOME") +cluster_name = "%CLUSTER_NAME%" +number_of_ms = %CONFIGURED_MANAGED_SERVER_COUNT% +cluster_type = "%CLUSTER_TYPE%" +domain_logs = os.environ.get("DOMAIN_LOGS_DIR") + +print('domain_path : [%s]' % domain_path); +print('domain_name : [%DOMAIN_NAME%]'); +print('admin_username : [%s]' % admin_username); +print('admin_port : [%ADMIN_PORT%]'); +print('cluster_name : [%s]' % cluster_name); +print('server_port : [%s]' % server_port); +print('cluster_type : [%s]' % cluster_type); + +# Open default domain template +# ============================ +readTemplate("/u01/oracle/wlserver/common/templates/wls/wls.jar") + +set('Name', '%DOMAIN_NAME%') +setOption('DomainName', '%DOMAIN_NAME%') +create('%DOMAIN_NAME%','Log') +cd('/Log/%DOMAIN_NAME%'); +set('FileName', '%DOMAIN_LOGS_DIR%/%DOMAIN_NAME%.log') + +# Configure the Administration Server +# =================================== +cd('/Servers/AdminServer') +set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') +set('ListenPort', %ADMIN_PORT%) +set('Name', '%ADMIN_SERVER_NAME%') + +create('T3Channel', 'NetworkAccessPoint') +cd('/Servers/%ADMIN_SERVER_NAME%/NetworkAccessPoints/T3Channel') +set('PublicPort', %T3_CHANNEL_PORT%) +set('PublicAddress', '%T3_PUBLIC_ADDRESS%') +set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') +set('ListenPort', %T3_CHANNEL_PORT%) + +cd('/Servers/%ADMIN_SERVER_NAME%') +create('%ADMIN_SERVER_NAME%', 'Log') +cd('/Servers/%ADMIN_SERVER_NAME%/Log/%ADMIN_SERVER_NAME%') +set('FileName', '%DOMAIN_LOGS_DIR%/%ADMIN_SERVER_NAME%.log') + +# Set the admin user's username and password +# ========================================== +cd('/Security/%DOMAIN_NAME%/User/weblogic') +cmo.setName(admin_username) +cmo.setPassword(admin_password) + +# Write the domain and close the domain template +# ============================================== +setOption('OverwriteDomain', 'true') + +# Configure the node manager +# ========================== +cd('/NMProperties') +set('ListenAddress','0.0.0.0') +set('ListenPort',5556) +set('CrashRecoveryEnabled', 'true') +set('NativeVersionEnabled', 'true') +set('StartScriptEnabled', 'false') +set('SecureListener', 'false') +set('LogLevel', 'FINEST') +set('DomainsDirRemoteSharingEnabled', 'true') + +# Set the Node Manager user name and password (domain name will change after writeDomain) +cd('/SecurityConfiguration/base_domain') +set('NodeManagerUsername', admin_username) +set('NodeManagerPasswordEncrypted', admin_password) + +# Create a cluster +# ====================== +cd('/') +cl=create(cluster_name, 'Cluster') + +if cluster_type == "CONFIGURED": + + # Create managed servers + for index in range(0, number_of_ms): + cd('/') + + msIndex = index+1 + name = '%MANAGED_SERVER_NAME_BASE%%s' % msIndex + name_svc = '%MANAGED_SERVER_NAME_BASE_SVC%%s' % msIndex + + create(name, 'Server') + cd('/Servers/%s/' % name ) + print('managed server name is %s' % name); + set('ListenAddress', '%DOMAIN_UID%-%s' % name_svc) + set('ListenPort', server_port) + set('NumOfRetriesBeforeMSIMode', 0) + set('RetryIntervalBeforeMSIMode', 1) + set('Cluster', cluster_name) + + create(name,'Log') + cd('/Servers/%s/Log/%s' % (name, name)) + set('FileName', '%DOMAIN_LOGS_DIR%/%s.log' % name) +else: + print('Configuring Dynamic Cluster %s' % cluster_name) + + templateName = cluster_name + "-template" + print('Creating Server Template: %s' % templateName) + st1=create(templateName, 'ServerTemplate') + print('Done creating Server Template: %s' % templateName) + cd('/ServerTemplates/%s' % templateName) + cmo.setListenPort(server_port) + cmo.setListenAddress('%DOMAIN_UID%-%MANAGED_SERVER_NAME_BASE_SVC%${id}') + cmo.setCluster(cl) + print('Done setting attributes for Server Template: %s' % templateName); + + + cd('/Clusters/%s' % cluster_name) + create(cluster_name, 'DynamicServers') + cd('DynamicServers/%s' % cluster_name) + set('ServerTemplate', st1) + set('ServerNamePrefix', "%MANAGED_SERVER_NAME_BASE%") + set('DynamicClusterSize', number_of_ms) + set('MaxDynamicClusterSize', number_of_ms) + set('CalculatedListenPorts', false) + set('Id', 1) + + print('Done setting attributes for Dynamic Cluster: %s' % cluster_name); + +# Write Domain +# ============ +writeDomain(domain_path) +closeTemplate() +print 'Domain Created' + +# Update Domain +readDomain(domain_path) +cd('/') +cmo.setProductionModeEnabled(%PRODUCTION_MODE_ENABLED%) +updateDomain() +closeDomain() +print 'Domain Updated' +print 'Done' + +# Exit WLST +# ========= +exit() diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py new file mode 100644 index 00000000000..40084f2ba3b --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py @@ -0,0 +1,15 @@ +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +# Read username secret +file = open('/weblogic-operator/secrets/username', 'r') +admin_username = file.read() +file.close() + +# Read password secret +file = open('/weblogic-operator/secrets/password', 'r') +admin_password = file.read() +file.close() + + diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh new file mode 100644 index 00000000000..6e68fc97420 --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. + +# +# Report an error and fail the job +# $1 - text of error +function fail { + echo ERROR: $1 + exit 1 +} + +# +# Create a folder +# $1 - path of folder to create +function createFolder { + mkdir -m 777 -p $1 + if [ ! -d $1 ]; then + fail "Unable to create folder $1" + fi +} + +# +# Check a file exists +# $1 - path of file to check +function checkFileExists { + if [ ! -f $1 ]; then + fail "The file $1 does not exist" + fi +} + From ccaf561e0799de4d73de45c47c1a43636c14878b Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 28 Sep 2018 10:02:30 -0700 Subject: [PATCH 3/9] Rename the properties and modified the default handling Signed-off-by: doxiao --- .../create-weblogic-sample-domain-inputs.yaml | 30 +++++++-------- .../create-weblogic-sample-domain.sh | 38 ++++++++++++------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml index 8df0b421713..91d32209fa1 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml @@ -85,20 +85,18 @@ javaOptions: -Dweblogic.StdoutDebugEnabled=false # Name of the persistent volume claim persistentVolumeClaimName: domain1-weblogic-domain-pvc -# Pod domain root directory -# This should match the directory in the WebLogic Server pod's file system that -# the domain's persistent volume is mounted on. -podDomainRootDir: /shared - -# Pod script root directory -# This should match the directory in the WebLogic Server pod's file system that -# the create domain scripts are located -createDomainScriptDir: /u01/weblogic - -# Script that creates the domain -createDomainScript: create-domain-job.sh - -# Directory that contains the files/scripts that are needed to create the domain. -# This directory should contain all the files that are required for creating a domain, including -# the script that is specified by createDomainScript. +# Mount path of the domain persistent volume. The default is /shared. +domainPVMountPath: + +# Mount path of the directory where the create domain scripts are located inside the pod +# The default is /u01/weblogic. +createDomainScriptsMountPath: + +# Script that creates the domain. The default is create-domain-job.sh. +createDomainScriptName: + +# Directory to get all the create domain scripts and supporting files, including +# the script that is specified by the createDomainScriptName property. +# The default is the "wlst" subdirectory under the directory where the +# create-weblogic-sample-domain.sh script is located. createDomainFilesDir: diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh index 272fd7b9296..3b620fededd 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh @@ -214,10 +214,7 @@ function initialize { namespace \ t3PublicAddress \ version \ - persistentVolumeClaimName \ - podDomainRootDir \ - createDomainScriptDir \ - createDomainScript + persistentVolumeClaimName validateIntegerInputParamsSpecified \ adminPort \ @@ -276,6 +273,22 @@ function createYamlFiles { if [ -z "${weblogicImage}" ]; then weblogicImage="store/oracle/weblogic:12.2.1.3" fi + + # Use the default value if not defined. + if [ -z "${domainPVMountPath}" ]; then + domainPVMountPath="/shared" + fi + + # Use the default value if not defined. + if [ -z "${createDomainScriptsMountPath}" ]; then + createDomainScriptsMountPath="/u01/weblogic" + fi + + # Use the default value if not defined. + if [ -z "${createDomainScriptName}" ]; then + createDomainScriptName="create-domain-job.sh" + fi + # Must escape the ':' value in weblogicImage for sed to properly parse and replace weblogicImage=$(echo ${weblogicImage} | sed -e "s/\:/\\\:/g") @@ -303,9 +316,9 @@ function createYamlFiles { sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${createJobOutput} sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${createJobOutput} - sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${createJobOutput} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptDir}:g" ${createJobOutput} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScript}:g" ${createJobOutput} + sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${createJobOutput} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptsMountPath}:g" ${createJobOutput} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScriptName}:g" ${createJobOutput} # Generate the yaml to create the kubernetes job that will delete the weblogic domain_home folder echo Generating ${deleteJobOutput} @@ -319,8 +332,7 @@ function createYamlFiles { sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${deleteJobOutput} - sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${deleteJobOutput} - sed -i -e "s:%DOMAIN_LOGS_DIR%:${podDomainRootDir}/logs:g" ${outputFile} + sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${deleteJobOutput} # Generate the yaml to create the domain custom resource echo Generating ${dcrOutput} @@ -393,10 +405,10 @@ function create_domain_configmap { sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${outputFile} sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${outputFile} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${outputFile} - sed -i -e "s:%DOMAIN_ROOT_DIR%:${podDomainRootDir}:g" ${outputFile} - sed -i -e "s:%DOMAIN_LOGS_DIR%:${podDomainRootDir}/logs:g" ${outputFile} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptDir}:g" ${outputFile} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScript}:g" ${outputFile} + sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${outputFile} + sed -i -e "s:%DOMAIN_LOGS_DIR%:${domainPVMountPath}/logs:g" ${outputFile} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptsMountPath}:g" ${outputFile} + sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScriptName}:g" ${outputFile} done From bdd5b00ea276fd9e408b6756282fe045e4bece91 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 28 Sep 2018 10:08:54 -0700 Subject: [PATCH 4/9] Minor correction in create-domain-job.sh Signed-off-by: doxiao --- .../domain-home-on-pv/wlst/create-domain-job.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh index badbb714780..08bc799d537 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh @@ -1,7 +1,6 @@ #!/bin/bash # Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. -#!/bin/bash # # Include common utility functions From 1e6973669f5a4b6245523c890381606f49031576 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 28 Sep 2018 10:25:37 -0700 Subject: [PATCH 5/9] Remove a redundant log message Signed-off-by: doxiao --- src/integration-tests/bash/run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/integration-tests/bash/run.sh b/src/integration-tests/bash/run.sh index bdf03736478..7074770485d 100755 --- a/src/integration-tests/bash/run.sh +++ b/src/integration-tests/bash/run.sh @@ -1054,8 +1054,6 @@ function create_domain_home_on_pv_non_helm { local inputsDomain="$tmp_dir/create-weblogic-sample-domain-load-balancer-inputs.yaml" - trace "Create the domain home, and start domain resources" - cp $PROJECT_ROOT/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml $inputsDomain # customize inputs properties From 96d2cfa6a9fd1a07245a49806c0cd7ab527fceef Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 28 Sep 2018 16:30:07 -0700 Subject: [PATCH 6/9] Address review comments - add failure handling for cm creation and fix copyright Signed-off-by: doxiao --- .../create-weblogic-sample-domain.sh | 12 ++++++++++-- .../domain-home-on-pv/wlst/create-domain-job.sh | 2 +- .../domain-home-on-pv/wlst/create-domain-script.sh | 2 +- .../domain-home-on-pv/wlst/create-domain.py | 2 +- .../domain-home-on-pv/wlst/read-domain-secret.py | 2 +- .../domain-home-on-pv/wlst/utility.sh | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh index 3b620fededd..18c3598ebbc 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh @@ -413,8 +413,16 @@ function create_domain_configmap { done # create the configmap and label it properly - kubectl create configmap ${domainUID}-create-weblogic-sample-domain-job-cm -n $namespace --from-file $externalFilesTmpDir - kubectl label configmap ${domainUID}-create-weblogic-sample-domain-job-cm -n $namespace weblogic.resourceVersion=domain-v1 weblogic.domainUID=$domainUID weblogic.domainName=$domainName + local cmName=${domainUID}-create-weblogic-sample-domain-job-cm + kubectl create configmap ${cmName} -n $namespace --from-file $externalFilesTmpDir + + echo Checking the configmap $cmName was created + local num=`kubectl get cm -n $namespace | grep ${cmName} | wc | awk ' { print $1; } '` + if [ "$num" != "1" ]; then + fail "The configmap ${cmName} was not created" + fi + + kubectl label configmap ${cmName} -n $namespace weblogic.resourceVersion=domain-v1 weblogic.domainUID=$domainUID weblogic.domainName=$domainName } # diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh index 08bc799d537..ea70d08b9f4 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh index 3e7222a600c..7c6cfc112be 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # Include common utility functions diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py index d53156201a4..3a197e099c0 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py @@ -1,4 +1,4 @@ -# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # This python script is used to create a WebLogic domain diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py index 40084f2ba3b..a61df6a9974 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/read-domain-secret.py @@ -1,4 +1,4 @@ -# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh index 6e68fc97420..bd958ec5169 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/utility.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # From 201957c8b129c6697d4741624262b685dfcdc135 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 2 Oct 2018 06:13:17 -0700 Subject: [PATCH 7/9] Use env variables instead of string substitution and change the image and image pull secrete property names Signed-off-by: doxiao --- kubernetes/samples/scripts/common/utility.sh | 19 ++++ .../create-weblogic-sample-domain-inputs.yaml | 8 +- ...e-weblogic-sample-domain-job-template.yaml | 36 +++++++- .../create-weblogic-sample-domain.sh | 66 ++++---------- .../wlst/create-domain-job.sh | 4 +- .../wlst/create-domain-script.sh | 4 +- .../domain-home-on-pv/wlst/create-domain.py | 87 +++++++++++-------- 7 files changed, 126 insertions(+), 98 deletions(-) diff --git a/kubernetes/samples/scripts/common/utility.sh b/kubernetes/samples/scripts/common/utility.sh index 0a85952e61a..3cfa09d5ba2 100644 --- a/kubernetes/samples/scripts/common/utility.sh +++ b/kubernetes/samples/scripts/common/utility.sh @@ -107,6 +107,25 @@ function toDNS1123Legal { echo "$val" } +# +# Check the state of a persistent volume. +# $1 - name of volume +# $2 - expected state of volume +function checkPvState { + + echo "Checking if the persistent volume ${1:?} is ${2:?}" + local pv_state=`kubectl get pv $1 -o jsonpath='{.status.phase}'` + attempts=0 + while [ ! "$pv_state" = "$2" ] && [ ! $attempts -eq 10 ]; do + attempts=$((attempts + 1)) + sleep 1 + pv_state=`kubectl get pv $1 -o jsonpath='{.status.phase}'` + done + if [ "$pv_state" != "$2" ]; then + fail "The persistent volume state should be $2 but is $pv_state" + fi +} + # # Function to check if a persistent volume exists # $1 - name of volume diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml index 91d32209fa1..c6fdbeadf90 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml @@ -41,11 +41,7 @@ managedServerNameBase: managed-server managedServerPort: 8001 # WebLogic Docker image -weblogicImage: store/oracle/weblogic:12.2.1.3 - -# Physical path of the domain's persistent storage. -# The following line must be uncomment and customized: -#weblogicDomainStoragePath: /scratch/k8s_dir/domain1 +image: store/oracle/weblogic:12.2.1.3 # Boolean indicating if production mode is enabled for the domain productionModeEnabled: true @@ -56,7 +52,7 @@ weblogicCredentialsSecretName: domain1-weblogic-credentials # Name of the Kubernetes secret to access the Docker Store to pull the WebLogic Server Docker image # The presence of the secret will be validated when this parameter is enabled. -#weblogicImagePullSecretName: +#imagePullSecretName: # Port for the T3Channel of the NetworkAccessPoint t3ChannelPort: 30012 diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml index e633bf3df2e..cff429d2ae9 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml @@ -31,12 +31,42 @@ spec: command: ["/bin/sh"] args: ["%CREATE_DOMAIN_SCRIPT_DIR%/%CREATE_DOMAIN_SCRIPT%"] env: + - name: DOMAIN_UID + value: "%DOMAIN_UID%" + - name: DOMAIN_NAME + value: "%DOMAIN_NAME%" + - name: ADMIN_SERVER_NAME + value: "%ADMIN_SERVER_NAME%" + - name: ADMIN_SERVER_NAME_SVC + value: "%ADMIN_SERVER_NAME_SVC%" + - name: ADMIN_PORT + value: "%ADMIN_PORT%" + - name: CLUSTER_NAME + value: "%CLUSTER_NAME%" + - name: CLUSTER_TYPE + value: "%CLUSTER_TYPE%" + - name: T3_CHANNEL_PORT + value: "%T3_CHANNEL_PORT%" + - name: T3_PUBLIC_ADDRESS + value: "%T3_PUBLIC_ADDRESS%" + - name: MANAGED_SERVER_NAME_BASE_SVC + value: "%MANAGED_SERVER_NAME_BASE_SVC%" + - name: MANAGED_SERVER_NAME_BASE + value: "%MANAGED_SERVER_NAME_BASE%" + - name: CONFIGURED_MANAGED_SERVER_COUNT + value: "%CONFIGURED_MANAGED_SERVER_COUNT%" + - name: MANAGED_SERVER_PORT + value: "%MANAGED_SERVER_PORT%" + - name: PRODUCTION_MODE_ENABLED + value: "%PRODUCTION_MODE_ENABLED%" + - name: CREATE_DOMAIN_SCRIPT_DIR + value: "%CREATE_DOMAIN_SCRIPT_DIR%" - name: DOMAIN_ROOT_DIR - value: %DOMAIN_ROOT_DIR% + value: "%DOMAIN_ROOT_DIR%" - name: DOMAIN_HOME_DIR - value: %DOMAIN_ROOT_DIR%/domain/%DOMAIN_NAME% + value: "%DOMAIN_ROOT_DIR%/domain/%DOMAIN_NAME%" - name: DOMAIN_LOGS_DIR - value: %DOMAIN_ROOT_DIR%/logs + value: "%DOMAIN_ROOT_DIR%/logs" volumes: - name: create-weblogic-sample-domain-job-cm-volume configMap: diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh index 18c3598ebbc..619391bca7c 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh @@ -111,16 +111,16 @@ function validateDomainSecret { # Function to validate the weblogic image pull secret name # function validateWeblogicImagePullSecretName { - if [ ! -z ${weblogicImagePullSecretName} ]; then - validateLowerCase weblogicImagePullSecretName ${weblogicImagePullSecretName} - weblogicImagePullSecretPrefix="" + if [ ! -z ${imagePullSecretName} ]; then + validateLowerCase imagePullSecretName ${imagePullSecretName} + imagePullSecretPrefix="" if [ "${generateOnly}" = false ]; then validateWeblogicImagePullSecret fi else # Set name blank when not specified, and comment out the yaml - weblogicImagePullSecretName="" - weblogicImagePullSecretPrefix="#" + imagePullSecretName="" + imagePullSecretPrefix="#" fi } @@ -142,7 +142,7 @@ function validateSecretExists { function validateWeblogicImagePullSecret { # The kubernetes secret for pulling images from the docker store is optional. # If it was specified, make sure it exists. - validateSecretExists ${weblogicImagePullSecretName} ${namespace} + validateSecretExists ${imagePullSecretName} ${namespace} failIfValidationErrors } @@ -270,8 +270,8 @@ function createYamlFiles { # For backward compatability, default to "store/oracle/weblogic:12.2.1.3" if not defined in # create-weblogic-sample-domain-inputs.yaml - if [ -z "${weblogicImage}" ]; then - weblogicImage="store/oracle/weblogic:12.2.1.3" + if [ -z "${image}" ]; then + image="store/oracle/weblogic:12.2.1.3" fi # Use the default value if not defined. @@ -289,8 +289,8 @@ function createYamlFiles { createDomainScriptName="create-domain-job.sh" fi - # Must escape the ':' value in weblogicImage for sed to properly parse and replace - weblogicImage=$(echo ${weblogicImage} | sed -e "s/\:/\\\:/g") + # Must escape the ':' value in image for sed to properly parse and replace + image=$(echo ${image} | sed -e "s/\:/\\\:/g") # Generate the yaml to create the kubernetes job that will create the weblogic domain echo Generating ${createJobOutput} @@ -298,9 +298,9 @@ function createYamlFiles { cp ${createJobInput} ${createJobOutput} sed -i -e "s:%NAMESPACE%:$namespace:g" ${createJobOutput} sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${createJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${createJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${createJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${weblogicImagePullSecretPrefix}:g" ${createJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${createJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${createJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${createJobOutput} sed -i -e "s:%PRODUCTION_MODE_ENABLED%:${productionModeEnabled}:g" ${createJobOutput} @@ -325,10 +325,10 @@ function createYamlFiles { cp ${deleteJobInput} ${deleteJobOutput} sed -i -e "s:%NAMESPACE%:$namespace:g" ${deleteJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${deleteJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${deleteJobOutput} sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${deleteJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${deleteJobOutput} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${weblogicImagePullSecretPrefix}:g" ${deleteJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${deleteJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${deleteJobOutput} sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${deleteJobOutput} @@ -355,8 +355,8 @@ function createYamlFiles { sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${dcrOutput} sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput} sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${dcrOutput} - sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${dcrOutput} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${dcrOutput} + sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${dcrOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput} sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${dcrOutput} sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput} sed -i -e "s:%EXPOSE_T3_CHANNEL_PREFIX%:${exposeAdminT3ChannelPrefix}:g" ${dcrOutput} @@ -382,36 +382,6 @@ function create_domain_configmap { mkdir -p $externalFilesTmpDir cp ${createDomainFilesDir}/* ${externalFilesTmpDir}/ - for fname in ${externalFilesTmpDir}/* - do - local outputFile=$fname - sed -i -e "s:%NAMESPACE%:$namespace:g" ${outputFile} - sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${outputFile} - sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${outputFile} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${outputFile} - sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${weblogicImagePullSecretPrefix}:g" ${outputFile} - sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${outputFile} - sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${outputFile} - sed -i -e "s:%PRODUCTION_MODE_ENABLED%:${productionModeEnabled}:g" ${outputFile} - sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${outputFile} - sed -i -e "s:%ADMIN_SERVER_NAME_SVC%:${adminServerNameSVC}:g" ${outputFile} - sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${outputFile} - sed -i -e "s:%CONFIGURED_MANAGED_SERVER_COUNT%:${configuredManagedServerCount}:g" ${outputFile} - sed -i -e "s:%MANAGED_SERVER_NAME_BASE%:${managedServerNameBase}:g" ${outputFile} - sed -i -e "s:%MANAGED_SERVER_NAME_BASE_SVC%:${managedServerNameBaseSVC}:g" ${outputFile} - sed -i -e "s:%MANAGED_SERVER_PORT%:${managedServerPort}:g" ${outputFile} - sed -i -e "s:%T3_CHANNEL_PORT%:${t3ChannelPort}:g" ${outputFile} - sed -i -e "s:%T3_PUBLIC_ADDRESS%:${t3PublicAddress}:g" ${outputFile} - sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${outputFile} - sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${outputFile} - sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${outputFile} - sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${outputFile} - sed -i -e "s:%DOMAIN_LOGS_DIR%:${domainPVMountPath}/logs:g" ${outputFile} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptsMountPath}:g" ${outputFile} - sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScriptName}:g" ${outputFile} - - done - # create the configmap and label it properly local cmName=${domainUID}-create-weblogic-sample-domain-job-cm kubectl create configmap ${cmName} -n $namespace --from-file $externalFilesTmpDir diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh index ea70d08b9f4..6205b76cd02 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-job.sh @@ -4,10 +4,10 @@ # # Include common utility functions -source %CREATE_DOMAIN_SCRIPT_DIR%/utility.sh +source ${CREATE_DOMAIN_SCRIPT_DIR}/utility.sh # Verify the script to create the domain exists -script=%CREATE_DOMAIN_SCRIPT_DIR%/create-domain-script.sh +script=${CREATE_DOMAIN_SCRIPT_DIR}/create-domain-script.sh if [ -f $script ]; then echo The domain will be created using the script $script else diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh index 7c6cfc112be..2361227165f 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain-script.sh @@ -3,12 +3,12 @@ # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. # Include common utility functions -source %CREATE_DOMAIN_SCRIPT_DIR%/utility.sh +source ${CREATE_DOMAIN_SCRIPT_DIR}/utility.sh export DOMAIN_HOME=${DOMAIN_HOME_DIR} # Create the domain -wlst.sh -skipWLSModuleScanning %CREATE_DOMAIN_SCRIPT_DIR%/create-domain.py +wlst.sh -skipWLSModuleScanning ${CREATE_DOMAIN_SCRIPT_DIR}/create-domain.py echo "Successfully Completed" diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py index 3a197e099c0..b787c4b2e87 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py @@ -3,56 +3,66 @@ # This python script is used to create a WebLogic domain -# Read the domain secrets from the common python file -execfile("%CREATE_DOMAIN_SCRIPT_DIR%/read-domain-secret.py") +domain_uid = os.environ.get("DOMAIN_UID") +server_port = int(os.environ.get("MANAGED_SERVER_PORT")) +domain_path = os.environ.get("DOMAIN_HOME") +cluster_name = os.environ.get("CLUSTER_NAME") +admin_server_name = os.environ.get("ADMIN_SERVER_NAME") +admin_server_name_svc = os.environ.get("ADMIN_SERVER_NAME_SVC") +admin_port = int(os.environ.get("ADMIN_PORT")) +domain_name = os.environ.get("DOMAIN_NAME") +t3_channel_port = int(os.environ.get("T3_CHANNEL_PORT")) +t3_public_address = os.environ.get("T3_PUBLIC_ADDRESS") +number_of_ms = int(os.environ.get("CONFIGURED_MANAGED_SERVER_COUNT")) +cluster_type = os.environ.get("CLUSTER_TYPE") +managed_server_name_base = os.environ.get("MANAGED_SERVER_NAME_BASE") +managed_server_name_base_svc = os.environ.get("MANAGED_SERVER_NAME_BASE_SVC") +domain_logs = os.environ.get("DOMAIN_LOGS_DIR") +script_dir = os.environ.get("CREATE_DOMAIN_SCRIPT_DIR") +production_mode_enabled = os.environ.get("PROUDCTION_MODE_ENABLED") -server_port = %MANAGED_SERVER_PORT% -domain_path = os.environ.get("DOMAIN_HOME") -cluster_name = "%CLUSTER_NAME%" -number_of_ms = %CONFIGURED_MANAGED_SERVER_COUNT% -cluster_type = "%CLUSTER_TYPE%" -domain_logs = os.environ.get("DOMAIN_LOGS_DIR") +# Read the domain secrets from the common python file +execfile('%s/read-domain-secret.py' % script_dir) print('domain_path : [%s]' % domain_path); -print('domain_name : [%DOMAIN_NAME%]'); +print('domain_name : [%s]' % domain_name); +print('admin_server_name : [%s]' % admin_server_name); print('admin_username : [%s]' % admin_username); -print('admin_port : [%ADMIN_PORT%]'); +print('admin_port : [%s]' % admin_port); print('cluster_name : [%s]' % cluster_name); print('server_port : [%s]' % server_port); -print('cluster_type : [%s]' % cluster_type); - # Open default domain template # ============================ readTemplate("/u01/oracle/wlserver/common/templates/wls/wls.jar") -set('Name', '%DOMAIN_NAME%') -setOption('DomainName', '%DOMAIN_NAME%') -create('%DOMAIN_NAME%','Log') -cd('/Log/%DOMAIN_NAME%'); -set('FileName', '%DOMAIN_LOGS_DIR%/%DOMAIN_NAME%.log') +set('Name', domain_name) +setOption('DomainName', domain_name) +create(domain_name,'Log') +cd('/Log/%s' % domain_name); +set('FileName', '%s/%s.log' % (domain_logs, domain_name)) # Configure the Administration Server # =================================== cd('/Servers/AdminServer') -set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') -set('ListenPort', %ADMIN_PORT%) -set('Name', '%ADMIN_SERVER_NAME%') +set('ListenAddress', '%s-%s' % (domain_uid, admin_server_name_svc)) +set('ListenPort', admin_port) +set('Name', admin_server_name) create('T3Channel', 'NetworkAccessPoint') -cd('/Servers/%ADMIN_SERVER_NAME%/NetworkAccessPoints/T3Channel') -set('PublicPort', %T3_CHANNEL_PORT%) -set('PublicAddress', '%T3_PUBLIC_ADDRESS%') -set('ListenAddress', '%DOMAIN_UID%-%ADMIN_SERVER_NAME_SVC%') -set('ListenPort', %T3_CHANNEL_PORT%) +cd('/Servers/%s/NetworkAccessPoints/T3Channel' % admin_server_name) +set('PublicPort', t3_channel_port) +set('PublicAddress', t3_public_address) +set('ListenAddress', '%s-%s' % (domain_uid, admin_server_name_svc)) +set('ListenPort', t3_channel_port) -cd('/Servers/%ADMIN_SERVER_NAME%') -create('%ADMIN_SERVER_NAME%', 'Log') -cd('/Servers/%ADMIN_SERVER_NAME%/Log/%ADMIN_SERVER_NAME%') -set('FileName', '%DOMAIN_LOGS_DIR%/%ADMIN_SERVER_NAME%.log') +cd('/Servers/%s' % admin_server_name) +create(admin_server_name, 'Log') +cd('/Servers/%s/Log/%s' % (admin_server_name, admin_server_name)) +set('FileName', '%s/%s.log' % (domain_logs, admin_server_name)) # Set the admin user's username and password # ========================================== -cd('/Security/%DOMAIN_NAME%/User/weblogic') +cd('/Security/%s/User/weblogic' % domain_name) cmo.setName(admin_username) cmo.setPassword(admin_password) @@ -89,13 +99,13 @@ cd('/') msIndex = index+1 - name = '%MANAGED_SERVER_NAME_BASE%%s' % msIndex - name_svc = '%MANAGED_SERVER_NAME_BASE_SVC%%s' % msIndex + name = '%s%s' % (managed_server_name_base, msIndex) + name_svc = '%s%s' % (managed_server_name_base_svc, msIndex) create(name, 'Server') cd('/Servers/%s/' % name ) print('managed server name is %s' % name); - set('ListenAddress', '%DOMAIN_UID%-%s' % name_svc) + set('ListenAddress', '%s-%s' % (domain_uid, name_svc)) set('ListenPort', server_port) set('NumOfRetriesBeforeMSIMode', 0) set('RetryIntervalBeforeMSIMode', 1) @@ -103,7 +113,7 @@ create(name,'Log') cd('/Servers/%s/Log/%s' % (name, name)) - set('FileName', '%DOMAIN_LOGS_DIR%/%s.log' % name) + set('FileName', '%s/%s.log' % (domain_logs,name)) else: print('Configuring Dynamic Cluster %s' % cluster_name) @@ -113,7 +123,7 @@ print('Done creating Server Template: %s' % templateName) cd('/ServerTemplates/%s' % templateName) cmo.setListenPort(server_port) - cmo.setListenAddress('%DOMAIN_UID%-%MANAGED_SERVER_NAME_BASE_SVC%${id}') + cmo.setListenAddress('%s-%s${id}' % (domain_uid, managed_server_name_base_svc)) cmo.setCluster(cl) print('Done setting attributes for Server Template: %s' % templateName); @@ -122,7 +132,7 @@ create(cluster_name, 'DynamicServers') cd('DynamicServers/%s' % cluster_name) set('ServerTemplate', st1) - set('ServerNamePrefix', "%MANAGED_SERVER_NAME_BASE%") + set('ServerNamePrefix', managed_server_name_base) set('DynamicClusterSize', number_of_ms) set('MaxDynamicClusterSize', number_of_ms) set('CalculatedListenPorts', false) @@ -139,7 +149,10 @@ # Update Domain readDomain(domain_path) cd('/') -cmo.setProductionModeEnabled(%PRODUCTION_MODE_ENABLED%) +if production_mode_enabled == "true": + cmo.setProductionModeEnabled(true) +else: + cmo.setProductionModeEnabled(false) updateDomain() closeDomain() print 'Domain Updated' From 8525b2ffa07fb4648d8527f70719691900f83c1f Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 2 Oct 2018 10:19:26 -0700 Subject: [PATCH 8/9] Add imagePullPolicy and checks for os.environ.get() call Signed-off-by: doxiao --- .../create-weblogic-sample-domain-inputs.yaml | 3 ++ ...e-weblogic-sample-domain-job-template.yaml | 2 +- .../create-weblogic-sample-domain.sh | 27 ++++++++++++ .../domain-custom-resource-template.yaml | 2 +- .../domain-home-on-pv/wlst/create-domain.py | 41 +++++++++++-------- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml index c6fdbeadf90..d022e124851 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml @@ -43,6 +43,9 @@ managedServerPort: 8001 # WebLogic Docker image image: store/oracle/weblogic:12.2.1.3 +# Image pull policy +imagePullPolicy: Never + # Boolean indicating if production mode is enabled for the domain productionModeEnabled: true diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml index cff429d2ae9..bfdde374985 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-job-template.yaml @@ -18,7 +18,7 @@ spec: containers: - name: create-weblogic-sample-domain-job image: %WEBLOGIC_IMAGE% - imagePullPolicy: IfNotPresent + imagePullPolicy: %WEBLOGIC_IMAGE_PULL_POLICY% ports: - containerPort: 7001 volumeMounts: diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh index 619391bca7c..ca334f7b5f1 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain.sh @@ -107,6 +107,29 @@ function validateDomainSecret { failIfValidationErrors } +# +# Function to validate the weblogic image pull policy +# +function validateWeblogicImagePullPolicy { + if [ ! -z ${imagePullPolicy} ]; then + case ${imagePullPolicy} in + "IfNotPresent") + ;; + "Always") + ;; + "Never") + ;; + *) + validationError "Invalid value for imagePullPolicy: ${imagePullPolicy}. Valid values are IfNotPresent, Always, and Never." + ;; + esac + else + # Set the default + imagePullPolicy="IfNotPresent" + fi + failIfValidationErrors +} + # # Function to validate the weblogic image pull secret name # @@ -238,6 +261,7 @@ function initialize { validateManagedServerNameBase validateClusterName validateWeblogicCredentialsSecretName + validateWeblogicImagePullPolicy validateWeblogicImagePullSecretName initAndValidateOutputDir validateStartupControl @@ -299,6 +323,7 @@ function createYamlFiles { sed -i -e "s:%NAMESPACE%:$namespace:g" ${createJobOutput} sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${createJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${createJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${createJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${createJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${createJobOutput} sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${createJobOutput} @@ -326,6 +351,7 @@ function createYamlFiles { cp ${deleteJobInput} ${deleteJobOutput} sed -i -e "s:%NAMESPACE%:$namespace:g" ${deleteJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${deleteJobOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${deleteJobOutput} sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${deleteJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${deleteJobOutput} sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${deleteJobOutput} @@ -356,6 +382,7 @@ function createYamlFiles { sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput} sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${dcrOutput} sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${dcrOutput} + sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${dcrOutput} sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput} sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${dcrOutput} sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput} diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml index 85be36e4cec..a88c4595ba5 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml @@ -23,7 +23,7 @@ spec: # The Operator currently does not support other images image: "%WEBLOGIC_IMAGE%" # imagePullPolicy defaults to "Always" if image version is :latest - imagePullPolicy: "IfNotPresent" + imagePullPolicy: "%WEBLOGIC_IMAGE_PULL_POLICY%" # Identify which Secret contains the credentials for pulling an image imagePullSecret: name: %WEBLOGIC_IMAGE_PULL_SECRET_NAME% diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py index b787c4b2e87..721e141deca 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/wlst/create-domain.py @@ -1,25 +1,32 @@ # Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +def getEnvVar(var): + val=os.environ.get(var) + if val==None: + print "ERROR: Env var ",var, " not set." + sys.exit(1) + return val + # This python script is used to create a WebLogic domain -domain_uid = os.environ.get("DOMAIN_UID") -server_port = int(os.environ.get("MANAGED_SERVER_PORT")) -domain_path = os.environ.get("DOMAIN_HOME") -cluster_name = os.environ.get("CLUSTER_NAME") -admin_server_name = os.environ.get("ADMIN_SERVER_NAME") -admin_server_name_svc = os.environ.get("ADMIN_SERVER_NAME_SVC") -admin_port = int(os.environ.get("ADMIN_PORT")) -domain_name = os.environ.get("DOMAIN_NAME") -t3_channel_port = int(os.environ.get("T3_CHANNEL_PORT")) -t3_public_address = os.environ.get("T3_PUBLIC_ADDRESS") -number_of_ms = int(os.environ.get("CONFIGURED_MANAGED_SERVER_COUNT")) -cluster_type = os.environ.get("CLUSTER_TYPE") -managed_server_name_base = os.environ.get("MANAGED_SERVER_NAME_BASE") -managed_server_name_base_svc = os.environ.get("MANAGED_SERVER_NAME_BASE_SVC") -domain_logs = os.environ.get("DOMAIN_LOGS_DIR") -script_dir = os.environ.get("CREATE_DOMAIN_SCRIPT_DIR") -production_mode_enabled = os.environ.get("PROUDCTION_MODE_ENABLED") +domain_uid = getEnvVar("DOMAIN_UID") +server_port = int(getEnvVar("MANAGED_SERVER_PORT")) +domain_path = getEnvVar("DOMAIN_HOME") +cluster_name = getEnvVar("CLUSTER_NAME") +admin_server_name = getEnvVar("ADMIN_SERVER_NAME") +admin_server_name_svc = getEnvVar("ADMIN_SERVER_NAME_SVC") +admin_port = int(getEnvVar("ADMIN_PORT")) +domain_name = getEnvVar("DOMAIN_NAME") +t3_channel_port = int(getEnvVar("T3_CHANNEL_PORT")) +t3_public_address = getEnvVar("T3_PUBLIC_ADDRESS") +number_of_ms = int(getEnvVar("CONFIGURED_MANAGED_SERVER_COUNT")) +cluster_type = getEnvVar("CLUSTER_TYPE") +managed_server_name_base = getEnvVar("MANAGED_SERVER_NAME_BASE") +managed_server_name_base_svc = getEnvVar("MANAGED_SERVER_NAME_BASE_SVC") +domain_logs = getEnvVar("DOMAIN_LOGS_DIR") +script_dir = getEnvVar("CREATE_DOMAIN_SCRIPT_DIR") +production_mode_enabled = getEnvVar("PRODUCTION_MODE_ENABLED") # Read the domain secrets from the common python file execfile('%s/read-domain-secret.py' % script_dir) From ecba3662aeeb45e14722055b1ae0c67c6e8ee5fc Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 2 Oct 2018 10:22:50 -0700 Subject: [PATCH 9/9] Add legal values and corrct defult for imagePullPolicy Signed-off-by: doxiao --- .../create-weblogic-sample-domain-inputs.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml index d022e124851..de151822574 100644 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-weblogic-sample-domain-inputs.yaml @@ -44,7 +44,8 @@ managedServerPort: 8001 image: store/oracle/weblogic:12.2.1.3 # Image pull policy -imagePullPolicy: Never +# Legal values are "IfNotPresent", "Always", or "Never" +imagePullPolicy: IfNotPresent # Boolean indicating if production mode is enabled for the domain productionModeEnabled: true