Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/clusters-deregister.go
3601 views
1
// Copyright (c) 2021 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
"context"
9
"fmt"
10
"io"
11
12
"github.com/spf13/cobra"
13
14
"github.com/gitpod-io/gitpod/common-go/log"
15
"github.com/gitpod-io/gitpod/ws-manager-bridge/api"
16
)
17
18
var clustersDeregisterOpts struct {
19
Force bool
20
}
21
22
// clustersDeregisterCmd represents the clustersDeregisterCmd command
23
var clustersDeregisterCmd = &cobra.Command{
24
Use: "deregister --name [cluster name]",
25
Short: "Deregister a cluster",
26
Long: "Deregisters the cluster [cluster name].",
27
Run: func(cmd *cobra.Command, args []string) {
28
ctx, cancel := context.WithCancel(context.Background())
29
defer cancel()
30
31
conn, client, err := getClustersClient(ctx)
32
if err != nil {
33
log.WithError(err).Fatal("cannot connect")
34
}
35
defer conn.Close()
36
37
name := getClusterName()
38
_, err = client.Deregister(ctx, &api.DeregisterRequest{Name: name, Force: clustersDeregisterOpts.Force})
39
if err != nil && err != io.EOF {
40
log.Fatal(err)
41
}
42
43
fmt.Printf("cluster '%s' deregistered\n", name)
44
},
45
}
46
47
func init() {
48
clustersCmd.AddCommand(clustersDeregisterCmd)
49
clustersDeregisterCmd.Flags().BoolVar(&clustersDeregisterOpts.Force, "force", false, "⚠️💥 force cluster deregistration even if there are still instances running. Use with great caution: this will break people's experience.")
50
}
51
52