Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
38a7d13
Update Go to 1.21
neoaggelos Apr 2, 2024
4c4edc1
remove use of rand.Seed()
neoaggelos Apr 2, 2024
a82df5c
Merge pull request #97 from canonical/KU-574/go
neoaggelos Apr 2, 2024
69295d4
set tls.crt and tls.key on the cluster CA secret
neoaggelos Apr 10, 2024
217d1f2
Merge pull request #99 from canonical/KU-638/fix-ca-secret-fields
neoaggelos Apr 10, 2024
8d2dcf7
do not list and iterate secrets
neoaggelos Apr 11, 2024
18e470f
reduce unnecessary apiserver interaction
neoaggelos Apr 11, 2024
e9bf45d
Merge pull request #100 from canonical/KU-638/secret-get
neoaggelos Apr 11, 2024
db854c9
Update cla-check.yml
beliaev-maksim Apr 12, 2024
c41bb8b
Update cla-check.yml
beliaev-maksim Apr 12, 2024
5f749ce
Update cla-check.yml
beliaev-maksim Apr 12, 2024
4044304
Merge pull request #101 from beliaev-maksim/patch-1
neoaggelos Apr 15, 2024
7e2601e
Update cluster-template-aws.yaml
eaudetcobello Apr 25, 2024
2c31152
Merge pull request #103 from canonical/update-cluster-template-aws
eaudetcobello Apr 26, 2024
b28e35c
Revert "Update cluster-template-aws.yaml"
eaudetcobello Apr 26, 2024
099d28f
Merge pull request #104 from canonical/revert-103-update-cluster-temp…
eaudetcobello Apr 26, 2024
2f2ae4d
Update infrastructure to v1beta2 because v1beta1 is not compatible wi…
eaudetcobello Apr 26, 2024
92b49a1
Merge branch 'main' into update-aws
eaudetcobello Apr 26, 2024
14ef2f2
Change ssh key name
eaudetcobello Apr 26, 2024
9ccf9d8
Match k8s version. can be updated later
eaudetcobello Apr 26, 2024
edf2f1f
Revert v - it's needed there but not elsewhere
eaudetcobello Apr 26, 2024
8d16800
Support watchNamespace for controller
jayesh-srivastava Apr 6, 2024
6c06ced
revert unneeded
eaudetcobello Jul 10, 2024
8295d78
Merge pull request #105 from canonical/update-aws
kwmonroe Jul 10, 2024
1f381fe
add new disableDefaultCNI field
eaudetcobello Jul 26, 2024
30ba873
rename json field
eaudetcobello Jul 26, 2024
9c3a962
wait for apiserver and add script to allScripts so the file is created
eaudetcobello Jul 26, 2024
002f165
newline at eof
eaudetcobello Jul 26, 2024
084b4c2
parens on newline
eaudetcobello Jul 26, 2024
a6aaa02
move disable-default-cni after wait-apiserver
eaudetcobello Jul 26, 2024
451bf2e
update bootstrap-components
eaudetcobello Jul 26, 2024
21373e2
wait for resources to be created
eaudetcobello Jul 29, 2024
b2ccc8e
Merge pull request #109 from canonical/eaudetcobello/KU-1189
eaudetcobello Jul 30, 2024
805ee61
add new SnapstoreProxyField
eaudetcobello Jul 30, 2024
50b5a79
' -> "
eaudetcobello Jul 30, 2024
45a04af
i.e. -> e.g.
eaudetcobello Jul 30, 2024
e382162
implement defaulting to http scheme
eaudetcobello Jul 31, 2024
38b67fb
update doc
eaudetcobello Jul 31, 2024
d6cf6e7
pass from api to input structs
eaudetcobello Jul 31, 2024
44fc40a
Merge pull request #98 from spectrocloud/support-watchnamespace
neoaggelos Jul 31, 2024
a1c6321
Merge pull request #111 from canonical/eaudetcobello/proxy-scheme
eaudetcobello Jul 31, 2024
869ed51
simplify impl. of disabledefaultcni
eaudetcobello Jul 30, 2024
6fa2d76
Merge pull request #110 from canonical/eaudetcobello/KU-1189
eaudetcobello Jul 31, 2024
fcbc441
update bootstrap-components.yaml
eaudetcobello Jul 31, 2024
7f6bc64
restart snapd after configuring snapstore proxy (#112)
eaudetcobello Aug 8, 2024
c5eb85a
Merge branch 'spectro-master' into microk8s-610
Kun483 Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cla-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check if CLA signed
uses: canonical/has-signed-canonical-cla@1.1.6
uses: canonical/has-signed-canonical-cla@v1
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.19"
go-version: "1.21"

- name: go fmt
run: make fmt
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.19"
go-version: "1.21"

- name: Run tests
run: make test
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.19"
go-version: "1.21"

- name: Try build
run: make
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ docker-push-manifest: ## Push the fat manifest docker image.

.PHONY: lint
lint: golangci-lint ## Lint the codebase
$(GOLANGCI_LINT) run -v --go=1.19 --timeout 3m0s
$(GOLANGCI_LINT) run -v --go=1.21 --timeout 3m0s

##@ Deployment

Expand Down Expand Up @@ -150,7 +150,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
.PHONY: golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2)

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
Expand Down
9 changes: 9 additions & 0 deletions apis/v1beta1/microk8sconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type InitConfiguration struct {
// +kubebuilder:default:=stable
RiskLevel string `json:"riskLevel,omitempty"`

// Whether or not to use the default CNI
// +optional
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"`

// The snap store proxy domain
// +optional
SnapstoreProxyDomain string `json:"snapstoreProxyDomain,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions bootstrap-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ spec:
- classic
- strict
type: string
disableDefaultCNI:
description: Whether or not to use the default CNI
type: boolean
extraKubeletArgs:
description: ExtraKubeletArgs is a list of extra arguments to
add to the kubelet.
Expand Down Expand Up @@ -187,6 +190,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 "://" Defaults to "http".
type: string
type: object
type: object
status:
Expand Down Expand Up @@ -369,6 +376,9 @@ spec:
- classic
- strict
type: string
disableDefaultCNI:
description: Whether or not to use the default CNI
type: boolean
extraKubeletArgs:
description: ExtraKubeletArgs is a list of extra arguments
to add to the kubelet.
Expand Down Expand Up @@ -462,6 +472,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 "://" Defaults to "http".
type: string
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ spec:
- classic
- strict
type: string
disableDefaultCNI:
description: Whether or not to use the default CNI
type: boolean
extraKubeletArgs:
description: ExtraKubeletArgs is a list of extra arguments to
add to the kubelet.
Expand Down Expand Up @@ -177,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 "://" Defaults to "http".
type: string
type: object
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ spec:
- classic
- strict
type: string
disableDefaultCNI:
description: Whether or not to use the default CNI
type: boolean
extraKubeletArgs:
description: ExtraKubeletArgs is a list of extra arguments
to add to the kubelet.
Expand Down Expand Up @@ -188,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 "://" Defaults to "http".
type: string
type: object
type: object
type: object
Expand Down
75 changes: 66 additions & 9 deletions controllers/cloudinit/cloudinit_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func TestCloudConfigInput(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())

if confinement == "classic" {
g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25/%s --classic"`, risk)))
g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25/%s --classic" false`, risk)))
} else {
g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25-strict/%s"`, risk)))
g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25-strict/%s" false`, risk)))
}

