mirror of https://github.com/k3s-io/k3s
Reduce csipb dependencies
Remove csipb dependency from everywhere except the CSI client in preperation for supporting multiple CSI clients.pull/58/head
parent
8f666d9e41
commit
2b44ec5e9c
|
@ -23,6 +23,7 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
|
@ -86,6 +87,7 @@ filegroup(
|
||||||
name = "all-srcs",
|
name = "all-srcs",
|
||||||
srcs = [
|
srcs = [
|
||||||
":package-srcs",
|
":package-srcs",
|
||||||
|
"//pkg/volume/csi/csiv0:all-srcs",
|
||||||
"//pkg/volume/csi/fake:all-srcs",
|
"//pkg/volume/csi/fake:all-srcs",
|
||||||
"//pkg/volume/csi/nodeinfomanager:all-srcs",
|
"//pkg/volume/csi/nodeinfomanager:all-srcs",
|
||||||
],
|
],
|
||||||
|
|
|
@ -29,7 +29,6 @@ import (
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
csipb "github.com/container-storage-interface/spec/lib/go/csi"
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
storage "k8s.io/api/storage/v1beta1"
|
storage "k8s.io/api/storage/v1beta1"
|
||||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
@ -349,7 +348,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||||
stageUnstageSet, err := hasStageUnstageCapability(ctx, csi)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -529,7 +528,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||||
stageUnstageSet, err := hasStageUnstageCapability(ctx, csi)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(log("attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v", err))
|
klog.Errorf(log("attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v", err))
|
||||||
return err
|
return err
|
||||||
|
@ -563,24 +562,6 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasStageUnstageCapability(ctx context.Context, csi csiClient) (bool, error) {
|
|
||||||
capabilities, err := csi.NodeGetCapabilities(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
stageUnstageSet := false
|
|
||||||
if capabilities == nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
for _, capability := range capabilities {
|
|
||||||
if capability.GetRpc().GetType() == csipb.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME {
|
|
||||||
stageUnstageSet = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stageUnstageSet, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getAttachmentName returns csi-<sha252(volName,csiDriverName,NodeName>
|
// getAttachmentName returns csi-<sha252(volName,csiDriverName,NodeName>
|
||||||
func getAttachmentName(volName, csiDriverName, nodeName string) string {
|
func getAttachmentName(volName, csiDriverName, nodeName string) string {
|
||||||
result := sha256.Sum256([]byte(fmt.Sprintf("%s%s%s", volName, csiDriverName, nodeName)))
|
result := sha256.Sum256([]byte(fmt.Sprintf("%s%s%s", volName, csiDriverName, nodeName)))
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
|
||||||
klog.V(4).Infof(log("blockMapper.stageVolumeForBlock stagingPath set [%s]", stagingPath))
|
klog.V(4).Infof(log("blockMapper.stageVolumeForBlock stagingPath set [%s]", stagingPath))
|
||||||
|
|
||||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||||
stageUnstageSet, err := hasStageUnstageCapability(ctx, csi)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
klog.Error(log("blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -287,7 +287,7 @@ func (m *csiBlockMapper) unpublishVolumeForBlock(ctx context.Context, csi csiCli
|
||||||
// unstageVolumeForBlock unstages a block volume from stagingPath
|
// unstageVolumeForBlock unstages a block volume from stagingPath
|
||||||
func (m *csiBlockMapper) unstageVolumeForBlock(ctx context.Context, csi csiClient, stagingPath string) error {
|
func (m *csiBlockMapper) unstageVolumeForBlock(ctx context.Context, csi csiClient, stagingPath string) error {
|
||||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||||
stageUnstageSet, err := hasStageUnstageCapability(ctx, csi)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
klog.Error(log("blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -36,7 +36,7 @@ type csiClient interface {
|
||||||
NodeGetInfo(ctx context.Context) (
|
NodeGetInfo(ctx context.Context) (
|
||||||
nodeID string,
|
nodeID string,
|
||||||
maxVolumePerNode int64,
|
maxVolumePerNode int64,
|
||||||
accessibleTopology *csipb.Topology,
|
accessibleTopology map[string]string,
|
||||||
err error)
|
err error)
|
||||||
NodePublishVolume(
|
NodePublishVolume(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
@ -66,7 +66,7 @@ type csiClient interface {
|
||||||
volumeContext map[string]string,
|
volumeContext map[string]string,
|
||||||
) error
|
) error
|
||||||
NodeUnstageVolume(ctx context.Context, volID, stagingTargetPath string) error
|
NodeUnstageVolume(ctx context.Context, volID, stagingTargetPath string) error
|
||||||
NodeGetCapabilities(ctx context.Context) ([]*csipb.NodeServiceCapability, error)
|
NodeSupportsStageUnstage(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// csiClient encapsulates all csi-plugin methods
|
// csiClient encapsulates all csi-plugin methods
|
||||||
|
@ -110,7 +110,7 @@ func newCsiDriverClient(driverName string) *csiDriverClient {
|
||||||
func (c *csiDriverClient) NodeGetInfo(ctx context.Context) (
|
func (c *csiDriverClient) NodeGetInfo(ctx context.Context) (
|
||||||
nodeID string,
|
nodeID string,
|
||||||
maxVolumePerNode int64,
|
maxVolumePerNode int64,
|
||||||
accessibleTopology *csipb.Topology,
|
accessibleTopology map[string]string,
|
||||||
err error) {
|
err error) {
|
||||||
klog.V(4).Info(log("calling NodeGetInfo rpc"))
|
klog.V(4).Info(log("calling NodeGetInfo rpc"))
|
||||||
|
|
||||||
|
@ -125,7 +125,11 @@ func (c *csiDriverClient) NodeGetInfo(ctx context.Context) (
|
||||||
return "", 0, nil, err
|
return "", 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.GetNodeId(), res.GetMaxVolumesPerNode(), res.GetAccessibleTopology(), nil
|
topology := res.GetAccessibleTopology()
|
||||||
|
if topology != nil {
|
||||||
|
accessibleTopology = topology.Segments
|
||||||
|
}
|
||||||
|
return res.GetNodeId(), res.GetMaxVolumesPerNode(), accessibleTopology, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *csiDriverClient) NodePublishVolume(
|
func (c *csiDriverClient) NodePublishVolume(
|
||||||
|
@ -288,21 +292,33 @@ func (c *csiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stagingT
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *csiDriverClient) NodeGetCapabilities(ctx context.Context) ([]*csipb.NodeServiceCapability, error) {
|
func (c *csiDriverClient) NodeSupportsStageUnstage(ctx context.Context) (bool, error) {
|
||||||
klog.V(4).Info(log("calling NodeGetCapabilities rpc"))
|
klog.V(4).Info(log("calling NodeGetCapabilities rpc to determine if NodeSupportsStageUnstage"))
|
||||||
|
|
||||||
nodeClient, closer, err := c.nodeClientCreator(c.driverName)
|
nodeClient, closer, err := c.nodeClientCreator(c.driverName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
req := &csipb.NodeGetCapabilitiesRequest{}
|
req := &csipb.NodeGetCapabilitiesRequest{}
|
||||||
resp, err := nodeClient.NodeGetCapabilities(ctx, req)
|
resp, err := nodeClient.NodeGetCapabilities(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return false, err
|
||||||
}
|
}
|
||||||
return resp.GetCapabilities(), nil
|
|
||||||
|
capabilities := resp.GetCapabilities()
|
||||||
|
|
||||||
|
stageUnstageSet := false
|
||||||
|
if capabilities == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
for _, capability := range capabilities {
|
||||||
|
if capability.GetRpc().GetType() == csipb.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME {
|
||||||
|
stageUnstageSet = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stageUnstageSet, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func asCSIAccessMode(am api.PersistentVolumeAccessMode) csipb.VolumeCapability_AccessMode_Mode {
|
func asCSIAccessMode(am api.PersistentVolumeAccessMode) csipb.VolumeCapability_AccessMode_Mode {
|
||||||
|
|
|
@ -43,10 +43,14 @@ func newFakeCsiDriverClient(t *testing.T, stagingCapable bool) *fakeCsiDriverCli
|
||||||
func (c *fakeCsiDriverClient) NodeGetInfo(ctx context.Context) (
|
func (c *fakeCsiDriverClient) NodeGetInfo(ctx context.Context) (
|
||||||
nodeID string,
|
nodeID string,
|
||||||
maxVolumePerNode int64,
|
maxVolumePerNode int64,
|
||||||
accessibleTopology *csipb.Topology,
|
accessibleTopology map[string]string,
|
||||||
err error) {
|
err error) {
|
||||||
resp, err := c.nodeClient.NodeGetInfo(ctx, &csipb.NodeGetInfoRequest{})
|
resp, err := c.nodeClient.NodeGetInfo(ctx, &csipb.NodeGetInfoRequest{})
|
||||||
return resp.GetNodeId(), resp.GetMaxVolumesPerNode(), resp.GetAccessibleTopology(), err
|
topology := resp.GetAccessibleTopology()
|
||||||
|
if topology != nil {
|
||||||
|
accessibleTopology = topology.Segments
|
||||||
|
}
|
||||||
|
return resp.GetNodeId(), resp.GetMaxVolumesPerNode(), accessibleTopology, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeCsiDriverClient) NodePublishVolume(
|
func (c *fakeCsiDriverClient) NodePublishVolume(
|
||||||
|
@ -140,14 +144,26 @@ func (c *fakeCsiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stag
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeCsiDriverClient) NodeGetCapabilities(ctx context.Context) ([]*csipb.NodeServiceCapability, error) {
|
func (c *fakeCsiDriverClient) NodeSupportsStageUnstage(ctx context.Context) (bool, error) {
|
||||||
c.t.Log("calling fake.NodeGetCapabilities...")
|
c.t.Log("calling fake.NodeGetCapabilities for NodeSupportsStageUnstage...")
|
||||||
req := &csipb.NodeGetCapabilitiesRequest{}
|
req := &csipb.NodeGetCapabilitiesRequest{}
|
||||||
resp, err := c.nodeClient.NodeGetCapabilities(ctx, req)
|
resp, err := c.nodeClient.NodeGetCapabilities(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return false, err
|
||||||
}
|
}
|
||||||
return resp.GetCapabilities(), nil
|
|
||||||
|
capabilities := resp.GetCapabilities()
|
||||||
|
|
||||||
|
stageUnstageSet := false
|
||||||
|
if capabilities == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
for _, capability := range capabilities {
|
||||||
|
if capability.GetRpc().GetType() == csipb.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME {
|
||||||
|
stageUnstageSet = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stageUnstageSet, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupClient(t *testing.T, stageUnstageSet bool) csiClient {
|
func setupClient(t *testing.T, stageUnstageSet bool) csiClient {
|
||||||
|
@ -173,7 +189,7 @@ func TestClientNodeGetInfo(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
expectedNodeID string
|
expectedNodeID string
|
||||||
expectedMaxVolumePerNode int64
|
expectedMaxVolumePerNode int64
|
||||||
expectedAccessibleTopology *csipb.Topology
|
expectedAccessibleTopology map[string]string
|
||||||
mustFail bool
|
mustFail bool
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
|
@ -181,9 +197,7 @@ func TestClientNodeGetInfo(t *testing.T) {
|
||||||
name: "test ok",
|
name: "test ok",
|
||||||
expectedNodeID: "node1",
|
expectedNodeID: "node1",
|
||||||
expectedMaxVolumePerNode: 16,
|
expectedMaxVolumePerNode: 16,
|
||||||
expectedAccessibleTopology: &csipb.Topology{
|
expectedAccessibleTopology: map[string]string{"com.example.csi-topology/zone": "zone1"},
|
||||||
Segments: map[string]string{"com.example.csi-topology/zone": "zone1"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "grpc error",
|
name: "grpc error",
|
||||||
|
@ -204,7 +218,9 @@ func TestClientNodeGetInfo(t *testing.T) {
|
||||||
nodeClient.SetNodeGetInfoResp(&csipb.NodeGetInfoResponse{
|
nodeClient.SetNodeGetInfoResp(&csipb.NodeGetInfoResponse{
|
||||||
NodeId: tc.expectedNodeID,
|
NodeId: tc.expectedNodeID,
|
||||||
MaxVolumesPerNode: tc.expectedMaxVolumePerNode,
|
MaxVolumesPerNode: tc.expectedMaxVolumePerNode,
|
||||||
AccessibleTopology: tc.expectedAccessibleTopology,
|
AccessibleTopology: &csipb.Topology{
|
||||||
|
Segments: tc.expectedAccessibleTopology,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return nodeClient, fakeCloser, nil
|
return nodeClient, fakeCloser, nil
|
||||||
},
|
},
|
||||||
|
@ -222,7 +238,7 @@ func TestClientNodeGetInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(accessibleTopology, tc.expectedAccessibleTopology) {
|
if !reflect.DeepEqual(accessibleTopology, tc.expectedAccessibleTopology) {
|
||||||
t.Errorf("expected accessibleTopology: %v; got: %v", *tc.expectedAccessibleTopology, *accessibleTopology)
|
t.Errorf("expected accessibleTopology: %v; got: %v", tc.expectedAccessibleTopology, accessibleTopology)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tc.mustFail {
|
if !tc.mustFail {
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
|
||||||
|
|
||||||
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
|
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
|
||||||
deviceMountPath := ""
|
deviceMountPath := ""
|
||||||
stageUnstageSet, err := hasStageUnstageCapability(ctx, csi)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capabilty: %v", err))
|
klog.Error(log("mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capabilty: %v", err))
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -21,7 +21,6 @@ go_library(
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
|
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
|
||||||
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned:go_default_library",
|
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned:go_default_library",
|
||||||
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
|
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -63,7 +62,6 @@ go_test(
|
||||||
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
|
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
|
||||||
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
|
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
|
||||||
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned/fake:go_default_library",
|
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned/fake:go_default_library",
|
||||||
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
|
|
||||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
csipb "github.com/container-storage-interface/spec/lib/go/csi"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
@ -40,7 +41,6 @@ import (
|
||||||
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -75,7 +75,7 @@ type Interface interface {
|
||||||
// Record in the cluster the given node information from the CSI driver with the given name.
|
// Record in the cluster the given node information from the CSI driver with the given name.
|
||||||
// Concurrent calls to InstallCSIDriver() is allowed, but they should not be intertwined with calls
|
// Concurrent calls to InstallCSIDriver() is allowed, but they should not be intertwined with calls
|
||||||
// to other methods in this interface.
|
// to other methods in this interface.
|
||||||
InstallCSIDriver(driverName string, driverNodeID string, maxVolumeLimit int64, topology *csipb.Topology) error
|
InstallCSIDriver(driverName string, driverNodeID string, maxVolumeLimit int64, topology map[string]string) error
|
||||||
|
|
||||||
// Remove in the cluster node information from the CSI driver with the given name.
|
// Remove in the cluster node information from the CSI driver with the given name.
|
||||||
// Concurrent calls to UninstallCSIDriver() is allowed, but they should not be intertwined with calls
|
// Concurrent calls to UninstallCSIDriver() is allowed, but they should not be intertwined with calls
|
||||||
|
@ -97,7 +97,7 @@ func NewNodeInfoManager(
|
||||||
// CSINodeInfo object. If the CSINodeInfo object doesn't yet exist, it will be created.
|
// CSINodeInfo object. If the CSINodeInfo object doesn't yet exist, it will be created.
|
||||||
// If multiple calls to InstallCSIDriver() are made in parallel, some calls might receive Node or
|
// If multiple calls to InstallCSIDriver() are made in parallel, some calls might receive Node or
|
||||||
// CSINodeInfo update conflicts, which causes the function to retry the corresponding update.
|
// CSINodeInfo update conflicts, which causes the function to retry the corresponding update.
|
||||||
func (nim *nodeInfoManager) InstallCSIDriver(driverName string, driverNodeID string, maxAttachLimit int64, topology *csipb.Topology) error {
|
func (nim *nodeInfoManager) InstallCSIDriver(driverName string, driverNodeID string, maxAttachLimit int64, topology map[string]string) error {
|
||||||
if driverNodeID == "" {
|
if driverNodeID == "" {
|
||||||
return fmt.Errorf("error adding CSI driver node info: driverNodeID must not be empty")
|
return fmt.Errorf("error adding CSI driver node info: driverNodeID must not be empty")
|
||||||
}
|
}
|
||||||
|
@ -321,13 +321,13 @@ func removeNodeIDFromNode(csiDriverName string) nodeUpdateFunc {
|
||||||
|
|
||||||
// updateTopologyLabels returns a function that updates labels of a Node object with the given
|
// updateTopologyLabels returns a function that updates labels of a Node object with the given
|
||||||
// topology information.
|
// topology information.
|
||||||
func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
|
func updateTopologyLabels(topology map[string]string) nodeUpdateFunc {
|
||||||
return func(node *v1.Node) (*v1.Node, bool, error) {
|
return func(node *v1.Node) (*v1.Node, bool, error) {
|
||||||
if topology == nil || len(topology.Segments) == 0 {
|
if topology == nil || len(topology) == 0 {
|
||||||
return node, false, nil
|
return node, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range topology.Segments {
|
for k, v := range topology {
|
||||||
if curVal, exists := node.Labels[k]; exists && curVal != v {
|
if curVal, exists := node.Labels[k]; exists && curVal != v {
|
||||||
return nil, false, fmt.Errorf("detected topology value collision: driver reported %q:%q but existing label is %q:%q", k, v, k, curVal)
|
return nil, false, fmt.Errorf("detected topology value collision: driver reported %q:%q but existing label is %q:%q", k, v, k, curVal)
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
|
||||||
if node.Labels == nil {
|
if node.Labels == nil {
|
||||||
node.Labels = make(map[string]string)
|
node.Labels = make(map[string]string)
|
||||||
}
|
}
|
||||||
for k, v := range topology.Segments {
|
for k, v := range topology {
|
||||||
node.Labels[k] = v
|
node.Labels[k] = v
|
||||||
}
|
}
|
||||||
return node, true, nil
|
return node, true, nil
|
||||||
|
@ -346,7 +346,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
|
||||||
func (nim *nodeInfoManager) updateCSINodeInfo(
|
func (nim *nodeInfoManager) updateCSINodeInfo(
|
||||||
driverName string,
|
driverName string,
|
||||||
driverNodeID string,
|
driverNodeID string,
|
||||||
topology *csipb.Topology) error {
|
topology map[string]string) error {
|
||||||
|
|
||||||
csiKubeClient := nim.volumeHost.GetCSIClient()
|
csiKubeClient := nim.volumeHost.GetCSIClient()
|
||||||
if csiKubeClient == nil {
|
if csiKubeClient == nil {
|
||||||
|
@ -371,7 +371,7 @@ func (nim *nodeInfoManager) tryUpdateCSINodeInfo(
|
||||||
csiKubeClient csiclientset.Interface,
|
csiKubeClient csiclientset.Interface,
|
||||||
driverName string,
|
driverName string,
|
||||||
driverNodeID string,
|
driverNodeID string,
|
||||||
topology *csipb.Topology) error {
|
topology map[string]string) error {
|
||||||
|
|
||||||
nodeInfo, err := csiKubeClient.CsiV1alpha1().CSINodeInfos().Get(string(nim.nodeName), metav1.GetOptions{})
|
nodeInfo, err := csiKubeClient.CsiV1alpha1().CSINodeInfos().Get(string(nim.nodeName), metav1.GetOptions{})
|
||||||
if nodeInfo == nil || errors.IsNotFound(err) {
|
if nodeInfo == nil || errors.IsNotFound(err) {
|
||||||
|
@ -428,7 +428,7 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
|
||||||
nodeInfo *csiv1alpha1.CSINodeInfo,
|
nodeInfo *csiv1alpha1.CSINodeInfo,
|
||||||
driverName string,
|
driverName string,
|
||||||
driverNodeID string,
|
driverNodeID string,
|
||||||
topology *csipb.Topology) error {
|
topology map[string]string) error {
|
||||||
|
|
||||||
csiKubeClient := nim.volumeHost.GetCSIClient()
|
csiKubeClient := nim.volumeHost.GetCSIClient()
|
||||||
if csiKubeClient == nil {
|
if csiKubeClient == nil {
|
||||||
|
@ -436,11 +436,9 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
topologyKeys := make(sets.String)
|
topologyKeys := make(sets.String)
|
||||||
if topology != nil {
|
for k := range topology {
|
||||||
for k := range topology.Segments {
|
|
||||||
topologyKeys.Insert(k)
|
topologyKeys.Insert(k)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
specModified := true
|
specModified := true
|
||||||
statusModified := true
|
statusModified := true
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
@ -49,7 +48,7 @@ type testcase struct {
|
||||||
existingNode *v1.Node
|
existingNode *v1.Node
|
||||||
existingNodeInfo *csiv1alpha1.CSINodeInfo
|
existingNodeInfo *csiv1alpha1.CSINodeInfo
|
||||||
inputNodeID string
|
inputNodeID string
|
||||||
inputTopology *csi.Topology
|
inputTopology map[string]string
|
||||||
inputVolumeLimit int64
|
inputVolumeLimit int64
|
||||||
expectedNodeIDMap map[string]string
|
expectedNodeIDMap map[string]string
|
||||||
expectedTopologyMap map[string]sets.String
|
expectedTopologyMap map[string]sets.String
|
||||||
|
@ -71,11 +70,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
driverName: "com.example.csi/driver1",
|
driverName: "com.example.csi/driver1",
|
||||||
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNodeIDMap: map[string]string{
|
||||||
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
||||||
},
|
},
|
||||||
|
@ -104,11 +101,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNodeIDMap: map[string]string{
|
||||||
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
||||||
},
|
},
|
||||||
|
@ -134,11 +129,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
nil, /* topologyKeys */
|
nil, /* topologyKeys */
|
||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNodeIDMap: map[string]string{
|
||||||
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
||||||
},
|
},
|
||||||
|
@ -168,11 +161,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNodeIDMap: map[string]string{
|
||||||
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
||||||
"net.example.storage/other-driver": "net.example.storage/test-node",
|
"net.example.storage/other-driver": "net.example.storage/test-node",
|
||||||
|
@ -205,11 +196,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/zone": "other-zone",
|
"com.example.csi/zone": "other-zone",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectFail: true,
|
expectFail: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -231,11 +220,9 @@ func TestInstallCSIDriver(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/other-node",
|
inputNodeID: "com.example.csi/other-node",
|
||||||
inputTopology: &csi.Topology{
|
inputTopology: map[string]string{
|
||||||
Segments: map[string]string{
|
|
||||||
"com.example.csi/rack": "rack1",
|
"com.example.csi/rack": "rack1",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNodeIDMap: map[string]string{
|
||||||
"com.example.csi/driver1": "com.example.csi/other-node",
|
"com.example.csi/driver1": "com.example.csi/other-node",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue