Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 8413e84

Browse files
committed
operator: revise deployment status API
Revised the Deployment.Status to accommodate the deployment state conditions and the driver state. Currently, Deployment has 3 conditions named CertsVerified, CertsReady, and DriverDeployed. It also records the summary of controller and node driver state, .i.e, number of nodes the driver is running. The state The state get refreshed on each time the reconcile loop run.
1 parent cbec310 commit 8413e84

File tree

5 files changed

+269
-29
lines changed

5 files changed

+269
-29
lines changed

docs/install.md

+89-26
Original file line numberDiff line numberDiff line change
@@ -270,36 +270,73 @@ pmem-csi.intel.com 50s
270270

271271
$ kubectl describe deployment.pmem-csi.intel.com/pmem-csi.intel.com
272272
Name: pmem-csi.intel.com
273-
Namespace: default
273+
Namespace:
274274
Labels: <none>
275275
Annotations: <none>
276276
API Version: pmem-csi.intel.com/v1alpha1
277277
Kind: Deployment
278278
Metadata:
279-
Creation Timestamp: 2020-01-23T13:40:32Z
279+
Creation Timestamp: 2020-10-07T07:31:58Z
280280
Generation: 1
281-
Resource Version: 3596387
282-
Self Link: /apis/pmem-csi.intel.com/v1alpha1/deployments/pmem-csi.intel.com
283-
UID: 454b5961-5aa2-41c3-b774-29fe932ae236
281+
Managed Fields:
282+
API Version: pmem-csi.intel.com/v1alpha1
283+
Fields Type: FieldsV1
284+
fieldsV1:
285+
f:spec:
286+
.:
287+
f:deviceMode:
288+
f:nodeSelector:
289+
.:
290+
f:storage:
291+
Manager: kubectl-create
292+
Operation: Update
293+
Time: 2020-10-07T07:31:58Z
294+
API Version: pmem-csi.intel.com/v1alpha1
295+
Fields Type: FieldsV1
296+
fieldsV1:
297+
f:status:
298+
.:
299+
f:conditions:
300+
f:driverComponents:
301+
f:lastUpdated:
302+
f:phase:
303+
Manager: pmem-csi-operator
304+
Operation: Update
305+
Time: 2020-10-07T07:32:22Z
306+
Resource Version: 1235740
307+
Self Link: /apis/pmem-csi.intel.com/v1alpha1/deployments/pmem-csi.intel.com
308+
UID: d8635490-53fa-4eec-970d-cd4c76f53b23
284309
Spec:
285-
Controller Resources:
286-
Requests:
287-
Cpu: 200m
288-
Memory: 100Mi
289310
Device Mode: lvm
290-
Image: localhost/pmem-csi-driver:canary
291-
Node Resources:
292-
Requests:
293-
Cpu: 200m
294-
Memory: 100Mi
311+
Node Selector:
312+
Storage: pmem
295313
Status:
296-
Phase: Running
314+
Conditions:
315+
Last Update Time: 2020-10-07T07:32:00Z
316+
Reason: Driver certificates are available.
317+
Status: True
318+
Type: CertsReady
319+
Last Update Time: 2020-10-07T07:32:02Z
320+
Reason: Driver deployed successfully.
321+
Status: True
322+
Type: DriverDeployed
323+
Driver Components:
324+
Component: Controller
325+
Last Updated: 2020-10-08T07:45:13Z
326+
Reason: 1 instance(s) of controller driver is running successfully
327+
Status: Ready
328+
Component: Node
329+
Last Updated: 2020-10-08T07:45:11Z
330+
Reason: All 3 node driver pod(s) running successfully
331+
Status: Ready
332+
Last Updated: 2020-10-07T07:32:21Z
333+
Phase: Running
334+
Reason: All driver components are deployed successfully
297335
Events:
298-
Type Reason Age From Message
299-
---- ------ ---- ---- -------
300-
Normal NewDeployment 34s pmem-csi-operator Processing new driver deployment
301-
Normal Running 2s (x10 over 26s) pmem-csi-operator Driver deployment successful
302-
336+
Type Reason Age From Message
337+
---- ------ ---- ---- -------
338+
Normal NewDeployment 58s pmem-csi-operator Processing new driver deployment
339+
Normal Running 39s pmem-csi-operator Driver deployment successful
303340