_, err = cloudinit.GenerateCloudConfig(c)
Expand All @@ -93,6 +93,48 @@ func TestCloudConfigInput(t *testing.T) {
}
})

t.Run("DisableDefaultCNI", func(t *testing.T) {
for _, tc := range []struct {
name string
makeCloudConfig func() (*cloudinit.CloudConfig, error)
}{
{
name: "ControlPlaneJoin",
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
return cloudinit.NewJoinControlPlane(&cloudinit.ControlPlaneJoinInput{
KubernetesVersion: "v1.25.0",
Confinement: "classic",
Token: strings.Repeat("a", 32),
TokenTTL: 100,
DisableDefaultCNI: true,
})
},
},
{
name: "ControlPlaneInit",
makeCloudConfig: func() (*cloudinit.CloudConfig, error) {
return cloudinit.NewInitControlPlane(&cloudinit.ControlPlaneInitInput{
KubernetesVersion: "v1.25.0",
Confinement: "classic",
Token: strings.Repeat("a", 32),
TokenTTL: 100,
DisableDefaultCNI: true,
})
},
},
} {
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-install-microk8s.sh "--channel 1.25 --classic" true`))
_, err = cloudinit.GenerateCloudConfig(c)
g.Expect(err).NotTo(HaveOccurred())
})
}
})

t.Run("ExtraWriteFiles", func(t *testing.T) {
files := []v1beta1.CloudInitWriteFile{{
Content: "contents",
Expand Down Expand Up @@ -228,38 +270,41 @@ 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: scheme,
SnapstoreProxyDomain: "snapstore.domain.com",
SnapstoreProxyId: "ID123456789",
})
},
},
{
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: scheme,
SnapstoreProxyDomain: "snapstore.domain.com",
SnapstoreProxyId: "ID123456789",
})
},
},
{
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: scheme,
SnapstoreProxyDomain: "snapstore.domain.com",
SnapstoreProxyId: "ID123456789",
})
Expand All @@ -268,10 +313,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 "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)))
})
}
})
}
})
Expand Down
12 changes: 10 additions & 2 deletions controllers/cloudinit/controlplane_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ type ControlPlaneInitInput struct {
Confinement string
// RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels.
RiskLevel string
// DisableDefaultCNI specifies whether to disable the default CNI plugin.
DisableDefaultCNI bool
// 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
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
Expand Down Expand Up @@ -86,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 {
Expand Down Expand Up @@ -139,9 +147,9 @@ 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 %v", scriptPath(installMicroK8sScript), installArgs, input.DisableDefaultCNI),
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
scriptPath(configureKubeletScript),
scriptPath(waitAPIServerScript),
Expand Down
5 changes: 3 additions & 2 deletions controllers/cloudinit/controlplane_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ func TestControlPlaneInit(t *testing.T) {
IPinIP: true,
Token: strings.Repeat("a", 32),
TokenTTL: 10000,
DisableDefaultCNI: true,
Confinement: "classic",
})
g.Expect(err).NotTo(HaveOccurred())

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/00-install-microk8s.sh "--channel 1.25 --classic" true`,
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
`/capi-scripts/10-configure-kubelet.sh`,
`/capi-scripts/50-wait-apiserver.sh`,
Expand Down
12 changes: 10 additions & 2 deletions controllers/cloudinit/controlplane_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ type ControlPlaneJoinInput struct {
Confinement string
// RiskLevel specifies the risk level (strict, candidate, beta, edge) for the snap channels.
RiskLevel string
// DisableDefaultCNI specifies whether to use the default CNI plugin.
DisableDefaultCNI bool
// 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
// SnapstoreProxyId specifies the snapstore proxy ID if one is to be used.
Expand Down Expand Up @@ -100,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 {
Expand All @@ -121,9 +129,9 @@ 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 %v", scriptPath(installMicroK8sScript), installArgs, input.DisableDefaultCNI),
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
scriptPath(configureKubeletScript),
scriptPath(waitAPIServerScript),
Expand Down
5 changes: 3 additions & 2 deletions controllers/cloudinit/controlplane_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestControlPlaneJoin(t *testing.T) {
ClusterAgentPort: "30000",
DqlitePort: "2379",
IPinIP: true,
DisableDefaultCNI: true,
Token: strings.Repeat("a", 32),
TokenTTL: 10000,
JoinNodeIPs: []string{"10.0.3.39", "10.0.3.40", "10.0.3.41"},
Expand All @@ -43,9 +44,9 @@ 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/00-install-microk8s.sh "--channel 1.25 --classic" true`,
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
`/capi-scripts/10-configure-kubelet.sh`,
`/capi-scripts/50-wait-apiserver.sh`,
Expand Down
Loading
Loading