Skip to content

Commit 22cc6d7

Browse files
authored
Merge pull request #183 from SovereignCloudStack/addons-new
✨ Multi-stage cluster addons and hook server
2 parents d104052 + 346b8cf commit 22cc6d7

File tree

386 files changed

+89178
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

386 files changed

+89178
-111
lines changed

.yamllint.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ rules:
1717
min-spaces-from-content: 1
1818

1919
yaml-files:
20-
- '*.yaml'
21-
- '*.yml'
20+
- "*.yaml"
21+
- "*.yml"
2222

2323
ignore:
24-
- '**/vendor/**'
25-
- '.cache'
24+
- "**/vendor/**"
25+
- ".cache"
2626
- _artifacts
2727
- config/crd/**/*.yaml
2828
- config/rbac/**/*.yaml
2929
- config/webhook/**/*.yaml
30+
- test/releases/**
31+
- test/cluster-stacks/**
32+
- .release/**
33+
- .cluster.yaml
34+
- .clusterstack.yaml

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ env-vars-for-wl-cluster:
184184
.PHONY: delete-bootstrap-cluster
185185
delete-bootstrap-cluster: $(CTLPTL) ## Deletes Kind-dev Cluster
186186
$(CTLPTL) delete cluster kind-cso
187-
$(CTLPTL) delete registry cso-registry
187+
$(CTLPTL) delete registry kind-registry
188188

189189
.PHONY: cluster
190190
cluster: get-dependencies $(CTLPTL) $(KUBECTL) ## Creates kind-dev Cluster

Tiltfile

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def deploy_capd():
6666
cmd = "curl -sSL {} | {} | kubectl apply -f -".format(capd_uri, envsubst_cmd)
6767
local(cmd, quiet = True)
6868

69-
7069
def prepare_environment():
7170
local("kubectl create namespace cluster --dry-run=client -o yaml | kubectl apply -f -")
7271

api/v1alpha1/clusteraddon_types.go

+98
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/clusteraddon"
2021
corev1 "k8s.io/api/core/v1"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -27,6 +28,52 @@ const (
2728
ClusterAddonFinalizer = "clusteraddon.clusterstack.x-k8s.io"
2829
)
2930

31+
// StageAnnotation is the annotation name and key for the stage annotation.
32+
const StageAnnotation = "ClusterAddonStage"
33+
34+
// StageAnnotationValue is the value of the stage annotation.
35+
type StageAnnotationValue string
36+
37+
const (
38+
// StageAnnotationValueCreated signifies the stage annotation created.
39+
StageAnnotationValueCreated = StageAnnotationValue("created")
40+
// StageAnnotationValueUpgraded signifies the stage annotation upgraded.
41+
StageAnnotationValueUpgraded = StageAnnotationValue("upgraded")
42+
)
43+
44+
// StagePhase defines the status of helm chart in the cluster addon.
45+
type StagePhase string
46+
47+
var (
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")
60+
)
61+
62+
// StageStatus represents the helm charts of the hook and it's phases.
63+
type StageStatus struct {
64+
// Name represent name of the helm chart
65+
// +optional
66+
Name string `json:"name"`
67+
68+
// Action is the action of the helm chart. e.g. - apply and delete.
69+
// +optional
70+
Action clusteraddon.Action `json:"action,omitempty"`
71+
72+
// Phase is the current phase of the helm chart.
73+
// +optional
74+
Phase StagePhase `json:"phase"`
75+
}
76+
3077
// ClusterAddonSpec defines the desired state of a ClusterAddon object.
3178
type ClusterAddonSpec struct {
3279
// ClusterStack is the full string <provider>-<name>-<Kubernetes version>-<version> that will be filled with the cluster stack that
@@ -38,6 +85,10 @@ type ClusterAddonSpec struct {
3885
// +optional
3986
Version string `json:"version,omitempty"`
4087

88+
// Hook specifies the runtime hook for the Cluster event.
89+
// +optional
90+
Hook string `json:"hook,omitempty"`
91+
4192
// ClusterRef is the reference to the clusterv1.Cluster object that corresponds to the workload cluster where this
4293
// controller applies the cluster addons.
4394
ClusterRef *corev1.ObjectReference `json:"clusterRef"`
@@ -49,6 +100,10 @@ type ClusterAddonStatus struct {
49100
// +optional
50101
Resources []*Resource `json:"resources,omitempty"`
51102

103+
// Stages shows the state of all stages in the current running hook.
104+
// +optional
105+
Stages []StageStatus `json:"stages,omitempty"`
106+
52107
// +optional
53108
// +kubebuilder:default:=false
54109
Ready bool `json:"ready"`
@@ -61,6 +116,7 @@ type ClusterAddonStatus struct {
61116
// +kubebuilder:object:root=true
62117
// +kubebuilder:subresource:status
63118
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Cluster\")].name"
119+
// +kubebuilder:printcolumn:name="Hook",type="string",JSONPath=".spec.hook",description="Present running hook"
64120
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
65121
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Cluster Addon"
66122
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
@@ -76,6 +132,48 @@ type ClusterAddon struct {
76132
Status ClusterAddonStatus `json:"status,omitempty"`
77133
}
78134

135+
// GetStagePhase returns helm chart status for the helm chart.
136+
func (r *ClusterAddon) GetStagePhase(stageName string, action clusteraddon.Action) StagePhase {
137+
for _, stage := range r.Status.Stages {
138+
if stage.Name == stageName && stage.Action == action {
139+
return stage.Phase
140+
}
141+
}
142+
143+
// This cannot occur as we populate phase value with "pending".
144+
return StagePhaseNone
145+
}
146+
147+
// SetStagePhase sets the helm chart status phase.
148+
func (r *ClusterAddon) SetStagePhase(stageName string, action clusteraddon.Action, phase StagePhase) {
149+
for i := range r.Status.Stages {
150+
if r.Status.Stages[i].Name == stageName && r.Status.Stages[i].Action == action {
151+
r.Status.Stages[i].Phase = phase
152+
}
153+
}
154+
}
155+
156+
// SetStageAnnotations sets the annotation whether the cluster got created or upgraded.
157+
func (r *ClusterAddon) SetStageAnnotations(value StageAnnotationValue) {
158+
if r.Annotations == nil {
159+
r.Annotations = make(map[string]string, 0)
160+
}
161+
_, found := r.Annotations[StageAnnotation]
162+
if !found {
163+
r.Annotations[StageAnnotation] = string(value)
164+
}
165+
}
166+
167+
// HasStageAnnotation returns whether the stage annotation exists with a certain value.
168+
func (r *ClusterAddon) HasStageAnnotation(value StageAnnotationValue) bool {
169+
val, found := r.Annotations[StageAnnotation]
170+
if found && val == string(value) {
171+
return true
172+
}
173+
174+
return false
175+
}
176+
79177
// GetConditions returns the observations of the operational state of the ClusterAddon resource.
80178
func (r *ClusterAddon) GetConditions() clusterv1.Conditions {
81179
return r.Status.Conditions

api/v1alpha1/conditions_const.go

+52
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ const (
2626
ControlPlaneNotReadyReason = "ControlPlaneNotReady"
2727
)
2828

29+
const (
30+
// EvaluatedCELCondition reports on whether the CEL expression is evaluated properly.
31+
EvaluatedCELCondition clusterv1.ConditionType = "EvaluatedCEL"
32+
33+
// FailedToEvaluatePreConditionReason is used when some pre CEL expression have been failed to evaluate.
34+
FailedToEvaluatePreConditionReason = "FailedToEvaluatePreCondition"
35+
36+
// FailedToEvaluatePostConditionReason is used when some post CEL expression have been failed to evaluate.
37+
FailedToEvaluatePostConditionReason = "FailedToEvaluatePostCondition"
38+
)
39+
40+
const (
41+
// HelmChartFoundCondition reports when mentioned helm chart is present in the cluster addon tar archive.
42+
HelmChartFoundCondition = "HelmChartFound"
43+
44+
// HelmChartMissingReason is used when mentioned helm chart is missing in the cluster addon tar archive.
45+
HelmChartMissingReason = "HelmChartMissing"
46+
)
47+
48+
const (
49+
// HelmChartTemplatedCondition reports on whether the relevant helm chart has been templated properly.
50+
HelmChartTemplatedCondition clusterv1.ConditionType = "HelmChartTemplated"
51+
52+
// TemplateOldClusterStackOverwriteFailedReason is used when old cluster stack overwrite.yaml is wrong.
53+
TemplateOldClusterStackOverwriteFailedReason = "TemplateOldClusterStackOverwriteFailed"
54+
55+
// TemplateOldClusterStackFailedReason is used when there is a issue doing helm template for the old cluster stack.
56+
TemplateOldClusterStackFailedReason = "TemplateOldClusterStackFailed"
57+
58+
// TemplateNewClusterStackOverwriteFailedReason is used when new cluster stack overwrite.yaml is wrong.
59+
TemplateNewClusterStackOverwriteFailedReason = "TemplateNewClusterStackOverwriteFailed"
60+
61+
// TemplateNewClusterStackFailedReason is used when there is a issue doing helm template for the new cluster stack.
62+
TemplateNewClusterStackFailedReason = "TemplateNewClusterStackFailed"
63+
)
64+
2965
const (
3066
// HelmChartAppliedCondition reports on whether the relevant helm chart has been applied.
3167
HelmChartAppliedCondition clusterv1.ConditionType = "HelmChartApplied"
@@ -37,6 +73,22 @@ const (
3773
ObjectsApplyingOngoingReason = "ObjectsApplyingOngoing"
3874
)
3975

76+
const (
77+
// HookServerReadyCondition reports on whether hook server is ready or not.
78+
HookServerReadyCondition clusterv1.ConditionType = "HookServerReady"
79+
80+
// HookServerUnresponsiveReason is used when hook server don't update the clusterAddon.Spec.Hook.
81+
HookServerUnresponsiveReason = "HookServerUnresponsive"
82+
)
83+
84+
const (
85+
// HelmChartDeletedCondition reports on whether the relevant helm chart has been applied.
86+
HelmChartDeletedCondition clusterv1.ConditionType = "HelmChartDeleted"
87+
88+
// FailedToDeleteObjectsReason is used when some objects have been failed to delete.
89+
FailedToDeleteObjectsReason = "FailedToDeleteObjects"
90+
)
91+
4092
const (
4193
// ProviderClusterStackReleasesSyncedCondition reports on whether the ProviderClusterStackReleases are ready.
4294
ProviderClusterStackReleasesSyncedCondition = "ProviderClusterStackReleasesSynced"

api/v1alpha1/zz_generated.deepcopy.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)