304341
$ kubectl get po
305342
NAME READY STATUS RESTARTS AGE
@@ -1176,21 +1213,47 @@ active volumes.
11761213

11771214
#### DeploymentStatus
11781215

1179-
A PMEM-CSI Deployment's `status` field is a `DeploymentStatus` object, which has
1180-
a `phase` field. The phase of a Deployment is high-level summary of where the
1181-
Deployment is in it's lifecycle.
1216+
A PMEM-CSI Deployment's `status` field is a `DeploymentStatus` object, which
1217+
carries the detailed state of the driver deployment. It comprises of [deployment
1218+
conditions](#deployment-conditions), [driver component status](#driver-component-status),
1219+
and a `phase` field. The phase of a Deployment is a high-level summary
1220+
of where the Deployment is in its lifecycle.
11821221

11831222
The possible `phase` values and their meaning are as below:
11841223

11851224
| Value | Meaning |
11861225
|---|---|
11871226
| empty string | A new deployment. |
1188-
| Initializing | All the direct sub-resources of the `Deployment` are created, but some indirect ones (like pods controlled by a daemon set) may still be missing. |
11891227
| Running | The operator has determined that the driver is usable<sup>1</sup>. |
1190-
| Failed | For some reason the state of the `Deployment` failed and cannot be progressed<sup>2</sup>. |
1228+
| Failed | For some reason the state of the `Deployment` failed and cannot be progressed. The failure reason is placed in the `DeploymentStatus.Reason` field. |
11911229

11921230
<sup>1</sup> This check has not been implemented yet. Instead, the deployment goes straight to `Running` after creating sub-resources.
1193-
<sup>2</sup> Failure reason is supposed to be carried by one of additional `DeploymentStatus` field, but not implemented yet.
1231+
1232+
#### Deployment Conditions
1233+
1234+
PMEM-CSI `DeploymentStatus` has an array of `conditions` through witch the
1235+
PMEM-CSI Deployment has or has not passed. Below are the possible condition
1236+
types and their meanings:
1237+
1238+
| Condition type | Meaning |
1239+
|---|---|
1240+
| CertsReady | Driver certificates/secrets are available. |
1241+
| CertsVerified | Verified that the provided certificates are valid. |
1242+
| DriverDeployed | All the componentes required for the PMEM-CSI deployment has been deployed. |
1243+
1244+
#### Driver component status
1245+
1246+
PMEM-CSI `DeploymentStatus` has an array of `components` of type `DriverStatus`
1247+
in which the operator records the brief driver(Controller and Node) components
1248+
status. This is useful to know if all the driver instances of a deployment are
1249+
ready. Below are the fields and their meanings of `DriverStatus`:
1250+
1251+
| Field | Meaning |
1252+
| --- | --- |
1253+
| component | Represents the driver component type; one of `Controller` or `Node`. |
1254+
| status | Represents the state of the component; one of `Ready` or `NotReady`. Component becomes `Ready` if all the instances of the driver component are running. Otherwise, `NotReady`. |
1255+
| reason | A brief message that explains why the component is in this state. |
1256+
| lastUpdateTime | Time at which the status updated. |
11941257

11951258
#### Deployment Events
11961259

pkg/apis/pmemcsi/v1alpha1/deployment_types.go

+95-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const (
5555
// Related issue : https://github.com/kubernetes-sigs/controller-tools/issues/478
5656
// Fails setting min/max for integers: https://github.com/helm/helm/issues/5806
5757

58+
// +k8s:deepcopy-gen=true
5859
// DeploymentSpec defines the desired state of Deployment
5960
type DeploymentSpec struct {
6061
// Important: Run "make operator-generate-k8s" to regenerate code after modifying this file
@@ -109,13 +110,77 @@ type DeploymentSpec struct {
109110
KubeletDir string `json:"kubeletDir,omitempty"`
110111
}
111112

113+
// DeploymentConditionType type for representing a deployment status condition
114+
type DeploymentConditionType string
115+
116+
const (
117+
// CertsVerified means the provided deployment secrets are verified and valid for usage
118+
CertsVerified DeploymentConditionType = "CertsVerified"
119+
// CertsReady means secrests/certificates required for running the PMEM-CSI driver
120+
// are ready and the deployment could progress further
121+
CertsReady DeploymentConditionType = "CertsReady"
122+
// DriverDeployed means that the all the sub-resources required for the deployment CR
123+
// got created
124+
DriverDeployed DeploymentConditionType = "DriverDeployed"
125+
)
126+
127+
// +k8s:deepcopy-gen=true
128+
type DeploymentCondition struct {
129+
// Type of condition.
130+
Type DeploymentConditionType `json:"type"`
131+
// Status of the condition, one of True, False, Unknown.
132+
Status corev1.ConditionStatus `json:"status"`
133+
// Message human readable text that explain why this condition is in this state
134+
// +optional
135+
Reason string `json:"reason,omitempty"`
136+
// Last time the condition was probed.
137+
// +optional
138+
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
139+
}
140+
141+
type DriverType int
142+
143+
const (
144+
ControllerDriver DriverType = iota
145+
NodeDriver
146+
)
147+
148+
func (t DriverType) String() string {
149+
switch t {
150+
case ControllerDriver:
151+
return "Controller"
152+
case NodeDriver:
153+
return "Node"
154+
}
155+
return ""
156+
}
157+
158+
// +k8s:deepcopy-gen=true
159+
type DriverStatus struct {
160+
// DriverComponent represents type of the driver: controller or node
161+
DriverComponent string `json:"component"`
162+
// Status represents the driver status : Ready, NotReady
163+
Status string `json:"status"`
164+
// Reason represents the human readable text that explains why the
165+
// driver is in this state.
166+
Reason string `json:"reason"`
167+
// LastUpdated time of the driver status
168+
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
169+
}
170+
171+
// +k8s:deepcopy-gen=true
172+
112173
// DeploymentStatus defines the observed state of Deployment
113174
type DeploymentStatus struct {
114175
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
115176
// Important: Run "make operator-generate-k8s" to regenerate code after modifying this file
116177

117178
// Phase indicates the state of the deployment
118-
Phase DeploymentPhase `json:"phase,omitempty"`
179+
Phase DeploymentPhase `json:"phase,omitempty"`
180+
Reason string `json:"reason,omitempty"`
181+
// Conditions
182+
Conditions []DeploymentCondition `json:"conditions,omitempty"`
183+
Components []DriverStatus `json:"driverComponents,omitempty"`
119184
// LastUpdated time of the deployment status
120185
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
121186
}
@@ -206,8 +271,6 @@ type DeploymentPhase string
206271
const (
207272
// DeploymentPhaseNew indicates a new deployment
208273
DeploymentPhaseNew DeploymentPhase = ""
209-
// DeploymentPhaseInitializing indicates deployment initialization is in progress
210-
DeploymentPhaseInitializing DeploymentPhase = "Initializing"
211274
// DeploymentPhaseRunning indicates that the deployment was successful
212275
DeploymentPhaseRunning DeploymentPhase = "Running"
213276
// DeploymentPhaseFailed indicates that the deployment was failed
@@ -259,6 +322,35 @@ func (c DeploymentChange) String() string {
259322
}[c]
260323
}
261324

325+
func (d *Deployment) SetCondition(t DeploymentConditionType, state corev1.ConditionStatus, reason string) {
326+
for _, c := range d.Status.Conditions {
327+
if c.Type == t {
328+
c.Status = state
329+
c.Reason = reason
330+
c.LastUpdateTime = metav1.Now()
331+
return
332+
}
333+
}
334+
d.Status.Conditions = append(d.Status.Conditions, DeploymentCondition{
335+
Type: t,
336+
Status: state,
337+
Reason: reason,
338+
LastUpdateTime: metav1.Now(),
339+
})
340+
}
341+
342+
func (d *Deployment) SetDriverStatus(t DriverType, status, reason string) {
343+
if d.Status.Components == nil {
344+
d.Status.Components = make([]DriverStatus, 2)
345+
}
346+
d.Status.Components[t] = DriverStatus{
347+
DriverComponent: t.String(),
348+
Status: status,
349+
Reason: reason,
350+
LastUpdated: metav1.Now(),
351+
}
352+
}
353+
262354
// EnsureDefaults make sure that the deployment object has all defaults set properly
263355
func (d *Deployment) EnsureDefaults(operatorImage string) error {
264356
if d.Spec.Image == "" {

pkg/apis/pmemcsi/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)