-
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 spc to cspc migration
Signed-off-by: shubham <[email protected]>
- Loading branch information
1 parent
5c766b7
commit 29e5e7f
Showing
12 changed files
with
960 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# This builds openebs migratte image using | ||
# its latest binary | ||
# | ||
|
||
FROM alpine:3.9 | ||
|
||
# copy the latest binary | ||
COPY migrate /usr/local/bin/migrate | ||
|
||
ARG BUILD_DATE | ||
|
||
LABEL org.label-schema.name="migrate" | ||
LABEL org.label-schema.description="migrates openebs components" | ||
LABEL org.label-schema.url="https://openebs.io/" | ||
LABEL org.label-schema.vcs-url="https://github.com/openebs/upgrade" | ||
LABEL org.label-schema.schema-version="1.0" | ||
LABEL org.label-schema.build-date=$BUILD_DATE | ||
|
||
ENTRYPOINT ["migrate"] |
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,32 @@ | ||
|
||
# Specify the name for the binaries | ||
MIGRATE=migrate | ||
|
||
# build migrate binary | ||
.PHONY: migrate | ||
migrate: | ||
@echo "----------------------------" | ||
@echo "--> ${MIGRATE} " | ||
@echo "----------------------------" | ||
@# PNAME is the sub-folder in ./bin where binary will be placed. | ||
@# CTLNAME indicates the folder/pkg under cmd that needs to be built. | ||
@# The output binary will be: ./bin/${PNAME}/<os-arch>/${CTLNAME} | ||
@# A copy of the binary will also be placed under: ./bin/${PNAME}/${CTLNAME} | ||
@PNAME=${MIGRATE} CTLNAME=${MIGRATE} CGO_ENABLED=0 sh -c "'$(PWD)/build/build.sh'" | ||
|
||
# build migrate image | ||
.PHONY: migrate-image | ||
migrate-image: migrate | ||
@echo "-----------------------------------------------" | ||
@echo "--> ${MIGRATE} image " | ||
@echo "${HUB_USER}/${M_MIGRATE_REPO_NAME}:${IMAGE_TAG}" | ||
@echo "-----------------------------------------------" | ||
@cp bin/${MIGRATE}/${MIGRATE} build/${MIGRATE}/ | ||
@cd build/${MIGRATE} && \ | ||
sudo docker build -t "${HUB_USER}/${M_MIGRATE_REPO_NAME}:${IMAGE_TAG}" --build-arg BUILD_DATE=${BUILD_DATE} . | ||
@rm build/${MIGRATE}/${MIGRATE} | ||
|
||
# cleanup migrate build | ||
.PHONY: cleanup-migrate | ||
cleanup-migrate: | ||
rm -rf ${GOPATH}/bin/${MIGRATE} |
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,45 @@ | ||
/* | ||
Copyright 2019 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" | ||
|
||
errors "github.com/pkg/errors" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// MigrateOptions stores information required for migrate | ||
type MigrateOptions struct { | ||
openebsNamespace string | ||
spcName string | ||
} | ||
|
||
var ( | ||
options = &MigrateOptions{ | ||
openebsNamespace: "openebs", | ||
} | ||
) | ||
|
||
// RunPreFlightChecks will ensure the sanity of the common migrate options | ||
func (u *MigrateOptions) RunPreFlightChecks(cmd *cobra.Command) error { | ||
if len(strings.TrimSpace(u.openebsNamespace)) == 0 { | ||
return errors.Errorf("Cannot execute migrate job: namespace is missing") | ||
} | ||
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2019 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 ( | ||
cstorSPCMigrateCmdHelpText = ` | ||
This command migrates the cStor SPC | ||
Usage: migrate pool --spc-name <spc-name> | ||
` | ||
) | ||
|
||
// NewMigratePoolJob migrates all the cStor Pools associated with | ||
// a given Storage Pool Claim | ||
func NewMigratePoolJob() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pool", | ||
Short: "Migrate cStor SPC", | ||
Long: cstorSPCMigrateCmdHelpText, | ||
Example: `migrate cstor-spc --spc-name <spc-name>`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) | ||
util.CheckErr(options.RunCStorSPCMigrateChecks(cmd), util.Fatal) | ||
util.CheckErr(options.RunCStorSPCMigrate(cmd), util.Fatal) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&options.spcName, | ||
"spc-name", "", | ||
options.spcName, | ||
"cstor SPC name to be migrated. Run \"kubectl get spc\", to get spc-name") | ||
|
||
return cmd | ||
} | ||
|
||
// RunCStorSPCMigrateChecks will ensure the sanity of the cstor SPC migrate options | ||
func (u *MigrateOptions) RunCStorSPCMigrateChecks(cmd *cobra.Command) error { | ||
if len(strings.TrimSpace(u.spcName)) == 0 { | ||
return errors.Errorf("Cannot execute migrate job: cstor spc name is missing") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// RunCStorSPCMigrate migrates the given spc. | ||
func (u *MigrateOptions) RunCStorSPCMigrate(cmd *cobra.Command) error { | ||
|
||
klog.Infof("Migrating spc %s to cspc", u.spcName) | ||
migrator := cstor.CSPCMigrator{} | ||
err := migrator.Migrate(u.spcName, u.openebsNamespace) | ||
if err != nil { | ||
klog.Error(err) | ||
return errors.Errorf("Failed to migrate cStor SPC : %s", u.spcName) | ||
} | ||
klog.Infof("Successfully migrated spc %s to cspc", u.spcName) | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2019 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 ( | ||
"flag" | ||
"strings" | ||
|
||
"github.com/openebs/upgrade/cmd/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewJob will setup a new migrate job | ||
func NewJob() *cobra.Command { | ||
// Create a new command. | ||
cmd := &cobra.Command{ | ||
Use: "migrate", | ||
Short: "OpenEBS Migrate Utility", | ||
Long: `An utility to migrate OpenEBS SPC Pools to CSPC and Non-CSI Volumes to CSI Volumes, | ||
run as a Kubernetes Job`, | ||
PersistentPreRun: PreRun, | ||
} | ||
|
||
cmd.AddCommand( | ||
NewMigratePoolJob(), | ||
) | ||
|
||
cmd.PersistentFlags().StringVarP(&options.openebsNamespace, | ||
"openebs-namespace", "", | ||
options.openebsNamespace, | ||
"namespace where openebs components are installed.") | ||
|
||
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine) | ||
|
||
// Hack: Without the following line, the logs will be prefixed with Error | ||
_ = flag.CommandLine.Parse([]string{}) | ||
|
||
return cmd | ||
} | ||
|
||
// PreRun will check for environement variables to be read and intialized. | ||
func PreRun(cmd *cobra.Command, args []string) { | ||
namespace := util.GetOpenEBSNamespace() | ||
if len(strings.TrimSpace(namespace)) != 0 { | ||
options.openebsNamespace = namespace | ||
} | ||
} |
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,32 @@ | ||
/* | ||
Copyright 2018 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 main | ||
|
||
import ( | ||
mlogger "github.com/openebs/maya/pkg/logs" | ||
"github.com/openebs/upgrade/cmd/migrate/executor" | ||
"github.com/openebs/upgrade/cmd/util" | ||
) | ||
|
||
func main() { | ||
// Init logging | ||
mlogger.InitLogs() | ||
defer mlogger.FlushLogs() | ||
|
||
err := executor.NewJob().Execute() | ||
util.CheckError(err) | ||
} |
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,30 @@ | ||
/* | ||
Copyright 2019 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 util | ||
|
||
import ( | ||
menv "github.com/openebs/maya/pkg/env/v1alpha1" | ||
) | ||
|
||
//This file defines the environement variable names that are specific | ||
// to this provisioner. In addition to the variables defined in this file, | ||
// provisioner also uses the following: | ||
// OPENEBS_NAMESPACE | ||
|
||
func GetOpenEBSNamespace() string { | ||
return menv.Get(menv.OpenEBSNamespace) | ||
} |
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,34 @@ | ||
/* | ||
Copyright 2019 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 util | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// CheckError prints err to stderr and exits with code 1 if err is not nil. Otherwise, it is a | ||
// no-op. | ||
func CheckError(err error) { | ||
if err != nil { | ||
if err != context.Canceled { | ||
fmt.Fprintf(os.Stderr, fmt.Sprintf("An error occurred: %v\n", err)) | ||
} | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.