Skip to content

Commit dcc2d0a

Browse files
committed
Merge branch 'okemodule' into 'main'
Convert OKE nightly tests to use terraform module See merge request weblogic-cloud/weblogic-kubernetes-operator!4731
2 parents 15a92e5 + c2e481e commit dcc2d0a

18 files changed

+1043
-17
lines changed

Jenkinsfile.oke

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pipeline {
5757
wle_download_url="https://github.com/oracle/weblogic-logging-exporter/releases/latest"
5858
kubeconfig_file = "${WORKSPACE}/terraform/${CLUSTER_NAME}_kubeconfig"
5959
availability_domain = "${env.JOB_NAME == 'wko-oke-nightly-parallel' ? 'mFEn:PHX-AD-1' : 'mFEn:PHX-AD-1'}"
60-
oke_run = "${env.JOB_NAME == 'wko-oke-nightly' ? 'okeint' : 'okeintdev'}"
60+
//oke_run = "${env.JOB_NAME == 'wko-oke-nightly' ? 'okemodule' : 'okeintdev'}"
61+
oke_run = "okemodule"
6162

6263
}
6364

@@ -142,7 +143,8 @@ pipeline {
142143
defaultValue: "VM.Standard.E3.Flex"
143144
)
144145
string(name: 'MOUNT_TARGET_OCID',
145-
description: 'only for debug runs on wko-oke-dev'
146+
description: 'only for debug runs on wko-oke-dev',
147+
defaultValue: "ocid1.mounttarget.oc1.phx.aaaaaby27vhqpci5obuhqllqojxwiotqnb4c2ylefuzqaaaa"
146148

147149
)
148150
string(name: 'BRANCH',
@@ -335,6 +337,7 @@ pipeline {
335337
#export IMAGE_TAG_WEBLOGIC="12.2.1.4"
336338
#export IMAGE_TAG_FMWINFRA="12.2.1.4"
337339
ssh_pubkey=`cat ${wkotest_ssh_pubcert}`
340+
ssh_pk=`cat ${wkotest_ssh_pk}`
338341

339342
#################
340343
echo "Generating property file oci.prop for terraform scripts"
@@ -361,13 +364,15 @@ mounttarget.ocid=${MOUNT_TARGET_OCID}
361364
nodepool.imagename=${IMAGE_ID}
362365
k8s.version=v${OKE_KUBE_VERSION}
363366
nodepool.ssh.pubkey=${ssh_pubkey}
367+
nodepool.ssh.pk=${ssh_pk}
368+
nodepool.ssh.pubkeypath=${wkotest_ssh_pubcert}
369+
nodepool.ssh.pkpath=${wkotest_ssh_pk}
364370
terraform.installdir=${WORKSPACE}/terraform/terraforminstall
365371
EOF
366372

367373
##################
368374
echo "prop files "
369375
cat $OCI_PROP_FILE
370-
cp -rf ${WORKSPACE}/kubernetes/samples/scripts/terraform/template.tfvars ${WORKSPACE}/terraform/.
371376
mkdir -p ${WORKSPACE}/terraform/terraforminstall
372377
'''
373378

@@ -414,7 +419,7 @@ EOF
414419

415420
echo 'Create a OKE cluster ${CLUSTER_NAME}'
416421

417-
cp -rf ${terraform_script_dir_name}/*.* ${WORKSPACE}/terraform/.
422+
cp -rf ${terraform_script_dir_name}/* ${WORKSPACE}/terraform/.
418423

419424
chmod 777 ${WORKSPACE}/terraform/*.sh
420425
mkdir -p ${WORKSPACE}/terraform/terraforminstall
@@ -461,11 +466,7 @@ EOF
461466
compartment_ocid=${compartment_id}
462467
echo "creating storage class to setup OFSS ..."
463468
echo "getting MountTarget ID"
464-
if [ "${JOB_NAME}" = "wko-oke-nightly" ]; then
465-
mount_target_id=`oci fs mount-target list --compartment-id=${compartment_ocid} --display-name=${clusterName}-mt --availability-domain=${availability_domain} | jq -r '.data[] | .id'`
466-
else
467-
mount_target_id=${MOUNT_TARGET_OCID}
468-
fi
469+
mount_target_id=${MOUNT_TARGET_OCID}
469470

470471

471472
clusterIP=$(oci ce cluster list --compartment-id=${compartment_id} | jq '.data[] | select(."name" == '\"${CLUSTER_NAME}\"' and (."lifecycle-state" == "ACTIVE"))' | jq ' ."endpoints" | ."public-endpoint"')
@@ -492,7 +493,9 @@ EOF
492493
environment {
493494
runtime_path = "${WORKSPACE}/bin:${PATH}"
494495
clusterName = "${CLUSTER_NAME}"
495-
FSS_DIR = "${env.JOB_NAME == 'wko-oke-nightly' ? '/oketest1,/oketest2,/oketest3,/oketest4,/oketest5,/oketest6,/oketest7,/oketest8,/oketest9,/oketest10,/oketest11,/oketest12,/oketest13,/oketest14,/oketest15' : '/${clusterName}oketest1,/${clusterName}oketest2'}"
496+
497+
FSS_DIR = "${env.JOB_NAME == 'wko-oke-nightly' ? '/${clusterName}oketest1,/${clusterName}oketest2' : '/${clusterName}oketest1,/${clusterName}oketest2'}"
498+
496499

497500

498501
}
@@ -548,13 +551,7 @@ EOF
548551
NODE_IP=`kubectl get nodes -o wide| awk '{print $7}'| head -n2 | tail -n1`
549552
echo "second node external IP ${NODE_IP}"
550553
export NODE_IP=${NODE_IP}
551-
if [ "${JOB_NAME}" = "wko-oke-nightly" ]; then
552-
echo "Mount Target setup for wko-oke-nightly"
553-
mt_privateip_id=`oci fs mount-target list --compartment-id=${compartment_ocid} --display-name=${clusterName}-mt --availability-domain=${availability_domain} | jq -r '.data[] | ."private-ip-ids"[]'`
554-
555-
else
556-
mt_privateip_id=`oci fs mount-target get --mount-target-id=${MOUNT_TARGET_OCID} | jq -r '.data| ."private-ip-ids"[]'`
557-
fi
554+
mt_privateip_id=`oci fs mount-target get --mount-target-id=${MOUNT_TARGET_OCID} | jq -r '.data| ."private-ip-ids"[]'`
558555
# Check if the mt_privateip_id is an array
559556
if [ "$(declare -p mt_privateip_id 2>/dev/null | grep -o 'declare -a')" == "declare -a" ]; then
560557
# Select first
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Copyright (c) 2024 Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
5+
data "oci_containerengine_cluster_kube_config" "public" {
6+
count = local.cluster_enabled && local.public_endpoint_available ? 1 : 0
7+
8+
cluster_id = local.cluster_id
9+
endpoint = "PUBLIC_ENDPOINT"
10+
}
11+
12+
13+
data "oci_containerengine_cluster_kube_config" "private" {
14+
count = local.cluster_enabled && local.private_endpoint_available ? 1 : 0
15+
16+
cluster_id = local.cluster_id
17+
endpoint = "PRIVATE_ENDPOINT"
18+
}
19+
20+
data "oci_containerengine_clusters" "existing_cluster" {
21+
count = var.cluster_id != null ? 1 : 0
22+
compartment_id = var.compartment_id
23+
24+
state = ["ACTIVE","UPDATING"]
25+
filter {
26+
name = "id"
27+
values = [var.cluster_id]
28+
}
29+
}
30+
31+
# Obtain cluster Kubeconfig.
32+
data "oci_containerengine_cluster_kube_config" "kube_config" {
33+
#cluster_id = oci_containerengine_cluster.k8s_cluster.id
34+
cluster_id = one(module.c1[*].cluster_id)
35+
}
36+
37+
38+
output "cluster_id" {
39+
description = "ID of the OKE cluster"
40+
value = one(module.c1[*].cluster_id)
41+
}
42+
43+
44+
output "cluster_kubeconfig" {
45+
description = "OKE kubeconfig"
46+
value = var.output_detail ? (
47+
local.public_endpoint_available ? local.kubeconfig_public : local.kubeconfig_private
48+
) : null
49+
}
50+
51+
variable "cluster_kube_config_expiration" {
52+
default = 2592000
53+
}
54+
55+
variable "cluster_kube_config_token_version" {
56+
default = "2.0.0"
57+
}
58+
59+
output "cluster_ca_cert" {
60+
description = "OKE cluster CA certificate"
61+
value = var.output_detail && length(local.cluster_ca_cert) > 0 ? local.cluster_ca_cert : null
62+
}
63+
64+
output "apiserver_private_host" {
65+
description = "Private OKE cluster endpoint address"
66+
value = local.apiserver_private_host
67+
}
68+
69+
70+
locals {
71+
cluster_enabled = var.create_cluster || coalesce(var.cluster_id, "none") != "none"
72+
cluster_id = var.create_cluster ? one(module.c1[*].cluster_id) : var.cluster_id
73+
cluster_name = var.cluster_name
74+
75+
cluster-context = try(format("context-%s", substr(local.cluster_id, -11, -1)), "")
76+
77+
existing_cluster_endpoints = coalesce(one(flatten(data.oci_containerengine_clusters.existing_cluster[*].clusters[*].endpoints)), tomap({}))
78+
public_endpoint_available = var.cluster_id != null ? length(lookup(local.existing_cluster_endpoints, "public_endpoint", "")) > 0 : var.control_plane_is_public && var.assign_public_ip_to_control_plane
79+
private_endpoint_available = var.cluster_id != null ? length(lookup(local.existing_cluster_endpoints, "private_endpoint", "")) > 0 : true
80+
kubeconfig_public = var.control_plane_is_public ? try(yamldecode(replace(lookup(one(data.oci_containerengine_cluster_kube_config.public), "content", ""), local.cluster-context, var.cluster_name)), tomap({})) : null
81+
kubeconfig_private = try(yamldecode(replace(lookup(one(data.oci_containerengine_cluster_kube_config.private), "content", ""), local.cluster-context, var.cluster_name)), tomap({}))
82+
83+
kubeconfig_clusters = try(lookup(local.kubeconfig_private, "clusters", []), [])
84+
apiserver_private_host = (var.create_cluster
85+
? try(split(":", one(module.c1[*].endpoints.private_endpoint))[0], "")
86+
: split(":", replace(try(lookup(lookup(local.kubeconfig_clusters[0], "cluster", {}), "server", ""), "none"), "https://", ""))[0])
87+
88+
kubeconfig_ca_cert = try(lookup(lookup(local.kubeconfig_clusters[0], "cluster", {}), "certificate-authority-data", ""), "none")
89+
cluster_ca_cert = coalesce(var.cluster_ca_cert, local.kubeconfig_ca_cert)
90+
}
91+
92+
93+
module "c1" {
94+
95+
source = "oracle-terraform-modules/oke/oci"
96+
version = "5.1.1"
97+
98+
count = lookup(lookup(var.clusters, "c1"), "enabled") ? 1 : 0
99+
100+
home_region = lookup(local.regions, var.home_region)
101+
102+
#region = lookup(local.regions, lookup(lookup(var.clusters, "c1"), "region"))
103+
region = lookup(local.regions, var.home_region)
104+
105+
tenancy_id = var.tenancy_id
106+
107+
# general oci parameters
108+
compartment_id = var.compartment_id
109+
110+
# ssh keys
111+
ssh_private_key_path = var.ssh_private_key_path
112+
ssh_public_key_path = var.ssh_public_key_path
113+
114+
# Network
115+
create_vcn = false
116+
vcn_id = var.vcn_id
117+
118+
119+
# networking
120+
create_drg = var.oke_control_plane == "private" ? true : false
121+
drg_display_name = var.cluster_name
122+
123+
124+
vcn_cidrs = [lookup(lookup(var.clusters, "c1"), "vcn")]
125+
vcn_name = "VCN-wktiso1"
126+
127+
#subnets
128+
subnets = {
129+
pub_lb = { id = var.pub_lb_id }
130+
operator = { id = var.pub_lb_id }
131+
bastion = { id = var.pub_lb_id }
132+
workers = { id = var.worker_subnet_id }
133+
cp = {id = var.control_plane_subnet_id }
134+
}
135+
136+
# bastion host
137+
create_bastion = true # *true/false
138+
bastion_allowed_cidrs = [] # e.g. ["0.0.0.0/0"] to allow traffic from all sources
139+
bastion_availability_domain = null # Defaults to first available
140+
bastion_image_id = null # Ignored when
141+
bastion_image_os = "Oracle Linux" # Ignored when bastion_image_type = "custom"
142+
bastion_image_os_version = "8" # Ignored when bastion_image_type = "custom"
143+
bastion_image_type = "platform" # platform/custom
144+
bastion_nsg_ids = [] # Combined with created NSG when enabled in var.nsgs
145+
bastion_public_ip = null # Ignored when create_bastion = true
146+
#bastion_type = "public" # *public/private
147+
bastion_upgrade = false # true/*false
148+
bastion_user = "opc"
149+
150+
bastion_shape = {shape = var.node_shape,ocpus = 1,memory = 4,boot_volume_size = 50}
151+
#create_bastion = true
152+
allow_bastion_cluster_access = true
153+
bastion_is_public = true
154+
#bastion_allowed_cidrs = ["0.0.0.0/0"]
155+
#bastion_upgrade = false
156+
157+
# operator host
158+
create_operator = false
159+
operator_upgrade = false
160+
operator_install_helm = true
161+
#operator_install_kubectl_from_repo = true
162+
operator_cloud_init = []
163+
create_iam_resources = false
164+
create_iam_operator_policy = "never"
165+
operator_install_k9s = false
166+
167+
# oke cluster options
168+
cluster_name = var.cluster_name
169+
cluster_type = var.cluster_type
170+
cni_type = var.preferred_cni
171+
control_plane_is_public = true
172+
control_plane_allowed_cidrs = [local.anywhere]
173+
kubernetes_version = var.kubernetes_version
174+
services_cidr = lookup(lookup(var.clusters, "c1"), "services")
175+
176+
177+
# node pools
178+
allow_worker_ssh_access = true
179+
kubeproxy_mode = "iptables"
180+
worker_pool_mode = "node-pool"
181+
worker_pools = var.nodepools
182+
worker_cloud_init = local.worker_cloud_init
183+
worker_image_type = "oke"
184+
185+
# oke load balancers
186+
load_balancers = "both"
187+
preferred_load_balancer = "public"
188+
189+
190+
191+
user_id = var.user_id
192+
providers = {
193+
oci = oci.c1
194+
oci.home = oci.home
195+
}
196+
}
197+
198+
199+
resource "local_file" "test_kube_config_file" {
200+
content = data.oci_containerengine_cluster_kube_config.kube_config.content
201+
filename = "${path.module}/${var.cluster_name}_kubeconfig"
202+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
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+
resource "oci_file_storage_export" "oketest_export1" {
6+
#Required
7+
export_set_id = oci_file_storage_export_set.oketest_export_set.id
8+
file_system_id = oci_file_storage_file_system.oketest_fs1.id
9+
path = "/${var.cluster_name}oketest1"
10+
}
11+
resource "oci_file_storage_export" "oketest_export2" {
12+
#Required
13+
export_set_id = oci_file_storage_export_set.oketest_export_set.id
14+
file_system_id = oci_file_storage_file_system.oketest_fs2.id
15+
path = "/${var.cluster_name}oketest2"
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
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+
6+
resource "oci_file_storage_export_set" "oketest_export_set" {
7+
# Required
8+
mount_target_id = var.mount_target_ocid
9+
# mount_target_id = oci_file_storage_mount_target.oketest_mount_target.id
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
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+
6+
7+
resource "oci_file_storage_file_system" "oketest_fs1" {
8+
#Required
9+
availability_domain = var.availability_domain
10+
11+
#availability_domain = data.oci_identity_availability_domain.ad1.name
12+
compartment_id = var.compartment_id
13+
}
14+
resource "oci_file_storage_file_system" "oketest_fs2" {
15+
#Required
16+
availability_domain = var.availability_domain
17+
compartment_id = var.compartment_id
18+
}

0 commit comments

Comments
 (0)