mirror of
https://github.com/kastenhq/kubestr.git
synced 2024-12-14 11:57:56 +00:00
Support csi v1 (#46)
* support csi v1 * fio file * Adding missing files * adding missing UT for version
This commit is contained in:
parent
461543547c
commit
782d565c18
8 changed files with 143 additions and 73 deletions
24
pkg/common/common.go
Normal file
24
pkg/common/common.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
const (
|
||||||
|
// VolSnapClassAlphaDriverKey describes alpha driver key
|
||||||
|
VolSnapClassAlphaDriverKey = "snapshotter"
|
||||||
|
// VolSnapClassBetaDriverKey describes beta driver key
|
||||||
|
VolSnapClassBetaDriverKey = "driver"
|
||||||
|
// VolSnapClassStableDriverKey describes the stable driver key
|
||||||
|
VolSnapClassStableDriverKey = "driver"
|
||||||
|
// DefaultPodImage the default pod image
|
||||||
|
DefaultPodImage = "ghcr.io/kastenhq/kubestr:latest"
|
||||||
|
// SnapGroupName describes the snapshot group name
|
||||||
|
SnapGroupName = "snapshot.storage.k8s.io"
|
||||||
|
// VolumeSnapshotClassResourcePlural describes volume snapshot classses
|
||||||
|
VolumeSnapshotClassResourcePlural = "volumesnapshotclasses"
|
||||||
|
// VolumeSnapshotResourcePlural is "volumesnapshots"
|
||||||
|
VolumeSnapshotResourcePlural = "volumesnapshots"
|
||||||
|
// SnapshotAlphaVersion is the apiversion of the alpha relase
|
||||||
|
SnapshotAlphaVersion = "snapshot.storage.k8s.io/v1alpha1"
|
||||||
|
// SnapshotBetaVersion is the apiversion of the beta relase
|
||||||
|
SnapshotBetaVersion = "snapshot.storage.k8s.io/v1beta1"
|
||||||
|
// SnapshotStableVersion is the apiversion of the stable release
|
||||||
|
SnapshotStableVersion = "snapshot.storage.k8s.io/v1"
|
||||||
|
)
|
|
@ -8,6 +8,7 @@ import (
|
||||||
kankube "github.com/kanisterio/kanister/pkg/kube"
|
kankube "github.com/kanisterio/kanister/pkg/kube"
|
||||||
kansnapshot "github.com/kanisterio/kanister/pkg/kube/snapshot"
|
kansnapshot "github.com/kanisterio/kanister/pkg/kube/snapshot"
|
||||||
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/kastenhq/kubestr/pkg/csi/types"
|
"github.com/kastenhq/kubestr/pkg/csi/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
@ -21,24 +22,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SnapGroupName describes the snapshot group name
|
|
||||||
SnapGroupName = "snapshot.storage.k8s.io"
|
|
||||||
// VolumeSnapshotClassResourcePlural describes volume snapshot classses
|
|
||||||
VolumeSnapshotClassResourcePlural = "volumesnapshotclasses"
|
|
||||||
// VolumeSnapshotResourcePlural is "volumesnapshots"
|
|
||||||
VolumeSnapshotResourcePlural = "volumesnapshots"
|
|
||||||
// VolSnapClassAlphaDriverKey describes alpha driver key
|
|
||||||
VolSnapClassAlphaDriverKey = "snapshotter"
|
|
||||||
// VolSnapClassBetaDriverKey describes beta driver key
|
|
||||||
VolSnapClassBetaDriverKey = "driver"
|
|
||||||
alphaVersion = "snapshot.storage.k8s.io/v1alpha1"
|
|
||||||
betaVersion = "snapshot.storage.k8s.io/v1beta1"
|
|
||||||
originalPVCGenerateName = "kubestr-csi-original-pvc"
|
originalPVCGenerateName = "kubestr-csi-original-pvc"
|
||||||
originalPodGenerateName = "kubestr-csi-original-pod"
|
originalPodGenerateName = "kubestr-csi-original-pod"
|
||||||
clonedPVCGenerateName = "kubestr-csi-cloned-pvc"
|
clonedPVCGenerateName = "kubestr-csi-cloned-pvc"
|
||||||
clonedPodGenerateName = "kubestr-csi-cloned-pod"
|
clonedPodGenerateName = "kubestr-csi-cloned-pod"
|
||||||
createdByLabel = "created-by-kubestr-csi"
|
createdByLabel = "created-by-kubestr-csi"
|
||||||
DefaultPodImage = "ghcr.io/kastenhq/kubestr:latest"
|
|
||||||
clonePrefix = "kubestr-clone-"
|
clonePrefix = "kubestr-clone-"
|
||||||
snapshotPrefix = "kubestr-snapshot-"
|
snapshotPrefix = "kubestr-snapshot-"
|
||||||
)
|
)
|
||||||
|
@ -347,7 +335,7 @@ func (o *validateOperations) ValidateVolumeSnapshotClass(ctx context.Context, vo
|
||||||
if o.dynCli == nil {
|
if o.dynCli == nil {
|
||||||
return nil, fmt.Errorf("dynCli not initialized")
|
return nil, fmt.Errorf("dynCli not initialized")
|
||||||
}
|
}
|
||||||
VolSnapClassGVR := schema.GroupVersionResource{Group: SnapGroupName, Version: groupVersion.Version, Resource: VolumeSnapshotClassResourcePlural}
|
VolSnapClassGVR := schema.GroupVersionResource{Group: common.SnapGroupName, Version: groupVersion.Version, Resource: common.VolumeSnapshotClassResourcePlural}
|
||||||
return o.dynCli.Resource(VolSnapClassGVR).Get(ctx, volumeSnapshotClass, metav1.GetOptions{})
|
return o.dynCli.Resource(VolSnapClassGVR).Get(ctx, volumeSnapshotClass, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +400,7 @@ func (c *applicationCreate) CreatePod(ctx context.Context, args *types.CreatePod
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if args.ContainerImage == "" {
|
if args.ContainerImage == "" {
|
||||||
args.ContainerImage = DefaultPodImage
|
args.ContainerImage = common.DefaultPodImage
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
|
@ -526,7 +514,7 @@ func (c *snapshotCreate) CreateFromSourceCheck(ctx context.Context, snapshotter
|
||||||
return errors.Wrapf(err, "Failed to create a VolumeSnapshotClass to use to restore the snapshot")
|
return errors.Wrapf(err, "Failed to create a VolumeSnapshotClass to use to restore the snapshot")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
VolSnapClassGVR := schema.GroupVersionResource{Group: SnapGroupName, Version: SnapshotGroupVersion.Version, Resource: VolumeSnapshotClassResourcePlural}
|
VolSnapClassGVR := schema.GroupVersionResource{Group: common.SnapGroupName, Version: SnapshotGroupVersion.Version, Resource: common.VolumeSnapshotClassResourcePlural}
|
||||||
err := c.dynCli.Resource(VolSnapClassGVR).Delete(ctx, targetSnapClassName, metav1.DeleteOptions{})
|
err := c.dynCli.Resource(VolSnapClassGVR).Delete(ctx, targetSnapClassName, metav1.DeleteOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Delete VSC Error (%s) - (%v)\n", targetSnapClassName, err)
|
fmt.Printf("Delete VSC Error (%s) - (%v)\n", targetSnapClassName, err)
|
||||||
|
@ -587,7 +575,7 @@ func (c *cleanse) DeleteSnapshot(ctx context.Context, snapshotName string, names
|
||||||
if SnapshotGroupVersion == nil || SnapshotGroupVersion.Version == "" {
|
if SnapshotGroupVersion == nil || SnapshotGroupVersion.Version == "" {
|
||||||
return fmt.Errorf("snapshot group version not provided")
|
return fmt.Errorf("snapshot group version not provided")
|
||||||
}
|
}
|
||||||
VolSnapGVR := schema.GroupVersionResource{Group: SnapGroupName, Version: SnapshotGroupVersion.Version, Resource: VolumeSnapshotResourcePlural}
|
VolSnapGVR := schema.GroupVersionResource{Group: common.SnapGroupName, Version: SnapshotGroupVersion.Version, Resource: common.VolumeSnapshotResourcePlural}
|
||||||
return c.dynCli.Resource(VolSnapGVR).Namespace(namespace).Delete(ctx, snapshotName, metav1.DeleteOptions{})
|
return c.dynCli.Resource(VolSnapGVR).Namespace(namespace).Delete(ctx, snapshotName, metav1.DeleteOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,7 +597,7 @@ func (p *apiVersionFetch) GetCSISnapshotGroupVersion() (*metav1.GroupVersionForD
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
if group.Name == SnapGroupName {
|
if group.Name == common.SnapGroupName {
|
||||||
return &group.PreferredVersion, nil
|
return &group.PreferredVersion, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,14 +625,18 @@ func getDriverNameFromUVSC(vsc unstructured.Unstructured, version string) string
|
||||||
var driverName interface{}
|
var driverName interface{}
|
||||||
var ok bool
|
var ok bool
|
||||||
switch version {
|
switch version {
|
||||||
case alphaVersion:
|
case common.SnapshotAlphaVersion:
|
||||||
driverName, ok = vsc.Object[VolSnapClassAlphaDriverKey]
|
driverName, ok = vsc.Object[common.VolSnapClassAlphaDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
case common.SnapshotBetaVersion:
|
||||||
case betaVersion:
|
driverName, ok = vsc.Object[common.VolSnapClassBetaDriverKey]
|
||||||
driverName, ok = vsc.Object[VolSnapClassBetaDriverKey]
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case common.SnapshotStableVersion:
|
||||||
|
driverName, ok = vsc.Object[common.VolSnapClassStableDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
kansnapshot "github.com/kanisterio/kanister/pkg/kube/snapshot"
|
kansnapshot "github.com/kanisterio/kanister/pkg/kube/snapshot"
|
||||||
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
||||||
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1beta1"
|
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1beta1"
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/kastenhq/kubestr/pkg/csi/types"
|
"github.com/kastenhq/kubestr/pkg/csi/types"
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
@ -34,42 +35,67 @@ func (s *CSITestSuite) TestGetDriverNameFromUVSC(c *C) {
|
||||||
{
|
{
|
||||||
vsc: unstructured.Unstructured{
|
vsc: unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
VolSnapClassAlphaDriverKey: "p2",
|
common.VolSnapClassAlphaDriverKey: "p2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
version: alphaVersion,
|
version: common.SnapshotAlphaVersion,
|
||||||
expOut: "p2",
|
expOut: "p2",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vsc: unstructured.Unstructured{
|
vsc: unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{},
|
Object: map[string]interface{}{},
|
||||||
},
|
},
|
||||||
version: alphaVersion,
|
version: common.SnapshotAlphaVersion,
|
||||||
expOut: "",
|
expOut: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vsc: unstructured.Unstructured{
|
vsc: unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
VolSnapClassBetaDriverKey: "p2",
|
common.VolSnapClassBetaDriverKey: "p2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
version: betaVersion,
|
version: common.SnapshotBetaVersion,
|
||||||
expOut: "p2",
|
expOut: "p2",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vsc: unstructured.Unstructured{
|
vsc: unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{},
|
Object: map[string]interface{}{},
|
||||||
},
|
},
|
||||||
version: betaVersion,
|
version: common.SnapshotBetaVersion,
|
||||||
expOut: "",
|
expOut: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vsc: unstructured.Unstructured{
|
vsc: unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
VolSnapClassBetaDriverKey: map[string]string{},
|
common.VolSnapClassBetaDriverKey: map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
version: betaVersion,
|
version: common.SnapshotBetaVersion,
|
||||||
|
expOut: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vsc: unstructured.Unstructured{
|
||||||
|
Object: map[string]interface{}{
|
||||||
|
common.VolSnapClassStableDriverKey: "p2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
version: common.SnapshotStableVersion,
|
||||||
|
expOut: "p2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vsc: unstructured.Unstructured{
|
||||||
|
Object: map[string]interface{}{},
|
||||||
|
},
|
||||||
|
version: common.SnapshotStableVersion,
|
||||||
|
expOut: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vsc: unstructured.Unstructured{
|
||||||
|
Object: map[string]interface{}{
|
||||||
|
common.VolSnapClassStableDriverKey: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
version: common.SnapshotStableVersion,
|
||||||
expOut: "",
|
expOut: "",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
@ -192,7 +218,7 @@ func (s *CSITestSuite) TestValidateVolumeSnapshotClass(c *C) {
|
||||||
ops := &validateOperations{
|
ops := &validateOperations{
|
||||||
dynCli: fakedynamic.NewSimpleDynamicClient(runtime.NewScheme()),
|
dynCli: fakedynamic.NewSimpleDynamicClient(runtime.NewScheme()),
|
||||||
}
|
}
|
||||||
uVSC, err := ops.ValidateVolumeSnapshotClass(ctx, "vsc", &metav1.GroupVersionForDiscovery{GroupVersion: alphaVersion})
|
uVSC, err := ops.ValidateVolumeSnapshotClass(ctx, "vsc", &metav1.GroupVersionForDiscovery{GroupVersion: common.SnapshotAlphaVersion})
|
||||||
c.Check(err, NotNil)
|
c.Check(err, NotNil)
|
||||||
c.Check(uVSC, IsNil)
|
c.Check(uVSC, IsNil)
|
||||||
|
|
||||||
|
@ -480,7 +506,7 @@ func (s *CSITestSuite) TestCreatePod(c *C) {
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
if tc.args.ContainerImage == "" {
|
if tc.args.ContainerImage == "" {
|
||||||
c.Assert(pod.Spec.Containers[0].Image, Equals, DefaultPodImage)
|
c.Assert(pod.Spec.Containers[0].Image, Equals, common.DefaultPodImage)
|
||||||
} else {
|
} else {
|
||||||
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.args.ContainerImage)
|
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.args.ContainerImage)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
"github.com/kanisterio/kanister/pkg/kube/snapshot/apis/v1alpha1"
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/kastenhq/kubestr/pkg/csi/mocks"
|
"github.com/kastenhq/kubestr/pkg/csi/mocks"
|
||||||
"github.com/kastenhq/kubestr/pkg/csi/types"
|
"github.com/kastenhq/kubestr/pkg/csi/types"
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
|
@ -42,13 +43,13 @@ func (s *CSITestSuite) TestValidateArgs(c *C) {
|
||||||
}, nil),
|
}, nil),
|
||||||
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
||||||
&metav1.GroupVersionForDiscovery{
|
&metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}, nil),
|
}, nil),
|
||||||
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}).Return(&unstructured.Unstructured{
|
}).Return(&unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
VolSnapClassAlphaDriverKey: "p1",
|
common.VolSnapClassAlphaDriverKey: "p1",
|
||||||
},
|
},
|
||||||
}, nil),
|
}, nil),
|
||||||
)
|
)
|
||||||
|
@ -70,13 +71,13 @@ func (s *CSITestSuite) TestValidateArgs(c *C) {
|
||||||
}, nil),
|
}, nil),
|
||||||
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
||||||
&metav1.GroupVersionForDiscovery{
|
&metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}, nil),
|
}, nil),
|
||||||
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}).Return(&unstructured.Unstructured{
|
}).Return(&unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
VolSnapClassAlphaDriverKey: "p2",
|
common.VolSnapClassAlphaDriverKey: "p2",
|
||||||
},
|
},
|
||||||
}, nil),
|
}, nil),
|
||||||
)
|
)
|
||||||
|
@ -98,10 +99,10 @@ func (s *CSITestSuite) TestValidateArgs(c *C) {
|
||||||
}, nil),
|
}, nil),
|
||||||
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
f.versionOps.EXPECT().GetCSISnapshotGroupVersion().Return(
|
||||||
&metav1.GroupVersionForDiscovery{
|
&metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}, nil),
|
}, nil),
|
||||||
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
f.validateOps.EXPECT().ValidateVolumeSnapshotClass(gomock.Any(), "vsc", &metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: alphaVersion,
|
GroupVersion: common.SnapshotAlphaVersion,
|
||||||
}).Return(nil, fmt.Errorf("vsc error")),
|
}).Return(nil, fmt.Errorf("vsc error")),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
kankube "github.com/kanisterio/kanister/pkg/kube"
|
kankube "github.com/kanisterio/kanister/pkg/kube"
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
sv1 "k8s.io/api/storage/v1"
|
sv1 "k8s.io/api/storage/v1"
|
||||||
|
@ -22,7 +23,7 @@ const (
|
||||||
PodNamespaceEnvKey = "POD_NAMESPACE"
|
PodNamespaceEnvKey = "POD_NAMESPACE"
|
||||||
// DefaultFIOJob describes the default FIO job
|
// DefaultFIOJob describes the default FIO job
|
||||||
DefaultFIOJob = "default-fio"
|
DefaultFIOJob = "default-fio"
|
||||||
// KubestrFIOJob describes the default FIO job
|
// KubestrFIOJobGenName describes the generate name
|
||||||
KubestrFIOJobGenName = "kubestr-fio"
|
KubestrFIOJobGenName = "kubestr-fio"
|
||||||
// ConfigMapJobKey is the default fio job key
|
// ConfigMapJobKey is the default fio job key
|
||||||
ConfigMapJobKey = "fiojob"
|
ConfigMapJobKey = "fiojob"
|
||||||
|
@ -42,7 +43,6 @@ const (
|
||||||
VolumeMountPath = "/dataset"
|
VolumeMountPath = "/dataset"
|
||||||
// CreatedByFIOLabel is the key that desrcibes the label used to mark configmaps
|
// CreatedByFIOLabel is the key that desrcibes the label used to mark configmaps
|
||||||
CreatedByFIOLabel = "createdbyfio"
|
CreatedByFIOLabel = "createdbyfio"
|
||||||
DefaultPodImage = "ghcr.io/kastenhq/kubestr:latest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIO is an interface that represents FIO related commands
|
// FIO is an interface that represents FIO related commands
|
||||||
|
@ -238,7 +238,7 @@ func (s *fioStepper) createPod(ctx context.Context, pvcName, configMapName, test
|
||||||
}
|
}
|
||||||
|
|
||||||
if image == "" {
|
if image == "" {
|
||||||
image = DefaultPodImage
|
image = common.DefaultPodImage
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
@ -641,7 +642,7 @@ func (s *FIOTestSuite) TestCreatPod(c *C) {
|
||||||
{Name: "config-map", MountPath: ConfigMapMountPath},
|
{Name: "config-map", MountPath: ConfigMapMountPath},
|
||||||
})
|
})
|
||||||
if tc.image == "" {
|
if tc.image == "" {
|
||||||
c.Assert(pod.Spec.Containers[0].Image, Equals, DefaultPodImage)
|
c.Assert(pod.Spec.Containers[0].Image, Equals, common.DefaultPodImage)
|
||||||
} else {
|
} else {
|
||||||
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.image)
|
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.image)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
kanvolume "github.com/kanisterio/kanister/pkg/kube/volume"
|
kanvolume "github.com/kanisterio/kanister/pkg/kube/volume"
|
||||||
|
"github.com/kastenhq/kubestr/pkg/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
sv1 "k8s.io/api/storage/v1"
|
sv1 "k8s.io/api/storage/v1"
|
||||||
|
@ -20,16 +21,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SnapGroupName describes the snapshot group name
|
|
||||||
SnapGroupName = "snapshot.storage.k8s.io"
|
|
||||||
// VolumeSnapshotClassResourcePlural describes volume snapshot classses
|
|
||||||
VolumeSnapshotClassResourcePlural = "volumesnapshotclasses"
|
|
||||||
alphaVersion = "snapshot.storage.k8s.io/v1alpha1"
|
|
||||||
betaVersion = "snapshot.storage.k8s.io/v1beta1"
|
|
||||||
// VolSnapClassAlphaDriverKey describes alpha driver key
|
|
||||||
VolSnapClassAlphaDriverKey = "snapshotter"
|
|
||||||
// VolSnapClassBetaDriverKey describes beta driver key
|
|
||||||
VolSnapClassBetaDriverKey = "driver"
|
|
||||||
// APIVersionKey describes the APIVersion key
|
// APIVersionKey describes the APIVersion key
|
||||||
APIVersionKey = "apiVersion"
|
APIVersionKey = "apiVersion"
|
||||||
// FeatureGateTestPVCName is the name of the pvc created by the feature gate
|
// FeatureGateTestPVCName is the name of the pvc created by the feature gate
|
||||||
|
@ -284,14 +275,20 @@ func (p *Kubestr) validateVolumeSnapshotClass(vsc unstructured.Unstructured, gro
|
||||||
Raw: vsc,
|
Raw: vsc,
|
||||||
}
|
}
|
||||||
switch groupVersion {
|
switch groupVersion {
|
||||||
case alphaVersion:
|
case common.SnapshotAlphaVersion:
|
||||||
_, ok := vsc.Object[VolSnapClassAlphaDriverKey]
|
_, ok := vsc.Object[common.VolSnapClassAlphaDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
retVSC.StatusList = append(retVSC.StatusList,
|
retVSC.StatusList = append(retVSC.StatusList,
|
||||||
makeStatus(StatusError, fmt.Sprintf("VolumeSnapshotClass (%s) missing 'snapshotter' field", vsc.GetName()), nil))
|
makeStatus(StatusError, fmt.Sprintf("VolumeSnapshotClass (%s) missing 'snapshotter' field", vsc.GetName()), nil))
|
||||||
}
|
}
|
||||||
case betaVersion:
|
case common.SnapshotBetaVersion:
|
||||||
_, ok := vsc.Object[VolSnapClassBetaDriverKey]
|
_, ok := vsc.Object[common.VolSnapClassBetaDriverKey]
|
||||||
|
if !ok {
|
||||||
|
retVSC.StatusList = append(retVSC.StatusList,
|
||||||
|
makeStatus(StatusError, fmt.Sprintf("VolumeSnapshotClass (%s) missing 'driver' field", vsc.GetName()), nil))
|
||||||
|
}
|
||||||
|
case common.SnapshotStableVersion:
|
||||||
|
_, ok := vsc.Object[common.VolSnapClassStableDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
retVSC.StatusList = append(retVSC.StatusList,
|
retVSC.StatusList = append(retVSC.StatusList,
|
||||||
makeStatus(StatusError, fmt.Sprintf("VolumeSnapshotClass (%s) missing 'driver' field", vsc.GetName()), nil))
|
makeStatus(StatusError, fmt.Sprintf("VolumeSnapshotClass (%s) missing 'driver' field", vsc.GetName()), nil))
|
||||||
|
@ -325,7 +322,7 @@ func (p *Kubestr) loadStorageClasses(ctx context.Context) (*sv1.StorageClassList
|
||||||
|
|
||||||
func (p *Kubestr) loadVolumeSnapshotClasses(ctx context.Context, version string) (*unstructured.UnstructuredList, error) {
|
func (p *Kubestr) loadVolumeSnapshotClasses(ctx context.Context, version string) (*unstructured.UnstructuredList, error) {
|
||||||
if p.volumeSnapshotClassList == nil {
|
if p.volumeSnapshotClassList == nil {
|
||||||
VolSnapClassGVR := schema.GroupVersionResource{Group: SnapGroupName, Version: version, Resource: VolumeSnapshotClassResourcePlural}
|
VolSnapClassGVR := schema.GroupVersionResource{Group: common.SnapGroupName, Version: version, Resource: common.VolumeSnapshotClassResourcePlural}
|
||||||
us, err := p.dynCli.Resource(VolSnapClassGVR).List(ctx, metav1.ListOptions{})
|
us, err := p.dynCli.Resource(VolSnapClassGVR).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -340,14 +337,18 @@ func (p *Kubestr) getDriverNameFromUVSC(vsc unstructured.Unstructured, version s
|
||||||
var driverName interface{}
|
var driverName interface{}
|
||||||
var ok bool
|
var ok bool
|
||||||
switch version {
|
switch version {
|
||||||
case alphaVersion:
|
case common.SnapshotAlphaVersion:
|
||||||
driverName, ok = vsc.Object[VolSnapClassAlphaDriverKey]
|
driverName, ok = vsc.Object[common.VolSnapClassAlphaDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
case common.SnapshotBetaVersion:
|
||||||
case betaVersion:
|
driverName, ok = vsc.Object[common.VolSnapClassBetaDriverKey]
|
||||||
driverName, ok = vsc.Object[VolSnapClassBetaDriverKey]
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case common.SnapshotStableVersion:
|
||||||
|
driverName, ok = vsc.Object[common.VolSnapClassStableDriverKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -366,7 +367,7 @@ func (p *Kubestr) getCSIGroupVersion() *metav1.GroupVersionForDiscovery {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
if group.Name == SnapGroupName {
|
if group.Name == common.SnapGroupName {
|
||||||
return &group.PreferredVersion
|
return &group.PreferredVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,3 +325,28 @@ func (s *ProvisionerTestSuite) TestGetDriverNameFromUVSC(c *C) {
|
||||||
c.Assert(out, Equals, tc.out)
|
c.Assert(out, Equals, tc.out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func (s *ProvisionerTestSuite) TestGetDriverStats(c *C) {
|
||||||
|
// var snapshotCount int
|
||||||
|
// var expansionCount int
|
||||||
|
// var cloningCount int
|
||||||
|
// featureMap := make(map[string]struct{})
|
||||||
|
// for _, driver := range CSIDriverList {
|
||||||
|
// if strings.Contains("Snapshot", driver.Features) {
|
||||||
|
// snapshotCount++
|
||||||
|
// }
|
||||||
|
// if strings.Contains("Expansion", driver.Features) {
|
||||||
|
// expansionCount++
|
||||||
|
// }
|
||||||
|
// if strings.Contains("Cloning", driver.Features) {
|
||||||
|
// cloningCount++
|
||||||
|
// }
|
||||||
|
// featureMap[driver.Features] = struct{}{}
|
||||||
|
// }
|
||||||
|
// c.Log("totalcsidrivers: ", len(CSIDriverList))
|
||||||
|
// c.Log("snapshotCount: ", snapshotCount)
|
||||||
|
// c.Log("expansionCount: ", expansionCount)
|
||||||
|
// c.Log("cloningCount: ", cloningCount)
|
||||||
|
// c.Log("unique combinations: ", len(featureMap))
|
||||||
|
// c.Assert(true, Equals, false)
|
||||||
|
// }
|
||||||
|
|
Loading…
Reference in a new issue