Skip to content

Commit 3d66eaf

Browse files
support deploying provision probe or mount probe only
Currently, when a user deploys a PieProbe object, both of provision and mount probes are deployed. However, under some circumstances, it is enough to deploy either provision probes or mount probes only. This commit supports deploying either provision probes or mount probes only, by adding disableProvisionProbes and disableMountProbes fields to PieProbe spec. Signed-off-by: Ryotaro Banno <[email protected]>
1 parent fdba009 commit 3d66eaf

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

api/pie/v1alpha1/pieprobe_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ type PieProbeSpec struct {
3232
//+kubebuilder:validation:Optional
3333
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="pvcCapacity is immutable"
3434
PVCCapacity *resource.Quantity `json:"pvcCapacity"`
35+
36+
//+kubebuilder:default:=false
37+
//+kubebuilder:validation:Optional
38+
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="disableProvisionProbe is immutable"
39+
DisableProvisionProbes bool `json:"disableProvisionProbe"`
40+
41+
//+kubebuilder:default:=false
42+
//+kubebuilder:validation:Optional
43+
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="disableMountProbe is immutable"
44+
DisableMountProbes bool `json:"disableMountProbe"`
3545
}
3646

3747
// PieProbeStatus defines the observed state of PieProbe

charts/pie/templates/pie.topolvm.io_pieprobes.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ spec:
3939
spec:
4040
description: PieProbeSpec defines the desired state of PieProbe
4141
properties:
42+
disableMountProbe:
43+
default: false
44+
type: boolean
45+
x-kubernetes-validations:
46+
- message: disableMountProbe is immutable
47+
rule: self == oldSelf
48+
disableProvisionProbe:
49+
default: false
50+
type: boolean
51+
x-kubernetes-validations:
52+
- message: disableProvisionProbe is immutable
53+
rule: self == oldSelf
4254
monitoringStorageClass:
4355
type: string
4456
x-kubernetes-validations:

config/crd/bases/pie.topolvm.io_pieprobes.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ spec:
3939
spec:
4040
description: PieProbeSpec defines the desired state of PieProbe
4141
properties:
42+
disableMountProbe:
43+
default: false
44+
type: boolean
45+
x-kubernetes-validations:
46+
- message: disableMountProbe is immutable
47+
rule: self == oldSelf
48+
disableProvisionProbe:
49+
default: false
50+
type: boolean
51+
x-kubernetes-validations:
52+
- message: disableProvisionProbe is immutable
53+
rule: self == oldSelf
4254
monitoringStorageClass:
4355
type: string
4456
x-kubernetes-validations:

internal/controller/pie/pieprobe_controller.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,31 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
8787
return ctrl.Result{}, nil
8888
}
8989

90-
// Create a provision-probe CronJob for each sc
91-
err = r.createOrUpdateJob(
92-
ctx,
93-
ProvisionProbe,
94-
&pieProbe,
95-
nil,
96-
)
97-
if err != nil {
98-
return ctrl.Result{}, err
90+
if !pieProbe.Spec.DisableProvisionProbes {
91+
if err := r.reconcileProvisionProbe(ctx, &pieProbe); err != nil {
92+
return ctrl.Result{}, err
93+
}
94+
}
95+
96+
if !pieProbe.Spec.DisableMountProbes {
97+
if err := r.reconcileMountProbes(ctx, &pieProbe); err != nil {
98+
return ctrl.Result{}, err
99+
}
99100
}
100101

102+
return ctrl.Result{}, nil
103+
}
104+
105+
func (r *PieProbeReconciler) reconcileProvisionProbe(ctx context.Context, pieProbe *piev1alpha1.PieProbe) error {
106+
// Create a provision-probe CronJob for each sc
107+
return r.createOrUpdateJob(ctx, ProvisionProbe, pieProbe, nil)
108+
}
109+
110+
func (r *PieProbeReconciler) reconcileMountProbes(ctx context.Context, pieProbe *piev1alpha1.PieProbe) error {
101111
// Get a node list and create a PVC and a mount-probe CronJob for each node and sc.
102112
nodeSelector, err := nodeaffinity.NewNodeSelector(&pieProbe.Spec.NodeSelector)
103113
if err != nil {
104-
return ctrl.Result{}, err
114+
return err
105115
}
106116
allNodeList := corev1.NodeList{}
107117
r.client.List(ctx, &allNodeList)
@@ -112,22 +122,13 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
112122
}
113123
availableNodeList = append(availableNodeList, node)
114124

115-
err = r.createOrUpdatePVC(
116-
ctx,
117-
node.Name,
118-
&pieProbe,
119-
)
125+
err = r.createOrUpdatePVC(ctx, node.Name, pieProbe)
120126
if err != nil {
121-
return ctrl.Result{}, err
127+
return err
122128
}
123-
err = r.createOrUpdateJob(
124-
ctx,
125-
MountProbe,
126-
&pieProbe,
127-
&node.Name,
128-
)
129+
err = r.createOrUpdateJob(ctx, MountProbe, pieProbe, &node.Name)
129130
if err != nil {
130-
return ctrl.Result{}, err
131+
return err
131132
}
132133
}
133134

@@ -144,7 +145,7 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
144145
}),
145146
})
146147
if err != nil {
147-
return ctrl.Result{}, err
148+
return err
148149
}
149150
for _, cronJob := range cronJobList.Items {
150151
nodeName := cronJob.GetLabels()[constants.ProbeNodeLabelKey]
@@ -156,7 +157,7 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
156157
}
157158
err := r.deleteCronJob(ctx, &cronJob)
158159
if client.IgnoreNotFound(err) != nil {
159-
return ctrl.Result{}, err
160+
return err
160161
}
161162
}
162163

@@ -168,7 +169,7 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
168169
}),
169170
})
170171
if err != nil {
171-
return ctrl.Result{}, err
172+
return err
172173
}
173174
for _, pvc := range pvcList.Items {
174175
nodeName := pvc.GetLabels()[constants.ProbeNodeLabelKey]
@@ -177,11 +178,11 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
177178
}
178179
err = r.deletePVC(ctx, &pvc)
179180
if client.IgnoreNotFound(err) != nil {
180-
return ctrl.Result{}, err
181+
return err
181182
}
182183
}
183184

184-
return ctrl.Result{}, nil
185+
return nil
185186
}
186187

187188
func (r *PieProbeReconciler) deletePVC(ctx context.Context, pvc *corev1.PersistentVolumeClaim) error {

0 commit comments

Comments
 (0)