Skip to content

Commit

Permalink
Changes for getting NodeUID
Browse files Browse the repository at this point in the history
  • Loading branch information
harshitap26 committed Oct 10, 2024
1 parent a770eb2 commit 0f082ad
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 51 deletions.
4 changes: 1 addition & 3 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export SDC_GUID=$(/bin/emc/scaleio/drv_cfg --query_guid)
# Alternate GUID is for another system for testing expose volume to multiple hosts
export ALT_GUID=

# Kubernetes variables
export KUBE_CONFIG=/root/.kube/config
export KUBE_NODE_NAME=""
# Interface variables
export NODE_INTERFACES="nodeName:interfaceName"

#Debug variables for goscaleio library
Expand Down
2 changes: 2 additions & 0 deletions service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,13 +1624,15 @@ func (s *service) ControllerUnpublishVolume(
ipAddresses, err = s.findNetworkInterfaceIPs()
if err != nil || len(ipAddresses) == 0 {

Log.Printf("ControllerUnPublish - No network interfaces found, trying to get SDC IPs")
ipAddresses, err = s.getSDCIPs(nodeID, systemID)
if err != nil {
return nil, status.Errorf(codes.NotFound, "%s", err.Error())
} else if len(ipAddresses) == 0 {
return nil, status.Errorf(codes.NotFound, "%s", "received empty sdcIPs")
}
}
Log.Printf("ControllerUnPublish - ipAddresses %v", ipAddresses)

// unexport for NFS
err = s.unexportFilesystem(ctx, req, adminClient, fs, req.GetVolumeId(), ipAddresses, nodeID)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ sh validate_http_unauthorized.sh
rc=$?
if [ $rc -ne 0 ]; then echo "failed http unauthorized test"; exit $rc; fi

rm -f unix.sock
source ../../env.sh
rm -f unix_sock
. ../../env.sh
echo $SDC_GUID
GOOS=linux CGO_ENABLED=0 GO111MODULE=on go test -v -coverprofile=c.linux.out -timeout 60m -coverpkg=github.com/dell/csi-vxflexos/service *test.go &
if [ -f ./csi-sanity ] ; then
Expand Down
128 changes: 82 additions & 46 deletions test/integration/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ import (
"syscall"
"time"

"github.com/dell/csi-vxflexos/v2/k8sutils"

"github.com/dell/csi-vxflexos/v2/service"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/clientcmd"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/cucumber/godog"
Expand All @@ -57,8 +56,9 @@ const (
MaxRetries = 10
RetrySleepTime = 10 * time.Second
SleepTime = 100 * time.Millisecond
Pool1 = "SP-SW_SSD-1"
NfsPool = "SP-SW_SSD-1"
Pool1 = "pool1"
NfsPool = "Env8-SP-SW_SSD-1"
NodeName = "node1"
DriverConfigMap = "vxflexos-config-params"
DriverNamespace = "vxflexos"
)
Expand Down Expand Up @@ -226,21 +226,65 @@ func (f *feature) getArrayConfig() (map[string]*ArrayConnectionData, error) {
return arrays, nil
}

func (f *feature) GetNodeUID() (string, error) {
kubeConfig := os.Getenv("KUBE_CONFIG")
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
if err != nil {
return "", fmt.Errorf("error building kubeconfig: %s", err.Error())
func (f *feature) createConfigMap() error {
var configYAMLContent strings.Builder

for _, iface := range strings.Split(os.Getenv("NODE_INTERFACES"), ",") {

interfaceData := strings.Split(strings.TrimSpace(iface), ":")
interfaceIP, err := f.getIPAddressByInterface(interfaceData[1])
if err != nil {
fmt.Printf("Error while getting IP address for interface %s: %v\n", interfaceData[1], err)
continue
}
configYAMLContent.WriteString(fmt.Sprintf(" %s: %s\n", interfaceData[0], interfaceIP))
}

configMapData := map[string]string{
"driver-config-params.yaml": fmt.Sprintf(`interfaceNames:
%s`, configYAMLContent.String()),
}

clientSet, err := kubernetes.NewForConfig(config)
configMap := &apiv1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
Name: DriverConfigMap,
Namespace: DriverNamespace,
},
Data: configMapData,
}

_, err := service.K8sClientset.CoreV1().ConfigMaps(DriverNamespace).Create(context.TODO(), configMap, v1.CreateOptions{})
if err != nil {
return "", fmt.Errorf("error building kubernetes clientset: %s", err.Error())
fmt.Printf("Failed to create configMap: %v\n", err)
return err
}
return nil
}

func (f *feature) setFakeNode() (*apiv1.Node, error) {
fakeNode := &apiv1.Node{
ObjectMeta: v1.ObjectMeta{
Name: NodeName,
Labels: map[string]string{"label1": "value1", "label2": "value2"},
UID: "1aa4c285-d41b-4911-bf3e-621253bfbade",
},
}
return service.K8sClientset.CoreV1().Nodes().Create(context.TODO(), fakeNode, v1.CreateOptions{})
}

func (f *feature) GetNodeUID() (string, error) {
if service.K8sClientset == nil {
err := k8sutils.CreateKubeClientSet()
if err != nil {
return "", fmt.Errorf("init client failed with error: %v", err)
}
service.K8sClientset = k8sutils.Clientset
}

node, err := clientSet.CoreV1().Nodes().Get(context.TODO(), os.Getenv("KUBE_NODE_NAME"), v1.GetOptions{})
// access the API to fetch node object
node, err := service.K8sClientset.CoreV1().Nodes().Get(context.TODO(), NodeName, v1.GetOptions{})
if err != nil {
return "", fmt.Errorf("error getting node: %s", err.Error())
return "", fmt.Errorf("unable to fetch the node details. Error: %v", err)
}
return string(node.UID), nil
}
Expand Down Expand Up @@ -2257,42 +2301,21 @@ func (f *feature) controllerPublishVolumeForNfsWithoutSDC(id string) error {
if f.createVolumeRequest == nil {
return nil
}
req := f.getControllerPublishVolumeRequest()
req.VolumeId = id
req.NodeId, _ = f.GetNodeUID()

clientSet := fake.NewSimpleClientset()
service.K8sClientset = clientSet
var configYAMLContent strings.Builder

for _, iface := range strings.Split(os.Getenv("NODE_INTERFACES"), ",") {

interfaceData := strings.Split(strings.TrimSpace(iface), ":")
interfaceIP, err := f.getIPAddressByInterface(interfaceData[1])
if err != nil {
fmt.Printf("Error while getting IP address for interface %s: %v\n", interfaceData[1], err)
continue
}
configYAMLContent.WriteString(fmt.Sprintf(" %s: %s\n", interfaceData[0], interfaceIP))
}

configMapData := map[string]string{
"driver-config-params.yaml": fmt.Sprintf(`interfaceNames:
%s`, configYAMLContent.String()),
_, err := f.setFakeNode()
if err != nil {
return fmt.Errorf("setFakeNode failed with error: %v", err)
}

configMap := &apiv1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
Name: DriverConfigMap,
Namespace: DriverNamespace,
},
Data: configMapData,
}
req := f.getControllerPublishVolumeRequest()
req.VolumeId = id
req.NodeId, _ = f.GetNodeUID()

_, err := clientSet.CoreV1().ConfigMaps(DriverNamespace).Create(context.TODO(), configMap, v1.CreateOptions{})
err = f.createConfigMap()
if err != nil {
fmt.Printf("Failed to create configMap: %v\n", err)
return err
return fmt.Errorf("createConfigMap failed with error: %v", err)
}

if f.arrays == nil {
Expand Down Expand Up @@ -2503,12 +2526,25 @@ func (f *feature) controllerUnpublishVolumeForNfsWithoutSDC(id string) error {
if f.createVolumeRequest == nil {
return nil
}

clientSet := fake.NewSimpleClientset()
service.K8sClientset = clientSet
_, err := f.setFakeNode()
if err != nil {
return fmt.Errorf("setFakeNode failed with error: %v", err)
}

req := new(csi.ControllerUnpublishVolumeRequest)
req.VolumeId = id
req.NodeId, _ = f.GetNodeUID()
err = f.createConfigMap()
if err != nil {
return fmt.Errorf("createConfigMap failed with error: %v", err)
}

ctx := context.Background()
client := csi.NewControllerClient(grpcClient)
_, err := client.ControllerUnpublishVolume(ctx, req)
_, err = client.ControllerUnpublishVolume(ctx, req)
return err
}

Expand Down

0 comments on commit 0f082ad

Please sign in to comment.