From db264f90b8d1ae93e3bd928f0bea4e1505391352 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Tue, 9 Jan 2024 23:36:06 +0530 Subject: [PATCH] Open ebs provider cleanup Signed-off-by: sushanthakumar --- build/lib/golang.sh | 2 - build/lib/release.sh | 1 - cmd/openebs-zfs/main.go | 34 --- controllers/volumebackup/controller.go | 2 +- .../openebs-zfs-provider-deployment.yaml | 100 -------- providers/openebs-zfs/server/app.go | 215 ---------------- providers/openebs-zfs/server/options/flags.go | 60 ----- .../openebs-zfs/server/options/kubeconfig.go | 49 ---- .../openebs-zfs/server/options/options.go | 23 -- providers/openebs-zfs/server/server.go | 231 ------------------ 10 files changed, 1 insertion(+), 716 deletions(-) delete mode 100644 cmd/openebs-zfs/main.go delete mode 100644 deploy/volumeprovider/openebs-zfs-provider-deployment.yaml delete mode 100644 providers/openebs-zfs/server/app.go delete mode 100644 providers/openebs-zfs/server/options/flags.go delete mode 100644 providers/openebs-zfs/server/options/kubeconfig.go delete mode 100644 providers/openebs-zfs/server/options/options.go delete mode 100644 providers/openebs-zfs/server/server.go diff --git a/build/lib/golang.sh b/build/lib/golang.sh index 0bcdec7e..a23d3a38 100644 --- a/build/lib/golang.sh +++ b/build/lib/golang.sh @@ -29,7 +29,6 @@ readonly KAHU_STATIC_BINARIES=( controller-manager meta-service volume-service - openebs-zfs csi-snapshotter nfs-provider ) @@ -41,7 +40,6 @@ golang::targets() { cmd/meta-service cmd/volume-service providers/nfs/nfs-provider - cmd/openebs-zfs cmd/csi-snapshotter ) echo "${targets[@]}" diff --git a/build/lib/release.sh b/build/lib/release.sh index 3e4c7603..9988dee9 100644 --- a/build/lib/release.sh +++ b/build/lib/release.sh @@ -38,7 +38,6 @@ build::get_docker_wrapped_binaries() { controller-manager meta-service volume-service - openebs-zfs csi-snapshotter nfs-provider ) diff --git a/cmd/openebs-zfs/main.go b/cmd/openebs-zfs/main.go deleted file mode 100644 index 1a4d4cf5..00000000 --- a/cmd/openebs-zfs/main.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "math/rand" - "os" - "time" - - "github.com/soda-cdm/kahu/providers/openebs-zfs/server" -) - -func main() { - rand.Seed(time.Now().UnixNano()) - - command := server.NewLVMProviderCommand() - if err := command.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/controllers/volumebackup/controller.go b/controllers/volumebackup/controller.go index 53c0c7cf..191d19fa 100644 --- a/controllers/volumebackup/controller.go +++ b/controllers/volumebackup/controller.go @@ -51,7 +51,7 @@ const ( ) var volBackupSupport = map[string]string{ - "zfs.csi.openebs.io": "zfs.backup.openebs.io", + "zfs.csi.openebs.io": "snapshotter.backup.csi.io", "linstor.csi.linbit.com": "snapshotter.backup.csi.io", "cephfs.csi.ceph.com": "snapshotter.backup.csi.io", "hostpath.csi.k8s.io": "snapshotter.backup.csi.io", diff --git a/deploy/volumeprovider/openebs-zfs-provider-deployment.yaml b/deploy/volumeprovider/openebs-zfs-provider-deployment.yaml deleted file mode 100644 index 449c8989..00000000 --- a/deploy/volumeprovider/openebs-zfs-provider-deployment.yaml +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright 2022 The SODA Authors. -# Copyright 2022 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This mounts the lvm volume claim into /mnt and continuously -# overwrites /mnt/index.html with the time and hostname of the pod. - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: kahu-openebs-zfs-provider - namespace: kahu -spec: - replicas: 1 - selector: - matchLabels: - app: openebs-zfs-provider - template: - metadata: - labels: - app: openebs-zfs-provider - spec: - serviceAccountName: kahu-openebs-zfs-provider - containers: - - image: sodacdm/kahu-openebs-zfs-provider:v1.0.0 - imagePullPolicy: IfNotPresent - name: openebs-zfs-driver - command: ["/usr/local/bin/openebs-zfs"] - volumeMounts: - - name: socket - mountPath: "/tmp" - - image: sodacdm/kahu-volume-service:v1.0.0 - imagePullPolicy: IfNotPresent - name: volume-service - command: ["/usr/local/bin/volume-service"] - env: - - name: NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.labels['app'] - - name: NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - volumeMounts: - # name must match the volume name below - - name: socket - mountPath: "/tmp" - volumes: - - name: socket - emptyDir: {} ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: kahu-openebs-zfs-provider - namespace: kahu ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: kahu - name: kahu-openebs-zfs-provider-clusterrole-binding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: kahu-openebs-zfs-provider-clusterrole -subjects: - - kind: ServiceAccount - name: kahu-openebs-zfs-provider - namespace: kahu ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: kahu - name: kahu-openebs-zfs-provider-clusterrole -rules: - - apiGroups: ["kahu.io"] - resources: ["providers", "providers/status"] - verbs: ["create", "delete", "watch", "update", "patch", "get", "watch", "list"] - - apiGroups: [ "*" ] - resources: ["*"] - verbs: ["create", "delete", "watch", "update", "patch", "get", "watch", "list"] ---- diff --git a/providers/openebs-zfs/server/app.go b/providers/openebs-zfs/server/app.go deleted file mode 100644 index 50ce1992..00000000 --- a/providers/openebs-zfs/server/app.go +++ /dev/null @@ -1,215 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package server defines LVM Provider server service -package server - -import ( - "context" - "fmt" - "net" - "os" - - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/grpc" - - provider "github.com/soda-cdm/kahu/providers/lib/go" - "github.com/soda-cdm/kahu/providers/openebs-zfs/server/options" - "github.com/soda-cdm/kahu/utils" - logOptions "github.com/soda-cdm/kahu/utils/logoptions" -) - -const ( - // LVMService component name - componentLVMService = "lvmprovider" - columnWrapSize = 2 -) - -// NewLVMProviderCommand creates a *cobra.Command object with default parameters -func NewLVMProviderCommand() *cobra.Command { - cleanFlagSet := pflag.NewFlagSet(componentLVMService, pflag.ContinueOnError) - - lvmServiceFlags := options.NewLVMServiceFlags() - loggingOptions := logOptions.NewLogOptions() - kubeconfigFlags := options.NewKahuClientOptions() - - cmd := &cobra.Command{ - Use: componentLVMService, - Long: `The Volume backup provider using snapshot`, - // Disabled flag parsing from cobra framework - DisableFlagParsing: true, - Run: func(cmd *cobra.Command, args []string) { - // initial flag parse, since we disable cobra's flag parsing - if err := cleanFlagSet.Parse(args); err != nil { - log.Error("Failed to parse meta service flag ", err) - _ = cmd.Usage() - os.Exit(1) - } - - // check if there are non-flag arguments in the command line - cmds := cleanFlagSet.Args() - if len(cmds) > 0 { - log.Error("Unknown command ", cmds[0]) - _ = cmd.Usage() - os.Exit(1) - } - - // short-circuit on help - help, err := cleanFlagSet.GetBool("help") - if err != nil { - log.Error(`"help" flag is non-bool`) - os.Exit(1) - } - if help { - _ = cmd.Help() - return - } - - // validate flags - if err := validateFlags(cmd, cleanFlagSet, args); err != nil { - return - } - - // validate and apply initial LVMService Flags - if err := lvmServiceFlags.Apply(); err != nil { - log.Error("Failed to validate provider service flags ", err) - return - } - - // validate and apply initial LVMService Flags - if err := kubeconfigFlags.Apply(); err != nil { - log.Error("Failed to validate kube config flags ", err) - return - } - - // validate and apply logging flags - if err := loggingOptions.Apply(); err != nil { - log.Error("Failed to apply logging flags ", err) - return - } - - ctx, cancel := context.WithCancel(context.Background()) - // setup signal handler - utils.SetupSignalHandler(cancel) - - // run the meta service - if err := Run(ctx, options.LVMProviderOptions{LVMServiceFlags: *lvmServiceFlags, - KubeClientOptions: *kubeconfigFlags}); err != nil { - log.Error("Failed to run LVM provider service", err) - return - } - - }, - } - - lvmServiceFlags.AddFlags(cleanFlagSet) - kubeconfigFlags.AddFlags(cleanFlagSet) - // add logging flags - loggingOptions.AddFlags(cleanFlagSet) - cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name())) - - const usageFmt = "Usage:\n %s\n\nFlags:\n%s" - cmd.SetUsageFunc(func(cmd *cobra.Command) error { - fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine(), - cleanFlagSet.FlagUsagesWrapped(columnWrapSize)) - return nil - }) - cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { - fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine(), - cleanFlagSet.FlagUsagesWrapped(columnWrapSize)) - }) - - return cmd -} - -// validateFlags validates LVM provider arguments -func validateFlags(cmd *cobra.Command, cleanFlagSet *pflag.FlagSet, args []string) error { - // initial flag parse, since we disable cobra's flag parsing - if err := cleanFlagSet.Parse(args); err != nil { - log.Error("Failed to parse LVM provider service flag ", err) - _ = cmd.Usage() - return err - } - - // check if there are non-flag arguments in the command line - cmds := cleanFlagSet.Args() - if len(cmds) > 0 { - log.Error("unknown command ", cmds[0]) - _ = cmd.Usage() - return errors.New("unknown command") - } - - // short-circuit on help - help, err := cleanFlagSet.GetBool("help") - if err != nil { - log.Error(`"help" flag is non-bool`) - return err - } - if help { - _ = cmd.Help() - return err - } - return nil -} - -// Run start and run LVM Provider service -func Run(ctx context.Context, serviceOptions options.LVMProviderOptions) error { - log.Info("Starting Server ...") - - serverAddr, err := net.ResolveUnixAddr("unix", serviceOptions.UnixSocketPath) - if err != nil { - log.Fatal("failed to resolve unix addr") - return errors.New("failed to resolve unix addr") - } - if _, err := os.Stat(serviceOptions.UnixSocketPath); err == nil { - if err := os.RemoveAll(serviceOptions.UnixSocketPath); err != nil { - log.Fatal(err) - return err - } - } - lis, err := net.ListenUnix("unix", serverAddr) - if err != nil { - log.Fatal("failed to listen: ", err) - return err - } - defer func() { - err := lis.Close() - if err != nil { - log.Errorf("failed to close listening socket %s", err) - } - }() - - var opts []grpc.ServerOption - grpcServer := grpc.NewServer(opts...) - backupServer, err := NewVolumeBackupServer(ctx, serviceOptions) - if err != nil { - log.Errorf("Unable to initialize backup server %s", err) - return err - } - - provider.RegisterVolumeBackupServer(grpcServer, backupServer) - provider.RegisterIdentityServer(grpcServer, NewIdentityServer(ctx, serviceOptions)) - - go func(ctx context.Context, server *grpc.Server) { - <-ctx.Done() - server.Stop() - }(ctx, grpcServer) - - return grpcServer.Serve(lis) -} diff --git a/providers/openebs-zfs/server/options/flags.go b/providers/openebs-zfs/server/options/flags.go deleted file mode 100644 index 3eef19e8..00000000 --- a/providers/openebs-zfs/server/options/flags.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package options defines NFS Provider flag options -package options - -import ( - "errors" - - "github.com/spf13/pflag" -) - -const ( - // NFSService component name - unixSocketPath = "/tmp/volumeservice.sock" - defaultProviderName = "zfs.backup.openebs.io" - defaultProviderVersion = "v1" -) - -// LVMServiceFlags defines flags for NFS Services -type LVMServiceFlags struct { - UnixSocketPath string - ProviderName string - ProviderVersion string -} - -// NewLVMServiceFlags creates new NFS Service flags -func NewLVMServiceFlags() *LVMServiceFlags { - return &LVMServiceFlags{ - UnixSocketPath: unixSocketPath, - } -} - -// AddFlags exposes available command line options -func (options *LVMServiceFlags) AddFlags(fs *pflag.FlagSet) { - fs.StringVarP(&options.UnixSocketPath, "socket", "s", - options.UnixSocketPath, "Unix socket path") - fs.StringVarP(&options.ProviderName, "provider", "p", defaultProviderName, "Provider name") - fs.StringVarP(&options.ProviderVersion, "version", "V", - defaultProviderVersion, "Volume packaup provider version") -} - -// Apply checks validity of available command line options -func (options *LVMServiceFlags) Apply() error { - if options.ProviderName == "" { - return errors.New("empty provider name") - } - return nil -} diff --git a/providers/openebs-zfs/server/options/kubeconfig.go b/providers/openebs-zfs/server/options/kubeconfig.go deleted file mode 100644 index cbd653b8..00000000 --- a/providers/openebs-zfs/server/options/kubeconfig.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package options - -import ( - "github.com/spf13/pflag" - - "github.com/soda-cdm/kahu/client" -) - -type KubeClientOptions struct { - *client.Config -} - -func NewKahuClientOptions() *KubeClientOptions { - return &KubeClientOptions{ - Config: client.NewFactoryConfig(), - } -} - -func (opt *KubeClientOptions) AddFlags(fs *pflag.FlagSet) { - opt.Config.AddFlags(fs) -} - -func (opt *KubeClientOptions) Apply() error { - return nil -} - -func (opt *KubeClientOptions) Validate() []error { - if err := opt.Config.Validate(); err != nil { - return []error{err} - } - - return nil -} diff --git a/providers/openebs-zfs/server/options/options.go b/providers/openebs-zfs/server/options/options.go deleted file mode 100644 index 4d8138ad..00000000 --- a/providers/openebs-zfs/server/options/options.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package options defines NFSProvider flag options -package options - -// NFSProviderOptions defines flag options -type LVMProviderOptions struct { - LVMServiceFlags - KubeClientOptions - // TODO: Add configuration file options here -} diff --git a/providers/openebs-zfs/server/server.go b/providers/openebs-zfs/server/server.go deleted file mode 100644 index a4083137..00000000 --- a/providers/openebs-zfs/server/server.go +++ /dev/null @@ -1,231 +0,0 @@ -/* -Copyright 2022 The SODA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package server implements LVM provider service interfaces -package server - -import ( - "context" - - snapshotapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" - snapshotclientset "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - - "github.com/soda-cdm/kahu/client" - pb "github.com/soda-cdm/kahu/providers/lib/go" - "github.com/soda-cdm/kahu/providers/openebs-zfs/server/options" -) - -type volBackupServer struct { - ctx context.Context - options options.LVMProviderOptions - snapshotCli *snapshotclientset.Clientset - kubeClient kubernetes.Interface -} - -// NewVolumeBackupServer creates a new volume backup service -func NewVolumeBackupServer(ctx context.Context, - serviceOptions options.LVMProviderOptions) (pb.VolumeBackupServer, error) { - clientFactory := client.NewFactory("VolumeBackup", serviceOptions.KubeClientOptions.Config) - config, err := clientFactory.ClientConfig() - if err != nil { - return nil, err - } - snapshotCli, err := snapshotclientset.NewForConfig(config) - if err != nil { - return nil, errors.WithStack(err) - } - - kubeCli, err := kubernetes.NewForConfig(config) - if err != nil { - return nil, errors.WithStack(err) - } - - return &volBackupServer{ - ctx: ctx, - options: serviceOptions, - snapshotCli: snapshotCli, - kubeClient: kubeCli, - }, nil -} - -// NewIdentityServer creates a new Identify service -func NewIdentityServer(ctx context.Context, - serviceOptions options.LVMProviderOptions) pb.IdentityServer { - return &volBackupServer{ - ctx: ctx, - options: serviceOptions, - } -} - -// GetProviderInfo returns the basic information from provider side -func (server *volBackupServer) GetProviderInfo( - ctx context.Context, - GetProviderInfoRequest *pb.GetProviderInfoRequest) (*pb.GetProviderInfoResponse, error) { - log.Info("GetProviderInfo Called .... ") - response := &pb.GetProviderInfoResponse{ - Provider: server.options.ProviderName, - Version: server.options.ProviderVersion} - - return response, nil -} - -// GetProviderCapabilities returns the capabilities supported by provider -func (server *volBackupServer) GetProviderCapabilities( - _ context.Context, - _ *pb.GetProviderCapabilitiesRequest) (*pb.GetProviderCapabilitiesResponse, - error) { - log.Info("GetProviderCapabilities Called .... ") - return &pb.GetProviderCapabilitiesResponse{ - Capabilities: []*pb.ProviderCapability{ - { - Type: &pb.ProviderCapability_Service_{ - Service: &pb.ProviderCapability_Service{ - Type: pb.ProviderCapability_Service_VOLUME_BACKUP_SERVICE, - }, - }, - }, - }, - }, nil -} - -// Probe checks the healthy/availability state of the provider -func (server *volBackupServer) Probe(ctx context.Context, probeRequest *pb.ProbeRequest) (*pb.ProbeResponse, error) { - return &pb.ProbeResponse{}, nil -} - -// Create backup of the provided volumes -func (server *volBackupServer) StartBackup(ctx context.Context, req *pb.StartBackupRequest) (*pb.StartBackupResponse, error) { - backupIdentifiers := make([]*pb.BackupIdentifier, 0) - for _, backupInfo := range req.GetBackupInfo() { - backupIdentifiers = append(backupIdentifiers, &pb.BackupIdentifier{ - PvName: backupInfo.Pv.Name, - BackupIdentity: &pb.BackupIdentity{ - BackupHandle: backupInfo.Snapshot.SnapshotHandle, - BackupAttributes: backupInfo.Snapshot.SnapshotAttributes, - }, - }) - } - - return &pb.StartBackupResponse{ - BackupInfo: backupIdentifiers, - }, nil -} - -// Delete given backup -func (server *volBackupServer) DeleteBackup(context.Context, *pb.DeleteBackupRequest) (*pb.DeleteBackupResponse, error) { - return &pb.DeleteBackupResponse{}, nil -} - -// Cancel given backup -func (server *volBackupServer) CancelBackup(ctx context.Context, req *pb.CancelBackupRequest) (*pb.CancelBackupResponse, error) { - res, err := server.DeleteBackup(ctx, &pb.DeleteBackupRequest{ - BackupInfo: req.BackupInfo, - Parameters: req.Parameters, - }) - return &pb.CancelBackupResponse{ - Success: res.Success, - Errors: res.Errors, - }, err -} - -// Get backup statistics -func (server *volBackupServer) GetBackupStat(ctx context.Context, - req *pb.GetBackupStatRequest) (*pb.GetBackupStatResponse, error) { - stat := make([]*pb.BackupStat, 0) - for _, info := range req.BackupInfo { - stat = append(stat, &pb.BackupStat{ - BackupHandle: info.BackupHandle, - Progress: 100, - }) - } - return &pb.GetBackupStatResponse{ - BackupStats: stat, - }, nil -} - -// Create volume from backup (for restore) -func (server *volBackupServer) CreateVolumeFromBackup(ctx context.Context, - restoreReq *pb.CreateVolumeFromBackupRequest) (*pb.CreateVolumeFromBackupResponse, error) { - - restoreIDs := make([]*pb.RestoreVolumeIdentifier, 0) - for _, restoreInfo := range restoreReq.RestoreInfo { - snapshotContentName := restoreInfo.GetBackupIdentity().BackupHandle - snapshotContent, err := server.snapshotCli.SnapshotV1(). - VolumeSnapshotContents(). - Get(context.TODO(), snapshotContentName, metav1.GetOptions{}) - if err != nil { - return nil, err - } - - snapshotRef := snapshotContent.Spec.VolumeSnapshotRef - - pvc := v1.PersistentVolumeClaim{} - pvc.Name = restoreInfo.Pvc.Name - pvc.Namespace = restoreInfo.Pvc.Namespace - pvc.Spec.DataSource = &v1.TypedLocalObjectReference{ - Name: snapshotRef.Name, - Kind: "VolumeSnapshot", - APIGroup: &snapshotapi.SchemeGroupVersion.Group, - } - pvc.Spec.StorageClassName = restoreInfo.Pvc.Spec.StorageClassName - pvc.Spec.AccessModes = restoreInfo.Pvc.Spec.AccessModes - pvc.Spec.Resources = restoreInfo.Pvc.Spec.Resources - - k8sPVC, err := server.kubeClient. - CoreV1(). - PersistentVolumeClaims(snapshotRef.Namespace). - Create(context.TODO(), &pvc, metav1.CreateOptions{}) - if err != nil { - return nil, err - } - - restoreIDs = append(restoreIDs, &pb.RestoreVolumeIdentifier{ - PvcName: k8sPVC.Name, - VolumeIdentity: &pb.RestoreVolumeIdentity{ - VolumeHandle: k8sPVC.Name, - }, - }) - } - - return &pb.CreateVolumeFromBackupResponse{ - VolumeIdentifiers: restoreIDs, - }, nil -} - -// Cancel given restore -func (server *volBackupServer) CancelRestore(context.Context, *pb.CancelRestoreRequest) (*pb.CancelRestoreResponse, error) { - return &pb.CancelRestoreResponse{}, nil -} - -// Get restore statistics -func (server *volBackupServer) GetRestoreStat(ctx context.Context, req *pb.GetRestoreStatRequest) (*pb.GetRestoreStatResponse, error) { - restoreStats := make([]*pb.RestoreStat, 0) - for _, volID := range req.RestoreVolumeIdentity { - restoreStats = append(restoreStats, &pb.RestoreStat{ - RestoreVolumeHandle: volID.VolumeHandle, - Progress: 100, - }) - } - - return &pb.GetRestoreStatResponse{ - RestoreVolumeStat: restoreStats, - }, nil -}