-
Notifications
You must be signed in to change notification settings - Fork 787
/
upgrade_crd.go
64 lines (57 loc) · 1.59 KB
/
upgrade_crd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package upgrade
import (
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/kube"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
upgradeCRDsLong = templates.LongDesc(`
Upgrades the Jenkins X Custom Resource Definitions in the Kubernetes Cluster
`)
upgradeCRDsExample = templates.Examples(`
# Upgrades the Custom Resource Definitions
jx upgrade crd
`)
)
// UpgradeCRDsOptions the options for the upgrade CRDs command
type UpgradeCRDsOptions struct {
UpgradeOptions
}
// NewCmdUpgradeCRDs defines the command
func NewCmdUpgradeCRDs(commonOpts *opts.CommonOptions) *cobra.Command {
options := &UpgradeCRDsOptions{
UpgradeOptions: UpgradeOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "crd",
Short: "Upgrades the Jenkins X Custom Resource Definitions in the Kubernetes Cluster",
Long: upgradeCRDsLong,
Example: upgradeCRDsExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
return cmd
}
// Run implements the command
func (o *UpgradeCRDsOptions) Run() error {
apisClient, err := o.ApiExtensionsClient()
if err != nil {
return errors.Wrap(err, "failed to create the API extensions client")
}
err = kube.RegisterAllCRDs(apisClient)
if err != nil {
return errors.Wrap(err, "failed to register all CRDs")
}
log.Logger().Info("Jenkins X CRDs upgraded with success")
return nil
}