-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if PV/PVC Access Modes are Supported by the Destination Volume …
…Provider (#139) * WIP: Check PVC access mode * Still WIP * More WIP * Adding tests * Add more unit test * Passing UT * Add option to skip validation * Export PVCError * correctly return map * print when there are validation errors * don't overwrite status for non-pending pvcs * revert previous change * fix events and tab writer output * Add more unit test * Add pod ready timeout out for volume validation pods * convert pod ready timeout to second units * accept an int for timeout instead of duration * specify PVC copy operation timeout in seconds * rename flag * Refactor WIP * WIP: PR Review Refactor * WIP: More PR review refactor * Map all failures to exit code 1 * Address Ethan's PR review comments and suggestions * tweak Test_pvcForStorageClass test * convert podready timeout to correct unit * allow os signals to context * fix pod and pvc cleanup * simplify table output * speed up pod deletion * validate storage class resource is present in the cluster * Change output message * Add todo * Update flags and README * Update text for pod-ready-timeout flag * Add Ethan's suggestion * --skip-source-validation works with preflight validation * Simplify deleteTmpPVC() * Update README with --delete-pv-timeout flag * fix timeout flags * log name of the tempt pvc and not the struct
- Loading branch information
Showing
12 changed files
with
2,115 additions
and
539 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 |
---|---|---|
@@ -1,16 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"time" | ||
|
||
"github.com/replicatedhq/pvmigrate/pkg/migrate" | ||
"github.com/replicatedhq/pvmigrate/pkg/preflight" | ||
"github.com/replicatedhq/pvmigrate/pkg/version" | ||
k8sclient "k8s.io/client-go/kubernetes" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth" // this allows accessing a larger array of cloud providers | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
) | ||
|
||
func main() { | ||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) | ||
defer stop() | ||
|
||
fmt.Printf("Running pvmigrate build:\n") | ||
version.Print() | ||
|
||
migrate.Cli() | ||
// Cli uses CLI options to run Migrate | ||
var options migrate.Options | ||
var skipPreflightValidation bool | ||
var preflightValidationOnly bool | ||
var podReadyTimeout int | ||
var deletePVTimeout int | ||
flag.StringVar(&options.SourceSCName, "source-sc", "", "storage provider name to migrate from") | ||
flag.StringVar(&options.DestSCName, "dest-sc", "", "storage provider name to migrate to") | ||
flag.StringVar(&options.RsyncImage, "rsync-image", "eeacms/rsync:2.3", "the image to use to copy PVCs - must have 'rsync' on the path") | ||
flag.StringVar(&options.Namespace, "namespace", "", "only migrate PVCs within this namespace") | ||
flag.BoolVar(&options.SetDefaults, "set-defaults", false, "change default storage class from source to dest") | ||
flag.BoolVar(&options.VerboseCopy, "verbose-copy", false, "show output from the rsync command used to copy data between PVCs") | ||
flag.BoolVar(&options.SkipSourceValidation, "skip-source-validation", false, "migrate from PVCs using a particular StorageClass name, even if that StorageClass does not exist") | ||
flag.IntVar(&podReadyTimeout, "pod-ready-timeout", 60, "length of time to wait (in seconds) for validation pod(s) to go into Ready phase") | ||
flag.IntVar(&deletePVTimeout, "delete-pv-timeout", 300, "length of time to wait (in seconds) for backing PV to be removed when temporary PVC is deleted") | ||
flag.BoolVar(&skipPreflightValidation, "skip-preflight-validation", false, "skip preflight migration validation on the destination storage provider") | ||
flag.BoolVar(&preflightValidationOnly, "preflight-validation-only", false, "skip the migration and run preflight validation only") | ||
|
||
flag.Parse() | ||
|
||
// update options with flag values | ||
options.PodReadyTimeout = time.Duration(podReadyTimeout) * time.Second | ||
options.DeletePVTimeout = time.Duration(deletePVTimeout) * time.Second | ||
|
||
// setup logger | ||
logger := log.New(os.Stderr, "", 0) // this has no time prefix etc | ||
|
||
// setup k8s | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
logger.Printf("failed to get config: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
clientset, err := k8sclient.NewForConfig(cfg) | ||
if err != nil { | ||
logger.Printf("failed to create kubernetes clientset: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
if !skipPreflightValidation { | ||
failures, err := preflight.Validate(ctx, logger, clientset, options) | ||
if err != nil { | ||
logger.Printf("failed to run preflight validation checks") | ||
os.Exit(1) | ||
} | ||
|
||
if len(failures) != 0 { | ||
preflight.PrintValidationFailures(os.Stdout, failures) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// start the migration | ||
if !preflightValidationOnly { | ||
err = migrate.Migrate(ctx, logger, clientset, options) | ||
if err != nil { | ||
logger.Printf("migration failed: %s", err) | ||
os.Exit(1) | ||
} | ||
} | ||
} |
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.