|
| 1 | +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License-AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +package cmd |
| 6 | + |
| 7 | +import ( |
| 8 | +"fmt" |
| 9 | +"os" |
| 10 | + |
| 11 | +"github.com/gitpod-io/gitpod/common-go/log" |
| 12 | +"github.com/gitpod-io/gitpod/workspace-rollout-job/pkg/rollout" |
| 13 | +"github.com/gitpod-io/gitpod/workspace-rollout-job/pkg/wsbridge" |
| 14 | +"github.com/spf13/cobra" |
| 15 | +) |
| 16 | + |
| 17 | +var rootCmd = &cobra.Command{ |
| 18 | +Use: "workspace-rollout-job", |
| 19 | +Short: "Rollout from old to a new cluster while monitoring metrics", |
| 20 | +Run: func(cmd *cobra.Command, args []string) { |
| 21 | +log.Info("Starting workspace-rollout-job") |
| 22 | +var err error |
| 23 | +old, presence := os.LookupEnv("OLD_CLUSTER") |
| 24 | +if !presence { |
| 25 | +log.WithError(err).Fatal("cannot get old cluster") |
| 26 | +} |
| 27 | + |
| 28 | +new, presence := os.LookupEnv("NEW_CLUSTER") |
| 29 | +if !presence { |
| 30 | +log.WithError(err).Fatal("cannot get new cluster") |
| 31 | +} |
| 32 | + |
| 33 | +// Check if the old cluster has a 100 score. |
| 34 | +if err = wsbridge.CheckScore(old, 100); err != nil { |
| 35 | +log.WithError(err).Fatal("init condition does not satisfy") |
| 36 | +} |
| 37 | + |
| 38 | +// Check if the new cluster has a 0 zero score. |
| 39 | +// TODO: Check if the new cluster has no constraints. |
| 40 | +if err = wsbridge.CheckScore(new, 0); err != nil { |
| 41 | +log.WithError(err).Fatal("init condition does not satisfy") |
| 42 | +} |
| 43 | + |
| 44 | +// Start the rollout process. |
| 45 | +job := rollout.New(old, new, "http://prometheus:9090") |
| 46 | +job.Start() |
| 47 | +}, |
| 48 | +} |
| 49 | + |
| 50 | +// Execute adds all child commands to the root command and sets flags appropriately. |
| 51 | +// This is called by main.main(). It only needs to happen once to the rootCmd. |
| 52 | +func Execute() { |
| 53 | +if err := rootCmd.Execute(); err != nil { |
| 54 | +fmt.Println(err) |
| 55 | +os.Exit(1) |
| 56 | +} |
| 57 | +} |
0 commit comments