@@ -17,6 +17,7 @@ limitations under the License.
17
17
package v1alpha1
18
18
19
19
import (
20
+ "github.com/SovereignCloudStack/cluster-stack-operator/pkg/clusteraddon"
20
21
corev1 "k8s.io/api/core/v1"
21
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22
23
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -27,6 +28,52 @@ const (
27
28
ClusterAddonFinalizer = "clusteraddon.clusterstack.x-k8s.io"
28
29
)
29
30
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
+
30
77
// ClusterAddonSpec defines the desired state of a ClusterAddon object.
31
78
type ClusterAddonSpec struct {
32
79
// 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 {
38
85
// +optional
39
86
Version string `json:"version,omitempty"`
40
87
88
+ // Hook specifies the runtime hook for the Cluster event.
89
+ // +optional
90
+ Hook string `json:"hook,omitempty"`
91
+
41
92
// ClusterRef is the reference to the clusterv1.Cluster object that corresponds to the workload cluster where this
42
93
// controller applies the cluster addons.
43
94
ClusterRef * corev1.ObjectReference `json:"clusterRef"`
@@ -49,6 +100,10 @@ type ClusterAddonStatus struct {
49
100
// +optional
50
101
Resources []* Resource `json:"resources,omitempty"`
51
102
103
+ // Stages shows the state of all stages in the current running hook.
104
+ // +optional
105
+ Stages []StageStatus `json:"stages,omitempty"`
106
+
52
107
// +optional
53
108
// +kubebuilder:default:=false
54
109
Ready bool `json:"ready"`
@@ -61,6 +116,7 @@ type ClusterAddonStatus struct {
61
116
// +kubebuilder:object:root=true
62
117
// +kubebuilder:subresource:status
63
118
// +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"
64
120
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
65
121
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Cluster Addon"
66
122
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
@@ -76,6 +132,48 @@ type ClusterAddon struct {
76
132
Status ClusterAddonStatus `json:"status,omitempty"`
77
133
}
78
134
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
+
79
177
// GetConditions returns the observations of the operational state of the ClusterAddon resource.
80
178
func (r * ClusterAddon ) GetConditions () clusterv1.Conditions {
81
179
return r .Status .Conditions
0 commit comments