Skip to content

Commit e382162

Browse files
committed
implement defaulting to http scheme
1 parent 45a04af commit e382162

10 files changed

+42
-17
lines changed

apis/v1beta1/microk8sconfig_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type InitConfiguration struct {
8686
DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"`
8787

8888
// The snap store proxy domain's scheme, e.g. "http" or "https" without "://"
89+
// Defaults to "http".
8990
// +optional
9091
SnapstoreProxyScheme string `json:"snapstoreProxyScheme,omitempty"`
9192

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ spec:
182182
type: string
183183
snapstoreProxyScheme:
184184
description: The snap store proxy domain's scheme, e.g. "http"
185-
or "https" without "://"
185+
or "https" without "://" Defaults to "http".
186186
type: string
187187
type: object
188188
type: object

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ spec:
193193
type: string
194194
snapstoreProxyScheme:
195195
description: The snap store proxy domain's scheme, e.g.
196-
"http" or "https" without "://"
196+
"http" or "https" without "://" Defaults to "http".
197197
type: string
198198
type: object
199199
type: object

controllers/cloudinit/cloudinit_common_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,41 +228,41 @@ func TestCloudConfigInput(t *testing.T) {
228228
t.Run("SnapstoreProxy", func(t *testing.T) {
229229
for _, tc := range []struct {
230230
name string
231-
makeCloudConfig func() (*cloudinit.CloudConfig, error)
231+
makeCloudConfig func(scheme string) (*cloudinit.CloudConfig, error)
232232
}{
233233
{
234234
name: "ControlPlaneInit",
235-
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
235+
makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) {
236236
return cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInitInput{
237237
KubernetesVersion: "v1.25.0",
238238
Token: strings.Repeat("a", 32),
239239
TokenTTL: 100,
240-
SnapstoreProxyScheme: "https",
240+
SnapstoreProxyScheme: scheme,
241241
SnapstoreProxyDomain: "snapstore.domain.com",
242242
SnapstoreProxyId: "ID123456789",
243243
})
244244
},
245245
},
246246
{
247247
name: "ControlPlaneJoin",
248-
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
248+
makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) {
249249
return cloudinit.NewJoinControlPlane(&cloudinit.ControlPlaneJoinInput{
250250
KubernetesVersion: "v1.25.0",
251251
Token: strings.Repeat("a", 32),
252252
TokenTTL: 100,
253-
SnapstoreProxyScheme: "https",
253+
SnapstoreProxyScheme: scheme,
254254
SnapstoreProxyDomain: "snapstore.domain.com",
255255
SnapstoreProxyId: "ID123456789",
256256
})
257257
},
258258
},
259259
{
260260
name: "Worker",
261-
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
261+
makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) {
262262
return cloudinit.NewJoinWorker(&cloudinit.WorkerInput{
263263
KubernetesVersion: "v1.25.0",
264264
Token: strings.Repeat("a", 32),
265-
SnapstoreProxyScheme: "https",
265+
SnapstoreProxyScheme: scheme,
266266
SnapstoreProxyDomain: "snapstore.domain.com",
267267
SnapstoreProxyId: "ID123456789",
268268
})
@@ -271,10 +271,22 @@ func TestCloudConfigInput(t *testing.T) {
271271
} {
272272
t.Run(tc.name, func(t *testing.T) {
273273
g := NewWithT(t)
274-
c, err := tc.makeCloudConfig()
275-
g.Expect(err).NotTo(HaveOccurred())
276274

277-
g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "https" "snapstore.domain.com" "ID123456789"`))
275+
for _, withScheme := range []string{"", "http", "https"} {
276+
t.Run(fmt.Sprintf("withScheme=%q", withScheme), func(t *testing.T) {
277+
c, err := tc.makeCloudConfig(withScheme)
278+
g.Expect(err).NotTo(HaveOccurred())
279+
280+
// if scheme is unspecified, default to http
281+
var expectedScheme string
282+
if withScheme == "" {
283+
expectedScheme = "http"
284+
} else {
285+
expectedScheme = withScheme
286+
}
287+
g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-configure-snapstore-proxy.sh %q "snapstore.domain.com" "ID123456789"`, expectedScheme)))
288+
})
289+
}
278290
})
279291
}
280292
})

