Skip to content

Commit

Permalink
chore: update kbcli doc
Browse files Browse the repository at this point in the history
  • Loading branch information
nashtsai committed Mar 8, 2023
1 parent ae7ea3a commit 989c979
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 41 deletions.
8 changes: 4 additions & 4 deletions controllers/extensions/addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ func (r *stageCtx) setReconciled() {
r.updateResultNErr(&res, err)
}

func (r *stageCtx) setRequeue() {
res, err := intctrlutil.Requeue(r.reqCtx.Log, "")
r.updateResultNErr(&res, err)
}
// func (r *stageCtx) setRequeue() {
// res, err := intctrlutil.Requeue(r.reqCtx.Log, "")
// r.updateResultNErr(&res, err)
// }

func (r *stageCtx) setRequeueAfter(duration time.Duration, msg string) {
res, err := intctrlutil.RequeueAfter(time.Second, r.reqCtx.Log, msg)
Expand Down
2 changes: 1 addition & 1 deletion controllers/extensions/addon_controller_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (r *autoInstallCheckStage) Handle(ctx context.Context) {
return
}
r.reconciler.Recorder.Event(addon, "Normal", AddonAutoInstall,
fmt.Sprintf("Addon enabled auto-install"))
"Addon enabled auto-install")
r.setReconciled()
}

Expand Down
1 change: 0 additions & 1 deletion docs/user_docs/cli/kbcli_addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Addon command
### SEE ALSO

* [kbcli](kbcli.md) - KubeBlocks CLI
* [kbcli addon describe](kbcli_addon_describe.md) - Describe an addon specification
* [kbcli addon disable](kbcli_addon_disable.md) - Disable an addon
* [kbcli addon enable](kbcli_addon_enable.md) - Enable an addon
* [kbcli addon list](kbcli_addon_list.md) - List addons
Expand Down
7 changes: 6 additions & 1 deletion docs/user_docs/cli/kbcli_addon_disable.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ kbcli addon disable ADDON_NAME [flags]
### Options

```
-h, --help help for disable
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
--dry-run string[="unchanged"] Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. (default "none")
-h, --help help for disable
-o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file).
--show-managed-fields If true, keep the managedFields when printing objects in JSON or YAML format.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
```

### Options inherited from parent commands
Expand Down
25 changes: 15 additions & 10 deletions docs/user_docs/cli/kbcli_addon_enable.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ kbcli addon enable ADDON_NAME [flags]
kbcli addon enable prometheus
# Enabled "prometheus" addon with custom resources settings
kbcli addon enable prometheus --memory 512Mi:4Gi --storage 8Gi --replicas 2
kbcli addon enable prometheus --memory 512Mi/4Gi --storage 8Gi --replicas 2
# Enabled "prometheus" addon and its extra alertmanager component with custom resources settings
kbcli addon enable prometheus --memory 512Mi:4Gi --storage 8Gi --replicas 2 \
--memory alertmanager:16Mi:256Mi --storage: alertmanager:1Gi --replicas alertmanager:2
kbcli addon enable prometheus --memory 512Mi/4Gi --storage 8Gi --replicas 2 \
--memory alertmanager:16Mi/256Mi --storage: alertmanager:1Gi --replicas alertmanager:2
# Enabled "prometheus" addon with tolerations
kbcli addon enable prometheus --tolerations '[[{"key":"taintkey","operator":"Equal","effect":"NoSchedule","value":"true"}]]' \
Expand All @@ -27,13 +27,18 @@ kbcli addon enable ADDON_NAME [flags]
### Options

```
----cpu stringArray Sets addon CPU resource values (--cpu [extraName:]<request>:<limit>) (can specify multiple if has extra items))
----memory stringArray Sets addon memory resource values (--memory [extraName:]<request>:<limit>) (can specify multiple if has extra items))
----replicas stringArray Sets addon component replica count (--replicas [extraName:]<N>) (can specify multiple if has extra items))
----storage stringArray Sets addon storage size (--storage [extraName:]<request>) (can specify multiple if has extra items))
----storage-class stringArray Sets addon storage class name (--storage-class [extraName:]<SC name>) (can specify multiple if has extra items))
----tolerations stringArray Sets addon pod tolerations (--tolerations [extraName:]<toleration JSON list items>) (can specify multiple if has extra items))
-h, --help help for enable
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
--cpu stringArray Sets addon CPU resource values (--cpu [extraName:]<request>/<limit>) (can specify multiple if has extra items))
--dry-run string[="unchanged"] Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. (default "none")
-h, --help help for enable
--memory stringArray Sets addon memory resource values (--memory [extraName:]<request>/<limit>) (can specify multiple if has extra items))
-o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file).
--replicas stringArray Sets addon component replica count (--replicas [extraName:]<number>) (can specify multiple if has extra items))
--show-managed-fields If true, keep the managedFields when printing objects in JSON or YAML format.
--storage stringArray Sets addon storage size (--storage [extraName:]<request>) (can specify multiple if has extra items))
--storage-class stringArray Sets addon storage class name (--storage-class [extraName:]<storage class name>) (can specify multiple if has extra items))
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--tolerations stringArray Sets addon pod tolerations (--tolerations [extraName:]<toleration JSON list items>) (can specify multiple if has extra items))
```

### Options inherited from parent commands
Expand Down
6 changes: 5 additions & 1 deletion docs/user_docs/cli/kbcli_addon_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ kbcli addon list [flags]
### Options

```
-h, --help help for list
-A, --all-namespace If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
-h, --help help for list
-o, --output format prints the output in the specified format. Allowed values: table, json, yaml, wide (default table)
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints.
--show-labels When printing, show all labels as the last column (default hide labels column)
```

