init

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "init",
	Short: "Init.",
	Long:  `Init container for Galera and co-operates with mariadb-operator.`,
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if err := log.SetupLoggerWithCommand(cmd); err != nil {
			fmt.Printf("error setting up logger: %v\n", err)
			os.Exit(1)
		}
		logger.Info("Starting init")

		ctx, cancel := newContext()
		defer cancel()

		env, err := environment.GetPodEnv(ctx)
		if err != nil {
			logger.Error(err, "Error getting environment variables")
			os.Exit(1)
		}
		fileManager, err := filemanager.NewFileManager(configDir, stateDir)
		if err != nil {
			logger.Error(err, "Error creating file manager")
			os.Exit(1)
		}
		state := state.NewState(stateDir)
		k8sClient, err := getK8sClient()
		if err != nil {
			logger.Error(err, "Error getting Kubernetes client")
			os.Exit(1)
		}

		isGaleraInit, err := state.IsGaleraInit()
		if err != nil {
			logger.Error(err, "Error checking Galera init state")
			os.Exit(1)
		}
		podIndex, err := statefulset.PodIndex(env.PodName)
		if err != nil {
			logger.Error(err, "error getting index from Pod", "pod", env.PodName)
			os.Exit(1)
		}

		key := types.NamespacedName{
			Name:      env.MariadbName,
			Namespace: env.PodNamespace,
		}
		var mdb mariadbv1alpha1.MariaDB
		if err := k8sClient.Get(ctx, key, &mdb); err != nil {
			logger.Error(err, "Error getting MariaDB")

			if err := updateNodeAddress(fileManager, env); err != nil {
				logger.Error(err, "Error upddating node address")
				os.Exit(1)
			}
			logger.Info("Updated node address")
			os.Exit(0)
		}

		if err := configureGalera(fileManager, env, &mdb); err != nil {
			logger.Error(err, "error configuring Galera")
			os.Exit(1)
		}
		if err := configureGaleraBootstrap(fileManager, *podIndex, isGaleraInit); err != nil {
			logger.Error(err, "error configuring Galera bootstrap")
		}
		if err := waitForPreviousPod(ctx, k8sClient, env, &mdb, *podIndex, isGaleraInit); err != nil {
			logger.Error(err, "error waiting for previous Pod")
			os.Exit(1)
		}
		logger.Info("Init done")
	},
}

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