Skip to content

Commit 26379a7

Browse files
authored
Merge pull request #552 from oracle/samples/owls-70382
OWLS-70382: sample for WLS domain credential secret
2 parents 2c20c18 + ff7d2f5 commit 26379a7

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

kubernetes/samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Sample scripts
44

5+
* [Sample Secret for WebLogic Amin Credentials](scripts/create-weblogic-domain/create-weblogic-credentials.sh) for creating a Kubernetes secret that contains the admin server credentials. This secret can then be used in creating a WebLogic domain custom resource.
56
* [Sample PV and PVC](scripts/create-weblogic-domain-pv-pvc/README.md) for creating a PV or PVC that can be used by a domain custom resource as the persistent storage for the WebLogic domain home or log files.
67
* [Sample domain home on a persistent volume](scripts/create-weblogic-domain/domain-home-on-pv/README.md) for creating a WebLogic domain home on an existing PV or PVC, and the domain customer resource YAML file for deploying the generated WebLogic domain.
78
* [Sample Elasticsearch and Kibana configuration](scripts/elasticsearch_and_kibana.yaml) for configuring the Elasticsearch and Kibana deployments and services for the operator's logs.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
# Description
6+
# This sample script creates a Kubernetes secret for WebLogic domain admin credentials.
7+
#
8+
# The following pre-requisites must be handled prior to running this script:
9+
# * The kubernetes namespace must already be created
10+
#
11+
12+
script="${BASH_SOURCE[0]}"
13+
14+
#
15+
# Function to exit and print an error message
16+
# $1 - text of message
17+
function fail {
18+
echo [ERROR] $*
19+
exit 1
20+
}
21+
22+
# Try to execute kubectl to see whether kubectl is available
23+
function validateKubectlAvailable {
24+
if ! [ -x "$(command -v kubectl)" ]; then
25+
fail "kubectl is not installed"
26+
fi
27+
}
28+
29+
function usage {
30+
echo usage: ${script} -u username -p password [-d domainUID] [-n namespace] [-h]
31+
echo " -u username, must be specified."
32+
echo " -p password, must be specified."
33+
echo " -n namespace, optional."
34+
echo " -d domainUID, optional."
35+
echo " -h Help"
36+
exit $1
37+
}
38+
39+
#
40+
# Parse the command line options
41+
#
42+
domainUID=domain1
43+
namespace=default
44+
while getopts "hu:p:n:d:" opt; do
45+
case $opt in
46+
u) username="${OPTARG}"
47+
;;
48+
p) password="${OPTARG}"
49+
;;
50+
n) namespace="${OPTARG}"
51+
;;
52+
d) domainUID="${OPTARG}"
53+
;;
54+
h) usage 0
55+
;;
56+
*) usage 1
57+
;;
58+
esac
59+
done
60+
secretName=$domainUID-weblogic-credentials
61+
62+
if [ -z ${username} ]; then
63+
echo "${script}: -u must be specified."
64+
missingRequiredOption="true"
65+
fi
66+
67+
if [ -z ${password} ]; then
68+
echo "${script}: -p must be specified."
69+
missingRequiredOption="true"
70+
fi
71+
72+
if [ "${missingRequiredOption}" == "true" ]; then
73+
usage 1
74+
fi
75+
76+
# check and see if the secret already exists
77+
result=`kubectl get secret ${secretName} -n ${namespace} --ignore-not-found=true | grep ${secretName} | wc | awk ' { print $1; }'`
78+
if [ "${result:=Error}" != "0" ]; then
79+
fail "The secret ${secretName} already exists in namespace ${namespace}."
80+
fi
81+
82+
# create the secret
83+
kubectl -n $namespace create secret generic $secretName \
84+
--from-literal=username=$username \
85+
--from-literal=password=$password
86+
87+
# label the secret with domainUID
88+
kubectl label secret ${secretName} -n $namespace weblogic.domainUID=$domainUID weblogic.domainName=$domainUID
89+
90+
# Verify the secret exists
91+
SECRET=`kubectl get secret ${secretName} -n ${namespace} | grep ${secretName} | wc | awk ' { print $1; }'`
92+
if [ "${SECRET}" != "1" ]; then
93+
fail "The secret ${secretName} was not found in namespace ${namespace}"
94+
fi
95+
96+
echo "The secret ${secretName} has been successfully created in namespace ${namespace}"

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
23
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
34
#
45
# This is an example of how to define a Domain Custom Resource.
@@ -8,6 +9,10 @@ kind: Domain
89
metadata:
910
name: %DOMAIN_UID%
1011
namespace: %NAMESPACE%
12+
labels:
13+
weblogic.resourceVersion: domain-v2
14+
weblogic.domainUID: %DOMAIN_UID%
15+
weblogic.domainName: %DOMAIN_NAME%
1116
spec:
1217
# The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must
1318
# have its own unique domainUID. This does not have to be the same as the Domain Name. It is allowed
@@ -18,6 +23,8 @@ spec:
1823
domainName: %DOMAIN_NAME%
1924
# The WebLogic Domain Home
2025
domainHome: %DOMAIN_HOME%
26+
# If the domain home is in the image
27+
domainHomeInImage: false
2128
# The Operator currently does not support other images
2229
image: "%WEBLOGIC_IMAGE%"
2330
# imagePullPolicy defaults to "Always" if image version is :latest

0 commit comments

Comments
 (0)