Skip to content

Commit 8651216

Browse files
committed
🐛 Fix lint and bugs
Fixing bug that diff of old clusteraddons and new clusteraddons was calculated wrongly due to issues with pointers and for loops. Fixing the linting for the multi-stage cluster addons feature. Fix the extension hooks that didn't work properly until now. They should only update the clusteraddon once. Add hook server to localmode config. Update to yaml3 package. Allow missing values prefix in overwrite.yaml. Signed-off-by: janiskemper <[email protected]>
1 parent fe86746 commit 8651216

File tree

17 files changed

+460
-390
lines changed

17 files changed

+460
-390
lines changed

.yamllint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ ignore:
2929
- config/webhook/**/*.yaml
3030
- test/releases/**
3131
- test/cluster-stacks/**
32+
- .release/**
33+
- .cluster.yaml
34+
- .clusterstack.yaml

api/v1alpha1/clusteraddon_types.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,35 @@ const (
2828
ClusterAddonFinalizer = "clusteraddon.clusterstack.x-k8s.io"
2929
)
3030

31+
// StageAnnotation is the annotation name and key for the stage annotation.
3132
const StageAnnotation = "ClusterAddonStage"
3233

34+
// StageAnnotationValue is the value of the stage annotation.
3335
type StageAnnotationValue string
3436

3537
const (
36-
StageCreated = StageAnnotationValue("created")
37-
StageUpgraded = StageAnnotationValue("upgraded")
38+
// StageAnnotationValueCreated signifies the stage annotation created.
39+
StageAnnotationValueCreated = StageAnnotationValue("created")
40+
// StageAnnotationValueUpgraded signifies the stage annotation upgraded.
41+
StageAnnotationValueUpgraded = StageAnnotationValue("upgraded")
3842
)
3943

4044
// StagePhase defines the status of helm chart in the cluster addon.
4145
type StagePhase string
4246

4347
var (
44-
None = StagePhase("")
45-
Pending = StagePhase("Pending")
46-
WaitingForPreCondition = StagePhase("waitingForPreCondition")
47-
ApplyingOrDeleting = StagePhase("applyingOrDeleting")
48-
WaitingForPostCondition = StagePhase("waitingForPostCondition")
49-
Done = StagePhase("done")
48+
// StagePhaseNone signifies the empty stage phase.
49+
StagePhaseNone = StagePhase("")
50+
// StagePhasePending signifies the stage phase 'pending'.
51+
StagePhasePending = StagePhase("Pending")
52+
// StagePhaseWaitingForPreCondition signifies the stage phase 'waitingForPreCondition'.
53+
StagePhaseWaitingForPreCondition = StagePhase("waitingForPreCondition")
54+
// StagePhaseApplyingOrDeleting signifies the stage phase 'applyingOrDeleting'.
55+
StagePhaseApplyingOrDeleting = StagePhase("applyingOrDeleting")
56+
// StagePhaseWaitingForPostCondition signifies the stage phase 'waitingForPostCondition'.
57+
StagePhaseWaitingForPostCondition = StagePhase("waitingForPostCondition")
58+
// StagePhaseDone signifies the stage phase 'done'.
59+
StagePhaseDone = StagePhase("done")
5060
)
5161

5262
// StageStatus represents the helm charts of the hook and it's phases.
@@ -131,18 +141,19 @@ func (r *ClusterAddon) GetStagePhase(helmChartName string, action clusteraddon.A
131141
}
132142

133143
// This cannot occur as we populate phase value with "pending".
134-
return None
144+
return StagePhaseNone
135145
}
136146

137147
// SetStagePhase sets the helm chart status phase.
138148
func (r *ClusterAddon) SetStagePhase(helmChartName string, action clusteraddon.Action, phase StagePhase) {
139-
for i, _ := range r.Status.Stages {
149+
for i := range r.Status.Stages {
140150
if r.Status.Stages[i].Name == helmChartName && r.Status.Stages[i].Action == action {
141151
r.Status.Stages[i].Phase = phase
142152
}
143153
}
144154
}
145155

156+
// SetStageAnnotations sets the annotation whether the cluster got created or upgraded.
146157
func (r *ClusterAddon) SetStageAnnotations(value StageAnnotationValue) {
147158
if r.Annotations == nil {
148159
r.Annotations = make(map[string]string, 0)
@@ -153,7 +164,7 @@ func (r *ClusterAddon) SetStageAnnotations(value StageAnnotationValue) {
153164
}
154165
}
155166

156-
// HasAnnotation returns a bool if passed in annotation exists.
167+
// HasStageAnnotation returns whether the stage annotation exists with a certain value.
157168
func (r *ClusterAddon) HasStageAnnotation(value StageAnnotationValue) bool {
158169
val, found := r.Annotations[StageAnnotation]
159170
if found && val == string(value) {

api/v1alpha1/conditions_const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
// HelmChartDeletedCondition reports on whether the relevant helm chart has been applied.
6161
HelmChartDeletedCondition clusterv1.ConditionType = "HelmChartDeleted"
6262

63-
// FailedToApplyObjectsReason is used when some objects have been failed to delete.
63+
// FailedToDeleteObjectsReason is used when some objects have been failed to delete.
6464
FailedToDeleteObjectsReason = "FailedToDeleteObjects"
6565
)
6666

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
//+kubebuilder:scaffold:imports
2828
csov1alpha1 "github.com/SovereignCloudStack/cluster-stack-operator/api/v1alpha1"
29-
"github.com/SovereignCloudStack/cluster-stack-operator/extension/handlers"
29+
"github.com/SovereignCloudStack/cluster-stack-operator/extension"
3030
"github.com/SovereignCloudStack/cluster-stack-operator/internal/controller"
3131
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient"
3232
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/fake"
@@ -237,7 +237,7 @@ func main() {
237237
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-stack-operator-extension-manager")
238238

239239
// Create the ExtensionHandlers for the lifecycle hooks
240-
lifecycleExtensionHandlers := handlers.NewExtensionHandlers(mgr.GetClient(), scheme)
240+
lifecycleExtensionHandlers := extension.NewHandler(mgr.GetClient())
241241

242242
setupLog.Info("Add extension handlers")
243243
if err := hookServer.AddExtensionHandler(server.ExtensionHandler{

config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ spec:
216216
action:
217217
description: Action is the action of the helm chart. e.g. -
218218
apply and delete.
219+
type: string
219220
helmChartName:
220221
description: Name represent name of the helm chart
221222
type: string

config/localmode/kustomization.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ resources:
99
- ../crd
1010
- ../rbac
1111
- ../manager
12+
- ../hookserver
1213
- ../webhook
1314
- ../certmanager
1415

1516
patchesStrategicMerge:
1617
- manager_config_patch.yaml
1718
- manager_webhook_patch.yaml
19+
- manager_hookserver_patch.yaml
1820
- webhookcainjection_patch.yaml
1921
- manager_pull_policy.yaml
2022
vars:
@@ -26,21 +28,49 @@ vars:
2628
name: serving-cert # this name should match the one in certificate.yaml
2729
fieldref:
2830
fieldpath: metadata.namespace
31+
- name: HOOK_SERVER_CERTIFICATE_NAMESPACE # namespace of the certificate CR
32+
objref:
33+
kind: Certificate
34+
group: cert-manager.io
35+
version: v1
36+
name: hook-server-server-cert # this name should match the one in certificate.yaml
37+
fieldref:
38+
fieldpath: metadata.namespace
2939
- name: CERTIFICATE_NAME
40+
objref:
41+
group: cert-manager.io
42+
kind: Certificate
43+
name: serving-cert
44+
version: v1
45+
fieldref: {}
46+
- name: HOOK_SERVER_CERTIFICATE_NAME
3047
objref:
3148
kind: Certificate
3249
group: cert-manager.io
3350
version: v1
34-
name: serving-cert # this name should match the one in certificate.yaml
51+
name: hook-server-server-cert # this name should match the one in certificate.yaml
3552
- name: SERVICE_NAMESPACE # namespace of the service
3653
objref:
3754
kind: Service
3855
version: v1
3956
name: webhook-service
4057
fieldref:
4158
fieldpath: metadata.namespace
59+
- name: HOOK_SERVER_SERVICE_NAMESPACE # namespace of the service
60+
objref:
61+
kind: Service
62+
version: v1
63+
name: hook-server-svc
64+
fieldref:
65+
fieldpath: metadata.namespace
4266
- name: SERVICE_NAME
4367
objref:
4468
kind: Service
4569
version: v1
4670
name: webhook-service
71+
fieldref: {}
72+
- name: HOOK_SERVER_SERVICE_NAME
73+
objref:
74+
kind: Service
75+
version: v1
76+
name: hook-server-svc
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
ports:
12+
- containerPort: 9442
13+
name: hook-server-svc
14+
protocol: TCP
15+
volumeMounts:
16+
- mountPath: /tmp/k8s-hook-server/serving-certs
17+
name: hook-server-cert
18+
readOnly: true
19+
volumes:
20+
- name: hook-server-cert
21+
secret:
22+
defaultMode: 420
23+
secretName: cso-hook-server-server-cert

extension/handlers/hooks.go

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)