Skip to content

Commit f558512

Browse files
committed
remove hard coded cloud-config to ProxmoxMachine.spec.cloudInit
1 parent 5188912 commit f558512

File tree

7 files changed

+226
-72
lines changed

7 files changed

+226
-72
lines changed

api/v1beta1/cloudinit_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ type User struct {
1414
ChPasswd ChPasswd `yaml:"chpasswd,omitempty" json:"-"`
1515
Users []string `yaml:"users,omitempty" json:"-"`
1616
Password string `yaml:"password,omitempty" json:"password,omitempty"`
17-
Packages []string `yaml:"packages,omitempty" json:"-"`
17+
Packages []string `yaml:"packages,omitempty" json:"packages,omitempty"`
1818
PackageUpgrade bool `yaml:"package_upgrade,omitempty" json:"-"`
19-
WriteFiles []WriteFiles `yaml:"write_files,omitempty" json:"-"`
20-
RunCmd []string `yaml:"runcmd,omitempty" json:"-"`
19+
WriteFiles []WriteFiles `yaml:"write_files,omitempty" json:"writeFiles,omitempty"`
20+
RunCmd []string `yaml:"runcmd,omitempty" json:"runCmd,omitempty"`
2121
}
2222

2323
type GrowPart struct {
@@ -31,8 +31,8 @@ type ChPasswd struct {
3131
}
3232

3333
type WriteFiles struct {
34-
Path string `yaml:"path,omitempty" json:"-"`
35-
Owner string `yaml:"owner,omitempty" json:"-"`
36-
Permissions string `yaml:"permissions,omitempty" json:"-"`
37-
Content string `yaml:"content,omitempty" json:"-"`
34+
Path string `yaml:"path,omitempty" json:"path,omitempty"`
35+
Owner string `yaml:"owner,omitempty" json:"owner,omitempty"`
36+
Permissions string `yaml:"permissions,omitempty" json:"permissions,omitempty"`
37+
Content string `yaml:"content,omitempty" json:"content,omitempty"`
3838
}

cloud/services/compute/instance/cloudinit.go

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
1010
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/cloudinit"
11-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
1211
)
1312