### Options inherited from parent commands
Expand Down
45 changes: 28 additions & 17 deletions internal/cli/cmd/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ func newEnableCmd(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
},
}
cmd.Flags().StringArrayVar(&o.addonEnableFlags.MemorySets, "memory", []string{},
"Sets addon memory resource values (--memory [extraName:]<request>:<limit>) (can specify multiple if has extra items))")
"Sets addon memory resource values (--memory [extraName:]<request>/<limit>) (can specify multiple if has extra items))")
cmd.Flags().StringArrayVar(&o.addonEnableFlags.CPUSets, "cpu", []string{},
"Sets addon CPU resource values (--cpu [extraName:]<request>:<limit>) (can specify multiple if has extra items))")
"Sets addon CPU resource values (--cpu [extraName:]<request>/<limit>) (can specify multiple if has extra items))")
cmd.Flags().StringArrayVar(&o.addonEnableFlags.StorageSets, "storage", []string{},
"Sets addon storage size (--storage [extraName:]<request>) (can specify multiple if has extra items))")
cmd.Flags().StringArrayVar(&o.addonEnableFlags.ReplicaCountSets, "replicas", []string{},
"Sets addon component replica count (--replicas [extraName:]<N>) (can specify multiple if has extra items))")
"Sets addon component replica count (--replicas [extraName:]<number>) (can specify multiple if has extra items))")
cmd.Flags().StringArrayVar(&o.addonEnableFlags.StorageClassSets, "storage-class", []string{},
"Sets addon storage class name (--storage-class [extraName:]<SC name>) (can specify multiple if has extra items))")
"Sets addon storage class name (--storage-class [extraName:]<storage class name>) (can specify multiple if has extra items))")
cmd.Flags().StringArrayVar(&o.addonEnableFlags.TolerationsSet, "tolerations", []string{},
"Sets addon pod tolerations (--tolerations [extraName:]<toleration JSON list items>) (can specify multiple if has extra items))")

Expand Down Expand Up @@ -333,7 +333,7 @@ func (o *addonCmdOpts) buildEnablePatch(flags []*pflag.Flag, spec, install map[s

f := o.addonEnableFlags
for _, v := range f.ReplicaCountSets {
twoTuplesProcessor(v, "replicas", func(s, flag string) (interface{}, error) {
if err := twoTuplesProcessor(v, "replicas", func(s, flag string) (interface{}, error) {
v, err := strconv.Atoi(s)
if err != nil {
return nil, fmt.Errorf("wrong flag value --%s=%s, with error %v", flag, s, err)
Expand All @@ -342,49 +342,60 @@ func (o *addonCmdOpts) buildEnablePatch(flags []*pflag.Flag, spec, install map[s
return &r, nil
}, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
item.Replicas = i.(*int32)
})
}); err != nil {
return err
}
}

for _, v := range f.StorageClassSets {
twoTuplesProcessor(v, "storage-class", nil, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
if err := twoTuplesProcessor(v, "storage-class", nil, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
item.StorageClass = i.(string)
})
}); err != nil {
return err
}
}

for _, v := range f.TolerationsSet {
twoTuplesProcessor(v, "tolerations", nil, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
if err := twoTuplesProcessor(v, "tolerations", nil, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
item.Tolerations = i.(string)
})
}); err != nil {
return err
}
}

for _, v := range f.StorageSets {
twoTuplesProcessor(v, "storage", func(s, flag string) (interface{}, error) {
if err := twoTuplesProcessor(v, "storage", func(s, flag string) (interface{}, error) {
q, err := resource.ParseQuantity(s)
if err != nil {
return nil, fmt.Errorf("wrong flag value --%s=%s, with error %v", flag, s, err)
}
return q, nil
}, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
item.Resources.Requests[corev1.ResourceStorage] = i.(resource.Quantity)
})
}); err != nil {
return err
}
}

for _, v := range f.CPUSets {
twoTuplesProcessor(v, "cpu", reqLimitResTransformer, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
if err := twoTuplesProcessor(v, "cpu", reqLimitResTransformer, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
reqLim := i.([2]resource.Quantity)
item.Resources.Requests[corev1.ResourceCPU] = reqLim[0]
item.Resources.Limits[corev1.ResourceCPU] = reqLim[1]
})
}); err != nil {
return err
}
}

for _, v := range f.MemorySets {
twoTuplesProcessor(v, "memory", reqLimitResTransformer, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
if err := twoTuplesProcessor(v, "memory", reqLimitResTransformer, func(item *extensionsv1alpha1.AddonInstallSpecItem, i interface{}) {
reqLim := i.([2]resource.Quantity)
item.Resources.Requests[corev1.ResourceMemory] = reqLim[0]
item.Resources.Limits[corev1.ResourceMemory] = reqLim[1]
})
}); err != nil {
return err
}
}

return nil
}

Expand Down
5 changes: 0 additions & 5 deletions internal/cli/cmd/addon/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import (
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
)

const (
testAppName = "test-app"
testNamespace = "test"
)

var _ = Describe("Manage applications related to KubeBlocks", func() {
var streams genericclioptions.IOStreams
var tf *cmdtesting.TestFactory
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/testing/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func FakeBackupPolicyTemplate() *dpv1alpha1.BackupPolicyTemplate {
func FakeBackup(backupName string) *dpv1alpha1.Backup {
backup := &dpv1alpha1.Backup{
TypeMeta: metav1.TypeMeta{
APIVersion: fmt.Sprintf("%s/%s", types.DPAPIGroup, types.DPVersion),
APIVersion: fmt.Sprintf("%s/%s", types.DPAPIGroup, types.DPAPIVersion),
Kind: types.KindBackup,
},
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 989c979

Please sign in to comment.