github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/cmd/orbctl/cmds/takeoff.go (about) 1 package cmds 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 8 "gopkg.in/yaml.v3" 9 10 "github.com/caos/orbos/pkg/kubernetes/cli" 11 12 orbcfg "github.com/caos/orbos/pkg/orb" 13 14 "github.com/caos/orbos/internal/ctrlgitops" 15 16 "github.com/caos/orbos/mntr" 17 "github.com/caos/orbos/pkg/git" 18 "github.com/caos/orbos/pkg/kubernetes" 19 ) 20 21 func Takeoff( 22 monitor mntr.Monitor, 23 ctx context.Context, 24 orbConfig *orbcfg.Orb, 25 gitClient *git.Client, 26 recur bool, 27 deploy bool, 28 verbose bool, 29 version string, 30 gitCommit string, 31 kubeconfig string, 32 gitOps bool, 33 operators []string, 34 ) error { 35 36 if gitOps { 37 if err := orbcfg.IsComplete(orbConfig); err != nil { 38 return err 39 } 40 41 if err := gitClient.Configure(orbConfig.URL, []byte(orbConfig.Repokey)); err != nil { 42 return err 43 } 44 45 if err := gitClient.Clone(); err != nil { 46 return err 47 } 48 49 if gitClient.Exists(git.OrbiterFile) && deployOperator(operators, "orbiter") { 50 orbiterConfig := &ctrlgitops.OrbiterConfig{ 51 Recur: recur, 52 Deploy: deploy, 53 Verbose: verbose, 54 Version: version, 55 OrbConfigPath: orbConfig.Path, 56 GitCommit: gitCommit, 57 } 58 if err := ctrlgitops.Orbiter(ctx, monitor, orbiterConfig, gitClient); err != nil { 59 return err 60 } 61 } 62 } 63 64 if !deploy { 65 monitor.Info("Skipping operator deployments") 66 return nil 67 } 68 69 k8sClient, err := cli.Init( 70 monitor, 71 orbConfig, 72 gitClient, 73 kubeconfig, 74 gitOps, 75 false, 76 false, 77 ) 78 if err != nil { 79 return err 80 } 81 82 if err := kubernetes.EnsureCaosSystemNamespace(monitor, k8sClient); err != nil { 83 return fmt.Errorf("failed to apply common resources into k8s-cluster: %w", err) 84 } 85 86 if gitOps { 87 88 orbConfigBytes, err := yaml.Marshal(orbConfig) 89 if err != nil { 90 return err 91 } 92 93 if err := kubernetes.EnsureOrbconfigSecret(monitor, k8sClient, orbConfigBytes); err != nil { 94 return fmt.Errorf("failed to apply configuration resources into k8s-cluster: %w", err) 95 } 96 } 97 98 if deployOperator(operators, "boom") { 99 if err := deployBoom(monitor, gitClient, k8sClient, version, gitOps); err != nil { 100 return err 101 } 102 } 103 if deployOperator(operators, "networking") { 104 return deployNetworking(monitor, gitClient, k8sClient, version, gitOps) 105 } 106 return nil 107 } 108 109 func deployOperator(arguments []string, operator string) bool { 110 if len(arguments) == 0 { 111 return true 112 } 113 114 for idx := range arguments { 115 if strings.ToLower(arguments[idx]) == strings.ToLower(operator) { 116 return true 117 } 118 } 119 return false 120 }