-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migrate): add support for cstor volume migration (#9)
Commits add support for CSI volume migration Signed-off-by: shubham <[email protected]>
- Loading branch information
1 parent
cac3155
commit 09aa7fc
Showing
9 changed files
with
1,322 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2020 The OpenEBS 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 executor | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/openebs/maya/pkg/util" | ||
cstor "github.com/openebs/upgrade/pkg/migrate/cstor" | ||
"github.com/spf13/cobra" | ||
"k8s.io/klog" | ||
|
||
errors "github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
cstorVolumeMigrateCmdHelpText = ` | ||
This command migrates the cStor Volume to csi format | ||
Usage: migrate cstor-volume --pv-name <pv-name> | ||
` | ||
) | ||
|
||
// NewMigrateCStorVolumeJob migrates all the cStor Pools associated with | ||
// a given Storage Pool Claim | ||
func NewMigrateCStorVolumeJob() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "cstor-volume", | ||
Short: "Migrate cStor Volume", | ||
Long: cstorVolumeMigrateCmdHelpText, | ||
Example: `migrate cstor-volume <pv-name>`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(options.RunPreFlightChecks(), util.Fatal) | ||
util.CheckErr(options.RunCStorVolumeMigrateChecks(), util.Fatal) | ||
util.CheckErr(options.RunCStorVolumeMigrate(), util.Fatal) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&options.pvName, | ||
"pv-name", "", | ||
options.pvName, | ||
"cstor Volume name to be migrated. Run \"kubectl get pv\", to get pv-name") | ||
|
||
return cmd | ||
} | ||
|
||
// RunCStorVolumeMigrateChecks will ensure the sanity of the cstor Volume migrate options | ||
func (m *MigrateOptions) RunCStorVolumeMigrateChecks() error { | ||
if len(strings.TrimSpace(m.pvName)) == 0 { | ||
return errors.Errorf("Cannot execute migrate job: cstor pv name is missing") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// RunCStorVolumeMigrate migrates the given pv. | ||
func (m *MigrateOptions) RunCStorVolumeMigrate() error { | ||
|
||
klog.Infof("Migrating volume %s to csi spec", m.pvName) | ||
migrator := cstor.VolumeMigrator{} | ||
err := migrator.Migrate(m.pvName, m.openebsNamespace) | ||
if err != nil { | ||
klog.Error(err) | ||
return errors.Errorf("Failed to migrate cStor Volume : %s", m.pvName) | ||
} | ||
klog.Infof("Successfully migrated volume %s", m.pvName) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
type MigrateOptions struct { | ||
openebsNamespace string | ||
spcName string | ||
pvName string | ||
} | ||
|
||
var ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.