controllers/cloudinit/controlplane_init.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ControlPlaneInitInput struct {
5959
RiskLevel string
6060
// DisableDefaultCNI specifies whether to disable the default CNI plugin.
6161
DisableDefaultCNI bool
62-
// SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain.
62+
// SnapstoreProxyScheme specifies the scheme (e.g. http or https) of the domain. Defaults to "http".
6363
SnapstoreProxyScheme string
6464
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
6565
SnapstoreProxyDomain string
@@ -90,6 +90,10 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) {
9090
return nil, fmt.Errorf("join token TTL %q is not a positive number", input.TokenTTL)
9191
}
9292

93+
if input.SnapstoreProxyScheme == "" {
94+
input.SnapstoreProxyScheme = "http"
95+
}
96+
9397
// figure out endpoint type
9498
endpointType := "DNS"
9599
if net.ParseIP(input.ControlPlaneEndpoint) != nil {

controllers/cloudinit/controlplane_init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestControlPlaneInit(t *testing.T) {
4646
g.Expect(cloudConfig.RunCommands).To(Equal([]string{
4747
`set -x`,
4848
`/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`,
49-
`/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`,
49+
`/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`,
5050
`/capi-scripts/00-disable-host-services.sh`,
5151
`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`,
5252
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,

controllers/cloudinit/controlplane_join.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type ControlPlaneJoinInput struct {
5555
RiskLevel string
5656
// DisableDefaultCNI specifies whether to use the default CNI plugin.
5757
DisableDefaultCNI bool
58-
// SnapstoreProxyScheme specifies the scheme (e.g https://) of the domain.
58+
// SnapstoreProxyScheme specifies the scheme (e.g. http or https) of the domain. Defaults to "http".
5959
SnapstoreProxyScheme string
6060
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
6161
SnapstoreProxyDomain string
@@ -104,6 +104,10 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) {
104104
}
105105
installArgs := createInstallArgs(input.Confinement, input.RiskLevel, kubernetesVersion)
106106

107+
if input.SnapstoreProxyScheme == "" {
108+
input.SnapstoreProxyScheme = "http"
109+
}
110+
107111
cloudConfig := NewBaseCloudConfig()
108112
cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, input.ExtraWriteFiles...)
109113
if args := input.ExtraKubeletArgs; len(args) > 0 {

controllers/cloudinit/controlplane_join_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestControlPlaneJoin(t *testing.T) {
4444
g.Expect(cloudConfig.RunCommands).To(Equal([]string{
4545
`set -x`,
4646
`/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`,
47-
`/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`,
47+
`/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`,
4848
`/capi-scripts/00-disable-host-services.sh`,
4949
`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`,
5050
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,

controllers/cloudinit/worker_join.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) {
8585
return nil, fmt.Errorf("strict confinement is only available for microk8s v1.25+")
8686
}
8787

88+
if input.SnapstoreProxyScheme == "" {
89+
input.SnapstoreProxyScheme = "http"
90+
}
91+
8892
stopApiServerProxyRefreshes := "no"
8993
if kubernetesVersion.Minor() > 24 {
9094
stopApiServerProxyRefreshes = "yes"

controllers/cloudinit/worker_join_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestWorkerJoin(t *testing.T) {
4040
g.Expect(cloudConfig.RunCommands).To(Equal([]string{
4141
`set -x`,
4242
`/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`,
43-
`/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`,
43+
`/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`,
4444
`/capi-scripts/00-disable-host-services.sh`,
4545
`/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic"`,
4646
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,

0 commit comments

Comments
 (0)