migrate

package
v1.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "migrate",
	Short: "Migrates to the new Config Sync architecture by enabling the multi-repo mode.",
	Long:  "Migrates to the new Config Sync architecture by enabling the multi-repo mode. It provides you with additional features and gives you the flexibility to sync to a single repository, or multiple repositories.",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) error {

		cmd.SilenceUsage = true

		var contexts []string
		if len(flags.Contexts) == 0 {
			currentContext, err := restconfig.CurrentContextName()
			if err != nil {
				return fmt.Errorf("failed to get current context name with err: %w", err)
			}
			contexts = append(contexts, currentContext)
		} else if len(flags.Contexts) != 1 || flags.Contexts[0] != "all" {
			contexts = flags.Contexts
		}

		clientMap, err := status.ClusterClients(cmd.Context(), contexts)
		if err != nil {
			return err
		}

		var migrationContexts []string
		migrationError := false
		for context, c := range clientMap {
			migrationContexts = append(migrationContexts, context)
			fmt.Println()
			fmt.Println(util.Separator)
			cs := &status.ClusterState{Ref: context}
			if !c.IsInstalled(cmd.Context(), cs) {
				printError(cs.Error)
				migrationError = true
				continue
			}
			if isManagedByHub, err := c.ConfigManagement.IsManagedByHub(cmd.Context()); err != nil {
				printError(err)
				migrationError = true
				continue
			} else if isManagedByHub {
				printError("The cluster is managed by Hub. Migration is not supported.")
				migrationError = true
				continue
			}

			if err := migrateMonoRepo(cmd.Context(), c, context); err != nil {
				printError(err)
				migrationError = true
				continue
			}

			if removeConfigManagement {
				if err := migrateConfigManagement(cmd.Context(), c, context); err != nil {
					printError(err)
					migrationError = true
					continue
				}
			}

			printSuccess(migrationSuccess)
		}

		if migrationError {
			fmt.Println("\nFinished migration with errors. Please see above for errors and check the status with `nomos status`.")
		} else {
			fmt.Printf("\nFinished migration on the contexts: %s. Please check the sync status with `nomos status`.\n", strings.Join(migrationContexts, ", "))
		}
		return nil
	},
}

Cmd performs the migration from mono-repo to multi-repo for all the provided contexts.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL