Skip to content

Commit

Permalink
Update to new csi-lib-utils
Browse files Browse the repository at this point in the history
Add context where necessary.
  • Loading branch information
jsafrane committed May 13, 2024
1 parent 3949aad commit 3833dce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cmd/csi-node-driver-registrar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ func main() {
// can skip adding mapping to "csi.volume.kubernetes.io/nodeid" annotation.

klog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress)
csiConn, err := connection.ConnectWithoutMetrics(*csiAddress)
ctx := context.Background()
csiConn, err := connection.ConnectWithoutMetrics(ctx, *csiAddress)
if err != nil {
klog.Errorf("error connecting to CSI driver: %v", err)
os.Exit(1)
}

klog.V(1).Infof("Calling CSI driver to discover driver name")
ctx, cancel := context.WithTimeout(context.Background(), *operationTimeout)
ctx, cancel := context.WithTimeout(ctx, *operationTimeout)
defer cancel()

csiDriverName, err := csirpc.GetDriverName(ctx, csiConn)
Expand All @@ -174,5 +175,5 @@ func main() {
defer closeGrpcConnection(*csiAddress, csiConn)

// Run forever
nodeRegister(csiDriverName, addr)
nodeRegister(ctx, csiDriverName, addr)
}
12 changes: 6 additions & 6 deletions cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
)

func nodeRegister(csiDriverName, httpEndpoint string) {
func nodeRegister(ctx context.Context, csiDriverName, httpEndpoint string) {
// When kubeletRegistrationPath is specified then driver-registrar ONLY acts
// as gRPC server which replies to registration requests initiated by kubelet's
// plugins watcher infrastructure. Node labeling is done by kubelet's csi code.
Expand Down Expand Up @@ -67,7 +67,7 @@ func nodeRegister(csiDriverName, httpEndpoint string) {
// Registers kubelet plugin watcher api.
registerapi.RegisterRegistrationServer(grpcServer, registrar)

go httpServer(socketPath, httpEndpoint, csiDriverName)
go httpServer(ctx, socketPath, httpEndpoint, csiDriverName)
go removeRegSocket(csiDriverName)
// Starts service
if err := grpcServer.Serve(lis); err != nil {
Expand All @@ -83,7 +83,7 @@ func buildSocketPath(csiDriverName string) string {
return fmt.Sprintf("%s/%s-reg.sock", *pluginRegistrationPath, csiDriverName)
}

func httpServer(socketPath string, httpEndpoint string, csiDriverName string) {
func httpServer(ctx context.Context, socketPath string, httpEndpoint string, csiDriverName string) {
if httpEndpoint == "" {
klog.Infof("Skipping HTTP server because endpoint is set to: %q", httpEndpoint)
return
Expand All @@ -95,7 +95,7 @@ func httpServer(socketPath string, httpEndpoint string, csiDriverName string) {
mux.HandleFunc("/healthz", func(w http.ResponseWriter, req *http.Request) {
socketExists, err := util.DoesSocketExist(socketPath)
if err == nil && socketExists {
grpcSocketCheckError := checkLiveRegistrationSocket(socketPath, csiDriverName)
grpcSocketCheckError := checkLiveRegistrationSocket(ctx, socketPath, csiDriverName)
if grpcSocketCheckError != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(grpcSocketCheckError.Error()))
Expand Down Expand Up @@ -129,9 +129,9 @@ func httpServer(socketPath string, httpEndpoint string, csiDriverName string) {
klog.Fatal(http.ListenAndServe(httpEndpoint, mux))
}

func checkLiveRegistrationSocket(socketFile, csiDriverName string) error {
func checkLiveRegistrationSocket(ctx context.Context, socketFile, csiDriverName string) error {
klog.V(2).Infof("Attempting to open a gRPC connection with: %q", socketFile)
grpcConn, err := connection.ConnectWithoutMetrics(socketFile)
grpcConn, err := connection.ConnectWithoutMetrics(ctx, socketFile)
if err != nil {
return fmt.Errorf("error connecting to node-registrar socket %s: %v", socketFile, err)
}
Expand Down

0 comments on commit 3833dce

Please sign in to comment.