Skip to content

Commit 05035e5

Browse files
authored
Merge pull request #77 from hyder/calico
update for calico 3.9
2 parents 40a3095 + 65e86cf commit 05035e5

File tree

8 files changed

+65
-50
lines changed

8 files changed

+65
-50
lines changed

docs/terraformoptions.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
474474
|calico_version
475475
|Version of {uri-calico}[Calico] to install.
476476
|
477-
|3.6
477+
|3.9
478478
479479
|install_calico
480480
|Whether to install {uri-calico}[Calico] as {uri-calico-policy}[pod network policy].

modules/oke/calico.tf

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
## Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
22
## Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4-
#data "template_file" "install_calico" {
5-
# template = file("${path.module}/scripts/install_calico.template.sh")
6-
7-
# vars = {
8-
# calico_version = var.calico.calico_version
9-
# number_of_nodes = var.node_pools.nodepool_topology * var.node_pools.node_pools * var.node_pools.node_pool_quantity_per_subnet
10-
# pod_cidr = var.oke_cluster.cluster_options_kubernetes_network_config_pods_cidr
11-
# number_of_replicas = min(20,max((var.node_pools.nodepool_topology * var.node_pools.node_pools * var.node_pools.node_pool_quantity_per_subnet)/200,3))
12-
# user_ocid = var.oke_identity.user_ocid
13-
# }
14-
15-
# count = var.calico.install_calico == true ? 1 : 0
16-
#}
17-
18-
#resource null_resource "install_calico" {
19-
# connection {
20-
# host = var.oke_bastion.bastion_public_ip
21-
# private_key = file(var.oke_ssh_keys.ssh_private_key_path)
22-
# timeout = "40m"
23-
# type = "ssh"
24-
# user = var.oke_bastion.image_operating_system == "Canonical Ubuntu" ? "ubuntu" : "opc"
25-
# }
26-
27-
# depends_on = ["null_resource.install_kubectl_bastion", "null_resource.write_kubeconfig_bastion"]
28-
29-
# provisioner "file" {
30-
# content = data.template_file.install_calico[0].rendered
31-
# destination = "~/install_calico.sh"
32-
# }
33-
34-
# provisioner "remote-exec" {
35-
# inline = [
36-
# "chmod +x $HOME/install_calico.sh",
37-
# "$HOME/install_calico.sh",
38-
# "rm -f $HOME/install_calico.sh"
39-
# ]
40-
# }
41-
42-
# count = var.oke_bastion.create_bastion == true && var.calico.install_calico == true ? 1 : 0
43-
#}
4+
data "template_file" "install_calico" {
5+
template = file("${path.module}/scripts/install_calico.template.sh")
6+
7+
vars = {
8+
calico_version = var.calico.calico_version
9+
number_of_nodes = local.total_nodes
10+
pod_cidr = var.oke_cluster.cluster_options_kubernetes_network_config_pods_cidr
11+
number_of_replicas = min(20,max((local.total_nodes)/200,3))
12+
user_ocid = var.oke_identity.user_ocid
13+
}
14+
15+
count = var.calico.install_calico == true ? 1 : 0
16+
}
17+
18+
resource null_resource "install_calico" {
19+
connection {
20+
host = var.oke_bastion.bastion_public_ip
21+
private_key = file(var.oke_ssh_keys.ssh_private_key_path)
22+
timeout = "40m"
23+
type = "ssh"
24+
user = var.oke_bastion.image_operating_system == "Canonical Ubuntu" ? "ubuntu" : "opc"
25+
}
26+
27+
depends_on = ["null_resource.install_kubectl_bastion", "null_resource.write_kubeconfig_bastion"]
28+
29+
provisioner "file" {
30+
content = data.template_file.install_calico[0].rendered
31+
destination = "~/install_calico.sh"
32+
}
33+
34+
provisioner "remote-exec" {
35+
inline = [
36+
"chmod +x $HOME/install_calico.sh",
37+
"$HOME/install_calico.sh",
38+
"rm -f $HOME/install_calico.sh"
39+
]
40+
}
41+
42+
count = var.oke_bastion.create_bastion == true && var.calico.install_calico == true ? 1 : 0
43+
}

modules/oke/datasources.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ data "oci_containerengine_cluster_option" "k8s_cluster_option" {
1414
#Required
1515
cluster_option_id = "all"
1616
}
17+
18+
data "oci_containerengine_node_pools" "all_node_pools" {
19+
compartment_id = var.oke_identity.compartment_ocid
20+
cluster_id = oci_containerengine_cluster.k8s_cluster.id
21+
depends_on = ["oci_containerengine_node_pool.nodepools"]
22+
}

modules/oke/locals.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,14 @@ locals {
99
available_kubernetes_versions = data.oci_containerengine_cluster_option.k8s_cluster_option.kubernetes_versions
1010
num_kubernetes_versions = length(local.available_kubernetes_versions)
1111
kubernetes_version = var.oke_cluster.cluster_kubernetes_version == "LATEST" ? element(sort(local.available_kubernetes_versions), (local.num_kubernetes_versions - 1)) : var.oke_cluster.cluster_kubernetes_version
12-
}
1312

13+
node_pools_size_list = [
14+
for node_pool in data.oci_containerengine_node_pools.all_node_pools.node_pools:
15+
node_pool.node_config_details[0].size
16+
]
17+
18+
# workaround for summing a list of numbers: https://github.com/hashicorp/terraform/issues/17239
19+
total_nodes = length(flatten([
20+
for nodes in local.node_pools_size_list : range(nodes)
21+
]))
22+
}

modules/oke/scripts/install_calico.template.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ cd calico
88

99
kubectl create clusterrolebinding clusteradminrole --clusterrole=cluster-admin --user=${user_ocid}
1010

11-
curl https://docs.projectcalico.org/v${calico_version}/getting-started/kubernetes/installation/hosted/kubernetes-datastore/policy-only/1.7/calico.yaml -O
11+
curl https://docs.projectcalico.org/v${calico_version}/manifests/calico-policy-only.yaml -O
1212

13-
sed -i -e "s?192.168.0.0/16?${pod_cidr}?g" calico.yaml
13+
sed -i -e "s?192.168.0.0/16?${pod_cidr}?g" calico-policy-only.yaml
1414

1515
sleep 10
1616

1717
if [ ${number_of_nodes} -gt 50 ]; then
1818
echo "More than 50 nodes detected. Setting the typha service name"
19-
sed -i -e 's/typha_service_name:\s"none"/typha_service_name: calico-typha/g' calico.yaml
20-
kubectl apply -f calico.yaml
19+
sed -i -e 's/typha_service_name:\s"none"/typha_service_name: calico-typha/g' calico-policy-only.yaml
20+
kubectl apply -f calico-policy-only.yaml
2121
kubectl -n kube-system scale --current-replicas=1 --replicas=${number_of_replicas} deployment/calico-typha
2222
else
23-
kubectl apply -f calico.yaml
23+
kubectl apply -f calico-policy-only.yaml
2424
fi

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ output "kubeconfig" {
1616
output "ocirtoken" {
1717
value = module.auth.ocirtoken
1818
sensitive = true
19-
}
19+
}

terraform.tfvars.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ install_helm = true
139139

140140
# calico
141141

142-
calico_version = "3.6"
142+
calico_version = "3.9"
143143

144144
install_calico = false
145145

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ variable "install_helm" {
329329
# calico
330330
variable "calico_version" {
331331
description = "version of calico to install"
332-
default = "3.6"
332+
default = "3.9"
333333
}
334334

335335
variable "install_calico" {

0 commit comments

Comments
 (0)