Skip to content

Commit 805ee61

Browse files
committed
add new SnapstoreProxyField
1 parent b2ccc8e commit 805ee61

11 files changed

+38
-12
lines changed

apis/v1beta1/microk8sconfig_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ type InitConfiguration struct {
8585
// +optional
8686
DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"`
8787

88+
// The snap store proxy domain's scheme, e.g. "http" or "https" without '://'
89+
// +optional
90+
SnapstoreProxyScheme string `json:"snapstoreProxyScheme,omitempty"`
91+
8892
// The snap store proxy domain
8993
// +optional
9094
SnapstoreProxyDomain string `json:"snapstoreProxyDomain,omitempty"`

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ spec:
180180
snapstoreProxyId:
181181
description: The snap store proxy ID
182182
type: string
183+
snapstoreProxyScheme:
184+
description: The snap store proxy domain's scheme, e.g. "http"
185+
or "https" without '://'
186+
type: string
183187
type: object
184188
type: object
185189
status:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ spec:
191191
snapstoreProxyId:
192192
description: The snap store proxy ID
193193
type: string
194+
snapstoreProxyScheme:
195+
description: The snap store proxy domain's scheme, e.g.
196+
"http" or "https" without '://'
197+
type: string
194198
type: object
195199
type: object
196200
type: object

controllers/cloudinit/cloudinit_common_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func TestCloudConfigInput(t *testing.T) {
237237
KubernetesVersion: "v1.25.0",
238238
Token: strings.Repeat("a", 32),
239239
TokenTTL: 100,
240+
SnapstoreProxyScheme: "https",
240241
SnapstoreProxyDomain: "snapstore.domain.com",
241242
SnapstoreProxyId: "ID123456789",
242243
})
@@ -249,6 +250,7 @@ func TestCloudConfigInput(t *testing.T) {
249250
KubernetesVersion: "v1.25.0",
250251
Token: strings.Repeat("a", 32),
251252
TokenTTL: 100,
253+
SnapstoreProxyScheme: "https",
252254
SnapstoreProxyDomain: "snapstore.domain.com",
253255
SnapstoreProxyId: "ID123456789",
254256
})
@@ -260,6 +262,7 @@ func TestCloudConfigInput(t *testing.T) {
260262
return cloudinit.NewJoinWorker(&cloudinit.WorkerInput{
261263
KubernetesVersion: "v1.25.0",
262264
Token: strings.Repeat("a", 32),
265+
SnapstoreProxyScheme: "https",
263266
SnapstoreProxyDomain: "snapstore.domain.com",
264267
SnapstoreProxyId: "ID123456789",
265268
})
@@ -271,7 +274,7 @@ func TestCloudConfigInput(t *testing.T) {
271274
c, err := tc.makeCloudConfig()
272275
g.Expect(err).NotTo(HaveOccurred())
273276

274-
g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "snapstore.domain.com" "ID123456789"`))
277+
g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "https" "snapstore.domain.com" "ID123456789"`))
275278
})
276279
}
277280
})

controllers/cloudinit/controlplane_init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ 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.
63+
SnapstoreProxyScheme string
6264
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
6365
SnapstoreProxyDomain string
6466
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
@@ -141,7 +143,7 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) {
141143
cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...)
142144
cloudConfig.RunCommands = append(cloudConfig.RunCommands,
143145
fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy),
144-
fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId),
146+
fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId),
145147
scriptPath(disableHostServicesScript),
146148
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
147149
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),

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 "" "" ""`,
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type ControlPlaneJoinInput struct {
5555
RiskLevel string
5656
// DisableDefaultCNI specifies whether to use the default CNI plugin.
5757
DisableDefaultCNI bool
58+
// SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain.
59+
SnapstoreProxyScheme string
5860
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
5961
SnapstoreProxyDomain string
6062
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
@@ -123,7 +125,7 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) {
123125
cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...)
124126
cloudConfig.RunCommands = append(cloudConfig.RunCommands,
125127
fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy),
126-
fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId),
128+
fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId),
127129
scriptPath(disableHostServicesScript),
128130
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
129131
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),

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 "" "" ""`,
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 "" "" ""`,
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/bin/bash -xe
22

33
# Usage:
4-
# $0 $snapstore-domain $snapstore-id
4+
# $0 $snapstore-scheme $snapstore-domain $snapstore-id
5+
#
6+
# Arguments:
7+
# $snapstore-scheme The scheme for the domain (e.g. https or http without the ://)
8+
# $snapstore-domain The domain name (e.g. snapstore.domain.com)
9+
# $snapstore-id The store id (e.g. ID123456789)
510
#
611
# Assumptions:
712
# - snapd is installed
813

9-
if [ "$#" -ne 2 ] || [ -z "${1}" ] || [ -z "${2}" ] ; then
14+
if [ "$#" -ne 3 ] || [ -z "${1}" ] || [ -z "${2}" ] || [ -z "${3}" ] ; then
1015
echo "Using the default snapstore"
1116
exit 0
1217
fi
@@ -18,12 +23,12 @@ if ! type -P curl ; then
1823
done
1924
fi
2025

21-
while ! curl -sL http://"${1}"/v2/auth/store/assertions | snap ack /dev/stdin ; do
26+
while ! curl -sL "${1}"://"${2}"/v2/auth/store/assertions | snap ack /dev/stdin ; do
2227
echo "Failed to ACK store assertions, will retry"
2328
sleep 5
2429
done
2530

26-
while ! snap set core proxy.store="${2}" ; do
27-
echo "Failed to configure snapd with stire ID, will retry"
31+
while ! snap set core proxy.store="${3}" ; do
32+
echo "Failed to configure snapd with store ID, will retry"
2833
sleep 5
2934
done

controllers/cloudinit/worker_join.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type WorkerInput struct {
4646
Confinement string
4747
// RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels.
4848
RiskLevel string
49+
// SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain.
50+
SnapstoreProxyScheme string
4951
// SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used.
5052
SnapstoreProxyDomain string
5153
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
@@ -110,7 +112,7 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) {
110112
cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...)
111113
cloudConfig.RunCommands = append(cloudConfig.RunCommands,
112114
fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy),
113-
fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId),
115+
fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId),
114116
scriptPath(disableHostServicesScript),
115117
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
116118
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),

0 commit comments

Comments
 (0)