Skip to content

Commit f57e067

Browse files
authored
Merge pull request #282 from nixpanic/volume-condition-reporter
Deploy CSI-Addons with volume condition reporter
2 parents 3d21234 + 67bc1af commit f57e067

File tree

11 files changed

+198
-6
lines changed

11 files changed

+198
-6
lines changed

PendingReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
## Features
66

7+
- CSI-Addons Volume Condition reporting can be enabled by annotating a Driver with `addons.csi.ceph.io/volume-condition: true`.
8+
79
## NOTE

config/csi-rbac/cephfs_nodeplugin_cluster_role.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ rules:
1919
- apiGroups: [""]
2020
resources: ["serviceaccounts/token"]
2121
verbs: ["create"]
22+
# events and pv, pvc for volume condition reporter
23+
- apiGroups: [""]
24+
resources: ["events"]
25+
verbs: ["list", "watch", "create", "update", "patch"]
26+
- apiGroups: [""]
27+
resources: ["persistentvolumes", "persistentvolumeclaims"]
28+
verbs: ["get"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
kind: Role
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: cephfs-nodeplugin-r
5+
rules:
6+
- apiGroups: ["csiaddons.openshift.io"]
7+
resources: ["csiaddonsnodes"]
8+
verbs: ["get", "watch", "list", "create", "update", "delete"]
9+
- apiGroups: [""]
10+
resources: ["pods"]
11+
verbs: ["get"]
12+
- apiGroups: ["apps"]
13+
resources: ["replicasets"]
14+
verbs: ["get"]
15+
- apiGroups: ["apps"]
16+
resources: ["deployments/finalizers", "daemonsets/finalizers"]
17+
verbs: ["update"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: RoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: cephfs-nodeplugin-rb
5+
subjects:
6+
- kind: ServiceAccount
7+
name: cephfs-nodeplugin-sa
8+
namespace: system
9+
roleRef:
10+
kind: Role
11+
name: cephfs-nodeplugin-r
12+
apiGroup: rbac.authorization.k8s.io

config/csi-rbac/rbd_nodeplugin_cluster_role.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ rules:
2727
- apiGroups: ["authentication.k8s.io"]
2828
resources: ["tokenreviews"]
2929
verbs: ["create"]
30+
# events and pvc for volume condition reporter
31+
- apiGroups: [""]
32+
resources: ["events"]
33+
verbs: ["list", "watch", "create", "update", "patch"]
34+
- apiGroups: [""]
35+
resources: ["persistentvolumeclaims"]
36+
verbs: ["get"]

deploy/all-in-one/install.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28869,6 +28869,23 @@ rules:
2886928869
- serviceaccounts/token
2887028870
verbs:
2887128871
- create
28872+
- apiGroups:
28873+
- ""
28874+
resources:
28875+
- events
28876+
verbs:
28877+
- list
28878+
- watch
28879+
- create
28880+
- update
28881+
- patch
28882+
- apiGroups:
28883+
- ""
28884+
resources:
28885+
- persistentvolumes
28886+
- persistentvolumeclaims
28887+
verbs:
28888+
- get
2887228889
---
2887328890
apiVersion: rbac.authorization.k8s.io/v1
2887428891
kind: ClusterRole
@@ -29612,6 +29629,22 @@ rules:
2961229629
- tokenreviews
2961329630
verbs:
2961429631
- create
29632+
- apiGroups:
29633+
- ""
29634+
resources:
29635+
- events
29636+
verbs:
29637+
- list
29638+
- watch
29639+
- create
29640+
- update
29641+
- patch
29642+
- apiGroups:
29643+
- ""
29644+
resources:
29645+
- persistentvolumeclaims
29646+
verbs:
29647+
- get
2961529648
---
2961629649
apiVersion: rbac.authorization.k8s.io/v1
2961729650
kind: RoleBinding

deploy/charts/ceph-csi-operator/templates/cephfs-nodeplugin-cr-rbac.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,20 @@ rules:
3535
- serviceaccounts/token
3636
verbs:
3737
- create
38+
- apiGroups:
39+
- ""
40+
resources:
41+
- events
42+
verbs:
43+
- list
44+
- watch
45+
- create
46+
- update
47+
- patch
48+
- apiGroups:
49+
- ""
50+
resources:
51+
- persistentvolumes
52+
- persistentvolumeclaims
53+
verbs:
54+
- get

deploy/charts/ceph-csi-operator/templates/rbd-nodeplugin-cr-rbac.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ rules:
5656
- tokenreviews
5757
verbs:
5858
- create
59+
- apiGroups:
60+
- ""
61+
resources:
62+
- events
63+
verbs:
64+
- list
65+
- watch
66+
- create
67+
- update
68+
- patch
69+
- apiGroups:
70+
- ""
71+
resources:
72+
- persistentvolumeclaims
73+
verbs:
74+
- get

deploy/multifile/csi-rbac.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,23 @@ rules:
398398
- serviceaccounts/token
399399
verbs:
400400
- create
401+
- apiGroups:
402+
- ""
403+
resources:
404+
- events
405+
verbs:
406+
- list
407+
- watch
408+
- create
409+
- update
410+
- patch
411+
- apiGroups:
412+
- ""
413+
resources:
414+
- persistentvolumes
415+
- persistentvolumeclaims
416+
verbs:
417+
- get
401418
---
402419
apiVersion: rbac.authorization.k8s.io/v1
403420
kind: ClusterRole
@@ -813,6 +830,22 @@ rules:
813830
- tokenreviews
814831
verbs:
815832
- create
833+
- apiGroups:
834+
- ""
835+
resources:
836+
- events
837+
verbs:
838+
- list
839+
- watch
840+
- create
841+
- update
842+
- patch
843+
- apiGroups:
844+
- ""
845+
resources:
846+
- persistentvolumeclaims
847+
verbs:
848+
- get
816849
---
817850
apiVersion: rbac.authorization.k8s.io/v1
818851
kind: RoleBinding

internal/controller/driver_controller.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"reflect"
2727
"regexp"
2828
"slices"
29+
"strconv"
2930
"strings"
3031

3132
"github.com/go-logr/logr"
@@ -72,7 +73,10 @@ const (
7273
const (
7374
// Annotation name for ownerref information
7475
ownerRefAnnotationKey = "csi.ceph.io/ownerref"
75-
logRotateCmd = `while true; do logrotate --verbose /logrotate-config/csi; sleep 15m; done`
76+
// Annotation to enable CSI-Addons volume condition reporter
77+
driverCSIAddonsFeatureVolumeCondition = "addons.csi.ceph.io/volume-condition"
78+
79+
logRotateCmd = `while true; do logrotate --verbose /logrotate-config/csi; sleep 15m; done`
7680
)
7781

7882
// A regexp used to parse driver's prefix and type from the full name
@@ -236,10 +240,7 @@ func (r *driverReconcile) reconcile() error {
236240
r.reconcileControllerPluginDeployment,
237241
r.reconcileNodePluginDeamonSet,
238242
r.reconcileLivenessService,
239-
}
240-
241-
if r.isRbdDriver() {
242-
reconcilers = append(reconcilers, r.reconcileNodePluginDeamonSetForCsiAddons)
243+
r.reconcileNodePluginDeamonSetForCsiAddons,
243244
}
244245

245246
// Concurrently reconcile different aspects of the clusters actual state to meet
@@ -981,7 +982,38 @@ func (r *driverReconcile) reconcileNodePluginDeamonSetForCsiAddons() error {
981982

982983
log := r.log.WithValues("csiAddonsDaemonSetName", daemonSet.Name)
983984

984-
if !ptr.Deref(r.driver.Spec.DeployCsiAddons, false) {
985+
withCsiAddonsDaemonSet := false
986+
withCsiAddonsVolumeCondition := false
987+
988+
if r.isRbdDriver() {
989+
withCsiAddonsDaemonSet = ptr.Deref(r.driver.Spec.DeployCsiAddons, false)
990+
}
991+
992+
// check if the driver wants CSI-Addons features
993+
if feature := r.driver.GetAnnotations()[driverCSIAddonsFeatureVolumeCondition]; feature != "" {
994+
enabled, err := strconv.ParseBool(feature)
995+
if err != nil {
996+
r.log.Error(
997+
err,
998+
"Unable to parse annotation on driver.csi.ceph.io",
999+
"name",
1000+
client.ObjectKeyFromObject(&r.driver),
1001+
driverCSIAddonsFeatureVolumeCondition,
1002+
feature,
1003+
)
1004+
return err
1005+
}
1006+
1007+
withCsiAddonsVolumeCondition = enabled
1008+
// if the feature is enabled, enable the daemonset too
1009+
withCsiAddonsDaemonSet = withCsiAddonsDaemonSet || withCsiAddonsVolumeCondition
1010+
}
1011+
1012+
if r.isNfsDriver() {
1013+
withCsiAddonsDaemonSet = false
1014+
}
1015+
1016+
if !withCsiAddonsDaemonSet {
9851017
if err := r.Delete(r.ctx, daemonSet); client.IgnoreNotFound(err) != nil {
9861018
log.Error(err, "failed to delete csi addons daemonset")
9871019
return err
@@ -1062,6 +1094,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSetForCsiAddons() error {
10621094
utils.If(logRotationEnabled, utils.LogToStdErrContainerArg, ""),
10631095
utils.If(logRotationEnabled, utils.AlsoLogToStdErrContainerArg, ""),
10641096
utils.If(logRotationEnabled, utils.LogFileContainerArg("csi-addons"), ""),
1097+
utils.If(withCsiAddonsVolumeCondition, utils.CsiAddonsVolumeConditionArg, ""),
10651098
},
10661099
),
10671100
Ports: []corev1.ContainerPort{
@@ -1080,6 +1113,12 @@ func (r *driverReconcile) reconcileNodePluginDeamonSetForCsiAddons() error {
10801113
if logRotationEnabled {
10811114
mounts = append(mounts, utils.LogsDirVolumeMount)
10821115
}
1116+
if withCsiAddonsVolumeCondition {
1117+
mounts = append(mounts,
1118+
utils.PluginMountDirVolumeMount(kubeletDirPath),
1119+
utils.PodsMountDirVolumeMount(kubeletDirPath),
1120+
)
1121+
}
10831122
return mounts
10841123
}),
10851124
Resources: ptr.Deref(
@@ -1124,6 +1163,14 @@ func (r *driverReconcile) reconcileNodePluginDeamonSetForCsiAddons() error {
11241163
utils.LogRotateDirVolumeName(r.driver.Name),
11251164
)
11261165
}
1166+
1167+
if withCsiAddonsVolumeCondition {
1168+
volumes = append(
1169+
volumes,
1170+
utils.PluginMountDirVolume(kubeletDirPath),
1171+
utils.PodsMountDirVolume(kubeletDirPath),
1172+
)
1173+
}
11271174
return volumes
11281175
}),
11291176
},

0 commit comments

Comments
 (0)