Skip to content

Commit

Permalink
remove invalid code
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei committed Oct 11, 2023
1 parent bc005d5 commit 5e6ddfa
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 180 deletions.
4 changes: 3 additions & 1 deletion controllers/dataprotection/backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import (
dptypes "github.com/apecloud/kubeblocks/internal/dataprotection/types"
dputils "github.com/apecloud/kubeblocks/internal/dataprotection/utils"
"github.com/apecloud/kubeblocks/internal/generics"
"github.com/apecloud/kubeblocks/internal/testutil"
testapps "github.com/apecloud/kubeblocks/internal/testutil/apps"
testdp "github.com/apecloud/kubeblocks/internal/testutil/dataprotection"
testk8s "github.com/apecloud/kubeblocks/internal/testutil/k8s"
)

var _ = Describe("Backup Controller test", func() {
Expand Down Expand Up @@ -259,7 +261,7 @@ var _ = Describe("Backup Controller test", func() {

BeforeEach(func() {
// mock VolumeSnapshotClass for volume snapshot
testapps.CreateVolumeSnapshotClass(&testCtx)
testk8s.CreateVolumeSnapshotClass(&testCtx, testutil.DefaultStorageProvisoner)

By("create a backup from backupPolicy " + testdp.BackupPolicyName)
backup = testdp.NewFakeBackup(&testCtx, func(backup *dpv1alpha1.Backup) {
Expand Down
6 changes: 5 additions & 1 deletion internal/controllerutil/volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ func IsVolumeSnapshotEnabled(ctx context.Context, cli client.Client, storageClas
return false, client.IgnoreNotFound(err)
}

vsCli := VolumeSnapshotCompatClient{
Client: cli,
Ctx: ctx,
}
vscList := snapshotv1.VolumeSnapshotClassList{}
if err := cli.List(ctx, &vscList); err != nil {
if err := vsCli.List(&vscList); err != nil {
return false, err
}
for _, vsc := range vscList.Items {
Expand Down
41 changes: 0 additions & 41 deletions internal/dataprotection/action/action_create_vs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package action

import (
"context"
"fmt"
"strings"

vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
intctrlutil "github.com/apecloud/kubeblocks/internal/controllerutil"
"github.com/apecloud/kubeblocks/internal/dataprotection/builder"
dptypes "github.com/apecloud/kubeblocks/internal/dataprotection/types"
"github.com/apecloud/kubeblocks/internal/dataprotection/utils"
)
Expand Down Expand Up @@ -157,14 +154,6 @@ func (c *CreateVolumeSnapshotAction) createVolumeSnapshotIfNotExist(ctx Context,
return nil
}

// create volume snapshot
if pvc.Spec.StorageClassName != nil && *pvc.Spec.StorageClassName != "" {
vsc, err = createVolumeSnapshotClassIfNotExist(ctx.Ctx, ctx.Client, vsCli, *pvc.Spec.StorageClassName)
if err != nil {
return err
}
}

c.ObjectMeta.Name = key.Name
c.ObjectMeta.Namespace = key.Namespace

Expand Down Expand Up @@ -195,36 +184,6 @@ func (c *CreateVolumeSnapshotAction) createVolumeSnapshotIfNotExist(ctx Context,
return nil
}

func createVolumeSnapshotClassIfNotExist(
ctx context.Context,
cli client.Client,
vsCli intctrlutil.VolumeSnapshotCompatClient,
scName string) (*vsv1.VolumeSnapshotClass, error) {
scObj := storagev1.StorageClass{}
// ignore if not found storage class, use the default volume snapshot class
if err := cli.Get(ctx, client.ObjectKey{Name: scName}, &scObj); client.IgnoreNotFound(err) != nil {
return nil, err
}

vscList := vsv1.VolumeSnapshotClassList{}
if err := vsCli.List(&vscList); err != nil {
return nil, err
}
for _, item := range vscList.Items {
if item.Driver == scObj.Provisioner {
return item.DeepCopy(), nil
}
}

// not found matched volume snapshot class, create one
vscName := fmt.Sprintf("vsc-%s-%s", scName, scObj.UID[:8])
newVsc := builder.BuildVolumeSnapshotClass(vscName, scObj.Provisioner)
if err := vsCli.Create(newVsc); err != nil {
return nil, err
}
return newVsc, nil
}

func ensureVolumeSnapshotReady(
vsCli intctrlutil.VolumeSnapshotCompatClient,
key client.ObjectKey) (bool, *vsv1.VolumeSnapshot, error) {
Expand Down
41 changes: 0 additions & 41 deletions internal/dataprotection/builder/builder.go

This file was deleted.

36 changes: 0 additions & 36 deletions internal/dataprotection/builder/builder_test.go

This file was deleted.

47 changes: 0 additions & 47 deletions internal/dataprotection/builder/suite_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/dataprotection/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func VolumeSnapshotEnabled(ctx context.Context, cli client.Client, pod *corev1.P
return false, err
}
if !enabled {
return false, fmt.Errorf(`cannot find CSI of persistentVolumeClaim "%s" to do volume snapshot on pod "%s"`, storageClassMap[k], pod.Name)
return false, fmt.Errorf(`cannot find any VolumeSnapshotClass of persistentVolumeClaim "%s" to do volume snapshot on pod "%s"`, storageClassMap[k], pod.Name)
}
}
return true, nil
Expand Down
3 changes: 1 addition & 2 deletions internal/testutil/apps/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const (
Class2c4gName = "general-2c4g"
DefaultResourceConstraintName = "kb-resource-constraint"

StogrageProvisioner = "kubernetes.io/no-provisioner"
StogrageClassName = "test-sc"
StogrageClassName = "test-sc"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions internal/testutil/apps/native_object_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CreateStorageClass(testCtx *testutil.TestContext, storageClassName string,
storage.IsDefaultStorageClassAnnotation: "false",
},
},
Provisioner: StogrageProvisioner,
Provisioner: testutil.DefaultStorageProvisoner,
AllowVolumeExpansion: &allowVolumeExpansion,
}
return CreateK8sResource(testCtx, storageClass).(*storagev1.StorageClass)
Expand All @@ -89,7 +89,7 @@ func CreateVolumeSnapshotClass(testCtx *testutil.TestContext) {
ObjectMeta: metav1.ObjectMeta{
Name: "default-vs",
},
Driver: StogrageProvisioner,
Driver: testutil.DefaultStorageProvisoner,
DeletionPolicy: vsv1.VolumeSnapshotContentDelete,
}
CreateK8sResource(testCtx, volumeSnapshotClass)
Expand Down
12 changes: 6 additions & 6 deletions internal/testutil/k8s/storage_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
)

var (
DefaultStorageClassName string = "default-sc-for-testing"
defaultVolumeSnapshotClassName string = "default-vsc-for-testing"
defaultProvisioner string = "testing.kubeblocks.io"
DefaultStorageClassName = "default-sc-for-testing"
defaultVolumeSnapshotClassName = "default-vsc-for-testing"
defaultProvisioner = "testing.kubeblocks.io"
)

func GetDefaultStorageClass(testCtx *testutil.TestContext) *storagev1.StorageClass {
Expand Down Expand Up @@ -75,7 +75,7 @@ func MockEnableVolumeSnapshot(testCtx *testutil.TestContext, storageClassName st
}
vsc := getVolumeSnapshotClass(testCtx, sc)
if vsc == nil {
createVolumeSnapshotClass(testCtx, sc)
CreateVolumeSnapshotClass(testCtx, sc.Provisioner)
}
gomega.Expect(IsMockVolumeSnapshotEnabled(testCtx, storageClassName)).Should(gomega.BeTrue())
}
Expand Down Expand Up @@ -138,12 +138,12 @@ func getVolumeSnapshotClass(testCtx *testutil.TestContext, storageClass *storage
return nil
}

func createVolumeSnapshotClass(testCtx *testutil.TestContext, storageClass *storagev1.StorageClass) *snapshotv1.VolumeSnapshotClass {
func CreateVolumeSnapshotClass(testCtx *testutil.TestContext, storageProvisioner string) *snapshotv1.VolumeSnapshotClass {
vsc := &snapshotv1.VolumeSnapshotClass{
ObjectMeta: metav1.ObjectMeta{
Name: defaultVolumeSnapshotClassName,
},
Driver: storageClass.Provisioner,
Driver: storageProvisioner,
DeletionPolicy: snapshotv1.VolumeSnapshotContentDelete,
}
gomega.Expect(testCtx.Cli.Create(testCtx.Ctx, vsc)).Should(gomega.Succeed())
Expand Down
5 changes: 3 additions & 2 deletions internal/testutil/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ type TestContext struct {
var ErrUninitError = fmt.Errorf("cli uninitialized error")

const (
envExistingClusterType = "EXISTING_CLUSTER_TYPE"
envUseExistingCluster = "USE_EXISTING_CLUSTER"
envExistingClusterType = "EXISTING_CLUSTER_TYPE"
envUseExistingCluster = "USE_EXISTING_CLUSTER"
DefaultStorageProvisoner = "kubernetes.io/no-provisioner"
)

func init() {
Expand Down

0 comments on commit 5e6ddfa

Please sign in to comment.