Skip to content

Commit 7b44b45

Browse files
Merge pull request 'Remove clusterctl, kubeseal and k3d as runtime dependencies' (#255) from runtime-dependencies into main
Reviewed-on: https://gitea.obmondo.com/EnableIT/kubeaid-bootstrap-script/pulls/255
2 parents 229029e + 2ad738b commit 7b44b45

File tree

10 files changed

+89
-24
lines changed

10 files changed

+89
-24
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
SHELL = /bin/bash
33
CURRENT_DIR := $(CURDIR)
44
IMAGE_NAME=kubeaid-bootstrap-script-dev:latest
5+
NETWORK_NAME=k3d-$(MANAGEMENT_CLUSTER_NAME)
56
CONTAINER_NAME=kubeaid-bootstrap-script-dev
67
MANAGEMENT_CLUSTER_NAME=kubeaid-bootstrapper
7-
NETWORK_NAME=k3d-$(MANAGEMENT_CLUSTER_NAME)
88

99
.PHONY: lint
1010
lint:
1111
@golangci-lint run ./...
1212

13+
.PHONY: build
14+
build:
15+
@go build -o build/kubeaid-bootstrap-script ./cmd
16+
1317
.PHONY: build-image-dev
1418
build-image-dev:
1519
@docker build -f ./Dockerfile --build-arg CPU_ARCHITECTURE=arm64 -t $(IMAGE_NAME) .

cmd/cluster/cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cluster
33
import (
44
"github.com/spf13/cobra"
55

6+
"github.com/Obmondo/kubeaid-bootstrap-script/cmd/cluster/delete"
67
"github.com/Obmondo/kubeaid-bootstrap-script/cmd/cluster/upgrade"
78
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/config/parser"
89
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/constants"
@@ -34,7 +35,7 @@ func init() {
3435
ClusterCmd.AddCommand(BootstrapCmd)
3536
ClusterCmd.AddCommand(TestCmd)
3637
ClusterCmd.AddCommand(upgrade.UpgradeCmd)
37-
ClusterCmd.AddCommand(DeleteCmd)
38+
ClusterCmd.AddCommand(delete.DeleteCmd)
3839
ClusterCmd.AddCommand(RecoverCmd)
3940

4041
// Flags.

cmd/cluster/delete/delete.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package delete
2+
3+
import "github.com/spf13/cobra"
4+
5+
var DeleteCmd = &cobra.Command{
6+
Use: "delete",
7+
8+
RunE: func(cmd *cobra.Command, args []string) error {
9+
return cmd.Help()
10+
},
11+
}
12+
13+
func init() {
14+
// Subcommands.
15+
DeleteCmd.AddCommand(MainCmd)
16+
DeleteCmd.AddCommand(ManagementCmd)
17+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package cluster
1+
package delete
22

33
import (
44
"github.com/spf13/cobra"
55

66
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/core"
77
)
88

9-
var DeleteCmd = &cobra.Command{
10-
Use: "delete",
9+
var MainCmd = &cobra.Command{
10+
Use: "main",
1111

1212
Short: "Delete a KubeAid managed cluster",
1313

cmd/cluster/delete/management.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package delete
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/utils/kubernetes/k3d"
7+
)
8+
9+
var ManagementCmd = &cobra.Command{
10+
Use: "management",
11+
12+
Short: "Delete the K3D based local management cluster (used to bootstrap your KubeAid managed main cluster)",
13+
14+
Run: func(cmd *cobra.Command, args []string) {
15+
k3d.DeleteK3DCluster(cmd.Context())
16+
},
17+
}

docs/providers/azure.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ Additionally, have the following runtime dependencies installed :
3939

4040
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
4141

42-
- [kubeseal](https://github.com/bitnami-labs/sealed-secrets?tab=readme-ov-file#installation)
43-
44-
- [clusterctl](https://cluster-api.sigs.k8s.io/user/quick-start#install-clusterctl)
45-
46-
- [k3d](https://k3d.io/stable/#installation)
47-
4842
## Preparing the Configuration Files
4943

5044
You need to have 2 configuration files : `general.yaml` and `secrets.yaml` containing required credentials.
@@ -90,6 +84,6 @@ kubeaid-bootstrap-script cluster upgrade \
9084

9185
You can delete the cluster, by running :
9286
```shell script
93-
kubeaid-bootstrap-script cluster delete
94-
k3d cluster delete kubeaid-bootstrapper
87+
kubeaid-bootstrap-script cluster delete main
88+
kubeaid-bootstrap-script cluster delete management
9589
```

pkg/core/upgrade_cluster.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
argoCDV1Aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1111
yqCmdLib "github.com/mikefarah/yq/v4/cmd"
12+
clusterctlClientLib "sigs.k8s.io/cluster-api/cmd/clusterctl/client"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
1314

1415
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/config"
@@ -218,10 +219,17 @@ func upgradeControlPlane(
218219
)
219220

220221
// Rollout the control-plane, immediately
221-
utils.ExecuteCommandOrDie(fmt.Sprintf(
222-
"clusterctl alpha rollout restart kubeadmcontrolplane/%s -n %s",
223-
kubeadmControlPlaneName, kubernetes.GetCapiClusterNamespace(),
224-
))
222+
223+
clusterctlClient, err := clusterctlClientLib.New(ctx, "")
224+
assert.AssertErrNil(ctx, err, "Failed constructing clusterctl client")
225+
226+
err = clusterctlClient.RolloutRestart(ctx, clusterctlClientLib.RolloutRestartOptions{
227+
Namespace: kubernetes.GetCapiClusterNamespace(),
228+
Resources: []string{
229+
fmt.Sprintf("kubeadmcontrolplane/%s", kubeadmControlPlaneName),
230+
},
231+
})
232+
assert.AssertErrNil(ctx, err, "Failed rolling out KubeadmControlPlane")
225233
}
226234
}
227235

@@ -282,9 +290,18 @@ func upgradeNodeGroup(ctx context.Context,
282290
)
283291

284292
// Rollout the node-group, immediately.
285-
utils.ExecuteCommandOrDie(fmt.Sprintf(
286-
"clusterctl alpha rollout restart machinedeployment/%s -n %s",
287-
machineDeploymentName, kubernetes.GetCapiClusterNamespace(),
288-
))
293+
294+
clusterctlClient, err := clusterctlClientLib.New(ctx, "")
295+
assert.AssertErrNil(ctx, err, "Failed constructing clusterctl client")
296+
297+
err = clusterctlClient.RolloutRestart(ctx, clusterctlClientLib.RolloutRestartOptions{
298+
Namespace: kubernetes.GetCapiClusterNamespace(),
299+
Resources: []string{
300+
fmt.Sprintf("machinedeployment/%s", machineDeploymentName),
301+
},
302+
})
303+
assert.AssertErrNil(ctx, err, "Failed rolling out MachineDeployment",
304+
slog.String("name", machineDeploymentName),
305+
)
289306
}
290307
}

pkg/utils/fs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ func CreateIntermediateDirsForFile(ctx context.Context, filePath string) {
6565

6666
// Returns path to the directory containing cluster specific config, in the KubeAid Config dir.
6767
func GetClusterDir() string {
68-
return path.Join(constants.KubeAidConfigDirectory, "k8s", config.ParsedGeneralConfig.Cluster.Name)
68+
return path.Join(
69+
constants.KubeAidConfigDirectory, "k8s", config.ParsedGeneralConfig.Cluster.Name,
70+
)
6971
}
7072

7173
// Returns the path to the local temp directory, where contents of the given blob storage bucket

pkg/utils/kubernetes/k3d/k3d.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,15 @@ func doesK3dClusterExist(ctx context.Context, name string) bool {
166166
}
167167
return false
168168
}
169+
170+
func DeleteK3DCluster(ctx context.Context) {
171+
slog.InfoContext(ctx, "Deleting the K3D management cluster")
172+
173+
clusterDeleteCmd := cluster.NewCmdClusterDelete()
174+
clusterDeleteCmd.SetArgs([]string{
175+
"--config",
176+
constants.OutputPathManagementClusterK3DConfig,
177+
})
178+
err := clusterDeleteCmd.ExecuteContext(ctx)
179+
assert.AssertErrNil(ctx, err, "Failed deleting K3D cluster")
180+
}

pkg/utils/kubernetes/sealed_secrets.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ func InstallSealedSecrets(ctx context.Context) {
2828
Values: &values.Options{
2929
Values: []string{
3030
fmt.Sprintf("sealed-secrets.namespace=%s", constants.NamespaceSealedSecrets),
31-
fmt.Sprintf("sealed-secrets.fullnameOverride=%s", constants.SealedSecretsControllerName),
32-
31+
fmt.Sprintf(
32+
"sealed-secrets.fullnameOverride=%s", constants.SealedSecretsControllerName,
33+
),
3334
"backup=null",
3435
},
3536
},

0 commit comments

Comments
 (0)