Skip to content

Commit

Permalink
add new SnapstoreProxyField
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Jul 30, 2024
1 parent b2ccc8e commit 805ee61
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 12 deletions.
4 changes: 4 additions & 0 deletions apis/v1beta1/microk8sconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion controllers/cloudinit/cloudinit_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand All @@ -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",
})
Expand All @@ -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",
})
Expand All @@ -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"`))
})
}
})
Expand Down
4 changes: 3 additions & 1 deletion controllers/cloudinit/controlplane_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/controlplane_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "" "" ""`,
Expand Down
4 changes: 3 additions & 1 deletion controllers/cloudinit/controlplane_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/controlplane_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "" "" ""`,
Expand Down
15 changes: 10 additions & 5 deletions controllers/cloudinit/scripts/00-configure-snapstore-proxy.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion controllers/cloudinit/worker_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/worker_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "" "" ""`,
Expand Down

0 comments on commit 805ee61

Please sign in to comment.