From c1d8504e0856176b9105a17f704951158abb1ecf Mon Sep 17 00:00:00 2001 From: hackeramitkumar Date: Thu, 19 Jan 2023 00:12:43 +0530 Subject: [PATCH] removed clusterctl restore cmd --- cmd/clusterctl/client/client.go | 5 -- cmd/clusterctl/client/client_test.go | 4 - cmd/clusterctl/client/cluster/mover.go | 11 --- cmd/clusterctl/client/cluster/mover_test.go | 2 +- cmd/clusterctl/client/move.go | 22 ------ cmd/clusterctl/client/move_test.go | 18 ++--- cmd/clusterctl/cmd/restore.go | 76 ------------------- .../commands/additional-commands.md | 7 -- docs/book/src/clusterctl/commands/commands.md | 1 - .../src/developer/providers/v1.3-to-v1.4.md | 2 + 10 files changed, 12 insertions(+), 136 deletions(-) delete mode 100644 cmd/clusterctl/cmd/restore.go diff --git a/cmd/clusterctl/client/client.go b/cmd/clusterctl/client/client.go index 1aaf5b0e40ca..32d42dfac1ca 100644 --- a/cmd/clusterctl/client/client.go +++ b/cmd/clusterctl/client/client.go @@ -54,11 +54,6 @@ type Client interface { // Move moves all the Cluster API objects existing in a namespace (or from all the namespaces if empty) to a target management cluster. Move(options MoveOptions) error - // Restore restores all the Cluster API objects existing in a configured directory based on a glob to a target management cluster. - // - // Deprecated: This will be dropped in a future release. Please use Move. - Restore(options RestoreOptions) error - // PlanUpgrade returns a set of suggested Upgrade plans for the cluster, and more specifically: // - Upgrade to the latest version in the v1alpha3 series: .... // - Upgrade to the latest version in the v1alpha4 series: .... diff --git a/cmd/clusterctl/client/client_test.go b/cmd/clusterctl/client/client_test.go index ca24a33c069d..486384a2e0bc 100644 --- a/cmd/clusterctl/client/client_test.go +++ b/cmd/clusterctl/client/client_test.go @@ -108,10 +108,6 @@ func (f fakeClient) Move(options MoveOptions) error { return f.internalClient.Move(options) } -func (f fakeClient) Restore(options RestoreOptions) error { - return f.internalClient.Restore(options) -} - func (f fakeClient) PlanUpgrade(options PlanUpgradeOptions) ([]UpgradePlan, error) { return f.internalClient.PlanUpgrade(options) } diff --git a/cmd/clusterctl/client/cluster/mover.go b/cmd/clusterctl/client/cluster/mover.go index 61c23c045be2..c8c1ce1ee8e8 100644 --- a/cmd/clusterctl/client/cluster/mover.go +++ b/cmd/clusterctl/client/cluster/mover.go @@ -52,11 +52,6 @@ type ObjectMover interface { // FromDirectory reads all the Cluster API objects existing in a configured directory to a target management cluster. FromDirectory(toCluster Client, directory string) error - - // Restore restores all the Cluster API objects existing in a configured directory to a target management cluster. - // - // Deprecated: This will be dropped in a future release. Please use FromDirectory. - Restore(toCluster Client, directory string) error } // objectMover implements the ObjectMover interface. @@ -112,12 +107,6 @@ func (o *objectMover) ToDirectory(namespace string, directory string) error { return o.toDirectory(objectGraph, directory) } -func (o *objectMover) Restore(toCluster Client, directory string) error { - log := logf.Log - log.V(5).Info("Deprecated: This function will be dropped in a future release. Please use FromDirectory instead of Restore.") - return o.FromDirectory(toCluster, directory) -} - func (o *objectMover) FromDirectory(toCluster Client, directory string) error { log := logf.Log log.Info("Moving from directory...") diff --git a/cmd/clusterctl/client/cluster/mover_test.go b/cmd/clusterctl/client/cluster/mover_test.go index 499d28e5268e..56b10250d441 100644 --- a/cmd/clusterctl/client/cluster/mover_test.go +++ b/cmd/clusterctl/client/cluster/mover_test.go @@ -974,7 +974,7 @@ func Test_objectMover_filesToObjs(t *testing.T) { } } -func Test_objectMover_restore(t *testing.T) { +func Test_objectMover_fromDirectory(t *testing.T) { // NB. we are testing the move and move sequence using the same set of moveTests, but checking the results at different stages of the move process for _, tt := range backupRestoreTests { t.Run(tt.name, func(t *testing.T) { diff --git a/cmd/clusterctl/client/move.go b/cmd/clusterctl/client/move.go index 8f936af84500..32d90c65a578 100644 --- a/cmd/clusterctl/client/move.go +++ b/cmd/clusterctl/client/move.go @@ -48,18 +48,6 @@ type MoveOptions struct { DryRun bool } -// RestoreOptions holds options supported by restore. -// -// Deprecated: This will be dropped in a future release. Please use MoveOptions. -type RestoreOptions struct { - // FromKubeconfig defines the kubeconfig to use for accessing the target management cluster. If empty, - // default rules for kubeconfig discovery will be used. - ToKubeconfig Kubeconfig - - // Directory defines the local directory to restore cluster objects from - Directory string -} - func (c *clusterctlClient) Move(options MoveOptions) error { // Both backup and restore makes no sense. It's a complete move. if options.FromDirectory != "" && options.ToDirectory != "" { @@ -144,16 +132,6 @@ func (c *clusterctlClient) toDirectory(options MoveOptions) error { return fromCluster.ObjectMover().ToDirectory(options.Namespace, options.ToDirectory) } -// Restore restores all the Cluster API objects existing in a configured directory to a target management cluster. -// -// Deprecated: This will be dropped in a future release. Please use FromDirectory. -func (c *clusterctlClient) Restore(options RestoreOptions) error { - return c.Move(MoveOptions{ - ToKubeconfig: options.ToKubeconfig, - FromDirectory: options.Directory, - }) -} - func (c *clusterctlClient) getClusterClient(kubeconfig Kubeconfig) (cluster.Client, error) { cluster, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: kubeconfig}) if err != nil { diff --git a/cmd/clusterctl/client/move_test.go b/cmd/clusterctl/client/move_test.go index 94808b12167c..a34ba55cc31b 100644 --- a/cmd/clusterctl/client/move_test.go +++ b/cmd/clusterctl/client/move_test.go @@ -202,7 +202,7 @@ func Test_clusterctlClient_ToDirectory(t *testing.T) { } } -func Test_clusterctlClient_Restore(t *testing.T) { +func Test_clusterctlClient_FromDirectory(t *testing.T) { dir, err := os.MkdirTemp("/tmp", "cluster-api") if err != nil { t.Error(err) @@ -215,7 +215,7 @@ func Test_clusterctlClient_Restore(t *testing.T) { // These tests are checking the Restore scaffolding // The internal library handles the restore logic and tests can be found there type args struct { - options RestoreOptions + options MoveOptions } tests := []struct { name string @@ -229,9 +229,9 @@ func Test_clusterctlClient_Restore(t *testing.T) { client: fakeClientForMove(), // core v1.0.0 (v1.0.1 available), infra v2.0.0 (v2.0.1 available) }, args: args{ - options: RestoreOptions{ - ToKubeconfig: Kubeconfig{Path: "kubeconfig", Context: "mgmt-context"}, - Directory: dir, + options: MoveOptions{ + ToKubeconfig: Kubeconfig{Path: "kubeconfig", Context: "mgmt-context"}, + FromDirectory: dir, }, }, wantErr: false, @@ -242,9 +242,9 @@ func Test_clusterctlClient_Restore(t *testing.T) { client: fakeClientForMove(), // core v1.0.0 (v1.0.1 available), infra v2.0.0 (v2.0.1 available) }, args: args{ - options: RestoreOptions{ - ToKubeconfig: Kubeconfig{Path: "kubeconfig", Context: "does-not-exist"}, - Directory: dir, + options: MoveOptions{ + ToKubeconfig: Kubeconfig{Path: "kubeconfig", Context: "does-not-exist"}, + FromDirectory: dir, }, }, wantErr: true, @@ -255,7 +255,7 @@ func Test_clusterctlClient_Restore(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - err := tt.fields.client.Restore(tt.args.options) + err := tt.fields.client.Move(tt.args.options) if tt.wantErr { g.Expect(err).To(HaveOccurred()) return diff --git a/cmd/clusterctl/cmd/restore.go b/cmd/clusterctl/cmd/restore.go deleted file mode 100644 index 356e7a9c0027..000000000000 --- a/cmd/clusterctl/cmd/restore.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2019 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. -*/ - -package cmd - -import ( - "github.com/pkg/errors" - "github.com/spf13/cobra" - - "sigs.k8s.io/cluster-api/cmd/clusterctl/client" -) - -type restoreOptions struct { - toKubeconfig string - toKubeconfigContext string - directory string -} - -var ro = &restoreOptions{} - -var restoreCmd = &cobra.Command{ - Use: "restore", - GroupID: groupManagement, - Short: "Restore Cluster API objects from file by glob. Object files are searched in config directory", - Long: LongDesc(` - Restore Cluster API objects from file by glob. Object files are searched in the default config directory - or in the provided directory.`), - Example: Examples(` - Restore Cluster API objects from file by glob. Object files are searched in config directory. - clusterctl restore my-cluster`), - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runRestore() - }, - Deprecated: "use 'clusterctl move --from-directory' instead.", -} - -func init() { - restoreCmd.Flags().StringVar(&ro.toKubeconfig, "kubeconfig", "", - "Path to the kubeconfig file for the target management cluster to restore objects to. If unspecified, default discovery rules apply.") - restoreCmd.Flags().StringVar(&ro.toKubeconfigContext, "kubeconfig-context", "", - "Context to be used within the kubeconfig file for the target management cluster. If empty, current context will be used.") - restoreCmd.Flags().StringVar(&ro.directory, "directory", "", - "The directory to target when restoring Cluster API object yaml files") - - RootCmd.AddCommand(restoreCmd) -} - -func runRestore() error { - if ro.directory == "" { - return errors.New("please specify a directory to restore cluster API objects from using the --directory flag") - } - - c, err := client.New(cfgFile) - if err != nil { - return err - } - - return c.Move(client.MoveOptions{ - ToKubeconfig: client.Kubeconfig{Path: ro.toKubeconfig, Context: ro.toKubeconfigContext}, - FromDirectory: ro.directory, - }) -} diff --git a/docs/book/src/clusterctl/commands/additional-commands.md b/docs/book/src/clusterctl/commands/additional-commands.md index dbd0e138c523..278d8d9a1977 100644 --- a/docs/book/src/clusterctl/commands/additional-commands.md +++ b/docs/book/src/clusterctl/commands/additional-commands.md @@ -10,13 +10,6 @@ $HOME/.cluster-api/clusterctl.yaml file to add a new provider or to customize ex Help provides help for any command in the application. Simply type `clusterctl help [command]` for full details. -# clusterctl restore - -**DEPRECATED. Please use `clusterctl move --from-directory` instead.** - -Restore Cluster API objects from file by glob. Object files are searched in the default config directory -or in the provided directory. - # clusterctl version Print clusterctl version. diff --git a/docs/book/src/clusterctl/commands/commands.md b/docs/book/src/clusterctl/commands/commands.md index 52c68caf2bf1..c5b353155a49 100644 --- a/docs/book/src/clusterctl/commands/commands.md +++ b/docs/book/src/clusterctl/commands/commands.md @@ -16,7 +16,6 @@ | [`clusterctl init`](init.md) | Initialize a management cluster. | | [`clusterctl init list-images`](additional-commands.md#clusterctl-init-list-images) | Lists the container images required for initializing the management cluster. | | [`clusterctl move`](move.md) | Move Cluster API objects and all their dependencies between management clusters. | -| [`clusterctl restore`](additional-commands.md#clusterctl-restore) | Restore Cluster API objects from file by glob. **DEPRECATED. Please use `clusterctl move --from-directory` instead.** | | [`clusterctl upgrade plan`](upgrade.md#upgrade-plan) | Provide a list of recommended target versions for upgrading Cluster API providers in a management cluster. | | [`clusterctl upgrade apply`](upgrade.md#upgrade-apply) | Apply new versions of Cluster API core and providers in a management cluster. | | [`clusterctl version`](additional-commands.md#clusterctl-version) | Print clusterctl version. | diff --git a/docs/book/src/developer/providers/v1.3-to-v1.4.md b/docs/book/src/developer/providers/v1.3-to-v1.4.md index 1f783808e95e..14fc2ac13709 100644 --- a/docs/book/src/developer/providers/v1.3-to-v1.4.md +++ b/docs/book/src/developer/providers/v1.3-to-v1.4.md @@ -22,6 +22,7 @@ maintainers of providers and consumers of our Go API. ### Removals - `clusterctl backup` has been removed. +- `clusterctl restore` has been removed. - `api/v1beta1.MachineHealthCheckSuccededCondition` condition type has been removed. - `controller/external/util.CloneTemplate` and `controllers/external/util.CloneTemplateInput` has been removed. - The option `--list-images` from `clusterctl init` subcommand has been removed. @@ -32,6 +33,7 @@ maintainers of providers and consumers of our Go API. ### API Changes - `Backup(options BackupOptions) error` in the Client interface has been removed. +- `Restore(options RestoreOptions) error` in the Client interface has been removed. ### Other