github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/cluster/cluster.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package cluster 21 22 import ( 23 "github.com/spf13/cobra" 24 "k8s.io/cli-runtime/pkg/genericiooptions" 25 cmdutil "k8s.io/kubectl/pkg/cmd/util" 26 "k8s.io/kubectl/pkg/util/templates" 27 28 viper "github.com/1aal/kubeblocks/pkg/viperx" 29 ) 30 31 const ( 32 EnvExperimentalExpose = "KBCLI_EXPERIMENTAL_EXPOSE" 33 ) 34 35 func init() { 36 _ = viper.BindEnv(EnvExperimentalExpose) 37 } 38 39 // NewClusterCmd creates the cluster command 40 func NewClusterCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { 41 cmd := &cobra.Command{ 42 Use: "cluster", 43 Short: "Cluster command.", 44 } 45 46 groups := templates.CommandGroups{ 47 { 48 Message: "Basic Cluster Commands:", 49 Commands: []*cobra.Command{ 50 NewCreateCmd(f, streams), 51 NewConnectCmd(f, streams), 52 NewDescribeCmd(f, streams), 53 NewListCmd(f, streams), 54 NewListInstancesCmd(f, streams), 55 NewListComponentsCmd(f, streams), 56 NewListEventsCmd(f, streams), 57 NewLabelCmd(f, streams), 58 NewDeleteCmd(f, streams), 59 newRegisterCmd(f, streams), 60 }, 61 }, 62 { 63 Message: "Cluster Operation Commands:", 64 Commands: []*cobra.Command{ 65 NewUpdateCmd(f, streams), 66 NewStopCmd(f, streams), 67 NewStartCmd(f, streams), 68 NewRestartCmd(f, streams), 69 NewUpgradeCmd(f, streams), 70 NewVolumeExpansionCmd(f, streams), 71 NewVerticalScalingCmd(f, streams), 72 NewHorizontalScalingCmd(f, streams), 73 NewPromoteCmd(f, streams), 74 NewDescribeOpsCmd(f, streams), 75 NewListOpsCmd(f, streams), 76 NewDeleteOpsCmd(f, streams), 77 NewExposeCmd(f, streams), 78 NewCancelCmd(f, streams), 79 }, 80 }, 81 { 82 Message: "Cluster Configuration Operation Commands:", 83 Commands: []*cobra.Command{ 84 NewReconfigureCmd(f, streams), 85 NewEditConfigureCmd(f, streams), 86 NewDescribeReconfigureCmd(f, streams), 87 NewExplainReconfigureCmd(f, streams), 88 NewDiffConfigureCmd(f, streams), 89 }, 90 }, 91 { 92 Message: "Backup/Restore Commands:", 93 Commands: []*cobra.Command{ 94 NewListBackupPolicyCmd(f, streams), 95 NewEditBackupPolicyCmd(f, streams), 96 NewDescribeBackupPolicyCmd(f, streams), 97 NewCreateBackupCmd(f, streams), 98 NewListBackupCmd(f, streams), 99 NewDeleteBackupCmd(f, streams), 100 NewCreateRestoreCmd(f, streams), 101 NewDescribeBackupCmd(f, streams), 102 }, 103 }, 104 { 105 Message: "Troubleshooting Commands:", 106 Commands: []*cobra.Command{ 107 NewLogsCmd(f, streams), 108 NewListLogsCmd(f, streams), 109 }, 110 }, 111 112 { 113 Message: "User Accounts Commands:", 114 Commands: []*cobra.Command{ 115 NewCreateAccountCmd(f, streams), 116 NewDeleteAccountCmd(f, streams), 117 NewDescAccountCmd(f, streams), 118 NewListAccountsCmd(f, streams), 119 NewGrantOptions(f, streams), 120 NewRevokeOptions(f, streams), 121 }, 122 }, 123 } 124 125 // add subcommands 126 groups.Add(cmd) 127 templates.ActsAsRootCommand(cmd, nil, groups...) 128 129 return cmd 130 }