Skip to content

Commit dde4841

Browse files
authored
✨ Add clusteraddon controller (#28)
Add clusteraddon controller which is responsible to reconcile ClusterAddons. It templates the ClusterAddon Helm Chart from the cluster stack assets and applies its objects. It also updates the objects if the Helm Chart has been updates and only then - not necessarily on each update of a ClusterStack version. Signed-off-by: janiskemper <[email protected]>
1 parent f841eae commit dde4841

File tree

11 files changed

+702
-32
lines changed

11 files changed

+702
-32
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,30 @@ To tear down the kind cluster, use:
6464
$ make delete-bootstrap-cluster
6565
```
6666

67-
If you have any trouble finding the right command, then you can use `make help` to get a list of all available make targets.
67+
If you have any trouble finding the right command, then you can use `make help` to get a list of all available make targets.
68+
69+
## Troubleshooting
70+
71+
Check the latest events:
72+
73+
```shell
74+
kubectl get events -A --sort-by=.lastTimestamp
75+
```
76+
77+
Check the conditions:
78+
79+
```shell
80+
go run github.com/guettli/check-conditions@latest all
81+
```
82+
83+
Check with `clusterctl`:
84+
85+
```shell
86+
clusterctl describe cluster -n cluster my-cluster
87+
```
88+
89+
Check the logs. List all logs from all deployments. Show the logs of the last ten minutes:
90+
91+
```shell
92+
kubectl get deployment -A --no-headers | while read -r ns d _; do echo; echo "====== $ns $d"; kubectl logs --since=10m -n $ns deployment/$d; done
93+
```

cmd/main.go

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
3232
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
3333
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/utillog"
34+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster"
3435
"k8s.io/apimachinery/pkg/runtime"
3536
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3637
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -54,19 +55,23 @@ func init() {
5455
//+kubebuilder:scaffold:scheme
5556
}
5657

57-
func main() {
58-
var metricsAddr string
59-
var probeAddr string
60-
var enableLeaderElection bool
61-
var leaderElectionNamespace string
62-
var watchFilterValue string
63-
var watchNamespace string
64-
var clusterStackConcurrency int
65-
var clusterStackReleaseConcurrency int
66-
var clusterAddonConcurrency int
67-
var logLevel string
68-
var releaseDir string
58+
var (
59+
metricsAddr string
60+
probeAddr string
61+
enableLeaderElection bool
62+
leaderElectionNamespace string
63+
watchFilterValue string
64+
watchNamespace string
65+
clusterStackConcurrency int
66+
clusterStackReleaseConcurrency int
67+
clusterAddonConcurrency int
68+
logLevel string
69+
releaseDir string
70+
qps float64
71+
burst int
72+
)
6973

74+
func main() {
7075
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7176
flag.StringVar(&probeAddr, "health-probe-bind-address", ":9440", "The address the probe endpoint binds to.")
7277
flag.BoolVar(&enableLeaderElection, "leader-elect", true, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
@@ -78,6 +83,8 @@ func main() {
7883
flag.IntVar(&clusterAddonConcurrency, "clusteraddon-concurrency", 1, "Number of ClusterAddons to process simultaneously")
7984
flag.StringVar(&logLevel, "log-level", "info", "Specifies log level. Options are 'debug', 'info' and 'error'")
8085
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
86+
flag.Float64Var(&qps, "qps", 50, "Enable custom query per second for kubernetes API server")
87+
flag.IntVar(&burst, "burst", 100, "Enable custom burst defines how many queries the API server will accept before enforcing the limit established by qps")
8188

8289
flag.Parse()
8390

@@ -111,6 +118,15 @@ func main() {
111118

112119
gitFactory := githubclient.NewFactory()
113120

121+
restConfig := mgr.GetConfig()
122+
restConfig.QPS = float32(qps)
123+
restConfig.Burst = burst
124+
125+
restConfigSettings := controller.RestConfigSettings{
126+
QPS: float32(qps),
127+
Burst: burst,
128+
}
129+
114130
var wg sync.WaitGroup
115131
wg.Add(1)
116132

@@ -123,9 +139,10 @@ func main() {
123139
setupLog.Error(err, "unable to create controller", "controller", "ClusterStack")
124140
os.Exit(1)
125141
}
142+
126143
if err = (&controller.ClusterStackReleaseReconciler{
127144
Client: mgr.GetClient(),
128-
RESTConfig: mgr.GetConfig(),
145+
RESTConfig: restConfig,
129146
ReleaseDirectory: releaseDir,
130147
WatchFilterValue: watchFilterValue,
131148
KubeClientFactory: kube.NewFactory(),
@@ -135,6 +152,18 @@ func main() {
135152
os.Exit(1)
136153
}
137154

155+
if err = (&controller.ClusterAddonReconciler{
156+
Client: mgr.GetClient(),
157+
ReleaseDirectory: releaseDir,
158+
RestConfigSettings: restConfigSettings,
159+
WatchFilterValue: watchFilterValue,
160+
KubeClientFactory: kube.NewFactory(),
161+
WorkloadClusterFactory: workloadcluster.NewFactory(),
162+
}).SetupWithManager(ctx, mgr, controllerruntimecontroller.Options{MaxConcurrentReconciles: clusterAddonConcurrency}); err != nil {
163+
setupLog.Error(err, "unable to create controller", "controller", "ClusterAddon")
164+
os.Exit(1)
165+
}
166+
138167
if err = (&controller.ClusterAddonCreateReconciler{
139168
Client: mgr.GetClient(),
140169
}).SetupWithManager(ctx, mgr, controllerruntimecontroller.Options{}); err != nil {

config/crd/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ commonlabels:
77
resources:
88
- bases/clusterstack.x-k8s.io_clusterstacks.yaml
99
- bases/clusterstack.x-k8s.io_clusterstackreleases.yaml
10-
#- bases/clusterstack.x-k8s.io_clusteraddons.yaml
10+
- bases/clusterstack.x-k8s.io_clusteraddons.yaml
1111
#+kubebuilder:scaffold:crdkustomizeresource
1212

1313
patchesStrategicMerge:

config/cso/cluster.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: cluster.x-k8s.io/v1beta1
22
kind: Cluster
33
metadata:
44
name: "${CLUSTER_NAME}"
5-
namespace: ${NAMESPACE}
5+
namespace: cluster
66
spec:
77
clusterNetwork:
88
services:
@@ -23,4 +23,4 @@ spec:
2323
machineDeployments:
2424
- class: workeramd64
2525
name: md-0
26-
replicas: 1
26+
replicas: 1

config/rbac/role.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,38 @@ rules:
3939
- patch
4040
- update
4141
- watch
42+
- apiGroups:
43+
- cluster.x-k8s.io
44+
resources:
45+
- clusters
46+
verbs:
47+
- get
4248
- apiGroups:
4349
- clusterstack.x-k8s.io
4450
resources:
4551
- clusteraddons
4652
verbs:
4753
- create
54+
- delete
55+
- get
56+
- list
57+
- patch
58+
- update
59+
- watch
60+
- apiGroups:
61+
- clusterstack.x-k8s.io
62+
resources:
63+
- clusteraddons/finalizers
64+
verbs:
65+
- update
66+
- apiGroups:
67+
- clusterstack.x-k8s.io
68+
resources:
69+
- clusteraddons/status
70+
verbs:
71+
- get
72+
- patch
73+
- update
4874
- apiGroups:
4975
- clusterstack.x-k8s.io
5076
resources:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
github.com/go-logr/logr v1.2.4
7+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
78
github.com/google/go-github/v52 v52.0.0
89
github.com/onsi/ginkgo/v2 v2.11.0
910
github.com/onsi/gomega v1.27.8
@@ -21,7 +22,6 @@ require (
2122
)
2223

2324
require (
24-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
2525
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
2626
github.com/pkg/errors v0.9.1 // indirect
2727
github.com/pmezard/go-difflib v1.0.0 // indirect

hack/kind-dev.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ kindV1Alpha4Cluster:
4444
nodes:
4545
- role: control-plane
4646
image: kindest/node:${CLUSTER_VERSION}
47+
extraMounts:
48+
- hostPath: /var/run/docker.sock
49+
containerPath: /var/run/docker.sock
4750
networking:
4851
podSubnet: "10.244.0.0/16"
4952
serviceSubnet: "10.96.0.0/12"

0 commit comments

Comments
 (0)