1413
const (
@@ -89,71 +88,10 @@ func userSnippetPath(vmName string) string {
8988
return fmt.Sprintf(userSnippetPathFormat, vmName)
9089
}
9190

92-
// DEPRECATED : cicustom should be set via API
93-
func ApplyCICustom(vmid int, vmName, storageName, ciType string, ssh scope.SSHClient) error {
94-
if !cloudinit.IsValidType(ciType) {
95-
return errors.Errorf("invalid cloud init type: %s", ciType)
96-
}
97-
cicustom := fmt.Sprintf("%s=%s:snippets/%s-%s.yml", ciType, storageName, vmName, ciType)
98-
out, err := ssh.RunCommand(fmt.Sprintf("qm set %d --cicustom '%s'", vmid, cicustom))
99-
if err != nil {
100-
return errors.Errorf("ssh command error : %s : %v", out, err)
101-
}
102-
return nil
103-
}
104-
105-
// to do : remove these cloud-config
10691
func baseUserData(vmName string) *infrav1.User {
10792
return &infrav1.User{
108-
GrowPart: infrav1.GrowPart{Mode: "auto", Devices: []string{"/"}, IgnoreGrowrootDisabled: false},
109-
HostName: vmName,
110-
ManageEtcHosts: true,
111-
ChPasswd: infrav1.ChPasswd{Expire: "False"},
112-
Users: []string{"default"},
113-
Packages: []string{"socat", "conntrack"},
114-
PackageUpgrade: true,
115-
WriteFiles: []infrav1.WriteFiles{
116-
{
117-
Path: "/etc/modules-load.d/k8s.conf",
118-
Owner: "root:root",
119-
Permissions: "0640",
120-
Content: "overlay\nbr_netfilter",
121-
},
122-
{
123-
Path: "/etc/sysctl.d/k8s.conf",
124-
Owner: "root:root",
125-
Permissions: "0640",
126-
Content: `net.bridge.bridge-nf-call-iptables = 1
127-
net.bridge.bridge-nf-call-ip6tables = 1
128-
net.ipv4.ip_forward = 1`,
129-
},
130-
},
131-
RunCmd: []string{
132-
"modprobe overlay",
133-
"modprobe br_netfilter",
134-
"sysctl --system",
135-
`mkdir -p /usr/local/bin`,
136-
`curl -L "https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz" | tar Cxvz "/usr/local"`,
137-
`curl -L "https://raw.githubusercontent.com/containerd/containerd/main/containerd.service" -o /etc/systemd/system/containerd.service`,
138-
"mkdir -p /etc/containerd",
139-
"containerd config default > /etc/containerd/config.toml",
140-
"sed 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml -i",
141-
"systemctl daemon-reload",
142-
"systemctl enable --now containerd",
143-
"mkdir -p /usr/local/sbin",
144-
`curl -L "https://github.com/opencontainers/runc/releases/download/v1.1.7/runc.amd64" -o /usr/local/sbin/runc`,
145-
"chmod 755 /usr/local/sbin/runc",
146-
"mkdir -p /opt/cni/bin",
147-
`curl -L "https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz" | tar -C "/opt/cni/bin" -xz`,
148-
`curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.0/crictl-v1.27.0-linux-amd64.tar.gz" | tar -C "/usr/local/bin" -xz`,
149-
`curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubeadm -o /usr/local/bin/kubeadm`,
150-
`chmod +x /usr/local/bin/kubeadm`,
151-
`curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubelet -o /usr/local/bin/kubelet`,
152-
`chmod +x /usr/local/bin/kubelet`,
153-
`curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service`,
154-
`mkdir -p /etc/systemd/system/kubelet.service.d`,
155-
`curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf`,
156-
"systemctl enable kubelet.service",
157-
},
93+
HostName: vmName,
94+
Packages: []string{"qemu-guest-agent"},
95+
RunCmd: []string{"systemctl start qemu-guest-agent"},
15896
}
15997
}

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,31 @@ spec:
6565
properties:
6666
user:
6767
properties:
68+
packages:
69+
items:
70+
type: string
71+
type: array
6872
password:
6973
type: string
74+
runCmd:
75+
items:
76+
type: string
77+
type: array
7078
user:
7179
type: string
80+
writeFiles:
81+
items:
82+
properties:
83+
content:
84+
type: string
85+
owner:
86+
type: string
87+
path:
88+
type: string
89+
permissions:
90+
type: string
91+
type: object
92+
type: array
7293
type: object
7394
type: object
7495
failureDomain:

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,31 @@ spec:
8989
properties:
9090
user:
9191
properties:
92+
packages:
93+
items:
94+
type: string
95+
type: array
9296
password:
9397
type: string
98+
runCmd:
99+
items:
100+
type: string
101+
type: array
94102
user:
95103
type: string
104+
writeFiles:
105+
items:
106+
properties:
107+
content:
108+
type: string
109+
owner:
110+
type: string
111+
path:
112+
type: string
113+
permissions:
114+
type: string
115+
type: object
116+
type: array
96117
type: object
97118
type: object
98119
failureDomain:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: MachineDeployment
3+
metadata:
4+
name: ${CLUSTER_NAME}-md-2
5+
spec:
6+
clusterName: ${CLUSTER_NAME}
7+
replicas: 1
8+
selector:
9+
matchLabels: null
10+
template:
11+
spec:
12+
bootstrap:
13+
configRef:
14+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
15+
kind: KubeadmConfigTemplate
16+
name: ${CLUSTER_NAME}-md-2
17+
clusterName: ${CLUSTER_NAME}
18+
infrastructureRef:
19+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
20+
kind: ProxmoxMachineTemplate
21+
name: ${CLUSTER_NAME}-md-2
22+
version: v1.27.1
23+
24+
---
25+
26+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
27+
kind: KubeadmConfigTemplate
28+
metadata:
29+
name: ${CLUSTER_NAME}-md-2
30+
spec:
31+
template:
32+
spec: {}
33+
34+
---
35+
36+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
37+
kind: ProxmoxMachineTemplate
38+
metadata:
39+
name: ${CLUSTER_NAME}-md-2
40+
spec:
41+
template:
42+
spec:
43+
image:
44+
url: https://artifactory.nordix.org/artifactory/metal3/images/k8s_v1.27.1/UBUNTU_22.04_NODE_IMAGE_K8S_v1.27.1.qcow2
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: MachineDeployment
3+
metadata:
4+
name: ${CLUSTER_NAME}-md-1
5+
spec:
6+
clusterName: ${CLUSTER_NAME}
7+
replicas: 1
8+
selector:
9+
matchLabels: null
10+
template:
11+
spec:
12+
bootstrap:
13+
configRef:
14+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
15+
kind: KubeadmConfigTemplate
16+
name: ${CLUSTER_NAME}-md-1
17+
clusterName: ${CLUSTER_NAME}
18+
infrastructureRef:
19+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
20+
kind: ProxmoxMachineTemplate
21+
name: ${CLUSTER_NAME}-md-1
22+
version: v1.26.5
23+
24+
---
25+
26+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
27+
kind: KubeadmConfigTemplate
28+
metadata:
29+
name: ${CLUSTER_NAME}-md-1
30+
spec:
31+
template:
32+
spec: {}
33+
34+
---
35+
36+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
37+
kind: ProxmoxMachineTemplate
38+
metadata:
39+
name: ${CLUSTER_NAME}-md-1
40+
spec:
41+
template:
42+
spec:
43+
image:
44+
url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img
45+
cloudInit:
46+
user:
47+
packages:
48+
- socat
49+
- conntrack
50+
writeFiles:
51+
- path: /etc/modules-load.d/k8s.conf
52+
owner: root:root
53+
permissions: "0640"
54+
content: overlay\nbr_netfilter
55+
- path: /etc/sysctl.d/k8s.conf
56+
owner: root:root
57+
permissions: "0640"
58+
content: |
59+
net.bridge.bridge-nf-call-iptables = 1
60+
net.bridge.bridge-nf-call-ip6tables = 1
61+
net.ipv4.ip_forward = 1
62+
runCmd:
63+
- "modprobe overlay"
64+
- "modprobe br_netfilter"
65+
- "sysctl --system"
66+
- "mkdir -p /usr/local/bin"
67+
- curl -L "https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz" | tar Cxvz "/usr/local"
68+
- curl -L "https://raw.githubusercontent.com/containerd/containerd/main/containerd.service" -o /etc/systemd/system/containerd.service
69+
- "mkdir -p /etc/containerd"
70+
- "containerd config default > /etc/containerd/config.toml"
71+
- "sed 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml -i"
72+
- "systemctl daemon-reload"
73+
- "systemctl enable --now containerd"
74+
- "mkdir -p /usr/local/sbin"
75+
- curl -L "https://github.com/opencontainers/runc/releases/download/v1.1.7/runc.amd64" -o /usr/local/sbin/runc
76+
- "chmod 755 /usr/local/sbin/runc"
77+
- "mkdir -p /opt/cni/bin"
78+
- curl -L "https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz" | tar -C "/opt/cni/bin" -xz
79+
- curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.0/crictl-v1.27.0-linux-amd64.tar.gz" | tar -C "/usr/local/bin" -xz
80+
- curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubeadm -o /usr/local/bin/kubeadm
81+
- chmod +x /usr/local/bin/kubeadm
82+
- curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubelet -o /usr/local/bin/kubelet
83+
- chmod +x /usr/local/bin/kubelet
84+
- curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service
85+
- mkdir -p /etc/systemd/system/kubelet.service.d
86+
- curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
87+
- "systemctl enable kubelet.service"

templates/cluster-template.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,49 @@ spec:
9191
gateway: ${GATEWAY_ADDRESS}
9292
ip: "${CONTROLPLANE_HOST}/32"
9393
nameServer: ${NAMESERVER_ADDRESS}
94+
cloudInit:
95+
user:
96+
packages:
97+
- socat
98+
- conntrack
99+
writeFiles:
100+
- path: /etc/modules-load.d/k8s.conf
101+
owner: root:root
102+
permissions: "0640"
103+
content: overlay\nbr_netfilter
104+
- path: /etc/sysctl.d/k8s.conf
105+
owner: root:root
106+
permissions: "0640"
107+
content: |
108+
net.bridge.bridge-nf-call-iptables = 1
109+
net.bridge.bridge-nf-call-ip6tables = 1
110+
net.ipv4.ip_forward = 1
111+
runCmd:
112+
- "modprobe overlay"
113+
- "modprobe br_netfilter"
114+
- "sysctl --system"
115+
- "mkdir -p /usr/local/bin"
116+
- curl -L "https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz" | tar Cxvz "/usr/local"
117+
- curl -L "https://raw.githubusercontent.com/containerd/containerd/main/containerd.service" -o /etc/systemd/system/containerd.service
118+
- "mkdir -p /etc/containerd"
119+
- "containerd config default > /etc/containerd/config.toml"
120+
- "sed 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml -i"
121+
- "systemctl daemon-reload"
122+
- "systemctl enable --now containerd"
123+
- "mkdir -p /usr/local/sbin"
124+
- curl -L "https://github.com/opencontainers/runc/releases/download/v1.1.7/runc.amd64" -o /usr/local/sbin/runc
125+
- "chmod 755 /usr/local/sbin/runc"
126+
- "mkdir -p /opt/cni/bin"
127+
- curl -L "https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz" | tar -C "/opt/cni/bin" -xz
128+
- curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.0/crictl-v1.27.0-linux-amd64.tar.gz" | tar -C "/usr/local/bin" -xz
129+
- curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubeadm -o /usr/local/bin/kubeadm
130+
- chmod +x /usr/local/bin/kubeadm
131+
- curl -L --remote-name-all https://dl.k8s.io/release/v1.26.5/bin/linux/amd64/kubelet -o /usr/local/bin/kubelet
132+
- chmod +x /usr/local/bin/kubelet
133+
- curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service
134+
- mkdir -p /etc/systemd/system/kubelet.service.d
135+
- curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.15.1/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
136+
- "systemctl enable kubelet.service"
94137

95138
---
96139

0 commit comments

Comments
 (0)