Skip to content

Commit f371788

Browse files
Add tags on resources, update ipv6 func (rancher#233)
1 parent 091797e commit f371788

22 files changed

Lines changed: 222 additions & 96 deletions

File tree

docs/testing.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ Note/TODO: k3s external db fails working with etcd only node. Refer: https://doc
6464

6565
## Validating Dual-Stack
6666

67+
- Required vars for `.env` file
68+
69+
```
70+
TEST_DIR=dualstack
71+
```
72+
6773
- Required vars for `*.tfvars` file
6874
- `kubelet-arg: \n - node-ip=0.0.0.0` is required to be added to both server and worker flags if the public and private IPv6 IPs are same
6975

@@ -82,6 +88,13 @@ bastion_subnets = "<dual-stack-subnet>"
8288

8389
## Validating IPv6 Only
8490

91+
- Required vars for `.env` file
92+
93+
```
94+
ENV_MODULE=ipv6only
95+
TEST_DIR=ipv6only
96+
```
97+
8598
- Required vars for `*.tfvars` file
8699

87100
```

modules/airgap/setup/get_artifacts.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ product=${1}
1111
version=${2}
1212
platform=${3}
1313
arch=${4}
14-
server_flags=${5}
15-
tarball_type=${6}
14+
registry_url=${5}
15+
server_flags=${6}
16+
tarball_type=${7}
1617
k3s_binary=$product
1718

1819
validate_args() {
@@ -52,7 +53,7 @@ download_retry() {
5253
max_attempts=3
5354
attempt_num=1
5455

55-
while [ $attempt_num -le $max_attempts ]; do
56+
while [[ $attempt_num -le $max_attempts ]]; do
5657
if eval "$cmd"; then
5758
echo "Command succeeded after $attempt_num attempts."
5859
break
@@ -63,7 +64,7 @@ download_retry() {
6364
fi
6465
done
6566

66-
if [ $attempt_num -gt $max_attempts ]; then
67+
if [[ $attempt_num -ge $max_attempts ]]; then
6768
echo "Command failed after $max_attempts attempts."
6869
fi
6970
}
@@ -79,7 +80,12 @@ get_assets() {
7980
download_retry "wget $url/k3s-airgap-images-$arch.$tarball_type"
8081
fi
8182
elif [[ "$product" == "rke2" ]]; then
82-
url="https://github.com/rancher/rke2/releases/download/$version"
83+
if [[ -n "$registry_url" ]]; then
84+
url=$registry_url/rke2/$version
85+
else
86+
url="https://github.com/rancher/rke2/releases/download/$version"
87+
fi
88+
echo "Download assets using url: $url"
8389
download_retry "wget $url/sha256sum-$arch.txt"
8490
# Ref: https://docs.rke2.io/install/airgap
8591
if [[ -n "$server_flags" ]] && [[ "$server_flags" =~ "cni" ]]; then
@@ -102,7 +108,12 @@ get_assets() {
102108

103109
get_cni_assets() {
104110
if [[ -n "$server_flags" ]] && [[ "$server_flags" =~ "cni" ]] && [[ "$server_flags" != *"cni: none"* ]]; then
105-
url="https://github.com/rancher/rke2/releases/download/$version"
111+
if [[ -n "$registry_url" ]]; then
112+
url=$registry_url/rke2/$version
113+
else
114+
url="https://github.com/rancher/rke2/releases/download/$version"
115+
fi
116+
echo "Download cni assets using url: $url"
106117
cnis=("calico" "canal" "cilium" "flannel")
107118
for cni in "${cnis[@]}"; do
108119
if [[ "$server_flags" =~ $cni ]]; then

modules/airgap/setup/podman_cmds.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ for image_file in $image_files; do
3030
echo "Reading from file: $image_file"
3131
while read -r image_url_tag; do
3232
if [[ -n "$registry_url" ]]; then
33+
if [[ $registry_url =~ "http" ]]; then
34+
registry_url=$(echo $registry_url | cut -d '/' -f 3)
35+
fi
3336
image_url_tag="${image_url_tag/docker.io/$registry_url}"
3437
fi
3538
echo "Pulling image: $image_url_tag"

modules/bastion/instance_server.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "aws_instance" "bastion" {
2121
key_name = var.key_name
2222
tags = {
2323
Name = "${var.resource_name}-${local.resource_tag}-bastion-server"
24+
Team = local.resource_tag
2425
}
2526

2627
provisioner "file" {

modules/install/k3s_master.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ main() {
257257
fi
258258
if [[ "${install_or_enable}" == "enable" ]] || [[ "${install_or_enable}" == "both" ]]; then
259259
check_service
260-
if [ "$etcd_only_node" -eq 0 ]; then
260+
if [[ "$etcd_only_node" -eq 0 ]]; then
261261
# If etcd only node count is 0, then wait for nodes/pods to come up.
262262
# etcd only node needs api server to come up fully, which is in control plane node.
263263
# and hence we cannot wait for node/pod status in this case.

modules/ipv6only/instance/instance_server.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ resource "aws_instance" "master" {
1717
key_name = var.key_name
1818
tags = {
1919
Name = "${var.resource_name}-${local.resource_tag}-server${count.index + 1}"
20+
Team = local.resource_tag
2021
}
2122

2223
provisioner "local-exec" {
23-
command = "aws ec2 wait instance-status-ok --region ${var.region} --instance-ids ${aws_instance.master[count.index].id}"
24+
command = "aws ec2 wait instance-status-ok --region ${var.region} --instance-ids ${self.id}"
2425
}
2526
}
2627

@@ -43,10 +44,11 @@ resource "aws_instance" "worker" {
4344
key_name = var.key_name
4445
tags = {
4546
Name = "${var.resource_name}-${local.resource_tag}-worker${count.index + 1}"
47+
Team = local.resource_tag
4648
}
4749

4850
provisioner "local-exec" {
49-
command = "aws ec2 wait instance-status-ok --region ${var.region} --instance-ids ${aws_instance.worker[count.index].id}"
51+
command = "aws ec2 wait instance-status-ok --region ${var.region} --instance-ids ${self.id}"
5052
}
5153
}
5254

@@ -70,8 +72,11 @@ resource "aws_instance" "bastion" {
7072
availability_zone = var.availability_zone
7173
vpc_security_group_ids = [var.sg_id]
7274
key_name = var.key_name
75+
user_data = file("scripts/prepare.sh")
76+
7377
tags = {
7478
Name = "${var.resource_name}-${local.resource_tag}-bastion"
79+
Team = local.resource_tag
7580
}
7681

7782
provisioner "local-exec" {

modules/ipv6only/scripts/configure.sh

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,45 @@
33
set +x
44

55
instance_id=${1}
6+
product=${2}
7+
flags=${3}
68

79
ipv6_config() {
8-
echo "Stopping systemd-resolved"
9-
systemctl stop systemd-resolved.service
10-
echo "Updating /etc/hosts"
11-
sed -i -e 's/127.0.0.1/::1/g' -e "s/ip6-loopback/ip6-loopback $instance_id/g" /etc/hosts
12-
echo "Updating /etc/resolv.conf"
13-
sed -i 's/127.0.0.53/2a00:1098:2c::1/g' /etc/resolv.conf
10+
echo "Stopping systemd-resolved"
11+
systemctl stop systemd-resolved.service
12+
echo "Updating /etc/hosts"
13+
sed -i -e 's/127.0.0.1/::1/g' -e "s/ip6-loopback/ip6-loopback $instance_id/g" /etc/hosts
14+
echo "Updating /etc/resolv.conf"
15+
sed -i 's/127.0.0.53/2a00:1098:2c::1/g' /etc/resolv.conf
16+
}
17+
18+
# Ref: https://github.com/rancher/rke2/issues/8033
19+
cilium_config() {
20+
echo "Setting helmchartconfig for cilium with ipv6only"
21+
if [[ "$flags" =~ "cilium" ]]; then
22+
mkdir -p /var/lib/rancher/rke2/server/manifests
23+
cat <<EOF >>/var/lib/rancher/rke2/server/manifests/rke2-cilium-ipv6config.yaml
24+
---
25+
apiVersion: helm.cattle.io/v1
26+
kind: HelmChartConfig
27+
metadata:
28+
name: rke2-cilium
29+
namespace: kube-system
30+
spec:
31+
valuesContent: |-
32+
bgp:
33+
enabled: true
34+
announce:
35+
podCIDR: true
36+
EOF
37+
fi
1438
}
1539

1640
main() {
1741
ipv6_config
42+
if [[ "$product" == "rke2" ]] && [ -n "$flags" ]; then
43+
cilium_config
44+
fi
1845
}
1946

2047
main "$@"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# This script prepares bastion node with installing kubectl
4+
# set +x
5+
6+
arch=$(uname -m)
7+
if [ "$arch" = "aarch64" ]; then
8+
KUBE_ARCH="arm64"
9+
else
10+
KUBE_ARCH="amd64"
11+
fi
12+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/$KUBE_ARCH/kubectl" && \
13+
chmod +x ./kubectl && \
14+
mv ./kubectl /usr/local/bin

modules/k3s/master/instances_server.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ resource "aws_db_instance" "db" {
1212
password = var.db_password
1313
availability_zone = var.availability_zone
1414
tags = {
15-
Environment = var.environment
15+
Environment = var.environment
16+
Team = local.resource_tag
1617
}
1718
skip_final_snapshot = true
1819
}
@@ -29,6 +30,7 @@ resource "aws_rds_cluster" "db" {
2930
engine_mode = var.engine_mode
3031
tags = {
3132
Environment = var.environment
33+
Team = local.resource_tag
3234
}
3335
skip_final_snapshot = true
3436
}
@@ -45,8 +47,9 @@ resource "aws_rds_cluster_instance" "db" {
4547
resource "aws_eip" "master_with_eip" {
4648
count = var.create_eip ? 1 : 0
4749
domain = "vpc"
48-
tags = {
49-
Name ="${var.resource_name}-${local.resource_tag}-server1"
50+
tags = {
51+
Name = "${var.resource_name}-${local.resource_tag}-server1"
52+
Team = local.resource_tag
5053
}
5154
}
5255

@@ -77,8 +80,9 @@ resource "aws_instance" "master" {
7780
availability_zone = var.availability_zone
7881
vpc_security_group_ids = [var.sg_id]
7982
key_name = var.key_name
80-
tags = {
83+
tags = {
8184
Name = "${var.resource_name}-${local.resource_tag}-server1"
85+
Team = local.resource_tag
8286
}
8387

8488
provisioner "remote-exec" {
@@ -206,8 +210,9 @@ data "local_file" "token" {
206210
resource "aws_eip" "master2_with_eip" {
207211
count = var.create_eip ? local.secondary_masters : 0
208212
domain = "vpc"
209-
tags = {
210-
Name ="${var.resource_name}-${local.resource_tag}-server${count.index + 2}"
213+
tags = {
214+
Name = "${var.resource_name}-${local.resource_tag}-server${count.index + 2}"
215+
Team = local.resource_tag
211216
}
212217
depends_on = [aws_eip.master_with_eip ]
213218
}
@@ -243,6 +248,7 @@ resource "aws_instance" "master2-ha" {
243248
depends_on = [aws_instance.master]
244249
tags = {
245250
Name = "${var.resource_name}-${local.resource_tag}-server${count.index + 2}"
251+
Team = local.resource_tag
246252
}
247253
provisioner "remote-exec" {
248254
inline = [

modules/k3s/worker/instances_worker.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "aws_instance" "worker" {
2323
key_name = var.key_name
2424
tags = {
2525
Name = "${var.resource_name}-${local.resource_tag}-worker${count.index + 1}"
26+
Team = local.resource_tag
2627
}
2728
provisioner "remote-exec" {
2829
inline = [
@@ -69,6 +70,7 @@ resource "aws_eip" "worker_with_eip" {
6970
domain = "vpc"
7071
tags = {
7172
Name = "${var.resource_name}-${local.resource_tag}-worker${count.index + 1}"
73+
Team = local.resource_tag
7274
}
7375
}
7476

0 commit comments

Comments
 (0)