Skip to content

Commit 6fc3517

Browse files
committed
Deploy CSI-Addons with volume condition reporter
When a Driver gets annotated with addons.csi.ceph.io/volume-condition: true the CSI-Addons DaemonSet for that driver will get deployed with the extra `--enable-volume-condition=true` commandline flag. This causes the CSI-Addons sidecar to periodically check attached volumes for this Driver and report the condition in the logs of the sidecar and as an Event for the PersistentVolumeClaim. Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent 3d21234 commit 6fc3517

File tree

7 files changed

+99
-6
lines changed

7 files changed

+99
-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"]

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
},

internal/utils/csi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ var EnableVolumeGroupSnapshotsContainerArg = "--feature-gates=CSIVolumeGroupSnap
400400
var ForceCephKernelClientContainerArg = "--forcecephkernelclient=true"
401401
var LogToStdErrContainerArg = "--logtostderr=false"
402402
var AlsoLogToStdErrContainerArg = "--alsologtostderr=true"
403+
var CsiAddonsVolumeConditionArg = "--enable-volume-condition=true"
403404

404405
func LogVerbosityContainerArg(level int) string {
405406
return fmt.Sprintf("--v=%d", Clamp(level, 0, 5))

0 commit comments

Comments
 (0)