Skip to content

Commit b2ccc8e

Browse files
Merge pull request #109 from canonical/eaudetcobello/KU-1189
2 parents 8295d78 + 21373e2 commit b2ccc8e

12 files changed

+142
-0
lines changed

apis/v1beta1/microk8sconfig_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ type InitConfiguration struct {
8181
// +kubebuilder:default:=stable
8282
RiskLevel string `json:"riskLevel,omitempty"`
8383

84+
// Whether or not to use the default CNI
85+
// +optional
86+
DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"`
87+
8488
// The snap store proxy domain
8589
// +optional
8690
SnapstoreProxyDomain string `json:"snapstoreProxyDomain,omitempty"`

bootstrap-components.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ spec:
9797
- classic
9898
- strict
9999
type: string
100+
disableDefaultCNI:
101+
description: Whether or not to use the default CNI
102+
type: boolean
100103
extraKubeletArgs:
101104
description: ExtraKubeletArgs is a list of extra arguments to
102105
add to the kubelet.
@@ -369,6 +372,9 @@ spec:
369372
- classic
370373
- strict
371374
type: string
375+
disableDefaultCNI:
376+
description: Whether or not to use the default CNI
377+
type: boolean
372378
extraKubeletArgs:
373379
description: ExtraKubeletArgs is a list of extra arguments
374380
to add to the kubelet.

config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ spec:
8787
- classic
8888
- strict
8989
type: string
90+
disableDefaultCNI:
91+
description: Whether or not to use the default CNI
92+
type: boolean
9093
extraKubeletArgs:
9194
description: ExtraKubeletArgs is a list of extra arguments to
9295
add to the kubelet.

config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ spec:
9595
- classic
9696
- strict
9797
type: string
98+
disableDefaultCNI:
99+
description: Whether or not to use the default CNI
100+
type: boolean
98101
extraKubeletArgs:
99102
description: ExtraKubeletArgs is a list of extra arguments
100103
to add to the kubelet.

controllers/cloudinit/cloudinit_common_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,80 @@ func TestCloudConfigInput(t *testing.T) {
382382
})
383383
}
384384
})
385+
386+
t.Run("DisableDefaultCNI", func(t *testing.T) {
387+
for _, tc := range []struct {
388+
name string
389+
makeCloudConfig func() (*cloudinit.CloudConfig, error)
390+
}{
391+
{
392+
name: "ControlPlaneInit",
393+
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
394+
return cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInitInput{
395+
DisableDefaultCNI: true,
396+
KubernetesVersion: "v1.25.0",
397+
Token: strings.Repeat("a", 32),
398+
TokenTTL: 100,
399+
})
400+
},
401+
},
402+
{
403+
name: "ControlPlaneJoin",
404+
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
405+
return cloudinit.NewJoinControlPlane(&cloudinit.ControlPlaneJoinInput{
406+
DisableDefaultCNI: true,
407+
KubernetesVersion: "v1.25.0",
408+
Token: strings.Repeat("a", 32),
409+
TokenTTL: 100,
410+
})
411+
},
412+
},
413+
} {
414+
t.Run(tc.name, func(t *testing.T) {
415+
g := NewWithT(t)
416+
c, err := tc.makeCloudConfig()
417+
g.Expect(err).NotTo(HaveOccurred())
418+
419+
g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/10-disable-default-cni.sh`))
420+
})
421+
}
422+
})
423+
424+
t.Run("DefaultCNI", func(t *testing.T) {
425+
for _, tc := range []struct {
426+
name string
427+
makeCloudConfig func() (*cloudinit.CloudConfig, error)
428+
}{
429+
{
430+
name: "ControlPlaneInit",
431+
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
432+
return cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInitInput{
433+
DisableDefaultCNI: false,
434+
KubernetesVersion: "v1.25.0",
435+
Token: strings.Repeat("a", 32),
436+
TokenTTL: 100,
437+
})
438+
},
439+
},
440+
{
441+
name: "ControlPlaneJoin",
442+
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
443+
return cloudinit.NewJoinControlPlane(&cloudinit.ControlPlaneJoinInput{
444+
DisableDefaultCNI: false,
445+
KubernetesVersion: "v1.25.0",
446+
Token: strings.Repeat("a", 32),
447+
TokenTTL: 100,
448+
})
449+
},
450+
},
451+
} {
452+
t.Run(tc.name, func(t *testing.T) {
453+
g := NewWithT(t)
454+
c, err := tc.makeCloudConfig()
455+
g.Expect(err).NotTo(HaveOccurred())
456+
457+
g.Expect(c.RunCommands).NotTo(ContainElement(`/capi-scripts/10-disable-default-cni.sh`))
458+
})
459+
}
460+
})
385461
}

controllers/cloudinit/controlplane_init.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type ControlPlaneInitInput struct {
5757
Confinement string
5858
// RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels.
5959
RiskLevel string
60+
// DisableDefaultCNI specifies whether to disable the default CNI plugin.
61+
DisableDefaultCNI bool
6062
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
6163
SnapstoreProxyDomain string
6264
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
@@ -145,6 +147,13 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) {
145147
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
146148
scriptPath(configureKubeletScript),
147149
scriptPath(waitAPIServerScript),
150+
)
151+
152+
if input.DisableDefaultCNI {
153+
cloudConfig.RunCommands = append(cloudConfig.RunCommands, scriptPath(disableDefaultCNIScript))
154+
}
155+
156+
cloudConfig.RunCommands = append(cloudConfig.RunCommands,
148157
"microk8s refresh-certs /var/tmp",
149158
fmt.Sprintf("%s %v", scriptPath(configureCalicoIPIPScript), input.IPinIP),
150159
fmt.Sprintf("%s %q", scriptPath(configureClusterAgentPortScript), input.ClusterAgentPort),

controllers/cloudinit/controlplane_init_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestControlPlaneInit(t *testing.T) {
3838
IPinIP: true,
3939
Token: strings.Repeat("a", 32),
4040
TokenTTL: 10000,
41+
DisableDefaultCNI: true,
4142
Confinement: "classic",
4243
})
4344
g.Expect(err).NotTo(HaveOccurred())
@@ -51,6 +52,7 @@ func TestControlPlaneInit(t *testing.T) {
5152
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
5253
`/capi-scripts/10-configure-kubelet.sh`,
5354
`/capi-scripts/50-wait-apiserver.sh`,
55+
`/capi-scripts/10-disable-default-cni.sh`,
5456
`microk8s refresh-certs /var/tmp`,
5557
`/capi-scripts/10-configure-calico-ipip.sh true`,
5658
`/capi-scripts/10-configure-cluster-agent-port.sh "30000"`,

controllers/cloudinit/controlplane_join.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type ControlPlaneJoinInput struct {
5353
Confinement string
5454
// RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels.
5555
RiskLevel string
56+
// DisableDefaultCNI specifies whether to use the default CNI plugin.
57+
DisableDefaultCNI bool
5658
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
5759
SnapstoreProxyDomain string
5860
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
@@ -127,6 +129,13 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) {
127129
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
128130
scriptPath(configureKubeletScript),
129131
scriptPath(waitAPIServerScript),
132+
)
133+
134+
if input.DisableDefaultCNI {
135+
cloudConfig.RunCommands = append(cloudConfig.RunCommands, scriptPath(disableDefaultCNIScript))
136+
}
137+
138+
cloudConfig.RunCommands = append(cloudConfig.RunCommands,
130139
fmt.Sprintf("%s %v", scriptPath(configureCalicoIPIPScript), input.IPinIP),
131140
fmt.Sprintf("%s %q", scriptPath(configureClusterAgentPortScript), input.ClusterAgentPort),
132141
fmt.Sprintf("%s %q", scriptPath(configureDqlitePortScript), input.DqlitePort),

controllers/cloudinit/controlplane_join_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestControlPlaneJoin(t *testing.T) {
3434
ClusterAgentPort: "30000",
3535
DqlitePort: "2379",
3636
IPinIP: true,
37+
DisableDefaultCNI: true,
3738
Token: strings.Repeat("a", 32),
3839
TokenTTL: 10000,
3940
JoinNodeIPs: []string{"10.0.3.39", "10.0.3.40", "10.0.3.41"},
@@ -49,6 +50,7 @@ func TestControlPlaneJoin(t *testing.T) {
4950
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
5051
`/capi-scripts/10-configure-kubelet.sh`,
5152
`/capi-scripts/50-wait-apiserver.sh`,
53+
`/capi-scripts/10-disable-default-cni.sh`,
5254
`/capi-scripts/10-configure-calico-ipip.sh true`,
5355
`/capi-scripts/10-configure-cluster-agent-port.sh "30000"`,
5456
`/capi-scripts/10-configure-dqlite-port.sh "2379"`,

controllers/cloudinit/embed.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const (
4343
// disableHostServicesScript disables services like containerd or kubelet from the host OS image.
4444
disableHostServicesScript script = "00-disable-host-services.sh"
4545

46+
// disableDefaultCNIScript disables the default CNI plugin.
47+
disableDefaultCNIScript script = "10-disable-default-cni.sh"
48+
4649
// installMicroK8sScript installs MicroK8s on the host.
4750
installMicroK8sScript script = "00-install-microk8s.sh"
4851

@@ -85,6 +88,7 @@ var allScripts = []script{
8588
snapstoreHTTPProxyScript,
8689
disableHostServicesScript,
8790
installMicroK8sScript,
91+
disableDefaultCNIScript,
8892
configureCertLB,
8993
configureAPIServerScript,
9094
configureCalicoIPIPScript,

0 commit comments

Comments
 (0)