From cfb1567c7105c8f304b3ea48329884db012c60bf Mon Sep 17 00:00:00 2001 From: GunaKKIBM <92353386+GunaKKIBM@users.noreply.github.com> Date: Tue, 7 Feb 2023 14:40:59 +0530 Subject: [PATCH] Reading node instance ID from node spec provider ID (#116) * Reading node instance ID from node spec provider ID * Cleanup supported by csi-driver-registrar, removing manual cleanup --- .../kubernetes/manifests/node-server.yaml | 4 --- go.mod | 2 +- go.sum | 4 +-- .../ibm-csi-common/pkg/metadata/metadata.go | 27 ++++++++++++++----- .../IBM/ibm-csi-common/pkg/utils/constants.go | 9 ++++--- vendor/modules.txt | 2 +- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/deploy/kubernetes/driver/kubernetes/manifests/node-server.yaml b/deploy/kubernetes/driver/kubernetes/manifests/node-server.yaml index f645d5d1..15f14dfc 100644 --- a/deploy/kubernetes/driver/kubernetes/manifests/node-server.yaml +++ b/deploy/kubernetes/driver/kubernetes/manifests/node-server.yaml @@ -35,10 +35,6 @@ spec: - "--v=5" - "--csi-address=$(ADDRESS)" - "--kubelet-registration-path=$(DRIVER_REGISTRATION_SOCK)" - lifecycle: - preStop: - exec: - command: ["/bin/sh", "-c", "rm -rf /registration/vpc.block.csi.ibm.io /registration/vpc.block.csi.ibm.io-reg.sock"] env: - name: ADDRESS value: /csi/csi.sock diff --git a/go.mod b/go.mod index 6ee85325..d232abd3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/kubernetes-sigs/ibm-vpc-block-csi-driver go 1.18 require ( - github.com/IBM/ibm-csi-common v1.1.4 + github.com/IBM/ibm-csi-common v1.1.5 github.com/IBM/ibmcloud-volume-interface v1.1.2 github.com/IBM/ibmcloud-volume-vpc v1.1.3 github.com/IBM/secret-utils-lib v1.1.2 diff --git a/go.sum b/go.sum index 86d06744..069d9f42 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7 h1:eHgfQl6IeSmzWUyiSi13CvoFYsovoyq github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= github.com/IBM/go-sdk-core/v5 v5.9.1 h1:06pXbD9Rgmqqe2HA5YAeQbB4eYRRFgIoOT+Kh3cp1zo= github.com/IBM/go-sdk-core/v5 v5.9.1/go.mod h1:axE2JrRq79gIJTjKPBwV6gWHswvVptBjbcvvCPIxARM= -github.com/IBM/ibm-csi-common v1.1.4 h1:LXFFnzEeLy9/eUHBS6U6JtcVlxQnXhM2HWZVZJlxcTM= -github.com/IBM/ibm-csi-common v1.1.4/go.mod h1:ylboxxpsAnVxFn35fBfhu6VFnl1YZa2LHgX0hMpujqw= +github.com/IBM/ibm-csi-common v1.1.5 h1:hXCQ9xtO5Or5qhi5J5Ey7tfP0P+WpxPry1+u//z8xaw= +github.com/IBM/ibm-csi-common v1.1.5/go.mod h1:ylboxxpsAnVxFn35fBfhu6VFnl1YZa2LHgX0hMpujqw= github.com/IBM/ibmcloud-volume-interface v1.1.2 h1:7IByqGhG09a3aycsf3TQn9vkQDncMJYdvpo4hGQAN5A= github.com/IBM/ibmcloud-volume-interface v1.1.2/go.mod h1:H6bm3Tzq7cjN0De207du/A8mzrirEgxwV89j3ouwCwg= github.com/IBM/ibmcloud-volume-vpc v1.1.3 h1:nYb45M8xnKz2ae8qnW77OIGTrxVmsKwxbvt71jd/wzw= diff --git a/vendor/github.com/IBM/ibm-csi-common/pkg/metadata/metadata.go b/vendor/github.com/IBM/ibm-csi-common/pkg/metadata/metadata.go index 876ea03e..98460140 100644 --- a/vendor/github.com/IBM/ibm-csi-common/pkg/metadata/metadata.go +++ b/vendor/github.com/IBM/ibm-csi-common/pkg/metadata/metadata.go @@ -20,7 +20,6 @@ package metadata import ( "context" "fmt" - "os" "strings" "github.com/IBM/ibm-csi-common/pkg/utils" @@ -79,17 +78,23 @@ func (nodeManager *NodeInfoManager) NewNodeMetadata(logger *zap.Logger) (NodeMet } nodeLabels := node.ObjectMeta.Labels - if len(nodeLabels[utils.NodeWorkerIDLabel]) == 0 || len(nodeLabels[utils.NodeRegionLabel]) == 0 || len(nodeLabels[utils.NodeZoneLabel]) == 0 { - errorMsg := fmt.Errorf("One or few required node label(s) is/are missing [%s, %s, %s]. Node Labels Found = [#%v]", utils.NodeWorkerIDLabel, utils.NodeRegionLabel, utils.NodeZoneLabel, nodeLabels) //nolint:golint + if len(nodeLabels[utils.NodeRegionLabel]) == 0 || len(nodeLabels[utils.NodeZoneLabel]) == 0 { + errorMsg := fmt.Errorf("One or few required node label(s) is/are missing [%s, %s]. Node Labels Found = [#%v]", utils.NodeRegionLabel, utils.NodeZoneLabel, nodeLabels) //nolint:golint return nil, errorMsg } var workerID string - // In case of unmanaged cluster use label NodeInstanceIDLabel for workerID. - if os.Getenv(strings.ToUpper("IKS_ENABLED")) != "True" { + + // If the cluster is satellite, the machine-type label equals to UPI + if nodeLabels[utils.MachineTypeLabel] == utils.UPI { + // For a satellite cluster, workerID is fetched from vpc-instance-id node label, which is updated by the vpc-node-label-updater (init container) workerID = nodeLabels[utils.NodeInstanceIDLabel] } else { - workerID = nodeLabels[utils.NodeWorkerIDLabel] + // For managed and IPI cluster, workerID is fetched from the ProviderID in node spec. + workerID = fetchInstanceID(node.Spec.ProviderID) + if workerID == "" { + return nil, fmt.Errorf("Unable to fetch instance ID from node provider ID - %s", node.Spec.ProviderID) + } } return &nodeMetadataManager{ @@ -110,3 +115,13 @@ func (manager *nodeMetadataManager) GetRegion() string { func (manager *nodeMetadataManager) GetWorkerID() string { return manager.workerID } + +// fetchInstanceID fetches instance ID from the provider ID in node spec. +func fetchInstanceID(providerID string) string { + s := strings.Split(providerID, "/") + if len(s) != 7 { + return "" + } + + return s[6] +} diff --git a/vendor/github.com/IBM/ibm-csi-common/pkg/utils/constants.go b/vendor/github.com/IBM/ibm-csi-common/pkg/utils/constants.go index 9d17ed5a..32840ea9 100644 --- a/vendor/github.com/IBM/ibm-csi-common/pkg/utils/constants.go +++ b/vendor/github.com/IBM/ibm-csi-common/pkg/utils/constants.go @@ -58,12 +58,15 @@ const ( // NodeRegionLabel Region Label attached to node NodeRegionLabel = "failure-domain.beta.kubernetes.io/region" - // NodeWorkerIDLabel worker ID label attached to node - NodeWorkerIDLabel = "ibm-cloud.kubernetes.io/worker-id" - // NodeInstanceIDLabel VPC ID label attached to satellite host NodeInstanceIDLabel = "ibm-cloud.kubernetes.io/vpc-instance-id" + // MachineTypeLabel is the node label used to identify the cluster type (upi,ipi,etc) + MachineTypeLabel = "ibm-cloud.kubernetes.io/machine-type" + + // UPI is the expected value assigned to machine-type label on satellite cluster nodes + UPI = "upi" + // VolumeIDLabel ... VolumeIDLabel = "volumeId" diff --git a/vendor/modules.txt b/vendor/modules.txt index e3f28c10..6f0a5f8f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -8,7 +8,7 @@ github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest # github.com/IBM/go-sdk-core/v5 v5.9.1 ## explicit; go 1.14 github.com/IBM/go-sdk-core/v5/core -# github.com/IBM/ibm-csi-common v1.1.4 +# github.com/IBM/ibm-csi-common v1.1.5 ## explicit; go 1.18 github.com/IBM/ibm-csi-common/pkg/ibmcloudprovider github.com/IBM/ibm-csi-common/pkg/messages