Skip to content

Commit c414962

Browse files
doxiaomarkxnelson
authored andcommitted
Add image, imagePullPolicy and imagePullSecrets to domain-home-in-image sample (#674)
* Add imagePullPolicy and imagePullSecrets to domain-home-in-image sample Signed-off-by: doxiao <[email protected]> * Support customizable image name as well Signed-off-by: doxiao <[email protected]> * Fix the default image name for wdt case Signed-off-by: doxiao <[email protected]> * Update the README Signed-off-by: doxiao <[email protected]>
1 parent 31bb0d2 commit c414962

File tree

7 files changed

+93
-61
lines changed

7 files changed

+93
-61
lines changed

kubernetes/samples/scripts/common/utility.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ function getKubernetesClusterIP {
217217
#
218218
function createDomainResource {
219219
kubectl apply -f ${dcrOutput}
220-
DCR_AVAIL=`kubectl get domain -n ${namespace} | grep ${domainUID} | wc | awk ' { print $1; } '`
220+
221+
attempts=0
222+
while [ "$DCR_AVAIL" != "1" ] && [ ! $attempts -eq 10 ]; do
223+
attempts=$((attempts + 1))
224+
sleep 1
225+
DCR_AVAIL=`kubectl get domain ${domainUID} -n ${namespace} | grep ${domainUID} | wc | awk ' { print $1; } '`
226+
done
221227
if [ "${DCR_AVAIL}" != "1" ]; then
222228
fail "The domain resource ${domainUID} was not found"
223229
fi

kubernetes/samples/scripts/common/validate.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,56 @@ function validateWeblogicCredentialsSecretName {
153153
validateLowerCase "weblogicCredentialsSecretName" ${weblogicCredentialsSecretName}
154154
}
155155

156+
#
157+
# Function to validate the weblogic image pull policy
158+
#
159+
function validateWeblogicImagePullPolicy {
160+
if [ ! -z ${imagePullPolicy} ]; then
161+
case ${imagePullPolicy} in
162+
"IfNotPresent")
163+
;;
164+
"Always")
165+
;;
166+
"Never")
167+
;;
168+
*)
169+
validationError "Invalid value for imagePullPolicy: ${imagePullPolicy}. Valid values are IfNotPresent, Always, and Never."
170+
;;
171+
esac
172+
else
173+
# Set the default
174+
imagePullPolicy="IfNotPresent"
175+
fi
176+
failIfValidationErrors
177+
}
178+
179+
#
180+
# Function to validate the weblogic image pull secret name
181+
#
182+
function validateWeblogicImagePullSecretName {
183+
if [ ! -z ${imagePullSecretName} ]; then
184+
validateLowerCase imagePullSecretName ${imagePullSecretName}
185+
imagePullSecretPrefix=""
186+
if [ "${generateOnly}" = false ]; then
187+
validateWeblogicImagePullSecret
188+
fi
189+
else
190+
# Set name blank when not specified, and comment out the yaml
191+
imagePullSecretName=""
192+
imagePullSecretPrefix="#"
193+
fi
194+
}
195+
196+
#
197+
# Function to validate the weblogic image pull secret exists
198+
#
199+
function validateWeblogicImagePullSecret {
200+
# The kubernetes secret for pulling images from the docker store is optional.
201+
# If it was specified, make sure it exists.
202+
validateSecretExists ${imagePullSecretName} ${namespace}
203+
failIfValidationErrors
204+
}
205+
156206
# try to execute kubectl to see whether kubectl is available
157207
function validateKubectlAvailable {
158208
if ! [ -x "$(command -v kubectl)" ]; then
@@ -339,6 +389,9 @@ function validateCommonInputs {
339389
validateWeblogicCredentialsSecretName
340390
validateServerStartPolicy
341391
validateClusterType
392+
validateWeblogicImagePullPolicy
393+
validateWeblogicImagePullSecretName
394+
342395
failIfValidationErrors
343396
}
344397

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ The following parameters can be provided in the inputs file.
7777
| `domainUID` | Unique ID that will be used to identify this particular domain. Used as the name of the generated WebLogic domain as well as the name of the Kubernetes domain resource. This ID must be unique across all domains in a Kubernetes cluster. This ID cannot contain any character that is not valid in a Kubernetes service name. | `domain1` |
7878
| `exposeAdminNodePort` | Boolean indicating if the Administration Server is exposed outside of the Kubernetes cluster. | `false` |
7979
| `exposeAdminT3Channel` | Boolean indicating if the T3 administrative channel is exposed outside the Kubernetes cluster. | `false` |
80+
| `image` | WebLogic Docker image that the domain resource will use. If not specified, the value is the name of the generated Docker image. | `12213-domain-wdt` |
8081
| `imagePath` | The relative directory of the WebLogic domain home in image Docker image in `https://github.com/oracle/docker-images.git` project under the `docker-images/OracleWebLogic/samples` directory. | `12213-domain-home-in-image-wdt` |
82+
| `imagePullPolicy` | WebLogic Docker image pull policy. Legal values are "IfNotPresent", "Always", or "Never" | `IfNotPresent` |
83+
| `imagePullSecretName` | 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 specified | |
8184
| `includeServerOutInPodLog` | Boolean indicating whether to include server .out to the pod's stdout. | `true` |
8285
| `initialManagedServerReplicas` | Number of Managed Servers to initially start for the domain. | `2` |
8386
| `javaOptions` | Java options for starting the Administration and Managed Servers. A Java option can have references to one or more of the following pre-defined variables to obtain WebLogic domain information: `$(DOMAIN_NAME)`, `$(DOMAIN_HOME)`, `$(ADMIN_NAME)`, `$(ADMIN_PORT)`, and `$(SERVER_NAME)`. | `-Dweblogic.StdoutDebugEnabled=false` |

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain-inputs.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ managedServerPort: 8001
4040
# Boolean indicating if production mode is enabled for the domain
4141
productionModeEnabled: true
4242

43+
# WebLogic Docker image that the domain resource will use.
44+
# If not specified, the value is the name of the generated Docker image, which is
45+
# "12213-domain-home-in-image" if the imagePath property is specified as "12213-domain-home-in-image";
46+
# "12213-domain-wdt" if the imagePath property is specified as "12213-domain-home-in-image-wdt".
47+
image: 12213-domain-wdt
48+
49+
# Image pull policy
50+
# Legal values are "IfNotPresent", "Always", or "Never"
51+
imagePullPolicy: IfNotPresent
52+
53+
# Name of the Kubernetes secret to access the Docker Store to pull the WebLogic Server Docker image
54+
# The presence of the secret will be validated when this parameter is enabled.
55+
#imagePullSecretName:
56+
4357
# Name of the Kubernetes secret for the Admin Server's username and password
4458
# The name must be lowercase.
4559
# If not specified, the value is derived from the domainUID as <domainUID>-weblogic-credentials

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ function createFiles {
230230
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${dcrOutput}
231231
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${dcrOutput}
232232
sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput}
233+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
234+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${dcrOutput}
235+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput}
236+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
233237

