Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 3f58bef

Browse files
invidianknrt10
authored andcommitted
packet: enable CCM
This commit enables CCM for Packet platform to allow dropping hacky way of labeling Node objects on Packet via Ignition script for MetalLB autodiscovery to work, which we are doing right now. Closes #548 Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
1 parent dd4f967 commit 3f58bef

File tree

12 files changed

+90
-81
lines changed

12 files changed

+90
-81
lines changed

assets/terraform-modules/packet/flatcar-linux/kubernetes/bootkube.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ module "bootkube" {
4848
encrypt_pod_traffic = var.encrypt_pod_traffic
4949

5050
ignore_x509_cn_check = var.ignore_x509_cn_check
51+
cloud_provider = "external"
5152
}

assets/terraform-modules/packet/flatcar-linux/kubernetes/cl/controller.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ systemd:
131131
--client-ca-file=/etc/kubernetes/ca.crt \
132132
--cluster_dns=${k8s_dns_service_ip} \
133133
--cluster_domain=${cluster_domain_suffix} \
134+
--cloud-provider=external \
134135
--cni-conf-dir=/etc/cni/net.d \
135136
--config=/etc/kubernetes/kubelet.config \
136137
--exit-on-lock-contention \
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "local_file" "packet-ccm" {
2+
filename = "${var.asset_dir}/charts/kube-system/packet-ccm.yaml"
3+
content = templatefile("${path.module}/packet-ccm.yaml.tmpl", {
4+
api_key = var.auth_token
5+
project_id = var.project_id
6+
})
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apiKey: ${api_key}
2+
projectID: ${project_id}

assets/terraform-modules/packet/flatcar-linux/kubernetes/ssh.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ resource "null_resource" "copy-assets-dir" {
7171
null_resource.copy-controller-secrets,
7272
local_file.calico_host_protection,
7373
local_file.calico_crds,
74+
local_file.packet-ccm,
7475
]
7576

7677
connection {

assets/terraform-modules/packet/flatcar-linux/kubernetes/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ variable "project_id" {
1414
description = "Packet project ID (e.g. 405efe9c-cce9-4c71-87c1-949c290b27dc)"
1515
}
1616

17+
variable "auth_token" {
18+
description = "Packet Auth token (e.g. 4KUDZICtnKfNF4uJSGxxLi4GhWxhzKPj)"
19+
}
20+
1721
# Nodes
1822

1923
variable "os_arch" {

assets/terraform-modules/packet/flatcar-linux/kubernetes/workers/cl/worker.yaml.tmpl

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ systemd:
3434
ExecStart=/bin/sh -c 'while ! /usr/bin/grep '^[^#[:space:]]' /etc/resolv.conf > /dev/null; do sleep 1; done; /opt/wait-for-dns ${dns_zone} ${cluster_name}-private 3600'
3535
[Install]
3636
RequiredBy=kubelet.service
37-
%{~ if bgp_node_labels != "" ~}
38-
- name: bgp-metadata.service
39-
enable: true
40-
contents: |
41-
[Unit]
42-
Description=Write BGP metadata to disk
43-
Before=kubelet.service
44-
[Service]
45-
Type=oneshot
46-
RemainAfterExit=true
47-
ExecStart=/opt/bgp-metadata
48-
[Install]
49-
RequiredBy=kubelet.service
50-
%{~ endif ~}
5137
- name: coreos-metadata.service
5238
enable: true
5339
contents: |
@@ -69,7 +55,6 @@ systemd:
6955
Wants=rpc-statd.service
7056
[Service]
7157
EnvironmentFile=/run/metadata/flatcar
72-
EnvironmentFile=-/run/metadata/bgp
7358
EnvironmentFile=/etc/kubernetes/kubelet.env
7459
ExecStartPre=/bin/mkdir -p /var/lib/kubelet/volumeplugins
7560
ExecStartPre=/bin/mkdir -p /etc/kubernetes/manifests
@@ -107,6 +92,7 @@ systemd:
10792
--client-ca-file=/etc/kubernetes/ca.crt \
10893
--cluster_dns=${k8s_dns_service_ip} \
10994
--cluster_domain=${cluster_domain_suffix} \
95+
--cloud-provider=external \
11096
--cni-conf-dir=/etc/cni/net.d \
11197
--config=/etc/kubernetes/kubelet.config \
11298
--exit-on-lock-contention \
@@ -121,11 +107,7 @@ systemd:
121107
--network-plugin=cni \
122108
--node-labels=$${NODE_LABELS} \
123109
--node-labels=lokomotive.alpha.kinvolk.io/public-ipv4=$${COREOS_PACKET_IPV4_PUBLIC_0} \
124-
%{~ if bgp_node_labels != "" ~}
125-
--node-labels=$${BGP_NODE_LABELS} \
126-
--node-labels=metallb.lokomotive.io/peer-address=$${BGP_PEER_ADDRESS_0} \
127110
--node-labels=metallb.lokomotive.io/src-address=$${COREOS_PACKET_IPV4_PRIVATE_0} \
128-
%{~ endif ~}
129111
--pod-manifest-path=/etc/kubernetes/manifests \
130112
--read-only-port=0 \
131113
--register-with-taints=$${NODE_TAINTS} \
@@ -302,7 +284,6 @@ storage:
302284
KUBELET_IMAGE_URL=quay.io/poseidon/kubelet
303285
KUBELET_IMAGE_TAG=v1.19.3-${os_arch}
304286
NODE_LABELS="${join(",", [for k, v in node_labels : "${k}=${v}"])}"
305-
BGP_NODE_LABELS="${bgp_node_labels}"
306287
NODE_TAINTS="${join(",", [for k, v in taints : "${k}=${v}"])}"
307288
- path: /etc/sysctl.d/max-user-watches.conf
308289
filesystem: root
@@ -429,41 +410,6 @@ storage:
429410
done
430411
echo "$record.$zone is available on all nameservers"
431412
exit 0
432-
- path: /opt/bgp-metadata
433-
filesystem: root
434-
mode: 0544
435-
contents:
436-
inline: |
437-
#!/bin/bash
438-
set -o pipefail
439-
max_attempts=3600
440-
target=/run/metadata/bgp
441-
echo "Polling metadata service for BGP information"
442-
counter=0
443-
while [[ $counter -lt $max_attempts ]]; do
444-
out=$(curl -s -f --connect-timeout 5 \
445-
https://metadata.packet.net/metadata | jq -r .bgp_neighbors[0].peer_ips[0])
446-
ret=$?
447-
if [[ $ret -ne 0 ]]; then
448-
echo "Non-zero exit code: $ret"
449-
elif [[ "$out" = "" ]]; then
450-
echo "Empty response"
451-
elif [[ "$out" = "null" ]]; then
452-
echo "Null response"
453-
else
454-
echo "BGP metadata is available!"
455-
if [[ ! "$out" =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}$ ]]; then
456-
echo "Invalid IP $out"
457-
exit 1
458-
fi
459-
echo "BGP_PEER_ADDRESS_0=$out" > "$target"
460-
exit $?
461-
fi
462-
sleep 1
463-
counter=$((counter+1))
464-
done
465-
echo "BGP metadata did not become available in time"
466-
exit 1
467413
passwd:
468414
users:
469415
- name: core

assets/terraform-modules/packet/flatcar-linux/kubernetes/workers/workers.tf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ data "ct_config" "install-ignitions" {
4343
})
4444
}
4545

46-
resource "packet_bgp_session" "bgp" {
47-
count = var.disable_bgp == true ? 0 : var.worker_count
48-
device_id = packet_device.nodes[count.index].id
49-
address_family = "ipv4"
50-
}
51-
52-
# BGP node labels.
53-
locals {
54-
my_asn = format("metallb.lokomotive.io/my-asn=%d", data.packet_project.project.bgp_config.0.asn)
55-
# Packet always uses ASN 65530 as the remote ASN for local BGP.
56-
peer_asn = format("metallb.lokomotive.io/peer-asn=%d", 65530)
57-
}
58-
5946
data "ct_config" "ignitions" {
6047
content = templatefile(
6148
"${path.module}/cl/worker.yaml.tmpl",
@@ -74,7 +61,6 @@ data "ct_config" "ignitions" {
7461
"node.kubernetes.io/node" = "",
7562
"lokomotive.alpha.kinvolk.io/bgp-enabled" = format("%t", ! var.disable_bgp),
7663
}, var.labels)
77-
bgp_node_labels = var.disable_bgp ? "" : format("%s,%s", local.my_asn, local.peer_asn)
7864
taints = var.taints
7965
setup_raid = var.setup_raid
8066
setup_raid_hdd = var.setup_raid_hdd

pkg/assets/generated_assets.go

Lines changed: 26 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/platform/packet/packet.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ func (c *config) Initialize(ex *terraform.Executor) error {
196196
}
197197
}
198198

199+
// TODO: A transient change which shall be reverted in a follow up PR to handle
200+
// https://github.com/kinvolk/lokomotive/issues/716.
201+
// Extract host protection chart.
202+
src = filepath.Join(assets.ControlPlaneSource, "packet-ccm")
203+
dst = filepath.Join(assetDir,
204+
"cluster-assets", "charts", "kube-system", "packet-ccm")
205+
206+
if err := assets.Extract(src, dst); err != nil {
207+
return fmt.Errorf("extracting packet-ccm chart: %w", err)
208+
}
209+
199210
terraformRootDir := terraform.GetTerraformRootDir(assetDir)
200211

201212
return createTerraformConfigFile(c, terraformRootDir)

0 commit comments

Comments
 (0)