Skip to content

Commit

Permalink
Move fuction to get kubelet path into util package (#365)
Browse files Browse the repository at this point in the history
This function will be reused in upcoming `PodMounter` and `util` package
seems like a better place.

---

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Signed-off-by: Burak Varlı <[email protected]>
  • Loading branch information
unexge authored Jan 31, 2025
1 parent 8adcb20 commit 4dfb45c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
15 changes: 2 additions & 13 deletions pkg/driver/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ import (
"github.com/awslabs/aws-s3-csi-driver/pkg/driver/node/targetpath"
"github.com/awslabs/aws-s3-csi-driver/pkg/driver/node/volumecontext"
"github.com/awslabs/aws-s3-csi-driver/pkg/mountpoint"
"github.com/awslabs/aws-s3-csi-driver/pkg/util"
)

const (
defaultKubeletPath = "/var/lib/kubelet"
)

var kubeletPath = getKubeletPath()
var kubeletPath = util.KubeletPath()

var (
nodeCaps = []csi.NodeServiceCapability_RPC_Type{}
Expand Down Expand Up @@ -173,14 +170,6 @@ func compileMountOptions(currentOptions []string, newOptions []string) []string
return allMountOptions.List()
}

func getKubeletPath() string {
kubeletPath := os.Getenv("KUBELET_PATH")
if kubeletPath == "" {
return defaultKubeletPath
}
return kubeletPath
}

func (ns *S3NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
klog.V(4).Infof("NodeUnpublishVolume: called with args %+v", req)

Expand Down
15 changes: 15 additions & 0 deletions pkg/util/kubelet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package util

import "os"

const defaultKubeletPath = "/var/lib/kubelet"

// KubeletPath returns path of the kubelet.
// It looks for `KUBELET_PATH` variable, and returns a default path if its not defined.
func KubeletPath() string {
kubeletPath := os.Getenv("KUBELET_PATH")
if kubeletPath == "" {
return defaultKubeletPath
}
return kubeletPath
}

0 comments on commit 4dfb45c

Please sign in to comment.