234238
# Remove any "...yaml-e" files left over from running sed
235239
rm -f ${domainOutputDir}/*.yaml-e
@@ -245,14 +249,18 @@ function createDomainHome {
245249

246250
cp ${domainPropertiesOutput} ./docker-images/OracleWebLogic/samples/${imagePath}/properties/docker_build
247251

248-
imageName="12213-domain-home-in-image:latest"
252+
imageName="12213-domain-home-in-image"
249253
# use the existence of build-archive.sh file to determine if we need to download WDT
250254
if [ -f "./docker-images/OracleWebLogic/samples/${imagePath}/build-archive.sh" ]; then
251-
imageName="12213-domain-wdt:latest"
255+
imageName="12213-domain-wdt"
252256
fi
253257

254258
# now we know which image to use, update the domain yaml file
255-
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
259+
if [ -z $image ]; then
260+
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
261+
else
262+
sed -i -e "s|%IMAGE_NAME%|${image}|g" ${dcrOutput}
263+
fi
256264

257265
cd docker-images/OracleWebLogic/samples/${imagePath}
258266

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/domain-template.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ spec:
1818
domainHomeInImage: true
1919
# The Operator currently does not support other images
2020
image: %IMAGE_NAME%
21-
# imagePullPolicy defaults to "Never"
22-
imagePullPolicy: "Never"
21+
# imagePullPolicy defaults to "Always" if image version is :latest
22+
imagePullPolicy: "%WEBLOGIC_IMAGE_PULL_POLICY%"
23+
# Identify which Secret contains the credentials for pulling an image
24+
%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%imagePullSecrets:
25+
%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%- name: %WEBLOGIC_IMAGE_PULL_SECRET_NAME%
2326
# Identify which Secret contains the WebLogic Admin credentials (note that there is an example of
2427
# how to create that Secret at the end of this file)
2528
webLogicCredentialsSecret:

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,56 +85,6 @@ function initOutputDir {
8585
removeFileIfExists ${domainOutputDir}/domain.yaml
8686
}
8787

88-
#
89-
# Function to validate the weblogic image pull policy
90-
#
91-
function validateWeblogicImagePullPolicy {
92-
if [ ! -z ${imagePullPolicy} ]; then
93-
case ${imagePullPolicy} in
94-
"IfNotPresent")
95-
;;
96-
"Always")
97-
;;
98-
"Never")
99-
;;
100-
*)
101-
validationError "Invalid value for imagePullPolicy: ${imagePullPolicy}. Valid values are IfNotPresent, Always, and Never."
102-
;;
103-
esac
104-
else
105-
# Set the default
106-
imagePullPolicy="IfNotPresent"
107-
fi
108-
failIfValidationErrors
109-
}
110-
111-
#
112-
# Function to validate the weblogic image pull secret name
113-
#
114-
function validateWeblogicImagePullSecretName {
115-
if [ ! -z ${imagePullSecretName} ]; then
116-
validateLowerCase imagePullSecretName ${imagePullSecretName}
117-
imagePullSecretPrefix=""
118-
if [ "${generateOnly}" = false ]; then
119-
validateWeblogicImagePullSecret
120-
fi
121-
else
122-
# Set name blank when not specified, and comment out the yaml
123-
imagePullSecretName=""
124-
imagePullSecretPrefix="#"
125-
fi
126-
}
127-
128-
#
129-
# Function to validate the weblogic image pull secret exists
130-
#
131-
function validateWeblogicImagePullSecret {
132-
# The kubernetes secret for pulling images from the docker store is optional.
133-
# If it was specified, make sure it exists.
134-
validateSecretExists ${imagePullSecretName} ${namespace}
135-
failIfValidationErrors
136-
}
137-
13888
#
13989
#
14090
# Function to validate the domain's persistent volume claim has been created
@@ -189,11 +139,6 @@ function initialize {
189139

190140
validateCommonInputs
191141

192-
validateWeblogicImagePullPolicy
193-
validateWeblogicImagePullSecretName
194-
195-
failIfValidationErrors
196-
197142
initOutputDir
198143
}
199144

0 commit comments

Comments
 (0)