Skip to content

Commit f9e4fc6

Browse files
nixpanicmergify[bot]
authored andcommitted
sidecar: add --enable-volume-condition to start the Volume Condition Reporter
Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent 7c5fc77 commit f9e4fc6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

sidecar/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"context"
2121
"flag"
22+
"strings"
2223
"time"
2324

2425
"github.com/csi-addons/kubernetes-csi-addons/internal/sidecar/service"
@@ -28,6 +29,7 @@ import (
2829
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/csiaddonsnode"
2930
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/server"
3031
sideutil "github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/util"
32+
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/volume-condition"
3133

3234
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
3335
"github.com/kubernetes-csi/csi-lib-utils/standardflags"
@@ -61,6 +63,11 @@ func main() {
6163
leaderElectionRenewDeadline = flag.Duration("leader-election-renew-deadline", 10*time.Second, "Duration, in seconds, that the acting leader will retry refreshing leadership before giving up. Defaults to 10 seconds.")
6264
leaderElectionRetryPeriod = flag.Duration("leader-election-retry-period", 5*time.Second, "Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds.")
6365
enableAuthChecks = flag.Bool("enable-auth", true, "Enable Authorization checks and TLS communication (enabled by default)")
66+
67+
// volume condition reporting
68+
enableVolumeCondition = flag.Bool("enable-volume-condition", false, "Enable reporting of the volume condition")
69+
volumeConditionInterval = flag.Duration("volume-condition-interval", 1*time.Minute, "Interval between volume condition checks")
70+
volumeConditionRecorders = flag.String("volume-condition-recorders", "log,pvcEvent", "location(s) to report volume condition to")
6471
)
6572
klog.InitFlags(nil)
6673

@@ -130,6 +137,40 @@ func main() {
130137
}
131138
}()
132139

140+
// start the volume condition reporter
141+
if *enableVolumeCondition {
142+
go func() {
143+
driver, err := csiClient.GetDriverName()
144+
if err != nil {
145+
klog.Fatalf("failed to get the drivername from the CSI-plugin: %v", err)
146+
}
147+
148+
recorderOptions := make([]condition.RecorderOption, 0)
149+
for _, vcr := range strings.Split(*volumeConditionRecorders, ",") {
150+
switch vcr {
151+
case "log":
152+
recorderOptions = append(recorderOptions, condition.WithLogRecorder())
153+
case "pvcEvent":
154+
recorderOptions = append(recorderOptions, condition.WithEventRecorder())
155+
default:
156+
klog.Infof("condition recorder %q is unknown, skipping", vcr)
157+
}
158+
}
159+
160+
ctx := context.Background()
161+
reporter, err := condition.NewVolumeConditionReporter(ctx, kubeClient, *nodeID, driver, recorderOptions)
162+
if err != nil {
163+
klog.Fatalf("failed to create volume condition reporter: %v", err)
164+
}
165+
166+
klog.Info("starting volume condition reporter for driver: " + driver)
167+
err = reporter.Run(ctx, *volumeConditionInterval)
168+
if err != nil {
169+
klog.Fatalf("failed to start volume condition reporter: %v", err)
170+
}
171+
}()
172+
}
173+
133174
sidecarServer := server.NewSidecarServer(*controllerIP, *controllerPort, kubeClient, *enableAuthChecks)
134175
sidecarServer.RegisterService(service.NewIdentityServer(csiClient.GetGRPCClient()))
135176
sidecarServer.RegisterService(service.NewReclaimSpaceServer(csiClient.GetGRPCClient(), kubeClient, *stagingPath))

0 commit comments

Comments
 (0)