Skip to content

Commit

Permalink
Revert "updated GetNodeLabels method" (#279)
Browse files Browse the repository at this point in the history
This reverts commit 95eabe5.
  • Loading branch information
atye authored Jan 29, 2024
1 parent abaea30 commit b87d685
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
3 changes: 0 additions & 3 deletions service/envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,4 @@ const (

// EnvExternalAccess is the IP of an additional router you wish to add for nfs export
EnvExternalAccess = "X_CSI_POWERFLEX_EXTERNAL_ACCESS"

// EnvKubeNodeName is the name of the environment variable which stores current kubernetes node name
EnvKubeNodeName = "X_CSI_POWERFLEX_KUBE_NODE_NAME"
)
13 changes: 6 additions & 7 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ type Opts struct {
MaxVolumesPerNode int64
IsQuotaEnabled bool // allow driver to enable quota limits for NFS volumes
ExternalAccess string // used for adding extra IP/IP range to the NFS export
KubeNodeName string
}

type service struct {
Expand Down Expand Up @@ -349,7 +348,6 @@ func (s *service) BeforeServe(
"MaxVolumesPerNode": s.opts.MaxVolumesPerNode,
"IsQuotaEnabled": s.opts.IsQuotaEnabled,
"ExternalAccess": s.opts.ExternalAccess,
"KubeNodeName": s.opts.KubeNodeName,
}

Log.WithFields(fields).Infof("configured %s", Name)
Expand Down Expand Up @@ -451,9 +449,6 @@ func (s *service) BeforeServe(
}
}
}
if kubeNodeName, ok := csictx.LookupEnv(ctx, EnvKubeNodeName); ok {
opts.KubeNodeName = kubeNodeName
}

// log csiNode topology keys
if err = s.logCsiNodeTopologyKeys(); err != nil {
Expand Down Expand Up @@ -1658,9 +1653,13 @@ func (s *service) GetNodeLabels(ctx context.Context) (map[string]string, error)
}
K8sClientset = k8sutils.Clientset
}

hostName, ok := os.LookupEnv("HOSTNAME")
if !ok {
return nil, status.Errorf(codes.FailedPrecondition, "%s not set", "HOSTNAME")
}
hostName = strings.ToLower(hostName)
// access the API to fetch node object
node, err := K8sClientset.CoreV1().Nodes().Get(context.TODO(), s.opts.KubeNodeName, v1.GetOptions{})
node, err := K8sClientset.CoreV1().Nodes().Get(context.TODO(), hostName, v1.GetOptions{})
if err != nil {
return nil, status.Error(codes.Internal, GetMessage("Unable to fetch the node labels. Error: %v", err))
}
Expand Down
4 changes: 2 additions & 2 deletions service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ func mockGetNodeLabelsWithInvalidVolumeLimits(ctx context.Context, s *service) (
}

func (f *feature) setFakeNode() (*v1.Node, error) {
f.service.opts.KubeNodeName = "node1"
os.Setenv("HOSTNAME", "node1")
fakeNode := &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node1",
Expand Down Expand Up @@ -1896,7 +1896,7 @@ func mockLookupEnv(ctx context.Context, key string) (string, bool) {
}

func (f *feature) iCallGetNodeLabelsWithInvalidNode() error {
f.service.opts.KubeNodeName = "node2"
os.Setenv("HOSTNAME", "node2")
_, f.err = f.service.GetNodeLabels(f.context)
return nil
}
Expand Down

0 comments on commit b87d685

Please sign in to comment.