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

Commit c76d689

Browse files
committed
Pass container runtime as well
1 parent 0483fdf commit c76d689

File tree

4 files changed

+52
-43
lines changed

4 files changed

+52
-43
lines changed

config/default/machine_configs.yaml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ items:
33
- image: ubuntu_18_04
44
versions:
55
kubelet: 1.14.3
6+
containerRuntime: docker-ce=18.03.1~ce~3-0~ubuntu
67
- image: ubuntu_18_04
78
versions:
89
kubelet: 1.14.3
910
controlPlane: 1.14.3
11+
containerRuntime: docker-ce=18.03.1~ce~3-0~ubuntu
1012
userdata: |
1113
set -e
1214
set -x
1315
(
1416
ARCH=amd64
1517
1618
# Obtain server IP addresses.
17-
HOSTNAME=$(curl -s https://metadata.packet.net/2009-04-04/meta-data/hostname)
18-
PRIVATEIP=$(curl -s https://metadata.packet.net/2009-04-04/meta-data/local-ipv4)
19-
PUBLICIP=$(curl -s https://metadata.packet.net/2009-04-04/meta-data/public-ipv4)
19+
METADATA="https://metadata.packet.net/2009-04-04/meta-data"
20+
HOSTNAME=$(curl -s ${METADATA}/hostname)
21+
PRIVATEIP=$(curl -s ${METADATA}/local-ipv4)
22+
PUBLICIP=$(curl -s ${METADATA}/public-ipv4)
2023
2124
CA_CERT_DIR=/etc/kubernetes/pki
2225
@@ -60,14 +63,7 @@ items:
6063
$(lsb_release -cs) \
6164
stable"
6265
63-
export CR_PKG=''
64-
if [ -n "$CR_VERSION" ]; then
65-
export CR_PKG="$CR_PACKAGE=$CR_VERSION"
66-
else
67-
export CR_PKG="$CR_PACKAGE"
68-
fi
69-
70-
apt-get install -y ${CR_PKG}
66+
apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" ${CR_PACKAGE}
7167
echo 'DOCKER_OPTS="--iptables=false --ip-masq=false"' > /etc/default/docker
7268
systemctl daemon-reload
7369
systemctl enable docker
@@ -131,26 +127,32 @@ items:
131127
# Set up kubeadm config file to pass parameters to kubeadm init.
132128
touch /etc/kubernetes/kubeadm_config.yaml
133129
cat > /etc/kubernetes/kubeadm_config.yaml <<EOF
134-
apiVersion: kubeadm.k8s.io/v1alpha1
135-
kind: MasterConfiguration
136-
kubernetesVersion: v${CONTROL_PLANE_VERSION}
137-
token: ${TOKEN}
138-
api:
139-
advertiseAddress: ${PUBLICIP}
140-
bindPort: ${PORT}
141-
networking:
142-
serviceSubnet: ${SERVICE_CIDR}
143-
podSubnet: ${POD_CIDR}
144-
controllerManagerExtraArgs:
130+
apiVersion: kubeadm.k8s.io/v1beta1
131+
kind: InitConfiguration
132+
localApiEndpoint:
133+
advertiseAddress: ${PUBLICIP}
134+
bindPort: ${PORT}
135+
nodeRegistration:
136+
name: ${PUBLICIP}
137+
---
138+
apiVersion: kubeadm.k8s.io/v1beta1
139+
kind: ClusterConfiguration
140+
certificatesDir: ${CA_CERT_DIR}
141+
kubernetesVersion: v${CONTROL_PLANE_VERSION}
142+
networking:
143+
serviceSubnet: ${SERVICE_CIDR}
144+
podSubnet: ${POD_CIDR}
145+
controllerManager:
146+
extraArgs:
145147
cluster-cidr: ${POD_CIDR}
146148
service-cluster-ip-range: ${SERVICE_CIDR}
147149
allocate-node-cidrs: "true"
148-
apiServerCertSANs:
149-
- ${PUBLICIP}
150-
- ${PRIVATEIP}
151-
- ${HOSTNAME}
152-
- 127.0.0.1
153-
certificatesDir: ${CA_CERT_DIR}
150+
apiServer:
151+
certSANs:
152+
- ${PUBLICIP}
153+
- ${PRIVATEIP}
154+
- ${HOSTNAME}
155+
- 127.0.0.1
154156
EOF
155157

156158
install_custom_ca

pkg/cloud/packet/actuators/machine/actuator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
8585
}
8686
// generate userdata from the template
8787
// first we need to find the correct userdata
88-
userdataTmpl, err := a.machineConfigGetter.GetUserdata(machineConfig.OS, machine.Spec.Versions)
88+
userdataTmpl, containerRuntime, err := a.machineConfigGetter.GetUserdata(machineConfig.OS, machine.Spec.Versions)
8989
if err != nil {
9090
return fmt.Errorf("Unable to read userdata: %v", err)
9191
}
@@ -116,7 +116,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
116116
tags = append(tags, util.WorkerTag)
117117
}
118118

119-
userdata, err := parseUserdata(userdataTmpl, role, cluster, machine, machineConfig.OS, token, caCert, caKey, a.controlPort)
119+
userdata, err := parseUserdata(userdataTmpl, role, cluster, machine, machineConfig.OS, token, caCert, caKey, a.controlPort, containerRuntime)
120120
if err != nil {
121121
return fmt.Errorf("Unable to generate userdata: %v", err)
122122
}

pkg/cloud/packet/actuators/machine/machineconfig/machineconfig.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
)
1212

1313
type Getter interface {
14-
GetUserdata(string, clusterv1.MachineVersionInfo) (string, error)
14+
// GetUserdata given a requested OS and machine version info, get: userdata, container runtime package with optional version, error
15+
GetUserdata(string, clusterv1.MachineVersionInfo) (string, string, error)
1516
}
1617

1718
// config is a single machine setup config that has userdata and parameters such as image name.
@@ -30,37 +31,39 @@ type configList struct {
3031
type ConfigParams struct {
3132
Image string `json:"image"`
3233
Versions clusterv1.MachineVersionInfo `json:"versions"`
34+
// ContainerRuntime is a the name of the container runtime package to install, if any
35+
ContainerRuntime string `json:"containerRuntime"`
3336
}
3437

3538
type GetterFile struct {
3639
path string
3740
}
3841

3942
// GetUserdata gets the userdata for the given machine spec, or an error if none is found
40-
func (g *GetterFile) GetUserdata(image string, versions clusterv1.MachineVersionInfo) (string, error) {
43+
func (g *GetterFile) GetUserdata(image string, versions clusterv1.MachineVersionInfo) (string, string, error) {
4144
if image == "" {
42-
return "", fmt.Errorf("invalid empty image requested")
45+
return "", "", fmt.Errorf("invalid empty image requested")
4346
}
4447
f, err := os.Open(g.path)
4548
if err != nil {
46-
return "", err
49+
return "", "", err
4750
}
4851
defer f.Close()
4952
c, err := loadConfigs(f)
5053
if err != nil {
51-
return "", fmt.Errorf("unable to load configs from file %s: %v", g.path, err)
54+
return "", "", fmt.Errorf("unable to load configs from file %s: %v", g.path, err)
5255
}
5356
// now find the config we want
5457
params := &ConfigParams{
5558
Image: image,
5659
Versions: versions,
5760
}
58-
config, err := findMatchingConfig(c, params)
61+
config, containerRuntime, err := findMatchingConfig(c, params)
5962
if err != nil {
60-
return "", fmt.Errorf("unable to find matching config: %v", err)
63+
return "", "", fmt.Errorf("unable to find matching config: %v", err)
6164
}
6265

63-
return config.Userdata, nil
66+
return config.Userdata, containerRuntime, nil
6467

6568
}
6669

@@ -79,8 +82,9 @@ func loadConfigs(reader io.Reader) (*configList, error) {
7982
return c, nil
8083
}
8184

82-
func findMatchingConfig(configs *configList, params *ConfigParams) (*config, error) {
85+
func findMatchingConfig(configs *configList, params *ConfigParams) (*config, string, error) {
8386
matchingConfigs := make([]config, 0)
87+
containerRuntime := ""
8488
for _, conf := range configs.Items {
8589
for _, validParams := range conf.Params {
8690
if params.Image != validParams.Image {
@@ -90,14 +94,15 @@ func findMatchingConfig(configs *configList, params *ConfigParams) (*config, err
9094
continue
9195
}
9296
matchingConfigs = append(matchingConfigs, conf)
97+
containerRuntime = params.ContainerRuntime
9398
}
9499
}
95100

96101
if len(matchingConfigs) == 1 {
97-
return &matchingConfigs[0], nil
102+
return &matchingConfigs[0], containerRuntime, nil
98103
}
99104

100-
return nil, fmt.Errorf("could not find setup configs for params %#v", params)
105+
return nil, "", fmt.Errorf("could not find setup configs for params %#v", params)
101106
}
102107

103108
func NewFileGetter(p string) (*GetterFile, error) {

pkg/cloud/packet/actuators/machine/userdata.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ type userdataParams struct {
1818
PodCIDR string
1919
ServiceCIDR string
2020
CRPackage string
21-
CRVersion string
2221
CACertificate string
2322
CAPrivateKey string
2423
Role string
2524
Port int
2625
}
2726

28-
func parseUserdata(userdata, role string, cluster *clusterv1.Cluster, machine *clusterv1.Machine, image, token string, caCertificate, caKey []byte, port int) (string, error) {
27+
func parseUserdata(userdata, role string, cluster *clusterv1.Cluster, machine *clusterv1.Machine, image, token string, caCertificate, caKey []byte, port int, containerRuntime string) (string, error) {
2928
params := userdataParams{
3029
Cluster: cluster,
3130
Machine: machine,
@@ -36,6 +35,7 @@ func parseUserdata(userdata, role string, cluster *clusterv1.Cluster, machine *c
3635
CAPrivateKey: base64.StdEncoding.EncodeToString(caKey),
3736
Role: role,
3837
Port: port,
38+
CRPackage: containerRuntime,
3939
}
4040
vars := masterEnvironmentVariables
4141
if role == "node" {
@@ -83,6 +83,7 @@ SERVICE_CIDR={{ .ServiceCIDR }}
8383
MASTER_CA_CERTIFICATE={{ .CACertificate }}
8484
MASTER_CA_PRIVATE_KEY={{ .CAPrivateKey }}
8585
ROLE={{ .Role }}
86+
CR_PACKAGE={{ .CRPackage }}
8687
`
8788
// nodeEnvironmentVariables is the environment variables template for worker instances.
8889
nodeEnvironmentVariables = `#!/bin/bash
@@ -95,5 +96,6 @@ CLUSTER_DNS_DOMAIN={{ .Cluster.Spec.ClusterNetwork.ServiceDomain }}
9596
POD_CIDR={{ .PodCIDR }}
9697
SERVICE_CIDR={{ .ServiceCIDR }}
9798
ROLE={{ .Role }}
99+
CR_PACKAGE={{ .CRPackage }}
98100
`
99101
)

0 commit comments

Comments
 (0)