From 805ee61437187061ec532c54d3a92b1f473b8c0c Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Tue, 30 Jul 2024 19:17:01 -0400 Subject: [PATCH 1/6] add new SnapstoreProxyField --- apis/v1beta1/microk8sconfig_types.go | 4 ++++ ...ootstrap.cluster.x-k8s.io_microk8sconfigs.yaml | 4 ++++ ....cluster.x-k8s.io_microk8sconfigtemplates.yaml | 4 ++++ controllers/cloudinit/cloudinit_common_test.go | 5 ++++- controllers/cloudinit/controlplane_init.go | 4 +++- controllers/cloudinit/controlplane_init_test.go | 2 +- controllers/cloudinit/controlplane_join.go | 4 +++- controllers/cloudinit/controlplane_join_test.go | 2 +- .../scripts/00-configure-snapstore-proxy.sh | 15 ++++++++++----- controllers/cloudinit/worker_join.go | 4 +++- controllers/cloudinit/worker_join_test.go | 2 +- 11 files changed, 38 insertions(+), 12 deletions(-) diff --git a/apis/v1beta1/microk8sconfig_types.go b/apis/v1beta1/microk8sconfig_types.go index 0ae87c4..86c15c8 100644 --- a/apis/v1beta1/microk8sconfig_types.go +++ b/apis/v1beta1/microk8sconfig_types.go @@ -85,6 +85,10 @@ type InitConfiguration struct { // +optional DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"` + // The snap store proxy domain's scheme, e.g. "http" or "https" without '://' + // +optional + SnapstoreProxyScheme string `json:"snapstoreProxyScheme,omitempty"` + // The snap store proxy domain // +optional SnapstoreProxyDomain string `json:"snapstoreProxyDomain,omitempty"` diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml index 839139a..9efd5bf 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml @@ -180,6 +180,10 @@ spec: snapstoreProxyId: description: The snap store proxy ID type: string + snapstoreProxyScheme: + description: The snap store proxy domain's scheme, e.g. "http" + or "https" without '://' + type: string type: object type: object status: diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml index 67a9d2a..43decdc 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml @@ -191,6 +191,10 @@ spec: snapstoreProxyId: description: The snap store proxy ID type: string + snapstoreProxyScheme: + description: The snap store proxy domain's scheme, e.g. + "http" or "https" without '://' + type: string type: object type: object type: object diff --git a/controllers/cloudinit/cloudinit_common_test.go b/controllers/cloudinit/cloudinit_common_test.go index a790c43..5b7a365 100644 --- a/controllers/cloudinit/cloudinit_common_test.go +++ b/controllers/cloudinit/cloudinit_common_test.go @@ -237,6 +237,7 @@ func TestCloudConfigInput(t *testing.T) { KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), TokenTTL: 100, + SnapstoreProxyScheme: "https", SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -249,6 +250,7 @@ func TestCloudConfigInput(t *testing.T) { KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), TokenTTL: 100, + SnapstoreProxyScheme: "https", SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -260,6 +262,7 @@ func TestCloudConfigInput(t *testing.T) { return cloudinit.NewJoinWorker(&cloudinit.WorkerInput{ KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), + SnapstoreProxyScheme: "https", SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -271,7 +274,7 @@ func TestCloudConfigInput(t *testing.T) { c, err := tc.makeCloudConfig() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "snapstore.domain.com" "ID123456789"`)) + g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "https" "snapstore.domain.com" "ID123456789"`)) }) } }) diff --git a/controllers/cloudinit/controlplane_init.go b/controllers/cloudinit/controlplane_init.go index c08f83b..5b2e516 100644 --- a/controllers/cloudinit/controlplane_init.go +++ b/controllers/cloudinit/controlplane_init.go @@ -59,6 +59,8 @@ type ControlPlaneInitInput struct { RiskLevel string // DisableDefaultCNI specifies whether to disable the default CNI plugin. DisableDefaultCNI bool + // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string // SnapstoreProxyId specifies the snapstore proxy ID if one is to be used. @@ -141,7 +143,7 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) { cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...) cloudConfig.RunCommands = append(cloudConfig.RunCommands, fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), - fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), + fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), diff --git a/controllers/cloudinit/controlplane_init_test.go b/controllers/cloudinit/controlplane_init_test.go index f1eabd7..ec0e6a1 100644 --- a/controllers/cloudinit/controlplane_init_test.go +++ b/controllers/cloudinit/controlplane_init_test.go @@ -46,7 +46,7 @@ func TestControlPlaneInit(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, diff --git a/controllers/cloudinit/controlplane_join.go b/controllers/cloudinit/controlplane_join.go index b08e1cb..e739e5a 100644 --- a/controllers/cloudinit/controlplane_join.go +++ b/controllers/cloudinit/controlplane_join.go @@ -55,6 +55,8 @@ type ControlPlaneJoinInput struct { RiskLevel string // DisableDefaultCNI specifies whether to use the default CNI plugin. DisableDefaultCNI bool + // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string // SnapstoreProxyId specifies the snapstore proxy ID if one is to be used. @@ -123,7 +125,7 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) { cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...) cloudConfig.RunCommands = append(cloudConfig.RunCommands, fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), - fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), + fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), diff --git a/controllers/cloudinit/controlplane_join_test.go b/controllers/cloudinit/controlplane_join_test.go index 826a43f..d5fc09a 100644 --- a/controllers/cloudinit/controlplane_join_test.go +++ b/controllers/cloudinit/controlplane_join_test.go @@ -44,7 +44,7 @@ func TestControlPlaneJoin(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, diff --git a/controllers/cloudinit/scripts/00-configure-snapstore-proxy.sh b/controllers/cloudinit/scripts/00-configure-snapstore-proxy.sh index 90fa24a..ff6b5eb 100644 --- a/controllers/cloudinit/scripts/00-configure-snapstore-proxy.sh +++ b/controllers/cloudinit/scripts/00-configure-snapstore-proxy.sh @@ -1,12 +1,17 @@ #!/bin/bash -xe # Usage: -# $0 $snapstore-domain $snapstore-id +# $0 $snapstore-scheme $snapstore-domain $snapstore-id +# +# Arguments: +# $snapstore-scheme The scheme for the domain (e.g. https or http without the ://) +# $snapstore-domain The domain name (e.g. snapstore.domain.com) +# $snapstore-id The store id (e.g. ID123456789) # # Assumptions: # - snapd is installed -if [ "$#" -ne 2 ] || [ -z "${1}" ] || [ -z "${2}" ] ; then +if [ "$#" -ne 3 ] || [ -z "${1}" ] || [ -z "${2}" ] || [ -z "${3}" ] ; then echo "Using the default snapstore" exit 0 fi @@ -18,12 +23,12 @@ if ! type -P curl ; then done fi -while ! curl -sL http://"${1}"/v2/auth/store/assertions | snap ack /dev/stdin ; do +while ! curl -sL "${1}"://"${2}"/v2/auth/store/assertions | snap ack /dev/stdin ; do echo "Failed to ACK store assertions, will retry" sleep 5 done -while ! snap set core proxy.store="${2}" ; do - echo "Failed to configure snapd with stire ID, will retry" +while ! snap set core proxy.store="${3}" ; do + echo "Failed to configure snapd with store ID, will retry" sleep 5 done diff --git a/controllers/cloudinit/worker_join.go b/controllers/cloudinit/worker_join.go index 10efcc9..f5e4c01 100644 --- a/controllers/cloudinit/worker_join.go +++ b/controllers/cloudinit/worker_join.go @@ -46,6 +46,8 @@ type WorkerInput struct { Confinement string // RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels. RiskLevel string + // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string // SnapstoreProxyId specifies the snapstore proxy ID if one is to be used. @@ -110,7 +112,7 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) { cloudConfig.RunCommands = append(cloudConfig.RunCommands, input.PreRunCommands...) cloudConfig.RunCommands = append(cloudConfig.RunCommands, fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), - fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), + fmt.Sprintf("%s %q %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyScheme, input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), diff --git a/controllers/cloudinit/worker_join_test.go b/controllers/cloudinit/worker_join_test.go index bc57e86..118292f 100644 --- a/controllers/cloudinit/worker_join_test.go +++ b/controllers/cloudinit/worker_join_test.go @@ -40,7 +40,7 @@ func TestWorkerJoin(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, From 50b5a79733acfbd1f72f0e691b0d19f0bdf3f422 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Tue, 30 Jul 2024 19:29:17 -0400 Subject: [PATCH 2/6] ' -> " --- apis/v1beta1/microk8sconfig_types.go | 2 +- .../crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml | 2 +- .../bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apis/v1beta1/microk8sconfig_types.go b/apis/v1beta1/microk8sconfig_types.go index 86c15c8..4cb132d 100644 --- a/apis/v1beta1/microk8sconfig_types.go +++ b/apis/v1beta1/microk8sconfig_types.go @@ -85,7 +85,7 @@ type InitConfiguration struct { // +optional DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"` - // The snap store proxy domain's scheme, e.g. "http" or "https" without '://' + // The snap store proxy domain's scheme, e.g. "http" or "https" without "://" // +optional SnapstoreProxyScheme string `json:"snapstoreProxyScheme,omitempty"` diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml index 9efd5bf..3b55f67 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml @@ -182,7 +182,7 @@ spec: type: string snapstoreProxyScheme: description: The snap store proxy domain's scheme, e.g. "http" - or "https" without '://' + or "https" without "://" type: string type: object type: object diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml index 43decdc..5835e05 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml @@ -193,7 +193,7 @@ spec: type: string snapstoreProxyScheme: description: The snap store proxy domain's scheme, e.g. - "http" or "https" without '://' + "http" or "https" without "://" type: string type: object type: object From 45a04afd666c1dd0a4f1f93071780ee7273b86c7 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Tue, 30 Jul 2024 19:30:00 -0400 Subject: [PATCH 3/6] i.e. -> e.g. --- controllers/cloudinit/controlplane_join.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/cloudinit/controlplane_join.go b/controllers/cloudinit/controlplane_join.go index e739e5a..d0f5efe 100644 --- a/controllers/cloudinit/controlplane_join.go +++ b/controllers/cloudinit/controlplane_join.go @@ -55,7 +55,7 @@ type ControlPlaneJoinInput struct { RiskLevel string // DisableDefaultCNI specifies whether to use the default CNI plugin. DisableDefaultCNI bool - // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + // SnapstoreProxyScheme specifies the scheme (e.g https://) of the domain. SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string From e3821621a9cac8d83d7b38547b542314f2520cc3 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Wed, 31 Jul 2024 07:44:01 -0400 Subject: [PATCH 4/6] implement defaulting to http scheme --- apis/v1beta1/microk8sconfig_types.go | 1 + ...trap.cluster.x-k8s.io_microk8sconfigs.yaml | 2 +- ...ster.x-k8s.io_microk8sconfigtemplates.yaml | 2 +- .../cloudinit/cloudinit_common_test.go | 32 +++++++++++++------ controllers/cloudinit/controlplane_init.go | 6 +++- .../cloudinit/controlplane_init_test.go | 2 +- controllers/cloudinit/controlplane_join.go | 6 +++- .../cloudinit/controlplane_join_test.go | 2 +- controllers/cloudinit/worker_join.go | 4 +++ controllers/cloudinit/worker_join_test.go | 2 +- 10 files changed, 42 insertions(+), 17 deletions(-) diff --git a/apis/v1beta1/microk8sconfig_types.go b/apis/v1beta1/microk8sconfig_types.go index 4cb132d..0171826 100644 --- a/apis/v1beta1/microk8sconfig_types.go +++ b/apis/v1beta1/microk8sconfig_types.go @@ -86,6 +86,7 @@ type InitConfiguration struct { DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"` // The snap store proxy domain's scheme, e.g. "http" or "https" without "://" + // Defaults to "http". // +optional SnapstoreProxyScheme string `json:"snapstoreProxyScheme,omitempty"` diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml index 3b55f67..3f7ecbe 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigs.yaml @@ -182,7 +182,7 @@ spec: type: string snapstoreProxyScheme: description: The snap store proxy domain's scheme, e.g. "http" - or "https" without "://" + or "https" without "://" Defaults to "http". type: string type: object type: object diff --git a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml index 5835e05..cb8b941 100644 --- a/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml +++ b/config/crd/bases/bootstrap.cluster.x-k8s.io_microk8sconfigtemplates.yaml @@ -193,7 +193,7 @@ spec: type: string snapstoreProxyScheme: description: The snap store proxy domain's scheme, e.g. - "http" or "https" without "://" + "http" or "https" without "://" Defaults to "http". type: string type: object type: object diff --git a/controllers/cloudinit/cloudinit_common_test.go b/controllers/cloudinit/cloudinit_common_test.go index 5b7a365..34b3a25 100644 --- a/controllers/cloudinit/cloudinit_common_test.go +++ b/controllers/cloudinit/cloudinit_common_test.go @@ -228,16 +228,16 @@ func TestCloudConfigInput(t *testing.T) { t.Run("SnapstoreProxy", func(t *testing.T) { for _, tc := range []struct { name string - makeCloudConfig func() (*cloudinit.CloudConfig, error) + makeCloudConfig func(scheme string) (*cloudinit.CloudConfig, error) }{ { name: "ControlPlaneInit", - makeCloudConfig: func() (*cloudinit.CloudConfig, error) { + makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) { return cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInitInput{ KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), TokenTTL: 100, - SnapstoreProxyScheme: "https", + SnapstoreProxyScheme: scheme, SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -245,12 +245,12 @@ func TestCloudConfigInput(t *testing.T) { }, { name: "ControlPlaneJoin", - makeCloudConfig: func() (*cloudinit.CloudConfig, error) { + makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) { return cloudinit.NewJoinControlPlane(&cloudinit.ControlPlaneJoinInput{ KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), TokenTTL: 100, - SnapstoreProxyScheme: "https", + SnapstoreProxyScheme: scheme, SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -258,11 +258,11 @@ func TestCloudConfigInput(t *testing.T) { }, { name: "Worker", - makeCloudConfig: func() (*cloudinit.CloudConfig, error) { + makeCloudConfig: func(scheme string) (*cloudinit.CloudConfig, error) { return cloudinit.NewJoinWorker(&cloudinit.WorkerInput{ KubernetesVersion: "v1.25.0", Token: strings.Repeat("a", 32), - SnapstoreProxyScheme: "https", + SnapstoreProxyScheme: scheme, SnapstoreProxyDomain: "snapstore.domain.com", SnapstoreProxyId: "ID123456789", }) @@ -271,10 +271,22 @@ func TestCloudConfigInput(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - c, err := tc.makeCloudConfig() - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-configure-snapstore-proxy.sh "https" "snapstore.domain.com" "ID123456789"`)) + for _, withScheme := range []string{"", "http", "https"} { + t.Run(fmt.Sprintf("withScheme=%q", withScheme), func(t *testing.T) { + c, err := tc.makeCloudConfig(withScheme) + g.Expect(err).NotTo(HaveOccurred()) + + // if scheme is unspecified, default to http + var expectedScheme string + if withScheme == "" { + expectedScheme = "http" + } else { + expectedScheme = withScheme + } + g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-configure-snapstore-proxy.sh %q "snapstore.domain.com" "ID123456789"`, expectedScheme))) + }) + } }) } }) diff --git a/controllers/cloudinit/controlplane_init.go b/controllers/cloudinit/controlplane_init.go index 5b2e516..c8baae0 100644 --- a/controllers/cloudinit/controlplane_init.go +++ b/controllers/cloudinit/controlplane_init.go @@ -59,7 +59,7 @@ type ControlPlaneInitInput struct { RiskLevel string // DisableDefaultCNI specifies whether to disable the default CNI plugin. DisableDefaultCNI bool - // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + // SnapstoreProxyScheme specifies the scheme (e.g. http or https) of the domain. Defaults to "http". SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string @@ -90,6 +90,10 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) { return nil, fmt.Errorf("join token TTL %q is not a positive number", input.TokenTTL) } + if input.SnapstoreProxyScheme == "" { + input.SnapstoreProxyScheme = "http" + } + // figure out endpoint type endpointType := "DNS" if net.ParseIP(input.ControlPlaneEndpoint) != nil { diff --git a/controllers/cloudinit/controlplane_init_test.go b/controllers/cloudinit/controlplane_init_test.go index ec0e6a1..314ec35 100644 --- a/controllers/cloudinit/controlplane_init_test.go +++ b/controllers/cloudinit/controlplane_init_test.go @@ -46,7 +46,7 @@ func TestControlPlaneInit(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, diff --git a/controllers/cloudinit/controlplane_join.go b/controllers/cloudinit/controlplane_join.go index d0f5efe..488f8ee 100644 --- a/controllers/cloudinit/controlplane_join.go +++ b/controllers/cloudinit/controlplane_join.go @@ -55,7 +55,7 @@ type ControlPlaneJoinInput struct { RiskLevel string // DisableDefaultCNI specifies whether to use the default CNI plugin. DisableDefaultCNI bool - // SnapstoreProxyScheme specifies the scheme (e.g https://) of the domain. + // SnapstoreProxyScheme specifies the scheme (e.g. http or https) of the domain. Defaults to "http". SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string @@ -104,6 +104,10 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) { } installArgs := createInstallArgs(input.Confinement, input.RiskLevel, kubernetesVersion) + if input.SnapstoreProxyScheme == "" { + input.SnapstoreProxyScheme = "http" + } + cloudConfig := NewBaseCloudConfig() cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, input.ExtraWriteFiles...) if args := input.ExtraKubeletArgs; len(args) > 0 { diff --git a/controllers/cloudinit/controlplane_join_test.go b/controllers/cloudinit/controlplane_join_test.go index d5fc09a..cb73828 100644 --- a/controllers/cloudinit/controlplane_join_test.go +++ b/controllers/cloudinit/controlplane_join_test.go @@ -44,7 +44,7 @@ func TestControlPlaneJoin(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, diff --git a/controllers/cloudinit/worker_join.go b/controllers/cloudinit/worker_join.go index f5e4c01..e469af7 100644 --- a/controllers/cloudinit/worker_join.go +++ b/controllers/cloudinit/worker_join.go @@ -85,6 +85,10 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) { return nil, fmt.Errorf("strict confinement is only available for microk8s v1.25+") } + if input.SnapstoreProxyScheme == "" { + input.SnapstoreProxyScheme = "http" + } + stopApiServerProxyRefreshes := "no" if kubernetesVersion.Minor() > 24 { stopApiServerProxyRefreshes = "yes" diff --git a/controllers/cloudinit/worker_join_test.go b/controllers/cloudinit/worker_join_test.go index 118292f..3d5395b 100644 --- a/controllers/cloudinit/worker_join_test.go +++ b/controllers/cloudinit/worker_join_test.go @@ -40,7 +40,7 @@ func TestWorkerJoin(t *testing.T) { g.Expect(cloudConfig.RunCommands).To(Equal([]string{ `set -x`, `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, - `/capi-scripts/00-configure-snapstore-proxy.sh "" "" ""`, + `/capi-scripts/00-configure-snapstore-proxy.sh "http" "" ""`, `/capi-scripts/00-disable-host-services.sh`, `/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic"`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, From 38b67fb43076ac454ca7b098d796a4176d10e4a6 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Wed, 31 Jul 2024 07:47:24 -0400 Subject: [PATCH 5/6] update doc --- controllers/cloudinit/worker_join.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/cloudinit/worker_join.go b/controllers/cloudinit/worker_join.go index e469af7..f878f7b 100644 --- a/controllers/cloudinit/worker_join.go +++ b/controllers/cloudinit/worker_join.go @@ -46,7 +46,7 @@ type WorkerInput struct { Confinement string // RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels. RiskLevel string - // SnapstoreProxyScheme specifies the scheme (i.e https://) of the domain. + // SnapstoreProxyScheme specifies the scheme (e.g http or https) of the domain. Defaults to http. SnapstoreProxyScheme string // SnapstoreProxyDomain specifies the domain of the snapstore proxy if one is to be used. SnapstoreProxyDomain string From d6cf6e780654ceae8ce621c48290ce7768c73f02 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Wed, 31 Jul 2024 07:50:26 -0400 Subject: [PATCH 6/6] pass from api to input structs --- controllers/microk8sconfig_controller.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/microk8sconfig_controller.go b/controllers/microk8sconfig_controller.go index b836e7a..c4fb761 100644 --- a/controllers/microk8sconfig_controller.go +++ b/controllers/microk8sconfig_controller.go @@ -310,6 +310,7 @@ func (r *MicroK8sConfigReconciler) handleClusterNotInitialized(ctx context.Conte ContainerdHTTPProxy: microk8sConfig.Spec.InitConfiguration.HTTPProxy, ContainerdHTTPSProxy: microk8sConfig.Spec.InitConfiguration.HTTPSProxy, ContainerdNoProxy: microk8sConfig.Spec.InitConfiguration.NoProxy, + SnapstoreProxyScheme: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyScheme, SnapstoreProxyDomain: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyDomain, SnapstoreProxyId: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyId, Confinement: microk8sConfig.Spec.InitConfiguration.Confinement, @@ -414,6 +415,7 @@ func (r *MicroK8sConfigReconciler) handleJoiningControlPlaneNode(ctx context.Con ContainerdHTTPProxy: microk8sConfig.Spec.InitConfiguration.HTTPProxy, ContainerdHTTPSProxy: microk8sConfig.Spec.InitConfiguration.HTTPSProxy, ContainerdNoProxy: microk8sConfig.Spec.InitConfiguration.NoProxy, + SnapstoreProxyScheme: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyScheme, SnapstoreProxyDomain: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyDomain, SnapstoreProxyId: microk8sConfig.Spec.InitConfiguration.SnapstoreProxyId, RiskLevel: microk8sConfig.Spec.InitConfiguration.RiskLevel, @@ -515,6 +517,7 @@ func (r *MicroK8sConfigReconciler) handleJoiningWorkerNode(ctx context.Context, workerInput.ContainerdHTTPSProxy = c.HTTPSProxy workerInput.ContainerdHTTPProxy = c.HTTPProxy workerInput.ContainerdNoProxy = c.NoProxy + workerInput.SnapstoreProxyScheme = c.SnapstoreProxyScheme workerInput.SnapstoreProxyDomain = c.SnapstoreProxyDomain workerInput.SnapstoreProxyId = c.SnapstoreProxyId workerInput.SnapstoreHTTPProxy = c.SnapstoreHTTPProxy