Skip to content

Commit

Permalink
add infra command example
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Jul 5, 2023
1 parent a3c9680 commit 8793a52
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
66 changes: 64 additions & 2 deletions internal/cli/cmd/infrastructure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/spf13/cobra"
versionutil "k8s.io/apimachinery/pkg/util/version"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/util/templates"

"github.com/apecloud/kubeblocks/internal/cli/cmd/infrastructure/constant"
"github.com/apecloud/kubeblocks/internal/cli/cmd/infrastructure/tasks"
Expand All @@ -49,8 +50,69 @@ type createOptions struct {
outputKubeconfig string
}

var createExamples = `
`
var createExamples = templates.Examples(`
# Create kubernetes cluster with specified config yaml
kbcli infra create -c cluster.yaml
# example cluster.yaml
cat cluster.yaml
metadata:
name: kb-k8s-test-cluster
user:
name: user1
privateKeyPath: ~/.ssh/test.pem
nodes:
- name: kb-infra-node-0
address: 1.1.1.1
internalAddress: 10.128.0.19
- name: kb-infra-node-1
address: 1.1.1.2
internalAddress: 10.128.0.20
- name: kb-infra-node-2
address: 1.1.1.3
internalAddress: 10.128.0.21
options:
hugePageFeature:
hugePageSize: 10GB
roleGroup:
etcd:
- kb-infra-node-0
- kb-infra-node-1
- kb-infra-node-2
master:
- kb-infra-node-0
worker:
- kb-infra-node-1
- kb-infra-node-2
kubernetes:
containerManager: containerd
# apis/kubeadm/types.Networking
networking:
plugin: cilium
dnsDomain: cluster.local
podSubnet: 10.233.64.0/18
serviceSubnet: 10.233.0.0/18
controlPlaneEndpoint:
domain: lb.kubeblocks.local
port: 6443
cri:
containerRuntimeType: "containerd"
containerRuntimeEndpoint: "unix:///run/containerd/containerd.sock"
sandBoxImage: "k8s.gcr.io/pause:3.8"
addons:
- name: openebs
namespace: kube-blocks
sources:
chart:
name: openebs
version: 3.7.0
repo: https://openebs.github.io/charts
options:
values:
- "localprovisioner.basePath=/mnt/disks"
- "localprovisioner.hostpathClass.isDefaultClass=true"
`)

func (o *createOptions) Run() error {
const minKubernetesVersion = "v1.24.0"
Expand Down
8 changes: 7 additions & 1 deletion internal/cli/cmd/infrastructure/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/pipeline"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/util/templates"

"github.com/apecloud/kubeblocks/internal/cli/util"
)
Expand All @@ -39,6 +40,11 @@ type deleteOptions struct {
debug bool
}

var deleteExamples = templates.Examples(`
# delete kubernetes cluster with specified config yaml
kbcli infra delete -c cluster.yaml
`)

func (o *deleteOptions) Run() error {
o.Cluster.Kubernetes.AutoDefaultFill()
cluster, err := createClusterWithOptions(&gotemplate.TplValues{
Expand Down Expand Up @@ -99,7 +105,7 @@ func NewDeleteKubernetesCmd(streams genericclioptions.IOStreams) *cobra.Command
cmd := &cobra.Command{
Use: "delete",
Short: "delete kubernetes cluster.",
Example: createExamples,
Example: deleteExamples,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(o.Complete())
util.CheckErr(o.Validate())
Expand Down

0 comments on commit 8793a52

Please sign in to comment.