Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit 4c1db9e

Browse files
author
Sean Sundberg
authored
Adds implementation to provision OCP cluster (#1)
* Adds missing cluster_versions data * Renames cluster_type to ocp_version * Adds trigger to force login / kube config setup with each run * Adds resource to print vpc_name to force sequencing of module steps * Adds ibm provider config with region, generation, and ibmcloud_api_key * Updates default flavor to bx2.4x16 * Adds configuration for helm provider * Updates module metadata * Sets admin flag for cluster_config * Get cluster config twice, once with and once without admin * Adds sleep during kube-setup to allow RBAC to be configured * Cleans up COS instance provisioning - Removes logic and variables required to provision COS instance - Adds dependency on external module to provision cos and provide id Signed-off-by: Sean Sundberg <[email protected]>
1 parent 8aad45b commit 4c1db9e

22 files changed

+610
-118
lines changed

.github/scripts/validate-deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env bash

.github/workflows/verify.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
verify:
1414
if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }}
1515
runs-on: ubuntu-latest
16-
container: quay.io/ibmgaragecloud/cli-tools:v0.10.0-lite
16+
container: quay.io/ibmgaragecloud/cli-tools:v0.12.0-lite
1717

1818
strategy:
1919
matrix:
20-
platform: [ocp4_latest]
20+
platform: [ocp4vpc_latest]
2121
# max-parallel: 1
2222
fail-fast: false
2323

@@ -47,7 +47,6 @@ jobs:
4747
TF_VAR_ibmcloud_api_key: ${{ secrets.IBMCLOUD_API_KEY }}
4848
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
4949

50-
5150
release:
5251
# if: ${{ github.event_name == 'push' }}
5352
needs: verify

chart/cloud-setup/.helmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/

chart/cloud-setup/Chart.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: cloud-setup
3+
repository: https://ibm-garage-cloud.github.io/toolkit-charts/
4+
version: 0.3.1
5+
digest: sha256:2e9a33ceb66a2133f0745fafad8e6e83af8fb77e435130534253da6affc970b4
6+
generated: "2020-11-02T09:17:34.451862-06:00"

chart/cloud-setup/Chart.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v2
2+
name: cloud-setup
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
version: 0.1.0
18+
19+
# This is the version number of the application being deployed. This version number should be
20+
# incremented each time you make changes to the application.
21+
appVersion: 1.16.0
22+
23+
dependencies:
24+
- name: cloud-setup
25+
version: 0.3.1
26+
repository: https://ibm-garage-cloud.github.io/toolkit-charts/
3.11 KB
Binary file not shown.

chart/cloud-setup/templates/.gitkeep

Whitespace-only changes.

chart/cloud-setup/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Default values for cloud-setup.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
global:
5+
clusterType: ""
6+
ingressSubdomain: ""
7+
tlsSecretName: ""
8+
9+
cloud-setup:
10+
ibmcloud: {}
11+
12+
cntk-dev-guide: {}
13+
14+
first-app: {}

