Skip to content

Commit fe60ba8

Browse files
xiancaorjeberhard
authored andcommitted
backport MR 4862 to main
1 parent d8f3db9 commit fe60ba8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5122
-7
lines changed

Jenkinsfile.ocne

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ pipeline {
101101
description: 'oci image id for node pool, find image OCID for your region from https://docs.oracle.com/iaas/images/',
102102
//defaultValue7.6: 'ocid1.image.oc1.phx.aaaaaaaancucg25pze6m52agxwxmmfszvsdnhp3kvim53pts2tw6mik4xtha'
103103
defaultValue: 'ocid1.image.oc1.phx.aaaaaaaaaizmtmozeudeeuq7o5ir7dkl2bkxbbb3tgomshqbqn6jpomrsjza'
104-
105104
)
106105
string(name: 'KUBECTL_VERSION',
107106
description: 'kubectl version',

Jenkinsfile.ocne19

+667
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/InitializationTasks.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ public void beforeAll(ExtensionContext context) {
325325

326326
// set initialization success to true, not counting the istio installation as not all tests use istio
327327
isInitializationSuccessful = true;
328-
if ((!OKD && !OCNE && !CRIO)
329-
|| (OCNE && !CRIO && !assertDoesNotThrow(() -> Namespace.exists("istio-system")))) {
328+
if (!OKD && !CRIO) {
330329
logger.info("Installing istio before any test suites are run");
331330
installIstio();
332331
}
@@ -379,11 +378,11 @@ public void close() {
379378
if (SKIP_CLEANUP) {
380379
logger.info("Skipping RESULTS_ROOT clean up after test execution");
381380
} else {
382-
if (!OKD && !OCNE && !CRIO) {
381+
if (!OKD && !CRIO) {
383382
logger.info("Uninstall istio after all test suites are run");
384383
uninstallIstio();
385384
}
386-
if (!OKD && !OKE_CLUSTER && !OCNE && !CRIO) {
385+
if (!OKD && !OKE_CLUSTER && !CRIO) {
387386
logger.info("Delete istio-system namespace after all test suites are run");
388387
deleteNamespace("istio-system");
389388
deleteNamespace(ORACLE_OPERATOR_NS);

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/IstioUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public static void installIstio() {
104104
logger.info("replace istio installation hub in File {0}", installScript);
105105
assertDoesNotThrow(() -> replaceStringInFile(installScript, "gcr.io", ocneIstioRepo),
106106
String.format("Failed to replace string in File %s", installScript));
107+
assertDoesNotThrow(() -> replaceStringInFile(installScript, "--auth=instance_principal", " "),
108+
String.format("Failed to replace string in File %s", installScript));
107109
}
108110
String arch = "linux-amd64";
109111
if (ARM) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#!/bin/bash
2+
# Copyright (c) 2024, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
prop() {
6+
grep "${1}" ${propsFile}| grep -v "#" | cut -d'=' -f2
7+
}
8+
9+
generateTFVarFile() {
10+
tfVarsFile=${terraformVarDir}/terraform.tfvars
11+
rm -f ${tfVarsFile}
12+
cp ${terraformVarDir}/terraform.tfvars.template $tfVarsFile
13+
chmod 777 $tfVarsFile
14+
15+
sed -i -e "s:@OCI_TENANCY_ID@:${tenancy_id}:g" ${tfVarsFile}
16+
sed -i -e "s:@OCI_COMPARTMENT_ID@:${compartment_id}:g" ${tfVarsFile}
17+
sed -i -e "s:@OCI_USER_ID@:${user_id}:g" ${tfVarsFile}
18+
sed -i -e "s/@OCI_FINGERPRINT@/"${fingerprint}"/g" ${tfVarsFile}
19+
sed -i -e "s:@OCI_API_PRIVATE_KEY_PATH@:${api_private_key_path}:g" ${tfVarsFile}
20+
21+
sed -i -e "s:@OCI_REGION@:${region}:g" ${tfVarsFile}
22+
sed -i -e "s/@OCI_AVAILABILITY_DOMAIN_ID@/"${availability_domain_id}"/g" ${tfVarsFile}
23+
sed -i -e "s:@OCI_INSTANCE_PREFIX@:${prefix}:g" ${tfVarsFile}
24+
25+
sed -i -e "s:@OCI_DEPLOY_NETWORKING@:${deploy_networking}:g" ${tfVarsFile}
26+
sed -i -e "s:@OCI_SUBNET_ID@:${subnet_id}:g" ${tfVarsFile}
27+
sed -i -e "s:@OCI_VCN_ID@:${vcn_id}:g" ${tfVarsFile}
28+
29+
sed -i -e "s:@OCI_SSH_PUBLIC_KEY_PATH@:${ssh_public_key_path}:g" ${tfVarsFile}
30+
sed -i -e "s:@OCI_SSH_PRIVATE_KEY_PATH@:${ssh_private_key_path}:g" ${tfVarsFile}
31+
32+
sed -i -e "s:@OCI_ENABLE_BASTION@:${enable_bastion}:g" ${tfVarsFile}
33+
34+
sed -i -e "s:@OCI_VIRTUAL_IP@:${virtual_ip}:g" ${tfVarsFile}
35+
36+
sed -i -e "s:@OCNE_CONTROL_PLANE_NODE_COUNT@:${control_plane_node_count}:g" ${tfVarsFile}
37+
sed -i -e "s:@OCNE_WORKER_NODE_COUNT@:${worker_node_count}:g" ${tfVarsFile}
38+
sed -i -e "s:@OCNE_ENVIRONMENT_NAME@:${environment_name}:g" ${tfVarsFile}
39+
sed -i -e "s:@OCNE_K8S_CLUSTER_NAME@:${kubernetes_name}:g" ${tfVarsFile}
40+
41+
sed -i -e "s:@OCNE_VERSION@:${ocne_version}:g" ${tfVarsFile}
42+
43+
sed -i -e "s#@HTTP_PROXY@#${http_proxy}#g" ${tfVarsFile}
44+
sed -i -e "s:@NO_PROXY@:${no_proxy}:g" ${tfVarsFile}
45+
46+
echo "Generated TFVars file [${tfVarsFile}]"
47+
cat "${tfVarsFile}"
48+
}
49+
50+
setupTerraform() {
51+
mkdir ${terraformDir}
52+
cd ${terraformDir}
53+
if [[ "${OSTYPE}" == "darwin"* ]]; then
54+
os_type="darwin"
55+
elif [[ "${OSTYPE}" == "linux"* ]]; then
56+
os_type="linux"
57+
else
58+
echo "Unsupported OS"
59+
fi
60+
curl -O https://releases.hashicorp.com/terraform/1.8.1/terraform_1.8.1_${os_type}_${platform}64.zip
61+
unzip terraform_1.8.1_${os_type}_${platform}64.zip
62+
chmod +x ${terraformDir}/terraform
63+
64+
# install yq
65+
wget https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_${os_type}_${platform}64.tar.gz
66+
tar -zxvf yq_${os_type}_${platform}64.tar.gz
67+
mv yq_${os_type}_${platform}64 yq
68+
69+
export PATH=${terraformDir}:${PATH}
70+
}
71+
72+
deleteOlderVersionTerraformOCIProvider() {
73+
if [ -d ~/.terraform.d/plugins ]; then
74+
echo "Deleting older version of terraform plugins dir"
75+
rm -rf ~/.terraform.d/plugins
76+
fi
77+
if [ -d ${terraformVarDir}/.terraform ]; then
78+
rm -rf ${terraformVarDir}/.terraform
79+
fi
80+
if [ -e ~/.terraformrc ]; then
81+
rm ~/.terraformrc
82+
fi
83+
}
84+
85+
createCluster () {
86+
cd ${terraformVarDir}
87+
echo "terraform init -var-file=${terraformVarDir}/terraform.tfvars"
88+
terraform init -var-file=${terraformVarDir}/terraform.tfvars
89+
echo "terraform plan -var-file=${terraformVarDir}/terraform.tfvars"
90+
terraform plan -var-file=${terraformVarDir}/terraform.tfvars
91+
echo "terraform apply -auto-approve -var-file=${terraformVarDir}/terraform.tfvars"
92+
terraform apply -auto-approve -var-file=${terraformVarDir}/terraform.tfvars
93+
}
94+
95+
checkKubernetesCliConnection() {
96+
echo "Confirming ${KUBERNETES_CLI:-kubectl} can connect to the server..."
97+
98+
# Get the OCNE cluster control node private IP
99+
echo "command to get k8s_master_instance_id: oci compute instance list --compartment-id=${compartment_id} --display-name=${prefix}-control-plane-001 |jq -r '.data[] | select(."lifecycle-state" == "RUNNING") | ."id"'"
100+
k8s_master_instance_id=`oci compute instance list --compartment-id=${compartment_id} --display-name=${prefix}-control-plane-001 |jq -r '.data[] | select(."lifecycle-state" == "RUNNING") | ."id"'`
101+
echo "command to get k8s_master_instance_private_ip: oci compute instance list-vnics --compartment-id=${compartment_id} --instance-id=${k8s_master_instance_id} |jq -r '.data[]."private-ip"'"
102+
k8s_master_instance_private_ips=`oci compute instance list-vnics --compartment-id=${compartment_id} --instance-id=${k8s_master_instance_id} |jq -r '.data[]."private-ip"'`
103+
104+
if [ -z "$k8s_master_instance_private_ips" ]; then
105+
echo "[ERROR] No active cluster found with name ${kubernetes_name}."
106+
exit 1
107+
fi
108+
109+
echo "OCNE K8S cluster control node private ip: ### $k8s_master_instance_private_ips ###"
110+
declare -a k8s_master_instance_private_ip=(${k8s_master_instance_private_ips//\n/ })
111+
112+
local local_no_proxy=${no_proxy}
113+
for i in "${k8s_master_instance_private_ip[@]}"; do
114+
local_no_proxy+=",$i"
115+
done
116+
export NO_PROXY="$local_no_proxy"
117+
echo "NO_PROXY=$NO_PROXY"
118+
119+
export KUBECONFIG=${terraformVarDir}/kubeconfig
120+
echo "KUBECONFIG=$KUBECONFIG"
121+
122+
local myline_output=$(${KUBERNETES_CLI:-kubectl} get nodes -o wide 2>&1)
123+
124+
if echo "$myline_output" | grep -q "Unable to connect to the server: net/http: TLS handshake timeout"; then
125+
echo "[ERROR] Unable to connect to the server: net/http: TLS handshake timeout"
126+
echo '- could not talk to OCNE cluster, aborting'
127+
128+
cd "${terraformVarDir}"
129+
terraform destroy -auto-approve -var-file="${terraformVarDir}/terraform.tfvars"
130+
exit 1
131+
fi
132+
if echo "$myline_output" | grep -q "couldn't get current server API group"; then
133+
echo "[ERROR] Unable to connect to the server: couldn't get current server API group, connection refused"
134+
echo '- check errors during OKE cluster creation'
135+
echo '- could not talk to OCNE cluster, aborting'
136+
137+
cd "${terraformVarDir}"
138+
terraform destroy -auto-approve -var-file="${terraformVarDir}/terraform.tfvars"
139+
exit 1
140+
fi
141+
}
142+
143+
checkClusterRunning() {
144+
checkKubernetesCliConnection
145+
146+
local prefix=${prefix}
147+
declare -a myline=($(${KUBERNETES_CLI:-kubectl} get nodes -o wide | grep "${prefix}" | awk '{print $2}'))
148+
149+
local max=100
150+
local count=1
151+
152+
for (( i = 0; i < ${#myline[@]} ; i++ )); do
153+
while [ "${myline[i]}" != "Ready" ] && [ $count -le $max ]; do
154+
echo "[ERROR] Some Nodes in the Cluster are not in the Ready Status, sleeping for 10s..."
155+
sleep 10
156+
myline=($(${KUBERNETES_CLI:-kubectl} get nodes -o wide | grep "${prefix}" | awk '{print $2}'))
157+
echo "myline[i]: ${myline[i]}"
158+
echo "Status is ${myline[i]} Iter [$count/$max]"
159+
count=$((count + 1))
160+
done
161+
done
162+
163+
local NODES=$(${KUBERNETES_CLI:-kubectl} get nodes -o wide | grep "${prefix}" | wc -l)
164+
local number_nodes=$(($control_plane_node_count + $worker_node_count))
165+
if [ "$NODES" -eq "$number_nodes" ]; then
166+
echo '- looks good'
167+
else
168+
echo '- could not talk to OCNE cluster, aborting'
169+
cd "${terraformVarDir}"
170+
terraform destroy -auto-approve -var-file="${terraformVarDir}/${clusterTFVarsFile}.tfvars"
171+
exit 1
172+
fi
173+
174+
if [ $count -gt $max ]; then
175+
echo "[ERROR] Unable to start the nodes in the OCNE cluster after 200s"
176+
cd "${terraformVarDir}"
177+
terraform destroy -auto-approve -var-file="${terraformVarDir}/${clusterTFVarsFile}.tfvars"
178+
exit 1
179+
fi
180+
}
181+
182+
183+
#MAIN
184+
propsFile=${1:-$PWD/oci.props}
185+
terraformVarDir=${2:-$PWD}
186+
platform=${3:-amd}
187+
188+
#grep props's values from oci.props file
189+
190+
tenancy_id=$(prop 'tenancy_id')
191+
compartment_id=$(prop 'compartment_id')
192+
user_id=$(prop 'user_id')
193+
fingerprint=$(prop 'fingerprint')
194+
api_private_key_path=$(prop 'api_private_key_path')
195+
196+
region=$(prop 'region')
197+
availability_domain_id=$(prop 'availability_domain_id')
198+
prefix=$(prop 'prefix')
199+
200+
deploy_networking=$(prop 'deploy_networking')
201+
subnet_id=$(prop 'subnet_id')
202+
vcn_id=$(prop 'vcn_id')
203+
204+
ssh_public_key_path=$(prop 'ssh_public_key_path')
205+
ssh_private_key_path=$(prop 'ssh_private_key_path')
206+
207+
enable_bastion=$(prop 'enable_bastion')
208+
209+
virtual_ip=$(prop 'virtual_ip')
210+
211+
control_plane_node_count=$(prop 'control_plane_node_count')
212+
worker_node_count=$(prop 'worker_node_count')
213+
environment_name=$(prop 'environment_name')
214+
kubernetes_name=$(prop 'kubernetes_name')
215+
216+
ocne_version=$(prop 'ocne_version')
217+
218+
http_proxy=$(prop 'http_proxy')
219+
no_proxy=$(prop 'no_proxy')
220+
221+
terraformDir=$(prop 'terraform.installdir')
222+
223+
# generate terraform configuration file with name $(clusterTFVarsFile).tfvar
224+
generateTFVarFile
225+
226+
# cleanup previously installed terraform binaries
227+
rm -rf ${terraformDir}
228+
229+
# download terraform binaries into ${terraformDir}
230+
setupTerraform
231+
232+
# clean previous versions of terraform oci provider
233+
deleteOlderVersionTerraformOCIProvider
234+
235+
# run terraform init,plan,apply to create OCNE cluster based on the provided tfvar file ${tfVarsFile}
236+
createCluster
237+
238+
#check status of OCNE cluster nodes, destroy if can not access them
239+
export KUBECONFIG=${terraformVarDir}/kubeconfig
240+
checkClusterRunning
241+
echo "${kubernetes_name} is up and running"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# Copyright (c) 2024, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
#
5+
# This script deletes provisioned OKE Kubernetes cluster using terraform (https://www.terraform.io/)
6+
#
7+
8+
set -o errexit
9+
set -o pipefail
10+
11+
prop() {
12+
grep "${1}" ${oci_property_file}| grep -v "#" | cut -d'=' -f2
13+
}
14+
15+
deleteOCNECluster() {
16+
cd ${terraform_script_dir}
17+
terraform init -var-file=${terraform_script_dir}/terraform.tfvars
18+
terraform plan -var-file=${terraform_script_dir}/terraform.tfvars
19+
terraform destroy -auto-approve -var-file=${terraform_script_dir}/terraform.tfvars
20+
}
21+
22+
23+
#MAIN
24+
oci_property_file=${1:-$PWD/oci.props}
25+
terraform_script_dir=${2:-$PWD}
26+
27+
terraformDir=$(prop 'terraform.installdir')
28+
export PATH=${terraformDir}:$PATH
29+
30+
echo 'Deleting cluster'
31+
deleteOCNECluster || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
locals {
5+
provision_modes_map = {
6+
provision_mode_ocne = "OCNE"
7+
provision_mode_infrastucture = "Infrastructure"
8+
}
9+
10+
provision_modes_values_list = values(local.provision_modes_map)
11+
}
12+
13+
locals {
14+
secret_name = "${var.prefix}-${var.secret_name}"
15+
ocne_secret_name = "${var.prefix}-${var.ocne_secret_name}"
16+
}

0 commit comments

Comments
 (0)