Skip to content

Use node UID for VG creation instead of name #2022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions cmd/gce-pd-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
"k8s.io/utils/strings/slices"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
Expand Down Expand Up @@ -245,15 +246,26 @@ func handle() {
if err != nil {
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
}
isDataCacheEnabledNodePool, err := isDataCacheEnabledNodePool(ctx, *nodeName)
if err != nil {
klog.Fatalf("Failed to get node info from API server: %v", err.Error())
var node *v1.Node
var isDataCacheEnabledNodePoolCheck bool
if *nodeName == common.TestNode {
isDataCacheEnabledNodePoolCheck = true
} else if len(*nodeName) > 0 && *nodeName != common.TestNode {
node, err = driver.FetchNodeWithRetry(ctx, *nodeName)
if err != nil {
klog.Fatalf("Failed to get node info from API server: %v", err.Error())
}
isDataCacheEnabledNodePoolCheck, err = isDataCacheEnabledNodePool(ctx, node)
if err != nil {
klog.Fatalf("Unable to fetch node labels: %v", err.Error())
}
}
// isDataCacheEnabledNodePool := true
nsArgs := driver.NodeServerArgs{
EnableDeviceInUseCheck: *enableDeviceInUseCheck,
DeviceInUseTimeout: *deviceInUseTimeout,
EnableDataCache: *enableDataCacheFlag,
DataCacheEnabledNodePool: isDataCacheEnabledNodePool,
DataCacheEnabledNodePool: isDataCacheEnabledNodePoolCheck,
}
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, nsArgs)
if *maxConcurrentFormatAndMount > 0 {
Expand All @@ -264,7 +276,7 @@ func handle() {
klog.Errorf("Data Cache enabled, but --node-name not passed")
}
if nsArgs.DataCacheEnabledNodePool {
if err := setupDataCache(ctx, *nodeName, nodeServer.MetadataService.GetName()); err != nil {
if err := setupDataCache(ctx, node, *nodeName); err != nil {
klog.Errorf("Data Cache setup failed: %v", err)
}
go driver.StartWatcher(*nodeName)
Expand Down Expand Up @@ -351,15 +363,16 @@ func urlFlag(target **url.URL, name string, usage string) {
})
}

func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) (bool, error) {
func isDataCacheEnabledNodePool(ctx context.Context, node *v1.Node) (bool, error) {
if !*enableDataCacheFlag {
return false, nil
}
if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
return dataCacheLSSDCount != 0, err
}
return true, nil
// nodeName := node.Name
// if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, node)
return dataCacheLSSDCount != 0, err
// }
// return true, nil
}

func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
Expand Down Expand Up @@ -394,7 +407,7 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
return availableLssds[:lssdCount], nil
}

func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {
func setupDataCache(ctx context.Context, node *v1.Node, nodeName string) error {
isAlreadyRaided, err := driver.IsRaided()
if err != nil {
klog.V(4).Infof("Errored while scanning for available LocalSSDs err:%v; continuing Raiding", err)
Expand All @@ -404,9 +417,11 @@ func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {
}

lssdCount := common.LocalSSDCountForDataCache
nodeUid := nodeName
if nodeName != common.TestNode {
var err error
lssdCount, err = driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
nodeUid = string(node.ObjectMeta.UID)
// lssdCount := 4
lssdCount, err = driver.GetDataCacheCountFromNodeLabel(ctx, node)
if err != nil {
return err
}
Expand All @@ -425,7 +440,7 @@ func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {
}

// Initializing data cache node (VG checks w/ raided lssd)
if err := driver.InitializeDataCacheNode(nodeId); err != nil {
if err := driver.InitializeDataCacheNode(nodeUid); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion deploy/kubernetes/base/controller/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ spec:
- "--endpoint=unix:/csi/csi.sock"
- "--supports-dynamic-iops-provisioning=hyperdisk-balanced,hyperdisk-extreme"
- "--supports-dynamic-throughput-provisioning=hyperdisk-balanced,hyperdisk-throughput,hyperdisk-ml"
- --enable-data-cache
- "--run-node-service=false"
- --enable-data-cache=true
command:
- /gce-pd-csi-driver
env:
Expand Down
26 changes: 11 additions & 15 deletions pkg/gce-pd-csi-driver/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,7 @@ func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx con
return fmt.Errorf("Data Cache is not enabled for PVC (data-cache-size: %v, data-cache-mode: %v). Please set both parameters in StorageClass to enable caching", dataCacheSize, dataCacheMode)
}

func GetDataCacheCountFromNodeLabel(ctx context.Context, nodeName string) (int, error) {
cfg, err := rest.InClusterConfig()
if err != nil {
return 0, err
}
kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
return 0, err
}
node, err := getNodeWithRetry(ctx, kubeClient, nodeName)
if err != nil {
return 0, err
}
func GetDataCacheCountFromNodeLabel(ctx context.Context, node *v1.Node) (int, error) {
if val, found := node.GetLabels()[fmt.Sprintf(common.NodeLabelPrefix, common.DataCacheLssdCountLabel)]; found {
dataCacheCount, err := strconv.Atoi(val)
if err != nil {
Expand All @@ -272,14 +260,22 @@ func GetDataCacheCountFromNodeLabel(ctx context.Context, nodeName string) (int,
return 0, nil
}

func getNodeWithRetry(ctx context.Context, kubeClient *kubernetes.Clientset, nodeName string) (*v1.Node, error) {
func FetchNodeWithRetry(ctx context.Context, nodeName string) (*v1.Node, error) {
var nodeObj *v1.Node
cfg, err := rest.InClusterConfig()
if err != nil {
return nil, err
}
kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
return nil, err
}
backoff := wait.Backoff{
Duration: 1 * time.Second,
Factor: 2.0,
Steps: 5,
}
err := wait.ExponentialBackoffWithContext(ctx, backoff, func(_ context.Context) (bool, error) {
err = wait.ExponentialBackoffWithContext(ctx, backoff, func(_ context.Context) (bool, error) {
node, err := kubeClient.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
if err != nil {
klog.Warningf("Error getting node %s: %v, retrying...\n", nodeName, err)
Expand Down