main-2-config.tf

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
provider "helm" {
2+
version = ">= 1.1.1"
3+
4+
kubernetes {
5+
config_path = local.cluster_config
6+
}
7+
}
8+
9+
locals {
10+
gitops_dir = var.gitops_dir != "" ? var.gitops_dir : "${path.cwd}/gitops"
11+
chart_name = "cloud-setup"
12+
chart_dir = "${local.gitops_dir}/${local.chart_name}"
13+
global_config = {
14+
clusterType = local.cluster_type_code
15+
ingressSubdomain = local.ingress_hostname
16+
tlsSecretName = local.tls_secret
17+
}
18+
ibmcloud_config = {
19+
apikey = var.ibmcloud_api_key
20+
resource_group = var.resource_group_name
21+
server_url = local.server_url
22+
cluster_type = local.cluster_type
23+
cluster_name = local.cluster_name
24+
tls_secret_name = local.tls_secret
25+
ingress_subdomain = local.ingress_hostname
26+
region = var.region
27+
cluster_version = local.cluster_version
28+
}
29+
cntk_dev_guide_config = {
30+
name = "cntk-dev-guide"
31+
displayName = "Cloud-Native Toolkit"
32+
url = "https://cloudnativetoolkit.dev"
33+
}
34+
first_app_config = {
35+
name = "first-app"
36+
displayName = "Deploy first app"
37+
url = "https://cloudnativetoolkit.dev/getting-started-day-1/deploy-app/"
38+
}
39+
}
40+
41+
resource "null_resource" "list_tmp" {
42+
depends_on = [null_resource.create_dirs]
43+
44+
triggers = {
45+
always_run = timestamp()
46+
}
47+
48+
provisioner "local-exec" {
49+
command = "ls ${local.tmp_dir}"
50+
}
51+
}
52+
53+
data ibm_container_cluster_config cluster_admin {
54+
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.list_tmp]
55+
56+
cluster_name_id = local.cluster_name
57+
admin = true
58+
resource_group_id = data.ibm_resource_group.resource_group.id
59+
config_dir = local.cluster_config_dir
60+
}
61+
62+
data ibm_container_cluster_config cluster {
63+
depends_on = [
64+
ibm_container_vpc_cluster.cluster,
65+
null_resource.list_tmp,
66+
data.ibm_container_cluster_config.cluster_admin
67+
]
68+
69+
cluster_name_id = local.cluster_name
70+
resource_group_id = data.ibm_resource_group.resource_group.id
71+
config_dir = local.cluster_config_dir
72+
}
73+
74+
resource null_resource setup_kube_config {
75+
depends_on = [null_resource.create_dirs]
76+
77+
provisioner "local-exec" {
78+
command = "rm -f ${local.cluster_config} && ln -s ${data.ibm_container_cluster_config.cluster.config_file_path} ${local.cluster_config}"
79+
}
80+
81+
provisioner "local-exec" {
82+
command = "cp ${regex("(.*)/config.yml", data.ibm_container_cluster_config.cluster.config_file_path)[0]}/* ${local.cluster_config_dir}"
83+
}
84+
85+
provisioner "local-exec" {
86+
command = "echo 'Waiting for 5 minutes for permissions to be established...' && sleep 300"
87+
}
88+
}
89+
90+
resource null_resource setup-chart {
91+
provisioner "local-exec" {
92+
command = "mkdir -p ${local.chart_dir} && cp -R ${path.module}/chart/${local.chart_name}/* ${local.chart_dir}"
93+
}
94+
}
95+
96+
resource null_resource delete-helm-cloud-config {
97+
depends_on = [null_resource.setup_kube_config]
98+
99+
provisioner "local-exec" {
100+
command = "kubectl delete secret -n ${local.config_namespace} -l name=${local.ibmcloud_release_name} --ignore-not-found"
101+
102+
environment = {
103+
KUBECONFIG = local.cluster_config
104+
}
105+
}
106+
107+
provisioner "local-exec" {
108+
command = "kubectl delete secret -n ${local.config_namespace} -l name=cloud-setup --ignore-not-found"
109+
110+
environment = {
111+
KUBECONFIG = local.cluster_config
112+
}
113+
}
114+
115+
provisioner "local-exec" {
116+
command = "kubectl delete secret -n ${local.config_namespace} ibmcloud-apikey --ignore-not-found"
117+
118+
environment = {
119+
KUBECONFIG = local.cluster_config
120+
}
121+
}
122+
123+
provisioner "local-exec" {
124+
command = "kubectl delete configmap -n ${local.config_namespace} ibmcloud-config --ignore-not-found"
125+
126+
environment = {
127+
KUBECONFIG = local.cluster_config
128+
}
129+
}
130+
131+
provisioner "local-exec" {
132+
command = "kubectl delete secret -n ${local.config_namespace} cloud-access --ignore-not-found"
133+
134+
environment = {
135+
KUBECONFIG = local.cluster_config
136+
}
137+
}
138+
139+
provisioner "local-exec" {
140+
command = "kubectl delete configmap -n ${local.config_namespace} cloud-config --ignore-not-found"
141+
142+
environment = {
143+
KUBECONFIG = local.cluster_config
144+
}
145+
}
146+
}
147+
148+
resource "null_resource" "delete-consolelink" {
149+
depends_on = [null_resource.setup_kube_config]
150+
count = local.cluster_type_code == "ocp4" ? 1 : 0
151+
152+
provisioner "local-exec" {
153+
command = "kubectl delete consolelink toolkit-github --ignore-not-found"
154+
155+
environment = {
156+
KUBECONFIG = local.cluster_config
157+
}
158+
}
159+
160+
provisioner "local-exec" {
161+
command = "kubectl delete consolelink toolkit-registry --ignore-not-found"
162+
163+
environment = {
164+
KUBECONFIG = local.cluster_config
165+
}
166+
}
167+
}
168+
169+
resource "local_file" "cloud-values" {
170+
depends_on = [null_resource.setup-chart]
171+
172+
content = yamlencode({
173+
global = local.global_config
174+
cloud-setup = {
175+
ibmcloud = local.ibmcloud_config
176+
cntk-dev-guide = local.cntk_dev_guide_config
177+
first-app = local.first_app_config
178+
}
179+
})
180+
filename = "${local.chart_dir}/values.yaml"
181+
}
182+
183+
resource "null_resource" "print-values" {
184+
provisioner "local-exec" {
185+
command = "cat ${local_file.cloud-values.filename}"
186+
}
187+
}
188+
189+
resource "helm_release" "cloud_setup" {
190+
depends_on = [null_resource.setup_kube_config, null_resource.delete-helm-cloud-config, null_resource.delete-consolelink, local_file.cloud-values]
191+
192+
name = "cloud-setup"
193+
chart = local.chart_dir
194+
version = "0.1.0"
195+
namespace = local.config_namespace
196+
timeout = 1200
197+
dependency_update = true
198+
force_update = true
199+
replace = true
200+
201+
disable_openapi_validation = true
202+
}

0 commit comments

Comments
 (0)