diff --git a/docs/user_docs/cli/cli.md b/docs/user_docs/cli/cli.md index ef8a7d646..e54215722 100644 --- a/docs/user_docs/cli/cli.md +++ b/docs/user_docs/cli/cli.md @@ -150,20 +150,6 @@ Data protection command. * [kbcli dataprotection restore](kbcli_dataprotection_restore.md) - Restore a new cluster from backup -## [fault](kbcli_fault.md) - -Inject faults to pod. - -* [kbcli fault delete](kbcli_fault_delete.md) - Delete chaos resources. -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. -* [kbcli fault list](kbcli_fault_list.md) - List chaos resources. -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. -* [kbcli fault node](kbcli_fault_node.md) - Node chaos. -* [kbcli fault pod](kbcli_fault_pod.md) - Pod chaos. -* [kbcli fault stress](kbcli_fault_stress.md) - Add memory pressure or CPU load to the system. -* [kbcli fault time](kbcli_fault_time.md) - Clock skew failure. - - ## [kubeblocks](kbcli_kubeblocks.md) KubeBlocks operation commands. diff --git a/docs/user_docs/cli/kbcli.md b/docs/user_docs/cli/kbcli.md index 75a74fd02..203e87c32 100644 --- a/docs/user_docs/cli/kbcli.md +++ b/docs/user_docs/cli/kbcli.md @@ -63,7 +63,6 @@ kbcli [flags] * [kbcli clusterversion](kbcli_clusterversion.md) - ClusterVersion command. * [kbcli dashboard](kbcli_dashboard.md) - List and open the KubeBlocks dashboards. * [kbcli dataprotection](kbcli_dataprotection.md) - Data protection command. -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. * [kbcli kubeblocks](kbcli_kubeblocks.md) - KubeBlocks operation commands. * [kbcli options](kbcli_options.md) - Print the list of flags inherited by all commands. * [kbcli playground](kbcli_playground.md) - Bootstrap or destroy a playground KubeBlocks in local host or cloud. diff --git a/docs/user_docs/cli/kbcli_fault.md b/docs/user_docs/cli/kbcli_fault.md deleted file mode 100644 index c16772756..000000000 --- a/docs/user_docs/cli/kbcli_fault.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: kbcli fault ---- - -Inject faults to pod. - -### Options - -``` - -h, --help help for fault -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - - -* [kbcli fault delete](kbcli_fault_delete.md) - Delete chaos resources. -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. -* [kbcli fault list](kbcli_fault_list.md) - List chaos resources. -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. -* [kbcli fault node](kbcli_fault_node.md) - Node chaos. -* [kbcli fault pod](kbcli_fault_pod.md) - Pod chaos. -* [kbcli fault stress](kbcli_fault_stress.md) - Add memory pressure or CPU load to the system. -* [kbcli fault time](kbcli_fault_time.md) - Clock skew failure. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_delete.md b/docs/user_docs/cli/kbcli_fault_delete.md deleted file mode 100644 index 70837bee6..000000000 --- a/docs/user_docs/cli/kbcli_fault_delete.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: kbcli fault delete ---- - -Delete chaos resources. - -``` -kbcli fault delete [flags] -``` - -### Examples - -``` - # Delete all chaos resources - kbcli fault delete - - # Delete specific chaos resources - kbcli fault delete podchaos -``` - -### Options - -``` - -h, --help help for delete -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_io.md b/docs/user_docs/cli/kbcli_fault_io.md deleted file mode 100644 index 80f1f2ced..000000000 --- a/docs/user_docs/cli/kbcli_fault_io.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: kbcli fault io ---- - -IO chaos. - -### Options - -``` - -h, --help help for io -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. -* [kbcli fault io attribute](kbcli_fault_io_attribute.md) - Override the attributes of the file. -* [kbcli fault io errno](kbcli_fault_io_errno.md) - Causes IO operations to return specific errors. -* [kbcli fault io latency](kbcli_fault_io_latency.md) - Delayed IO operations. -* [kbcli fault io mistake](kbcli_fault_io_mistake.md) - Alters the contents of the file, distorting the contents of the file. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_io_attribute.md b/docs/user_docs/cli/kbcli_fault_io_attribute.md deleted file mode 100644 index b9cab95f6..000000000 --- a/docs/user_docs/cli/kbcli_fault_io_attribute.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: kbcli fault io attribute ---- - -Override the attributes of the file. - -``` -kbcli fault io attribute [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods. Delay all IO operations under the /data path by 10s. - kbcli fault io latency --delay=10s --volume-path=/data - - # Affects the first container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data - - # Affects the mysql container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data -c=mysql - - # There is a 50% probability of affecting the read IO operation of the test.txt file under the /data path. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data --path=test.txt --percent=50 --method=READ -c=mysql - - # Same as above.Make all IO operations under the /data path return the specified error number 22 (Invalid argument). - kbcli fault io errno --volume-path=/data --errno=22 - - # Same as above.Modify the IO operation permission attribute of the files under the /data path to 72.(110 in octal). - kbcli fault io attribute --volume-path=/data --perm=72 - - # Modify all files so that random positions of 1's with a maximum length of 10 bytes will be replaced with 0's. - kbcli fault io mistake --volume-path=/data --filling=zero --max-occurrences=10 --max-length=1 -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --blocks uint The number of blocks the file occupies. - -c, --container stringArray The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - --gid uint32 The owner's group ID. - -h, --help help for attribute - --ino uint ino number. - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method stringArray The file system calls that need to inject faults. For example: WRITE READ - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --nlink uint32 The number of hard links. - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The effective scope of the injection error can be a wildcard or a single file. - --percent int Probability of failure per operation, in %. (default 100) - --perm uint16 Decimal representation of file permissions. - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --size uint File size. - --uid uint32 Owner's user ID. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --volume-path string The mount point of the volume in the target container must be the root directory of the mount. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_io_errno.md b/docs/user_docs/cli/kbcli_fault_io_errno.md deleted file mode 100644 index 5e9bcb8c5..000000000 --- a/docs/user_docs/cli/kbcli_fault_io_errno.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: kbcli fault io errno ---- - -Causes IO operations to return specific errors. - -``` -kbcli fault io errno [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods. Delay all IO operations under the /data path by 10s. - kbcli fault io latency --delay=10s --volume-path=/data - - # Affects the first container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data - - # Affects the mysql container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data -c=mysql - - # There is a 50% probability of affecting the read IO operation of the test.txt file under the /data path. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data --path=test.txt --percent=50 --method=READ -c=mysql - - # Same as above.Make all IO operations under the /data path return the specified error number 22 (Invalid argument). - kbcli fault io errno --volume-path=/data --errno=22 - - # Same as above.Modify the IO operation permission attribute of the files under the /data path to 72.(110 in octal). - kbcli fault io attribute --volume-path=/data --perm=72 - - # Modify all files so that random positions of 1's with a maximum length of 10 bytes will be replaced with 0's. - kbcli fault io mistake --volume-path=/data --filling=zero --max-occurrences=10 --max-length=1 -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --container stringArray The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - --errno int The returned error number. - -h, --help help for errno - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method stringArray The file system calls that need to inject faults. For example: WRITE READ - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The effective scope of the injection error can be a wildcard or a single file. - --percent int Probability of failure per operation, in %. (default 100) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --volume-path string The mount point of the volume in the target container must be the root directory of the mount. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_io_latency.md b/docs/user_docs/cli/kbcli_fault_io_latency.md deleted file mode 100644 index 34dedaf53..000000000 --- a/docs/user_docs/cli/kbcli_fault_io_latency.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: kbcli fault io latency ---- - -Delayed IO operations. - -``` -kbcli fault io latency [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods. Delay all IO operations under the /data path by 10s. - kbcli fault io latency --delay=10s --volume-path=/data - - # Affects the first container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data - - # Affects the mysql container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data -c=mysql - - # There is a 50% probability of affecting the read IO operation of the test.txt file under the /data path. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data --path=test.txt --percent=50 --method=READ -c=mysql - - # Same as above.Make all IO operations under the /data path return the specified error number 22 (Invalid argument). - kbcli fault io errno --volume-path=/data --errno=22 - - # Same as above.Modify the IO operation permission attribute of the files under the /data path to 72.(110 in octal). - kbcli fault io attribute --volume-path=/data --perm=72 - - # Modify all files so that random positions of 1's with a maximum length of 10 bytes will be replaced with 0's. - kbcli fault io mistake --volume-path=/data --filling=zero --max-occurrences=10 --max-length=1 -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --container stringArray The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected. - --delay string Specific delay time. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for latency - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method stringArray The file system calls that need to inject faults. For example: WRITE READ - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The effective scope of the injection error can be a wildcard or a single file. - --percent int Probability of failure per operation, in %. (default 100) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --volume-path string The mount point of the volume in the target container must be the root directory of the mount. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_io_mistake.md b/docs/user_docs/cli/kbcli_fault_io_mistake.md deleted file mode 100644 index 60d8bdee4..000000000 --- a/docs/user_docs/cli/kbcli_fault_io_mistake.md +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: kbcli fault io mistake ---- - -Alters the contents of the file, distorting the contents of the file. - -``` -kbcli fault io mistake [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods. Delay all IO operations under the /data path by 10s. - kbcli fault io latency --delay=10s --volume-path=/data - - # Affects the first container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data - - # Affects the mysql container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data -c=mysql - - # There is a 50% probability of affecting the read IO operation of the test.txt file under the /data path. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data --path=test.txt --percent=50 --method=READ -c=mysql - - # Same as above.Make all IO operations under the /data path return the specified error number 22 (Invalid argument). - kbcli fault io errno --volume-path=/data --errno=22 - - # Same as above.Modify the IO operation permission attribute of the files under the /data path to 72.(110 in octal). - kbcli fault io attribute --volume-path=/data --perm=72 - - # Modify all files so that random positions of 1's with a maximum length of 10 bytes will be replaced with 0's. - kbcli fault io mistake --volume-path=/data --filling=zero --max-occurrences=10 --max-length=1 -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --container stringArray The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - --filling string The filling content of the error data can only be zero (filling with 0) or random (filling with random bytes). - -h, --help help for mistake - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --max-length int The maximum length (in bytes) of each error. (default 1) - --max-occurrences int The maximum number of times an error can occur per operation. (default 1) - --method stringArray The file system calls that need to inject faults. For example: WRITE READ - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The effective scope of the injection error can be a wildcard or a single file. - --percent int Probability of failure per operation, in %. (default 100) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --volume-path string The mount point of the volume in the target container must be the root directory of the mount. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault io](kbcli_fault_io.md) - IO chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_list.md b/docs/user_docs/cli/kbcli_fault_list.md deleted file mode 100644 index d1a168638..000000000 --- a/docs/user_docs/cli/kbcli_fault_list.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: kbcli fault list ---- - -List chaos resources. - -``` -kbcli fault list [flags] -``` - -### Examples - -``` - # List all chaos resources - kbcli fault list - - # List all chaos kind - kbcli fault list --kind - - # List specific chaos resources. Use 'kbcli fault list --kind' to get chaos kind. - kbcli fault list podchaos -``` - -### Options - -``` - -h, --help help for list - --kind Print chaos resource kind. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network.md b/docs/user_docs/cli/kbcli_fault_network.md deleted file mode 100644 index 414204069..000000000 --- a/docs/user_docs/cli/kbcli_fault_network.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: kbcli fault network ---- - -Network chaos. - -### Options - -``` - -h, --help help for network -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. -* [kbcli fault network bandwidth](kbcli_fault_network_bandwidth.md) - Limit the bandwidth that pods use to communicate with other objects. -* [kbcli fault network corrupt](kbcli_fault_network_corrupt.md) - Distorts the messages a pod communicates with other objects. -* [kbcli fault network delay](kbcli_fault_network_delay.md) - Make pods communicate with other objects lazily. -* [kbcli fault network dns](kbcli_fault_network_dns.md) - Inject faults into DNS server. -* [kbcli fault network duplicate](kbcli_fault_network_duplicate.md) - Make pods communicate with other objects to pick up duplicate packets. -* [kbcli fault network http](kbcli_fault_network_http.md) - Intercept HTTP requests and responses. -* [kbcli fault network loss](kbcli_fault_network_loss.md) - Cause pods to communicate with other objects to drop packets. -* [kbcli fault network partition](kbcli_fault_network_partition.md) - Make a pod network partitioned from other objects. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_bandwidth.md b/docs/user_docs/cli/kbcli_fault_network_bandwidth.md deleted file mode 100644 index c36c3e6d3..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_bandwidth.md +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: kbcli fault network bandwidth ---- - -Limit the bandwidth that pods use to communicate with other objects. - -``` -kbcli fault network bandwidth [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --buffer uint32 the maximum number of bytes that can be sent instantaneously. (default 1) - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for bandwidth - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --limit uint32 the number of bytes waiting in the queue. (default 1) - --minburst uint32 the size of the peakrate bucket. - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --peakrate uint the maximum consumption rate of the bucket. - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --rate string the rate at which the bandwidth is limited. For example : 10 bps/kbps/mbps/gbps. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_corrupt.md b/docs/user_docs/cli/kbcli_fault_network_corrupt.md deleted file mode 100644 index 2f8ad7bbb..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_corrupt.md +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: kbcli fault network corrupt ---- - -Distorts the messages a pod communicates with other objects. - -``` -kbcli fault network corrupt [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --correlation string Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100]. - --corrupt string Indicates the probability of a packet error occurring. Value range: [0, 100]. - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for corrupt - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_delay.md b/docs/user_docs/cli/kbcli_fault_network_delay.md deleted file mode 100644 index fcaba1dcb..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_delay.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: kbcli fault network delay ---- - -Make pods communicate with other objects lazily. - -``` -kbcli fault network delay [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --correlation string Indicates the probability of a packet error occurring. Value range: [0, 100]. - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for delay - --jitter string the variation range of the delay time. - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --latency string the length of time to delay. - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_dns.md b/docs/user_docs/cli/kbcli_fault_network_dns.md deleted file mode 100644 index e049edbbf..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_dns.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: kbcli fault network dns ---- - -Inject faults into DNS server. - -### Options - -``` - -h, --help help for dns -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. -* [kbcli fault network dns error](kbcli_fault_network_dns_error.md) - Make DNS return an error when resolving external domain names. -* [kbcli fault network dns random](kbcli_fault_network_dns_random.md) - Make DNS return any IP when resolving external domain names. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_dns_error.md b/docs/user_docs/cli/kbcli_fault_network_dns_error.md deleted file mode 100644 index d399fdad7..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_dns_error.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: kbcli fault network dns error ---- - -Make DNS return an error when resolving external domain names. - -``` -kbcli fault network dns error [flags] -``` - -### Examples - -``` - // Inject DNS faults into all pods under the default namespace, so that any IP is returned when accessing the bing.com domain name. - kbcli fault dns random --patterns=bing.com --duration=1m - - // Inject DNS faults into all pods under the default namespace, so that error is returned when accessing the bing.com domain name. - kbcli fault dns error --patterns=bing.com --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for error - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --patterns stringArray Select the domain name template that matching the failure behavior & supporting placeholders ? and wildcards *. - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network dns](kbcli_fault_network_dns.md) - Inject faults into DNS server. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_dns_random.md b/docs/user_docs/cli/kbcli_fault_network_dns_random.md deleted file mode 100644 index 5a53ed5c7..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_dns_random.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: kbcli fault network dns random ---- - -Make DNS return any IP when resolving external domain names. - -``` -kbcli fault network dns random [flags] -``` - -### Examples - -``` - // Inject DNS faults into all pods under the default namespace, so that any IP is returned when accessing the bing.com domain name. - kbcli fault dns random --patterns=bing.com --duration=1m - - // Inject DNS faults into all pods under the default namespace, so that error is returned when accessing the bing.com domain name. - kbcli fault dns error --patterns=bing.com --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for random - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --patterns stringArray Select the domain name template that matching the failure behavior & supporting placeholders ? and wildcards *. - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network dns](kbcli_fault_network_dns.md) - Inject faults into DNS server. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_duplicate.md b/docs/user_docs/cli/kbcli_fault_network_duplicate.md deleted file mode 100644 index 15196d2e1..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_duplicate.md +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: kbcli fault network duplicate ---- - -Make pods communicate with other objects to pick up duplicate packets. - -``` -kbcli fault network duplicate [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --correlation string Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100]. - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duplicate string the probability of a packet being repeated. Value range: [0, 100]. - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for duplicate - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_http.md b/docs/user_docs/cli/kbcli_fault_network_http.md deleted file mode 100644 index 294cf3082..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_http.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: kbcli fault network http ---- - -Intercept HTTP requests and responses. - -### Options - -``` - -h, --help help for http -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. -* [kbcli fault network http abort](kbcli_fault_network_http_abort.md) - Abort the HTTP request and response. -* [kbcli fault network http delay](kbcli_fault_network_http_delay.md) - Delay the HTTP request and response. -* [kbcli fault network http patch](kbcli_fault_network_http_patch.md) - Patch the HTTP request and response. -* [kbcli fault network http replace](kbcli_fault_network_http_replace.md) - Replace the HTTP request and response. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_http_abort.md b/docs/user_docs/cli/kbcli_fault_network_http_abort.md deleted file mode 100644 index 0be4dc89b..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_http_abort.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: kbcli fault network http abort ---- - -Abort the HTTP request and response. - -``` -kbcli fault network http abort [flags] -``` - -### Examples - -``` - # By default, the method of GET from port 80 is blocked. - kbcli fault network http abort --duration=1m - - # Block the method of GET from port 4399. - kbcli fault network http abort --port=4399 --duration=1m - - # Block the method of POST from port 4399. - kbcli fault network http abort --port=4399 --method=POST --duration=1m - - # Delays post requests from port 4399. - kbcli fault network http delay --port=4399 --method=POST --delay=15s - - # Replace the GET method sent from port 80 with the PUT method. - kbcli fault network http replace --replace-method=PUT --duration=1m - - # Replace the GET method sent from port 80 with the PUT method, and replace the request body. - kbcli fault network http replace --body="you are good luck" --replace-method=PUT --duration=2m - - # Replace the response content "you" from port 80. - kbcli fault network http replace --target=Response --body=you --duration=30s - - # Append content to the body of the post request sent from port 4399, in JSON format. - kbcli fault network http patch --method=POST --port=4399 --body="you are good luck" --type=JSON --duration=30s -``` - -### Options - -``` - --abort Indicates whether to inject the fault that interrupts the connection. (default true) - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --code int32 The status code responded by target. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for abort - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method string The HTTP method of the target request method. For example: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH. (default "GET") - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The URI path of the target request. Supports Matching wildcards. (default "*") - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --port int32 The TCP port that the target service listens on. (default 80) - --target string Specifies whether the target of fault injection is Request or Response. The target-related fields should be configured at the same time. (default "Request") - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network http](kbcli_fault_network_http.md) - Intercept HTTP requests and responses. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_http_delay.md b/docs/user_docs/cli/kbcli_fault_network_http_delay.md deleted file mode 100644 index 04ec969fb..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_http_delay.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: kbcli fault network http delay ---- - -Delay the HTTP request and response. - -``` -kbcli fault network http delay [flags] -``` - -### Examples - -``` - # By default, the method of GET from port 80 is blocked. - kbcli fault network http abort --duration=1m - - # Block the method of GET from port 4399. - kbcli fault network http abort --port=4399 --duration=1m - - # Block the method of POST from port 4399. - kbcli fault network http abort --port=4399 --method=POST --duration=1m - - # Delays post requests from port 4399. - kbcli fault network http delay --port=4399 --method=POST --delay=15s - - # Replace the GET method sent from port 80 with the PUT method. - kbcli fault network http replace --replace-method=PUT --duration=1m - - # Replace the GET method sent from port 80 with the PUT method, and replace the request body. - kbcli fault network http replace --body="you are good luck" --replace-method=PUT --duration=2m - - # Replace the response content "you" from port 80. - kbcli fault network http replace --target=Response --body=you --duration=30s - - # Append content to the body of the post request sent from port 4399, in JSON format. - kbcli fault network http patch --method=POST --port=4399 --body="you are good luck" --type=JSON --duration=30s -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --code int32 The status code responded by target. - --delay string The time for delay. (default "10s") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for delay - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method string The HTTP method of the target request method. For example: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH. (default "GET") - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The URI path of the target request. Supports Matching wildcards. (default "*") - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --port int32 The TCP port that the target service listens on. (default 80) - --target string Specifies whether the target of fault injection is Request or Response. The target-related fields should be configured at the same time. (default "Request") - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network http](kbcli_fault_network_http.md) - Intercept HTTP requests and responses. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_http_patch.md b/docs/user_docs/cli/kbcli_fault_network_http_patch.md deleted file mode 100644 index 31182bdf0..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_http_patch.md +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: kbcli fault network http patch ---- - -Patch the HTTP request and response. - -``` -kbcli fault network http patch [flags] -``` - -### Examples - -``` - # By default, the method of GET from port 80 is blocked. - kbcli fault network http abort --duration=1m - - # Block the method of GET from port 4399. - kbcli fault network http abort --port=4399 --duration=1m - - # Block the method of POST from port 4399. - kbcli fault network http abort --port=4399 --method=POST --duration=1m - - # Delays post requests from port 4399. - kbcli fault network http delay --port=4399 --method=POST --delay=15s - - # Replace the GET method sent from port 80 with the PUT method. - kbcli fault network http replace --replace-method=PUT --duration=1m - - # Replace the GET method sent from port 80 with the PUT method, and replace the request body. - kbcli fault network http replace --body="you are good luck" --replace-method=PUT --duration=2m - - # Replace the response content "you" from port 80. - kbcli fault network http replace --target=Response --body=you --duration=30s - - # Append content to the body of the post request sent from port 4399, in JSON format. - kbcli fault network http patch --method=POST --port=4399 --body="you are good luck" --type=JSON --duration=30s -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --body string The fault of the request body or response body with patch faults. - --code int32 The status code responded by target. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for patch - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method string The HTTP method of the target request method. For example: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH. (default "GET") - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The URI path of the target request. Supports Matching wildcards. (default "*") - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --port int32 The TCP port that the target service listens on. (default 80) - --target string Specifies whether the target of fault injection is Request or Response. The target-related fields should be configured at the same time. (default "Request") - --type string The type of patch faults of the request body or response body. Currently, it only supports JSON. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network http](kbcli_fault_network_http.md) - Intercept HTTP requests and responses. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_http_replace.md b/docs/user_docs/cli/kbcli_fault_network_http_replace.md deleted file mode 100644 index 4a1f02ccf..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_http_replace.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: kbcli fault network http replace ---- - -Replace the HTTP request and response. - -``` -kbcli fault network http replace [flags] -``` - -### Examples - -``` - # By default, the method of GET from port 80 is blocked. - kbcli fault network http abort --duration=1m - - # Block the method of GET from port 4399. - kbcli fault network http abort --port=4399 --duration=1m - - # Block the method of POST from port 4399. - kbcli fault network http abort --port=4399 --method=POST --duration=1m - - # Delays post requests from port 4399. - kbcli fault network http delay --port=4399 --method=POST --delay=15s - - # Replace the GET method sent from port 80 with the PUT method. - kbcli fault network http replace --replace-method=PUT --duration=1m - - # Replace the GET method sent from port 80 with the PUT method, and replace the request body. - kbcli fault network http replace --body="you are good luck" --replace-method=PUT --duration=2m - - # Replace the response content "you" from port 80. - kbcli fault network http replace --target=Response --body=you --duration=30s - - # Append content to the body of the post request sent from port 4399, in JSON format. - kbcli fault network http patch --method=POST --port=4399 --body="you are good luck" --type=JSON --duration=30s -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --body string The content of the request body or response body to replace the failure. - --code int32 The status code responded by target. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for replace - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --method string The HTTP method of the target request method. For example: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH. (default "GET") - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --path string The URI path of the target request. Supports Matching wildcards. (default "*") - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --port int32 The TCP port that the target service listens on. (default 80) - --replace-method string The replaced content of the HTTP request method. - --replace-path string The URI path used to replace content. - --target string Specifies whether the target of fault injection is Request or Response. The target-related fields should be configured at the same time. (default "Request") - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network http](kbcli_fault_network_http.md) - Intercept HTTP requests and responses. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_loss.md b/docs/user_docs/cli/kbcli_fault_network_loss.md deleted file mode 100644 index c6d0d401e..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_loss.md +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: kbcli fault network loss ---- - -Cause pods to communicate with other objects to drop packets. - -``` -kbcli fault network loss [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --correlation string Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100]. - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for loss - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --loss string Indicates the probability of a packet error occurring. Value range: [0, 100]. - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_network_partition.md b/docs/user_docs/cli/kbcli_fault_network_partition.md deleted file mode 100644 index 3d80f6362..000000000 --- a/docs/user_docs/cli/kbcli_fault_network_partition.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: kbcli fault network partition ---- - -Make a pod network partitioned from other objects. - -``` -kbcli fault network partition [flags] -``` - -### Examples - -``` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --direction string You can select "to"" or "from"" or "both"". (default "to") - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -e, --external-target stringArray a network target outside of Kubernetes, which can be an IPv4 address or a domain name, - such as "www.baidu.com". Only works with direction: to. - -h, --help help for partition - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --target-label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"' (default []) - --target-mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. - --target-ns-fault stringArray Specifies the namespace into which you want to inject faults. - --target-value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault network](kbcli_fault_network.md) - Network chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_node.md b/docs/user_docs/cli/kbcli_fault_node.md deleted file mode 100644 index e89be737b..000000000 --- a/docs/user_docs/cli/kbcli_fault_node.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: kbcli fault node ---- - -Node chaos. - -### Options - -``` - -h, --help help for node -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. -* [kbcli fault node detach-volume](kbcli_fault_node_detach-volume.md) - Detach volume -* [kbcli fault node restart](kbcli_fault_node_restart.md) - Restart instance -* [kbcli fault node stop](kbcli_fault_node_stop.md) - Stop instance - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_node_detach-volume.md b/docs/user_docs/cli/kbcli_fault_node_detach-volume.md deleted file mode 100644 index 5a3757e44..000000000 --- a/docs/user_docs/cli/kbcli_fault_node_detach-volume.md +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: kbcli fault node detach-volume ---- - -Detach volume - -``` -kbcli fault node detach-volume [flags] -``` - -### Examples - -``` - # Stop a specified EC2 instance. - kbcli fault node stop node1 -c=aws --region=cn-northwest-1 --duration=3m - - # Stop two specified EC2 instances. - kbcli fault node stop node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Restart two specified EC2 instances. - kbcli fault node restart node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Detach two specified volume from two specified EC2 instances. - kbcli fault node detach-volume node1 node2 -c=aws --region=cn-northwest-1 --duration=1m --volume-id=v1,v2 --device-name=/d1,/d2 - - # Stop two specified GCK instances. - kbcli fault node stop node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Restart two specified GCK instances. - kbcli fault node restart node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Detach two specified volume from two specified GCK instances. - kbcli fault node detach-volume node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering --device-name=/d1,/d2 -``` - -### Options - -``` - --auto-approve Skip interactive approval before create secret. - -c, --cloud-provider string Cloud provider type, one of [aws gcp] - --device-name strings The device name of the volume. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "30s") - -h, --help help for detach-volume - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --project string The name of the GCP project. Only available when cloud-provider=gcp. - --region string The region of the node. - --secret string The name of the secret containing cloud provider specific credentials. - --volume-id strings The volume ids of the ec2. Only available when cloud-provider=aws. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault node](kbcli_fault_node.md) - Node chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_node_restart.md b/docs/user_docs/cli/kbcli_fault_node_restart.md deleted file mode 100644 index 45bc50abf..000000000 --- a/docs/user_docs/cli/kbcli_fault_node_restart.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: kbcli fault node restart ---- - -Restart instance - -``` -kbcli fault node restart [flags] -``` - -### Examples - -``` - # Stop a specified EC2 instance. - kbcli fault node stop node1 -c=aws --region=cn-northwest-1 --duration=3m - - # Stop two specified EC2 instances. - kbcli fault node stop node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Restart two specified EC2 instances. - kbcli fault node restart node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Detach two specified volume from two specified EC2 instances. - kbcli fault node detach-volume node1 node2 -c=aws --region=cn-northwest-1 --duration=1m --volume-id=v1,v2 --device-name=/d1,/d2 - - # Stop two specified GCK instances. - kbcli fault node stop node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Restart two specified GCK instances. - kbcli fault node restart node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Detach two specified volume from two specified GCK instances. - kbcli fault node detach-volume node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering --device-name=/d1,/d2 -``` - -### Options - -``` - --auto-approve Skip interactive approval before create secret. - -c, --cloud-provider string Cloud provider type, one of [aws gcp] - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "30s") - -h, --help help for restart - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --project string The name of the GCP project. Only available when cloud-provider=gcp. - --region string The region of the node. - --secret string The name of the secret containing cloud provider specific credentials. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault node](kbcli_fault_node.md) - Node chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_node_stop.md b/docs/user_docs/cli/kbcli_fault_node_stop.md deleted file mode 100644 index 5c538dc52..000000000 --- a/docs/user_docs/cli/kbcli_fault_node_stop.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: kbcli fault node stop ---- - -Stop instance - -``` -kbcli fault node stop [flags] -``` - -### Examples - -``` - # Stop a specified EC2 instance. - kbcli fault node stop node1 -c=aws --region=cn-northwest-1 --duration=3m - - # Stop two specified EC2 instances. - kbcli fault node stop node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Restart two specified EC2 instances. - kbcli fault node restart node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Detach two specified volume from two specified EC2 instances. - kbcli fault node detach-volume node1 node2 -c=aws --region=cn-northwest-1 --duration=1m --volume-id=v1,v2 --device-name=/d1,/d2 - - # Stop two specified GCK instances. - kbcli fault node stop node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Restart two specified GCK instances. - kbcli fault node restart node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Detach two specified volume from two specified GCK instances. - kbcli fault node detach-volume node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering --device-name=/d1,/d2 -``` - -### Options - -``` - --auto-approve Skip interactive approval before create secret. - -c, --cloud-provider string Cloud provider type, one of [aws gcp] - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "30s") - -h, --help help for stop - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --project string The name of the GCP project. Only available when cloud-provider=gcp. - --region string The region of the node. - --secret string The name of the secret containing cloud provider specific credentials. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault node](kbcli_fault_node.md) - Node chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_pod.md b/docs/user_docs/cli/kbcli_fault_pod.md deleted file mode 100644 index 144789ad5..000000000 --- a/docs/user_docs/cli/kbcli_fault_pod.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: kbcli fault pod ---- - -Pod chaos. - -### Options - -``` - -h, --help help for pod -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. -* [kbcli fault pod failure](kbcli_fault_pod_failure.md) - failure pod -* [kbcli fault pod kill](kbcli_fault_pod_kill.md) - kill pod -* [kbcli fault pod kill-container](kbcli_fault_pod_kill-container.md) - kill containers - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_pod_failure.md b/docs/user_docs/cli/kbcli_fault_pod_failure.md deleted file mode 100644 index 407862761..000000000 --- a/docs/user_docs/cli/kbcli_fault_pod_failure.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: kbcli fault pod failure ---- - -failure pod - -``` -kbcli fault pod failure [flags] -``` - -### Examples - -``` - # kill all pods in default namespace - kbcli fault pod kill - - # kill any pod in default namespace - kbcli fault pod kill --mode=one - - # kill two pods in default namespace - kbcli fault pod kill --mode=fixed --value=2 - - # kill 50% pods in default namespace - kbcli fault pod kill --mode=percentage --value=50 - - # kill mysql-cluster-mysql-0 pod in default namespace - kbcli fault pod kill mysql-cluster-mysql-0 - - # kill all pods in default namespace - kbcli fault pod kill --ns-fault="default" - - # --label is required to specify the pods that need to be killed. - kbcli fault pod kill --label statefulset.kubernetes.io/pod-name=mysql-cluster-mysql-2 - - # kill pod under the specified node. - kbcli fault pod kill --node=minikube-m02 - - # kill pod under the specified node-label. - kbcli fault pod kill --node-label=kubernetes.io/arch=arm64 - - # Allow the experiment to last for one minute. - kbcli fault pod failure --duration=1m - - # kill container in pod - kbcli fault pod kill-container mysql-cluster-mysql-0 --container=mysql -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for failure - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault pod](kbcli_fault_pod.md) - Pod chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_pod_kill-container.md b/docs/user_docs/cli/kbcli_fault_pod_kill-container.md deleted file mode 100644 index dc02b6bf9..000000000 --- a/docs/user_docs/cli/kbcli_fault_pod_kill-container.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: kbcli fault pod kill-container ---- - -kill containers - -``` -kbcli fault pod kill-container [flags] -``` - -### Examples - -``` - # kill all pods in default namespace - kbcli fault pod kill - - # kill any pod in default namespace - kbcli fault pod kill --mode=one - - # kill two pods in default namespace - kbcli fault pod kill --mode=fixed --value=2 - - # kill 50% pods in default namespace - kbcli fault pod kill --mode=percentage --value=50 - - # kill mysql-cluster-mysql-0 pod in default namespace - kbcli fault pod kill mysql-cluster-mysql-0 - - # kill all pods in default namespace - kbcli fault pod kill --ns-fault="default" - - # --label is required to specify the pods that need to be killed. - kbcli fault pod kill --label statefulset.kubernetes.io/pod-name=mysql-cluster-mysql-2 - - # kill pod under the specified node. - kbcli fault pod kill --node=minikube-m02 - - # kill pod under the specified node-label. - kbcli fault pod kill --node-label=kubernetes.io/arch=arm64 - - # Allow the experiment to last for one minute. - kbcli fault pod failure --duration=1m - - # kill container in pod - kbcli fault pod kill-container mysql-cluster-mysql-0 --container=mysql -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --container stringArray the name of the container you want to kill, such as mysql, prometheus. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for kill-container - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault pod](kbcli_fault_pod.md) - Pod chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_pod_kill.md b/docs/user_docs/cli/kbcli_fault_pod_kill.md deleted file mode 100644 index 28addb53a..000000000 --- a/docs/user_docs/cli/kbcli_fault_pod_kill.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: kbcli fault pod kill ---- - -kill pod - -``` -kbcli fault pod kill [flags] -``` - -### Examples - -``` - # kill all pods in default namespace - kbcli fault pod kill - - # kill any pod in default namespace - kbcli fault pod kill --mode=one - - # kill two pods in default namespace - kbcli fault pod kill --mode=fixed --value=2 - - # kill 50% pods in default namespace - kbcli fault pod kill --mode=percentage --value=50 - - # kill mysql-cluster-mysql-0 pod in default namespace - kbcli fault pod kill mysql-cluster-mysql-0 - - # kill all pods in default namespace - kbcli fault pod kill --ns-fault="default" - - # --label is required to specify the pods that need to be killed. - kbcli fault pod kill --label statefulset.kubernetes.io/pod-name=mysql-cluster-mysql-2 - - # kill pod under the specified node. - kbcli fault pod kill --node=minikube-m02 - - # kill pod under the specified node-label. - kbcli fault pod kill --node-label=kubernetes.io/arch=arm64 - - # Allow the experiment to last for one minute. - kbcli fault pod failure --duration=1m - - # kill container in pod - kbcli fault pod kill-container mysql-cluster-mysql-0 --container=mysql -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -g, --grace-period int Grace period represents the duration in seconds before the pod should be killed - -h, --help help for kill - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault pod](kbcli_fault_pod.md) - Pod chaos. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_stress.md b/docs/user_docs/cli/kbcli_fault_stress.md deleted file mode 100644 index 74029b57c..000000000 --- a/docs/user_docs/cli/kbcli_fault_stress.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: kbcli fault stress ---- - -Add memory pressure or CPU load to the system. - -``` -kbcli fault stress [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods.Making CPU load up to 50%, and the memory up to 100MB. - kbcli fault stress --cpu-worker=2 --cpu-load=50 --memory-worker=1 --memory-size=100Mi - - # Affects the first container in mycluster-mysql-0 pod. Making the CPU load up to 50%, and the memory up to 500MB. - kbcli fault stress mycluster-mysql-0 --cpu-worker=2 --cpu-load=50 - - # Affects the mysql container in mycluster-mysql-0 pod. Making the memory up to 500MB. - kbcli fault stress mycluster-mysql-0 --memory-worker=2 --memory-size=500Mi -c=mysql -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - -c, --container stringArray The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected. - --cpu-load int Specifies the percentage of CPU occupied. 0 means no extra load added, 100 means full load. The total load is workers * load. - --cpu-worker int Specifies the number of threads that exert CPU pressure. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for stress - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --memory-size string Specify the size of the allocated memory or the percentage of the total memory, and the sum of the allocated memory is size. For example:256MB or 25% - --memory-worker int Specifies the number of threads that apply memory pressure. - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/docs/user_docs/cli/kbcli_fault_time.md b/docs/user_docs/cli/kbcli_fault_time.md deleted file mode 100644 index ec2271ed0..000000000 --- a/docs/user_docs/cli/kbcli_fault_time.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: kbcli fault time ---- - -Clock skew failure. - -``` -kbcli fault time [flags] -``` - -### Examples - -``` - # Affects the first container in default namespace's all pods.Shifts the clock back five seconds. - kbcli fault time --time-offset=-5s - - # Affects the first container in default namespace's all pods. - kbcli fault time --time-offset=-5m5s - - # Affects the first container in mycluster-mysql-0 pod. Shifts the clock forward five seconds. - kbcli fault time mycluster-mysql-0 --time-offset=+5s50ms - - # Affects the mysql container in mycluster-mysql-0 pod. Shifts the clock forward five seconds. - kbcli fault time mycluster-mysql-0 --time-offset=+5s -c=mysql - - # The clock that specifies the effect of time offset is CLOCK_REALTIME. - kbcli fault time mycluster-mysql-0 --time-offset=+5s --clock-id=CLOCK_REALTIME -c=mysql -``` - -### Options - -``` - --annotation stringToString Select the pod to inject the fault according to Annotation. (default []) - --clock-id stringArray Specifies the clock on which the time offset acts.If it's empty, it will be set to ['CLOCK_REALTIME'].See clock_gettime [https://man7.org/linux/man-pages/man2/clock_gettime.2.html] document for details. - -c, --container stringArray Specifies the injected container name. For example: mysql. If it's empty, the first container will be injected. - --dry-run string[="unchanged"] Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent. (default "none") - --duration string Supported formats of the duration are: ms / s / m / h. (default "10s") - -h, --help help for time - --label stringToString label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0. (default []) - --mode string You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with. (default "all") - --node stringArray Inject faults into pods in the specified node. - --node-label stringToString label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux. (default []) - --ns-fault stringArray Specifies the namespace into which you want to inject faults. (default [default]) - -o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml) - --phase stringArray Specify the pod that injects the fault by the state of the pod. - --time-offset string Specifies the length of the time offset. For example: -5s, -10m100ns. - --value string If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject. -``` - -### Options inherited from parent commands - -``` - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "$HOME/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - --match-server-version Require server version to match client version - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use -``` - -### SEE ALSO - -* [kbcli fault](kbcli_fault.md) - Inject faults to pod. - -#### Go Back to [CLI Overview](cli.md) Homepage. - diff --git a/pkg/cmd/cli.go b/pkg/cmd/cli.go index 486938a59..72c9f8f5d 100644 --- a/pkg/cmd/cli.go +++ b/pkg/cmd/cli.go @@ -46,7 +46,6 @@ import ( "github.com/apecloud/kbcli/pkg/cmd/clusterversion" "github.com/apecloud/kbcli/pkg/cmd/dashboard" "github.com/apecloud/kbcli/pkg/cmd/dataprotection" - "github.com/apecloud/kbcli/pkg/cmd/fault" "github.com/apecloud/kbcli/pkg/cmd/kubeblocks" "github.com/apecloud/kbcli/pkg/cmd/options" "github.com/apecloud/kbcli/pkg/cmd/playground" @@ -178,7 +177,6 @@ A Command Line Interface for KubeBlocks`, alert.NewAlertCmd(f, ioStreams), addon.NewAddonCmd(f, ioStreams), plugin.NewPluginCmd(ioStreams), - fault.NewFaultCmd(f, ioStreams), report.NewReportCmd(f, ioStreams), backuprepo.NewBackupRepoCmd(f, ioStreams), dataprotection.NewDataProtectionCmd(f, ioStreams), diff --git a/pkg/cmd/fault/fault.go b/pkg/cmd/fault/fault.go deleted file mode 100644 index bbf857ea1..000000000 --- a/pkg/cmd/fault/fault.go +++ /dev/null @@ -1,202 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "context" - "fmt" - "regexp" - "strconv" - "strings" - - "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/cli-runtime/pkg/genericiooptions" - "k8s.io/client-go/kubernetes" - "k8s.io/klog/v2" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/printer" - "github.com/apecloud/kbcli/pkg/util" -) - -type Selector struct { - PodNameSelectors map[string][]string `json:"pods"` - - NamespaceSelectors []string `json:"namespaces"` - - LabelSelectors map[string]string `json:"labelSelectors"` - - PodPhaseSelectors []string `json:"podPhaseSelectors"` - - NodeLabelSelectors map[string]string `json:"nodeSelectors"` - - AnnotationSelectors map[string]string `json:"annotationSelectors"` - - NodeNameSelectors []string `json:"nodes"` -} - -type FaultBaseOptions struct { - Action string `json:"action"` - - Mode string `json:"mode"` - - Value string `json:"value"` - - Duration string `json:"duration"` - - Selector `json:"selector"` - - action.CreateOptions `json:"-"` -} - -func NewFaultCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "fault", - Short: "Inject faults to pod.", - } - cmd.AddCommand( - NewPodChaosCmd(f, streams), - NewNetworkChaosCmd(f, streams), - NewTimeChaosCmd(f, streams), - NewIOChaosCmd(f, streams), - NewStressChaosCmd(f, streams), - NewNodeChaosCmd(f, streams), - NewListCmd(f, streams), - NewDeleteCmd(f, streams), - ) - return cmd -} - -func registerFlagCompletionFunc(cmd *cobra.Command, f cmdutil.Factory) { - var formatsWithDesc = map[string]string{ - "JSON": "Output result in JSON format", - "YAML": "Output result in YAML format", - } - util.CheckErr(cmd.RegisterFlagCompletionFunc("output", - func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - var names []string - for format, desc := range formatsWithDesc { - if strings.HasPrefix(format, toComplete) { - names = append(names, fmt.Sprintf("%s\t%s", format, desc)) - } - } - return names, cobra.ShellCompDirectiveNoFileComp - })) -} - -func (o *FaultBaseOptions) AddCommonFlag(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.Mode, "mode", "all", `You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with.`) - cmd.Flags().StringVar(&o.Value, "value", "", `If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject.`) - cmd.Flags().StringVar(&o.Duration, "duration", "10s", "Supported formats of the duration are: ms / s / m / h.") - cmd.Flags().StringToStringVar(&o.LabelSelectors, "label", map[string]string{}, `label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0.`) - cmd.Flags().StringArrayVar(&o.NamespaceSelectors, "ns-fault", []string{"default"}, `Specifies the namespace into which you want to inject faults.`) - cmd.Flags().StringArrayVar(&o.PodPhaseSelectors, "phase", []string{}, `Specify the pod that injects the fault by the state of the pod.`) - cmd.Flags().StringToStringVar(&o.NodeLabelSelectors, "node-label", map[string]string{}, `label for node, such as '"kubernetes.io/arch=arm64,kubernetes.io/hostname=minikube-m03,kubernetes.io/os=linux.`) - cmd.Flags().StringArrayVar(&o.NodeNameSelectors, "node", []string{}, `Inject faults into pods in the specified node.`) - cmd.Flags().StringToStringVar(&o.AnnotationSelectors, "annotation", map[string]string{}, `Select the pod to inject the fault according to Annotation.`) - cmd.Flags().StringVar(&o.DryRun, "dry-run", "none", `Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent.`) - cmd.Flags().Lookup("dry-run").NoOptDefVal = Unchanged - - printer.AddOutputFlagForCreate(cmd, &o.Format, false) -} - -func (o *FaultBaseOptions) BaseValidate() error { - if o.DryRun == "none" { - enable, err := o.checkChaosMeshEnable() - if err != nil { - return err - } - if !enable { - return fmt.Errorf("chaos-mesh is not enabled, use `kbcli addon enable fault-chaos-mesh` to enable chaos-mesh first") - } - } - - if ok, err := IsRegularMatch(o.Duration); !ok { - return err - } - - if o.Value == "" && (o.Mode == "fixed" || o.Mode == "fixed-percent" || o.Mode == "random-max-percent") { - return fmt.Errorf("you must use --value to specify an integer") - } - - if ok, err := IsInteger(o.Value); !ok { - return err - } - - return nil -} - -func (o *FaultBaseOptions) BaseComplete() error { - if len(o.Args) > 0 { - o.PodNameSelectors = make(map[string][]string, len(o.NamespaceSelectors)) - for _, ns := range o.NamespaceSelectors { - o.PodNameSelectors[ns] = o.Args - } - } - return nil -} - -func IsRegularMatch(str string) (bool, error) { - pattern := regexp.MustCompile(`^\d+(ms|s|m|h)$`) - if str != "" && !pattern.MatchString(str) { - return false, fmt.Errorf("invalid duration:%s; input format must be in the form of number + time unit, like 10s, 10m", str) - } else { - return true, nil - } -} - -func IsInteger(str string) (bool, error) { - if _, err := strconv.Atoi(str); str != "" && err != nil { - return false, fmt.Errorf("invalid value:%s; must be an integer", str) - } else { - return true, nil - } -} - -func GetGVR(group, version, resourceName string) schema.GroupVersionResource { - return schema.GroupVersionResource{Group: group, Version: version, Resource: resourceName} -} - -func (o *FaultBaseOptions) checkChaosMeshEnable() (bool, error) { - config, err := o.Factory.ToRESTConfig() - if err != nil { - return false, err - } - - clientSet, err := kubernetes.NewForConfig(config) - if err != nil { - return false, err - } - podList, err := clientSet.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{ - LabelSelector: "app.kubernetes.io/part-of=chaos-mesh", - }) - if err != nil { - klog.V(1).Info(err) - return false, err - } - - if len(podList.Items) > 0 { - return true, nil - } - return false, nil -} diff --git a/pkg/cmd/fault/fault_constant.go b/pkg/cmd/fault/fault_constant.go deleted file mode 100644 index 13ee17fe7..000000000 --- a/pkg/cmd/fault/fault_constant.go +++ /dev/null @@ -1,144 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import cp "github.com/apecloud/kbcli/pkg/cloudprovider" - -// Unchanged DryRun flag -const ( - Unchanged = "unchanged" -) - -// GVR -const ( - Group = "chaos-mesh.org" - Version = "v1alpha1" - GroupVersion = Group + "/" + Version - - ResourcePodChaos = "podchaos" - ResourceNetworkChaos = "networkchaos" - ResourceDNSChaos = "dnschaos" - ResourceHTTPChaos = "httpchaos" - ResourceIOChaos = "iochaos" - ResourceStressChaos = "stresschaos" - ResourceTimeChaos = "timechaos" - ResourceAWSChaos = "awschaos" - ResourceGCPChaos = "gcpchaos" - - KindAWSChaos = "AWSChaos" - KindGCPChaos = "GCPChaos" -) - -// Cue Template Name -const ( - CueTemplatePodChaos = "pod_chaos_template.cue" - CueTemplateNetworkChaos = "network_chaos_template.cue" - CueTemplateDNSChaos = "dns_chaos_template.cue" - CueTemplateHTTPChaos = "http_chaos_template.cue" - CueTemplateIOChaos = "io_chaos_template.cue" - CueTemplateStressChaos = "stress_chaos_template.cue" - CueTemplateTimeChaos = "time_chaos_template.cue" - CueTemplateNodeChaos = "node_chaos_template.cue" -) - -// Pod Chaos Command -const ( - Kill = "kill" - KillShort = "kill pod" - Failure = "failure" - FailureShort = "failure pod" - KillContainer = "kill-container" - KillContainerShort = "kill containers" -) - -// NetWork Chaos Command -const ( - Partition = "partition" - PartitionShort = "Make a pod network partitioned from other objects." - Loss = "loss" - LossShort = "Cause pods to communicate with other objects to drop packets." - Delay = "delay" - DelayShort = "Make pods communicate with other objects lazily." - Duplicate = "duplicate" - DuplicateShort = "Make pods communicate with other objects to pick up duplicate packets." - Corrupt = "corrupt" - CorruptShort = "Distorts the messages a pod communicates with other objects." - Bandwidth = "bandwidth" - BandwidthShort = "Limit the bandwidth that pods use to communicate with other objects." -) - -// DNS Chaos Command -const ( - Random = "random" - RandomShort = "Make DNS return any IP when resolving external domain names." - Error = "error" - ErrorShort = "Make DNS return an error when resolving external domain names." -) - -// HTTP Chaos Command -const ( - Abort = "abort" - AbortShort = "Abort the HTTP request and response." - HTTPDelay = "delay" - HTTPDelayShort = "Delay the HTTP request and response." - Replace = "replace" - ReplaceShort = "Replace the HTTP request and response." - Patch = "patch" - PatchShort = "Patch the HTTP request and response." -) - -// IO Chaos Command -const ( - Latency = "latency" - LatencyShort = "Delayed IO operations." - Errno = "errno" - ErrnoShort = "Causes IO operations to return specific errors." - Attribute = "attribute" - AttributeShort = "Override the attributes of the file." - Mistake = "mistake" - MistakeShort = "Alters the contents of the file, distorting the contents of the file." -) - -// Stress Chaos Command -const ( - Stress = "stress" - StressShort = "Add memory pressure or CPU load to the system." -) - -// Time Chaos Command -const ( - Time = "time" - TimeShort = "Clock skew failure." -) - -// Node Chaos Command -const ( - Stop = "stop" - StopShort = "Stop instance" - Restart = "restart" - RestartShort = "Restart instance" - DetachVolume = "detach-volume" - DetachVolumeShort = "Detach volume" - - AWSSecretName = "cloud-key-secret-aws" - GCPSecretName = "cloud-key-secret-gcp" -) - -var supportedCloudProviders = []string{cp.AWS, cp.GCP} diff --git a/pkg/cmd/fault/fault_dns.go b/pkg/cmd/fault/fault_dns.go deleted file mode 100644 index c51866f89..000000000 --- a/pkg/cmd/fault/fault_dns.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/util" -) - -var faultDNSExample = templates.Examples(` - // Inject DNS faults into all pods under the default namespace, so that any IP is returned when accessing the bing.com domain name. - kbcli fault dns random --patterns=bing.com --duration=1m - - // Inject DNS faults into all pods under the default namespace, so that error is returned when accessing the bing.com domain name. - kbcli fault dns error --patterns=bing.com --duration=1m -`) - -type DNSChaosOptions struct { - Patterns []string `json:"patterns"` - - FaultBaseOptions -} - -func NewDNSChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *DNSChaosOptions { - o := &DNSChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateDNSChaos, - GVR: GetGVR(Group, Version, ResourceDNSChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewDNSChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "dns", - Short: "Inject faults into DNS server.", - } - cmd.AddCommand( - NewRandomCmd(f, streams), - NewErrorCmd(f, streams), - ) - return cmd -} - -func NewRandomCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewDNSChaosOptions(f, streams, string(v1alpha1.RandomAction)) - cmd := o.NewCobraCommand(Random, RandomShort) - - o.AddCommonFlag(cmd) - util.CheckErr(cmd.MarkFlagRequired("patterns")) - - return cmd -} - -func NewErrorCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewDNSChaosOptions(f, streams, string(v1alpha1.ErrorAction)) - cmd := o.NewCobraCommand(Error, ErrorShort) - - o.AddCommonFlag(cmd) - util.CheckErr(cmd.MarkFlagRequired("patterns")) - - return cmd -} - -func (o *DNSChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultDNSExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *DNSChaosOptions) AddCommonFlag(cmd *cobra.Command) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().StringArrayVar(&o.Patterns, "patterns", nil, `Select the domain name template that matching the failure behavior & supporting placeholders ? and wildcards *.`) - - // register flag completion func - registerFlagCompletionFunc(cmd, o.Factory) -} - -func (o *DNSChaosOptions) Validate() error { - return o.BaseValidate() -} - -func (o *DNSChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *DNSChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.DNSChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_dns_test.go b/pkg/cmd/fault/fault_dns_test.go deleted file mode 100644 index 8b4d7c3a8..000000000 --- a/pkg/cmd/fault/fault_dns_test.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Network DNS", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - Context("test fault network dns", func() { - - It("fault network dns random", func() { - inputs := [][]string{ - {"--dry-run=client", "--patterns=kubeblocks.io"}, - {"--mode=one", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--ns-fault=kb-system", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--node=minikube-m02", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--patterns=kubeblocks.io", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--patterns=kubeblocks.io", "--dry-run=client"}, - } - o := NewDNSChaosOptions(tf, streams, string(v1alpha1.RandomAction)) - cmd := o.NewCobraCommand(Random, RandomShort) - o.AddCommonFlag(cmd) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network dns error", func() { - inputs := [][]string{ - {"--patterns=kubeblocks.io", "--dry-run=client"}, - } - o := NewDNSChaosOptions(tf, streams, string(v1alpha1.ErrorAction)) - cmd := o.NewCobraCommand(Error, ErrorShort) - o.AddCommonFlag(cmd) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_http.go b/pkg/cmd/fault/fault_http.go deleted file mode 100644 index b95a5819e..000000000 --- a/pkg/cmd/fault/fault_http.go +++ /dev/null @@ -1,243 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "fmt" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/json" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" -) - -var faultHTTPExample = templates.Examples(` - # By default, the method of GET from port 80 is blocked. - kbcli fault network http abort --duration=1m - - # Block the method of GET from port 4399. - kbcli fault network http abort --port=4399 --duration=1m - - # Block the method of POST from port 4399. - kbcli fault network http abort --port=4399 --method=POST --duration=1m - - # Delays post requests from port 4399. - kbcli fault network http delay --port=4399 --method=POST --delay=15s - - # Replace the GET method sent from port 80 with the PUT method. - kbcli fault network http replace --replace-method=PUT --duration=1m - - # Replace the GET method sent from port 80 with the PUT method, and replace the request body. - kbcli fault network http replace --body="you are good luck" --replace-method=PUT --duration=2m - - # Replace the response content "you" from port 80. - kbcli fault network http replace --target=Response --body=you --duration=30s - - # Append content to the body of the post request sent from port 4399, in JSON format. - kbcli fault network http patch --method=POST --port=4399 --body="you are good luck" --type=JSON --duration=30s -`) - -type HTTPReplace struct { - ReplaceBody []byte `json:"body,omitempty"` - InputReplaceBody string `json:"-"` - ReplacePath string `json:"path,omitempty"` - ReplaceMethod string `json:"method,omitempty"` -} - -type HTTPPatch struct { - HTTPPatchBody `json:"body,omitempty"` -} - -type HTTPPatchBody struct { - PatchBodyValue string `json:"value,omitempty"` - PatchBodyType string `json:"type,omitempty"` -} - -type HTTPChaosOptions struct { - Target string `json:"target"` - Port int32 `json:"port"` - Path string `json:"path"` - Method string `json:"method"` - Code int32 `json:"code,omitempty"` - - // abort command - Abort bool `json:"abort,omitempty"` - // delay command - Delay string `json:"delay,omitempty"` - // replace command - HTTPReplace `json:"replace,omitempty"` - // patch command - HTTPPatch `json:"patch,omitempty"` - - FaultBaseOptions -} - -func NewHTTPChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *HTTPChaosOptions { - o := &HTTPChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateHTTPChaos, - GVR: GetGVR(Group, Version, ResourceHTTPChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewHTTPChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "http", - Short: "Intercept HTTP requests and responses.", - } - cmd.AddCommand( - NewAbortCmd(f, streams), - NewHTTPDelayCmd(f, streams), - NewReplaceCmd(f, streams), - NewPatchCmd(f, streams), - ) - return cmd -} - -func NewAbortCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewHTTPChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(Abort, AbortShort) - - o.AddCommonFlag(cmd) - cmd.Flags().BoolVar(&o.Abort, "abort", true, `Indicates whether to inject the fault that interrupts the connection.`) - - return cmd -} - -func NewHTTPDelayCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewHTTPChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(HTTPDelay, HTTPDelayShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Delay, "delay", "10s", `The time for delay.`) - - return cmd -} - -func NewReplaceCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewHTTPChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(Replace, ReplaceShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.InputReplaceBody, "body", "", `The content of the request body or response body to replace the failure.`) - cmd.Flags().StringVar(&o.ReplacePath, "replace-path", "", `The URI path used to replace content.`) - cmd.Flags().StringVar(&o.ReplaceMethod, "replace-method", "", `The replaced content of the HTTP request method.`) - - return cmd -} - -func NewPatchCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewHTTPChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(Patch, PatchShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.PatchBodyValue, "body", "", `The fault of the request body or response body with patch faults.`) - cmd.Flags().StringVar(&o.PatchBodyType, "type", "", `The type of patch faults of the request body or response body. Currently, it only supports JSON.`) - - return cmd -} - -func (o *HTTPChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultHTTPExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *HTTPChaosOptions) AddCommonFlag(cmd *cobra.Command) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().StringVar(&o.Target, "target", "Request", `Specifies whether the target of fault injection is Request or Response. The target-related fields should be configured at the same time.`) - cmd.Flags().Int32Var(&o.Port, "port", 80, `The TCP port that the target service listens on.`) - cmd.Flags().StringVar(&o.Path, "path", "*", `The URI path of the target request. Supports Matching wildcards.`) - cmd.Flags().StringVar(&o.Method, "method", "GET", `The HTTP method of the target request method. For example: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH.`) - cmd.Flags().Int32Var(&o.Code, "code", 0, `The status code responded by target.`) - - // register flag completion func - registerFlagCompletionFunc(cmd, o.Factory) -} - -func (o *HTTPChaosOptions) Validate() error { - if o.PatchBodyType != "" && o.PatchBodyType != "JSON" { - return fmt.Errorf("--type only supports JSON") - } - if o.PatchBodyValue != "" && o.PatchBodyType == "" { - return fmt.Errorf("--type is required when --body is specified") - } - if o.PatchBodyType != "" && o.PatchBodyValue == "" { - return fmt.Errorf("--body is required when --type is specified") - } - - var msg interface{} - if o.PatchBodyValue != "" && json.Unmarshal([]byte(o.PatchBodyValue), &msg) != nil { - return fmt.Errorf("--body is not a valid JSON") - } - - if o.Target == "Request" && o.Code != 0 { - return fmt.Errorf("--code is only supported when --target=Response") - } - - if ok, err := IsRegularMatch(o.Delay); !ok { - return err - } - return o.BaseValidate() -} - -func (o *HTTPChaosOptions) Complete() error { - o.ReplaceBody = []byte(o.InputReplaceBody) - return o.BaseComplete() -} - -func (o *HTTPChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.HTTPChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_http_test.go b/pkg/cmd/fault/fault_http_test.go deleted file mode 100644 index d2960c253..000000000 --- a/pkg/cmd/fault/fault_http_test.go +++ /dev/null @@ -1,139 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Network HTPP", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test fault network http", func() { - It("fault network http abort", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--mode=one", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--dry-run=client"}, - {"--ns-fault=kb-system", "--dry-run=client"}, - {"--node=minikube-m02", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--dry-run=client"}, - {"--abort=true", "--dry-run=client"}, - } - o := NewHTTPChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Abort, AbortShort) - o.AddCommonFlag(cmd) - cmd.Flags().BoolVar(&o.Abort, "abort", true, `Indicates whether to inject the fault that interrupts the connection.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network http delay", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--delay=50s", "--dry-run=client"}, - } - o := NewHTTPChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Delay, DelayShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Delay, "delay", "10s", `The time for delay.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network http replace", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--replace-method=PUT", "--body=\"you are good luck\"", "--replace-path=/local/", "--duration=1m", "--dry-run=client"}, - {"--target=Response", "--replace-method=PUT", "--body=you", "--replace-path=/local/", "--duration=1m", "--dry-run=client"}, - } - o := NewHTTPChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Replace, ReplaceShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.InputReplaceBody, "body", "", `The content of the request body or response body to replace the failure.`) - cmd.Flags().StringVar(&o.ReplacePath, "replace-path", "", `The URI path used to replace content.`) - cmd.Flags().StringVar(&o.ReplaceMethod, "replace-method", "", `The replaced content of the HTTP request method.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network http patch", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--body=\"you are good luck\"", "--type=JSON", "--duration=1m", "--dry-run=client"}, - {"--target=Response", "--body=\"you are good luck\"", "--type=JSON", "--duration=1m", "--dry-run=client"}, - } - o := NewHTTPChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Patch, PatchShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.PatchBodyValue, "body", "", `The fault of the request body or response body with patch faults.`) - cmd.Flags().StringVar(&o.PatchBodyType, "type", "", `The type of patch faults of the request body or response body. Currently, it only supports JSON.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_io.go b/pkg/cmd/fault/fault_io.go deleted file mode 100644 index 726f3faa1..000000000 --- a/pkg/cmd/fault/fault_io.go +++ /dev/null @@ -1,231 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/util" -) - -var faultIOExample = templates.Examples(` - # Affects the first container in default namespace's all pods. Delay all IO operations under the /data path by 10s. - kbcli fault io latency --delay=10s --volume-path=/data - - # Affects the first container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data - - # Affects the mysql container in mycluster-mysql-0 pod. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data -c=mysql - - # There is a 50% probability of affecting the read IO operation of the test.txt file under the /data path. - kbcli fault io latency mycluster-mysql-0 --delay=10s --volume-path=/data --path=test.txt --percent=50 --method=READ -c=mysql - - # Same as above.Make all IO operations under the /data path return the specified error number 22 (Invalid argument). - kbcli fault io errno --volume-path=/data --errno=22 - - # Same as above.Modify the IO operation permission attribute of the files under the /data path to 72.(110 in octal). - kbcli fault io attribute --volume-path=/data --perm=72 - - # Modify all files so that random positions of 1's with a maximum length of 10 bytes will be replaced with 0's. - kbcli fault io mistake --volume-path=/data --filling=zero --max-occurrences=10 --max-length=1 -`) - -type IOAttribute struct { - Ino uint64 `json:"ino,omitempty"` - Size uint64 `json:"size,omitempty"` - Blocks uint64 `json:"blocks,omitempty"` - Perm uint16 `json:"perm,omitempty"` - Nlink uint32 `json:"nlink,omitempty"` - UID uint32 `json:"uid,omitempty"` - GID uint32 `json:"gid,omitempty"` -} - -type IOMistake struct { - Filling string `json:"filling,omitempty"` - MaxOccurrences int `json:"maxOccurrences,omitempty"` - MaxLength int `json:"maxLength,omitempty"` -} - -type IOChaosOptions struct { - // Parameters required by the `latency` command. - Delay string `json:"delay"` - - // Parameters required by the `fault` command. - Errno int `json:"errno"` - - // Parameters required by the `attribute` command. - IOAttribute `json:"attr,omitempty"` - - // Parameters required by the `mistake` command. - IOMistake `json:"mistake,omitempty"` - - VolumePath string `json:"volumePath"` - Path string `json:"path"` - Percent int `json:"percent"` - Methods []string `json:"methods,omitempty"` - ContainerNames []string `json:"containerNames,omitempty"` - - FaultBaseOptions -} - -func NewIOChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "io", - Short: "IO chaos.", - } - cmd.AddCommand( - NewIOLatencyCmd(f, streams), - NewIOFaultCmd(f, streams), - NewIOAttributeOverrideCmd(f, streams), - NewIOMistakeCmd(f, streams), - ) - return cmd -} - -func NewIOChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *IOChaosOptions { - o := &IOChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateIOChaos, - GVR: GetGVR(Group, Version, ResourceIOChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewIOLatencyCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewIOChaosOptions(f, streams, string(v1alpha1.IoLatency)) - cmd := o.NewCobraCommand(Latency, LatencyShort) - - o.AddCommonFlag(cmd, f) - cmd.Flags().StringVar(&o.Delay, "delay", "", `Specific delay time.`) - - util.CheckErr(cmd.MarkFlagRequired("delay")) - return cmd -} - -func NewIOFaultCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewIOChaosOptions(f, streams, string(v1alpha1.IoFaults)) - cmd := o.NewCobraCommand(Errno, ErrnoShort) - - o.AddCommonFlag(cmd, f) - cmd.Flags().IntVar(&o.Errno, "errno", 0, `The returned error number.`) - - util.CheckErr(cmd.MarkFlagRequired("errno")) - return cmd -} - -func NewIOAttributeOverrideCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewIOChaosOptions(f, streams, string(v1alpha1.IoAttrOverride)) - cmd := o.NewCobraCommand(Attribute, AttributeShort) - - o.AddCommonFlag(cmd, f) - cmd.Flags().Uint64Var(&o.Ino, "ino", 0, `ino number.`) - cmd.Flags().Uint64Var(&o.Size, "size", 0, `File size.`) - cmd.Flags().Uint64Var(&o.Blocks, "blocks", 0, `The number of blocks the file occupies.`) - cmd.Flags().Uint16Var(&o.Perm, "perm", 0, `Decimal representation of file permissions.`) - cmd.Flags().Uint32Var(&o.Nlink, "nlink", 0, `The number of hard links.`) - cmd.Flags().Uint32Var(&o.UID, "uid", 0, `Owner's user ID.`) - cmd.Flags().Uint32Var(&o.GID, "gid", 0, `The owner's group ID.`) - - return cmd -} - -func NewIOMistakeCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewIOChaosOptions(f, streams, string(v1alpha1.IoMistake)) - cmd := o.NewCobraCommand(Mistake, MistakeShort) - - o.AddCommonFlag(cmd, f) - cmd.Flags().StringVar(&o.Filling, "filling", "", `The filling content of the error data can only be zero (filling with 0) or random (filling with random bytes).`) - cmd.Flags().IntVar(&o.MaxOccurrences, "max-occurrences", 1, `The maximum number of times an error can occur per operation.`) - cmd.Flags().IntVar(&o.MaxLength, "max-length", 1, `The maximum length (in bytes) of each error.`) - - util.CheckErr(cmd.MarkFlagRequired("filling")) - util.CheckErr(cmd.MarkFlagRequired("max-occurrences")) - util.CheckErr(cmd.MarkFlagRequired("max-length")) - - return cmd -} - -func (o *IOChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultIOExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *IOChaosOptions) AddCommonFlag(cmd *cobra.Command, f cmdutil.Factory) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().StringVar(&o.VolumePath, "volume-path", "", `The mount point of the volume in the target container must be the root directory of the mount.`) - cmd.Flags().StringVar(&o.Path, "path", "", `The effective scope of the injection error can be a wildcard or a single file.`) - cmd.Flags().IntVar(&o.Percent, "percent", 100, `Probability of failure per operation, in %.`) - cmd.Flags().StringArrayVar(&o.Methods, "method", nil, "The file system calls that need to inject faults. For example: WRITE READ") - cmd.Flags().StringArrayVarP(&o.ContainerNames, "container", "c", nil, "The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected.") - - util.CheckErr(cmd.MarkFlagRequired("volume-path")) - - // register flag completion func - registerFlagCompletionFunc(cmd, f) -} - -func (o *IOChaosOptions) Validate() error { - return o.BaseValidate() -} - -func (o *IOChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *IOChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.IOChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_io_test.go b/pkg/cmd/fault/fault_io_test.go deleted file mode 100644 index 624228e2b..000000000 --- a/pkg/cmd/fault/fault_io_test.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault IO", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test fault io", func() { - - It("fault io latency", func() { - inputs := [][]string{ - {"--mode=one", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--ns-fault=kb-system", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--node=minikube-m02", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--delay=10s", "--volume-path=/data", "--dry-run=client"}, - {"--delay=10s", "--volume-path=/data", "--path=test.txt", "--percent=50", "--method=READ", "-c=mysql", "--dry-run=client"}, - } - o := NewIOChaosOptions(tf, streams, string(v1alpha1.IoLatency)) - cmd := o.NewCobraCommand(Latency, LatencyShort) - o.AddCommonFlag(cmd, tf) - cmd.Flags().StringVar(&o.Delay, "delay", "", `Specific delay time.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault io errno", func() { - inputs := [][]string{ - {"--errno=22", "--volume-path=/data", "--dry-run=client"}, - {"--errno=22", "--volume-path=/data", "--path=test.txt", "--percent=50", "--method=READ", "--dry-run=client"}, - } - o := NewIOChaosOptions(tf, streams, string(v1alpha1.IoFaults)) - cmd := o.NewCobraCommand(Errno, ErrnoShort) - o.AddCommonFlag(cmd, tf) - cmd.Flags().IntVar(&o.Errno, "errno", 0, `The returned error number.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault io attribute", func() { - inputs := [][]string{ - {"--perm=72", "--size=72", "--blocks=72", "--nlink=72", "--ino=72", - "--uid=72", "--gid=72", "--volume-path=/data", "--dry-run=client"}, - } - o := NewIOChaosOptions(tf, streams, string(v1alpha1.IoAttrOverride)) - cmd := o.NewCobraCommand(Attribute, AttributeShort) - o.AddCommonFlag(cmd, tf) - cmd.Flags().Uint64Var(&o.Ino, "ino", 0, `ino number.`) - cmd.Flags().Uint64Var(&o.Size, "size", 0, `File size.`) - cmd.Flags().Uint64Var(&o.Blocks, "blocks", 0, `The number of blocks the file occupies.`) - cmd.Flags().Uint16Var(&o.Perm, "perm", 0, `Decimal representation of file permissions.`) - cmd.Flags().Uint32Var(&o.Nlink, "nlink", 0, `The number of hard links.`) - cmd.Flags().Uint32Var(&o.UID, "uid", 0, `Owner's user ID.`) - cmd.Flags().Uint32Var(&o.GID, "gid", 0, `The owner's group ID.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault io mistake", func() { - inputs := [][]string{ - {"--volume-path=/data", "--filling=zero", "--max-occurrences=10", "--max-length=1", "--dry-run=client"}, - {"--volume-path=/data", "--filling=random", "--max-occurrences=10", "--max-length=1", "--dry-run=client"}, - {"--volume-path=/data", "--filling=zero", "--max-occurrences=10", "--max-length=1", "--path=test.txt", "--percent=50", "--method=READ", "--dry-run=client"}, - } - o := NewIOChaosOptions(tf, streams, string(v1alpha1.IoMistake)) - cmd := o.NewCobraCommand(Mistake, MistakeShort) - o.AddCommonFlag(cmd, tf) - cmd.Flags().StringVar(&o.Filling, "filling", "", `The filling content of the error data can only be zero (filling with 0) or random (filling with random bytes).`) - cmd.Flags().IntVar(&o.MaxOccurrences, "max-occurrences", 1, `The maximum number of times an error can occur per operation.`) - cmd.Flags().IntVar(&o.MaxLength, "max-length", 1, `The maximum length (in bytes) of each error.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - }) -}) diff --git a/pkg/cmd/fault/fault_network.go b/pkg/cmd/fault/fault_network.go deleted file mode 100644 index 7f7c27386..000000000 --- a/pkg/cmd/fault/fault_network.go +++ /dev/null @@ -1,355 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "fmt" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/util" -) - -var faultNetWorkExample = templates.Examples(` - # Isolate all pods network under the default namespace from the outside world, including the k8s internal network. - kbcli fault network partition - - # The specified pod is isolated from the k8s external network "kubeblocks.io". - kbcli fault network partition mycluster-mysql-1 --external-targets=kubeblocks.io - - # Isolate the network between two pods. - kbcli fault network partition mycluster-mysql-1 --target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2 - - // Like the partition command, the target can be specified through --target-label or --external-targets. The pod only has obstacles in communicating with this target. If the target is not specified, all communication will be blocked. - # Block all pod communication under the default namespace, resulting in a 50% packet loss rate. - kbcli fault network loss --loss=50 - - # Block the specified pod communication, so that the packet loss rate is 50%. - kbcli fault network loss mysql-cluster-mysql-2 --loss=50 - - kbcli fault network corrupt --corrupt=50 - - # Blocks specified pod communication with a 50% packet corruption rate. - kbcli fault network corrupt mysql-cluster-mysql-2 --corrupt=50 - - kbcli fault network duplicate --duplicate=50 - - # Block specified pod communication so that the packet repetition rate is 50%. - kbcli fault network duplicate mysql-cluster-mysql-2 --duplicate=50 - - kbcli fault network delay --latency=10s - - # Block the communication of the specified pod, causing its network delay for 10s. - kbcli fault network delay mysql-cluster-mysql-2 --latency=10s - - # Limit the communication bandwidth between mysql-cluster-mysql-2 and the outside. - kbcli fault network bandwidth mysql-cluster-mysql-2 --rate=1kbps --duration=1m -`) - -type Target struct { - TargetMode string `json:"mode,omitempty"` - TargetValue string `json:"value,omitempty"` - TargetSelector `json:"selector,omitempty"` -} - -type TargetSelector struct { - // Specifies the labels that target Pods come with. - TargetLabelSelectors map[string]string `json:"labelSelectors,omitempty"` - // Specifies the namespaces to which target Pods belong. - TargetNamespaceSelectors []string `json:"namespaces,omitempty"` -} - -// NetworkLoss Loss command -type NetworkLoss struct { - // The percentage of packet loss - Loss string `json:"loss,omitempty"` - // The correlation of loss or corruption or duplication or delay - Correlation string `json:"correlation,omitempty"` -} - -// NetworkDelay Delay command -type NetworkDelay struct { - // The latency of delay - Latency string `json:"latency,omitempty"` - // The jitter of delay - Jitter string `json:"jitter,omitempty"` - // The correlation of loss or corruption or duplication or delay - Correlation string `json:"correlation,omitempty"` -} - -// NetworkDuplicate Duplicate command -type NetworkDuplicate struct { - // The percentage of packet duplication - Duplicate string `json:"duplicate,omitempty"` - // The correlation of loss or corruption or duplication or delay - Correlation string `json:"correlation,omitempty"` -} - -// NetworkCorrupt Corrupt command -type NetworkCorrupt struct { - // The percentage of packet corruption - Corrupt string `json:"corrupt,omitempty"` - // The correlation of loss or corruption or duplication or delay - Correlation string `json:"correlation,omitempty"` -} - -// NetworkBandwidth Bandwidth command -type NetworkBandwidth struct { - // the rate at which the bandwidth is limited. - Rate string `json:"rate,omitempty"` - // the number of bytes waiting in the queue. - Limit uint32 `json:"limit,omitempty"` - // the maximum number of bytes that can be sent instantaneously. - Buffer uint32 `json:"buffer,omitempty"` - // the bucket's maximum consumption rate. Reference: https://man7.org/linux/man-pages/man8/tc-tbf.8.html. - Peakrate uint64 `json:"peakrate,omitempty"` - // the size of the peakrate bucket. Reference: https://man7.org/linux/man-pages/man8/tc-tbf.8.html. - Minburst uint32 `json:"minburst,omitempty"` -} - -type NetworkChaosOptions struct { - // Specify the network direction - Direction string `json:"direction"` - - // A network target outside of Kubernetes, which can be an IPv4 address or a domain name, - // such as "kubeblocks.io". Only works with direction: to. - ExternalTargets []string `json:"externalTargets,omitempty"` - - // A collection of target pods. Pods can be selected by namespace and label. - Target `json:"target,omitempty"` - - NetworkLoss `json:"loss,omitempty"` - - NetworkDelay `json:"delay,omitempty"` - - NetworkDuplicate `json:"duplicate,omitempty"` - - NetworkCorrupt `json:"corrupt,omitempty"` - - NetworkBandwidth `json:"bandwidth,omitempty"` - - FaultBaseOptions -} - -func NewNetworkChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *NetworkChaosOptions { - o := &NetworkChaosOptions{ - FaultBaseOptions: FaultBaseOptions{CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateNetworkChaos, - GVR: GetGVR(Group, Version, ResourceNetworkChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewNetworkChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "network", - Short: "Network chaos.", - } - cmd.AddCommand( - NewPartitionCmd(f, streams), - NewLossCmd(f, streams), - NewDelayCmd(f, streams), - NewDuplicateCmd(f, streams), - NewCorruptCmd(f, streams), - NewBandwidthCmd(f, streams), - NewDNSChaosCmd(f, streams), - NewHTTPChaosCmd(f, streams), - ) - return cmd -} - -func NewPartitionCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.PartitionAction)) - cmd := o.NewCobraCommand(Partition, PartitionShort) - - o.AddCommonFlag(cmd) - - return cmd -} - -func NewLossCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.LossAction)) - cmd := o.NewCobraCommand(Loss, LossShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Loss, "loss", "", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkLoss.Correlation, "correlation", "c", "", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - util.CheckErr(cmd.MarkFlagRequired("loss")) - - return cmd -} - -func NewDelayCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.DelayAction)) - cmd := o.NewCobraCommand(Delay, DelayShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Latency, "latency", "", `the length of time to delay.`) - cmd.Flags().StringVar(&o.Jitter, "jitter", "", `the variation range of the delay time.`) - cmd.Flags().StringVarP(&o.NetworkDelay.Correlation, "correlation", "c", "", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - - util.CheckErr(cmd.MarkFlagRequired("latency")) - - return cmd -} - -func NewDuplicateCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.DuplicateAction)) - cmd := o.NewCobraCommand(Duplicate, DuplicateShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Duplicate, "duplicate", "", `the probability of a packet being repeated. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkDuplicate.Correlation, "correlation", "c", "", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - util.CheckErr(cmd.MarkFlagRequired("duplicate")) - - return cmd -} - -func NewCorruptCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.CorruptAction)) - cmd := o.NewCobraCommand(Corrupt, CorruptShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Corrupt, "corrupt", "", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkCorrupt.Correlation, "correlation", "c", "", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - util.CheckErr(cmd.MarkFlagRequired("corrupt")) - - return cmd -} - -func NewBandwidthCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNetworkChaosOptions(f, streams, string(v1alpha1.BandwidthAction)) - cmd := o.NewCobraCommand(Bandwidth, BandwidthShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Rate, "rate", "", `the rate at which the bandwidth is limited. For example : 10 bps/kbps/mbps/gbps.`) - cmd.Flags().Uint32Var(&o.Limit, "limit", 1, `the number of bytes waiting in the queue.`) - cmd.Flags().Uint32Var(&o.Buffer, "buffer", 1, `the maximum number of bytes that can be sent instantaneously.`) - cmd.Flags().Uint64Var(&o.Peakrate, "peakrate", 0, `the maximum consumption rate of the bucket.`) - cmd.Flags().Uint32Var(&o.Minburst, "minburst", 0, `the size of the peakrate bucket.`) - - util.CheckErr(cmd.MarkFlagRequired("rate")) - - return cmd -} - -func (o *NetworkChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultNetWorkExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *NetworkChaosOptions) AddCommonFlag(cmd *cobra.Command) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().StringVar(&o.Direction, "direction", "to", `You can select "to"" or "from"" or "both"".`) - cmd.Flags().StringArrayVarP(&o.ExternalTargets, "external-target", "e", nil, "a network target outside of Kubernetes, which can be an IPv4 address or a domain name,\n\t such as \"www.baidu.com\". Only works with direction: to.") - cmd.Flags().StringVar(&o.TargetMode, "target-mode", "", `You can select "one", "all", "fixed", "fixed-percent", "random-max-percent", Specify the experimental mode, that is, which Pods to experiment with.`) - cmd.Flags().StringVar(&o.TargetValue, "target-value", "", `If you choose mode=fixed or fixed-percent or random-max-percent, you can enter a value to specify the number or percentage of pods you want to inject.`) - cmd.Flags().StringToStringVar(&o.TargetLabelSelectors, "target-label", nil, `label for pod, such as '"app.kubernetes.io/component=mysql, statefulset.kubernetes.io/pod-name=mycluster-mysql-0"'`) - cmd.Flags().StringArrayVar(&o.TargetNamespaceSelectors, "target-ns-fault", nil, `Specifies the namespace into which you want to inject faults.`) - - // register flag completion func - registerFlagCompletionFunc(cmd, o.Factory) -} - -func (o *NetworkChaosOptions) Validate() error { - if o.TargetValue == "" && (o.TargetMode == "fixed" || o.TargetMode == "fixed-percent" || o.TargetMode == "random-max-percent") { - return fmt.Errorf("--value is required to specify pod nums or percentage") - } - - if (o.TargetNamespaceSelectors != nil || o.TargetLabelSelectors != nil) && o.TargetMode == "" { - return fmt.Errorf("--target-mode is required to specify a target mode") - } - - if o.ExternalTargets != nil && o.Direction != "to" { - return fmt.Errorf("--direction=to is required when specifying external targets") - } - - if ok, err := IsInteger(o.TargetValue); !ok { - return err - } - - if ok, err := IsInteger(o.Loss); !ok { - return err - } - - if ok, err := IsInteger(o.Corrupt); !ok { - return err - } - - if ok, err := IsInteger(o.Duplicate); !ok { - return err - } - - if ok, err := IsRegularMatch(o.Latency); !ok { - return err - } - - if ok, err := IsRegularMatch(o.Jitter); !ok { - return err - } - - return o.BaseValidate() -} - -func (o *NetworkChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *NetworkChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.NetworkChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_network_test.go b/pkg/cmd/fault/fault_network_test.go deleted file mode 100644 index 8cec2a972..000000000 --- a/pkg/cmd/fault/fault_network_test.go +++ /dev/null @@ -1,184 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Network", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test fault network", func() { - It("fault network partition", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--mode=one", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--dry-run=client"}, - {"--ns-fault=kb-system", "--dry-run=client"}, - {"--node=minikube-m02", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--dry-run=client"}, - {"--external-target=kubeblocks.io", "--dry-run=client"}, - {"--target-mode=one", "--target-label=statefulset.kubernetes.io/pod-name=mycluster-mysql-2", "--target-ns-fault=default", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.PartitionAction)) - cmd := o.NewCobraCommand(Partition, PartitionShort) - o.AddCommonFlag(cmd) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network loss", func() { - inputs := [][]string{ - {"--loss=50", "--dry-run=client"}, - {"--loss=50", "--correlation=100", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.LossAction)) - cmd := o.NewCobraCommand(Loss, LossShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Loss, "loss", "", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkLoss.Correlation, "correlation", "c", "0", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network delay", func() { - inputs := [][]string{ - {"--latency=50s", "--dry-run=client"}, - {"--latency=50s", "--jitter=10s", "--dry-run=client"}, - {"--latency=50s", "--correlation=100", "--dry-run=client"}, - {"--latency=50s", "--jitter=10s", "--correlation=100", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.DelayAction)) - cmd := o.NewCobraCommand(Delay, DelayShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Latency, "latency", "", `the length of time to delay.`) - cmd.Flags().StringVar(&o.Jitter, "jitter", "0ms", `the variation range of the delay time.`) - cmd.Flags().StringVarP(&o.NetworkDelay.Correlation, "correlation", "c", "0", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network duplicate", func() { - inputs := [][]string{ - {"--duplicate=50", "--dry-run=client"}, - {"--duplicate=50", "--correlation=100", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.DuplicateAction)) - cmd := o.NewCobraCommand(Duplicate, DuplicateShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Duplicate, "duplicate", "", `the probability of a packet being repeated. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkDuplicate.Correlation, "correlation", "c", "0", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network corrupt", func() { - inputs := [][]string{ - {"--corrupt=50", "--dry-run=client"}, - {"--corrupt=50", "--correlation=100", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.CorruptAction)) - cmd := o.NewCobraCommand(Corrupt, CorruptShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Corrupt, "corrupt", "", `Indicates the probability of a packet error occurring. Value range: [0, 100].`) - cmd.Flags().StringVarP(&o.NetworkCorrupt.Correlation, "correlation", "c", "0", `Indicates the correlation between the probability of a packet error occurring and whether it occurred the previous time. Value range: [0, 100].`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault network bandwidth", func() { - inputs := [][]string{ - {"--rate=10kbps", "--dry-run=client"}, - {"--rate=10kbps", "--limit=1000", "--buffer=100", "--peakrate=10", "--minburst=5", "--dry-run=client"}, - } - o := NewNetworkChaosOptions(tf, streams, string(v1alpha1.BandwidthAction)) - cmd := o.NewCobraCommand(Bandwidth, BandwidthShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringVar(&o.Rate, "rate", "", `the rate at which the bandwidth is limited. For example : 10 bps/kbps/mbps/gbps.`) - cmd.Flags().Uint32Var(&o.Limit, "limit", 1, `the number of bytes waiting in the queue.`) - cmd.Flags().Uint32Var(&o.Buffer, "buffer", 1, `the maximum number of bytes that can be sent instantaneously.`) - cmd.Flags().Uint64Var(&o.Peakrate, "peakrate", 0, `the maximum consumption rate of the bucket.`) - cmd.Flags().Uint32Var(&o.Minburst, "minburst", 0, `the size of the peakrate bucket.`) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_node.go b/pkg/cmd/fault/fault_node.go deleted file mode 100644 index 9ad2606aa..000000000 --- a/pkg/cmd/fault/fault_node.go +++ /dev/null @@ -1,471 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "bufio" - "context" - "encoding/base64" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - corev1 "k8s.io/api/core/v1" - k8serrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - "k8s.io/client-go/kubernetes" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - cp "github.com/apecloud/kbcli/pkg/cloudprovider" - "github.com/apecloud/kbcli/pkg/printer" - "github.com/apecloud/kbcli/pkg/util" - "github.com/apecloud/kbcli/pkg/util/prompt" -) - -var faultNodeExample = templates.Examples(` - # Stop a specified EC2 instance. - kbcli fault node stop node1 -c=aws --region=cn-northwest-1 --duration=3m - - # Stop two specified EC2 instances. - kbcli fault node stop node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Restart two specified EC2 instances. - kbcli fault node restart node1 node2 -c=aws --region=cn-northwest-1 --duration=3m - - # Detach two specified volume from two specified EC2 instances. - kbcli fault node detach-volume node1 node2 -c=aws --region=cn-northwest-1 --duration=1m --volume-id=v1,v2 --device-name=/d1,/d2 - - # Stop two specified GCK instances. - kbcli fault node stop node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Restart two specified GCK instances. - kbcli fault node restart node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering - - # Detach two specified volume from two specified GCK instances. - kbcli fault node detach-volume node1 node2 -c=gcp --region=us-central1-c --project=apecloud-platform-engineering --device-name=/d1,/d2 -`) - -type NodeChaoOptions struct { - Kind string `json:"kind"` - - Action string `json:"action"` - - CloudProvider string `json:"-"` - - SecretName string `json:"secretName"` - - Region string `json:"region"` - - Instance string `json:"instance"` - - VolumeID string `json:"volumeID"` - VolumeIDs []string `json:"-"` - - DeviceName string `json:"deviceName,omitempty"` - DeviceNames []string `json:"-"` - - Project string `json:"project"` - - Duration string `json:"duration"` - - AutoApprove bool `json:"-"` - - action.CreateOptions `json:"-"` -} - -func NewNodeOptions(f cmdutil.Factory, streams genericiooptions.IOStreams) *NodeChaoOptions { - o := &NodeChaoOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateNodeChaos, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewNodeChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "node", - Short: "Node chaos.", - } - - cmd.AddCommand( - NewStopCmd(f, streams), - NewRestartCmd(f, streams), - NewDetachVolumeCmd(f, streams), - ) - return cmd -} - -func NewStopCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNodeOptions(f, streams) - cmd := o.NewCobraCommand(Stop, StopShort) - - o.AddCommonFlag(cmd) - return cmd -} - -func NewRestartCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNodeOptions(f, streams) - cmd := o.NewCobraCommand(Restart, RestartShort) - - o.AddCommonFlag(cmd) - return cmd -} - -func NewDetachVolumeCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewNodeOptions(f, streams) - cmd := o.NewCobraCommand(DetachVolume, DetachVolumeShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringSliceVar(&o.VolumeIDs, "volume-id", nil, "The volume ids of the ec2. Only available when cloud-provider=aws.") - cmd.Flags().StringSliceVar(&o.DeviceNames, "device-name", nil, "The device name of the volume.") - - util.CheckErr(cmd.MarkFlagRequired("device-name")) - return cmd -} - -func (o *NodeChaoOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultNodeExample, - Run: func(cmd *cobra.Command, args []string) { - cmdutil.CheckErr(o.Execute(use, args, false)) - }, - } -} - -func (o *NodeChaoOptions) Execute(action string, args []string, testEnv bool) error { - o.Args = args - if err := o.CreateOptions.Complete(); err != nil { - return err - } - if err := o.Complete(action); err != nil { - return err - } - if err := o.Validate(); err != nil { - return err - } - - for idx, arg := range o.Args { - o.Instance = arg - if o.DeviceNames != nil { - o.DeviceName = o.DeviceNames[idx] - } - if o.VolumeIDs != nil { - o.VolumeID = o.VolumeIDs[idx] - } - if err := o.CreateSecret(testEnv); err != nil { - return err - } - if err := o.Run(); err != nil { - return err - } - } - return nil -} - -func (o *NodeChaoOptions) AddCommonFlag(cmd *cobra.Command) { - cmd.Flags().StringVarP(&o.CloudProvider, "cloud-provider", "c", "", fmt.Sprintf("Cloud provider type, one of %v", supportedCloudProviders)) - cmd.Flags().StringVar(&o.Region, "region", "", "The region of the node.") - cmd.Flags().StringVar(&o.Project, "project", "", "The name of the GCP project. Only available when cloud-provider=gcp.") - cmd.Flags().StringVar(&o.SecretName, "secret", "", "The name of the secret containing cloud provider specific credentials.") - cmd.Flags().StringVar(&o.Duration, "duration", "30s", "Supported formats of the duration are: ms / s / m / h.") - - cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before create secret.") - cmd.Flags().StringVar(&o.DryRun, "dry-run", "none", `Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent.`) - cmd.Flags().Lookup("dry-run").NoOptDefVal = Unchanged - printer.AddOutputFlagForCreate(cmd, &o.Format, false) - - util.CheckErr(cmd.MarkFlagRequired("cloud-provider")) - util.CheckErr(cmd.MarkFlagRequired("region")) - - // register flag completion func - registerFlagCompletionFunc(cmd, o.Factory) -} - -func (o *NodeChaoOptions) Validate() error { - if ok, err := IsRegularMatch(o.Duration); !ok { - return err - } - - if len(o.Args) == 0 { - return fmt.Errorf("node instance is required") - } - - switch o.CloudProvider { - case cp.AWS: - if o.Project != "" { - return fmt.Errorf("--project is not supported when cloud provider is aws") - } - if o.Action == DetachVolume && o.VolumeIDs == nil { - return fmt.Errorf("--volume-id is required when cloud provider is aws") - } - if o.Action == DetachVolume && len(o.DeviceNames) != len(o.VolumeIDs) { - return fmt.Errorf("the number of volume-id must be equal to the number of device-name") - } - case cp.GCP: - if o.Project == "" { - return fmt.Errorf("--project is required when cloud provider is gcp") - } - if o.VolumeIDs != nil { - return fmt.Errorf(" --volume-id is not supported when cloud provider is gcp") - } - default: - return fmt.Errorf("cloud provider type, one of %v", supportedCloudProviders) - } - - if o.DeviceNames != nil && len(o.Args) != len(o.DeviceNames) { - return fmt.Errorf("the number of device-name must be equal to the number of node") - } - return nil -} - -func (o *NodeChaoOptions) Complete(action string) error { - if o.CloudProvider == cp.AWS { - o.GVR = GetGVR(Group, Version, ResourceAWSChaos) - o.Kind = KindAWSChaos - if o.SecretName == "" { - o.SecretName = AWSSecretName - } - switch action { - case Stop: - o.Action = string(v1alpha1.Ec2Stop) - case Restart: - o.Action = string(v1alpha1.Ec2Restart) - case DetachVolume: - o.Action = string(v1alpha1.DetachVolume) - } - } else if o.CloudProvider == cp.GCP { - o.GVR = GetGVR(Group, Version, ResourceGCPChaos) - o.Kind = KindGCPChaos - if o.SecretName == "" { - o.SecretName = GCPSecretName - } - switch action { - case Stop: - o.Action = string(v1alpha1.NodeStop) - case Restart: - o.Action = string(v1alpha1.NodeReset) - case DetachVolume: - o.Action = string(v1alpha1.DiskLoss) - } - } - return nil -} - -func (o *NodeChaoOptions) PreCreate(obj *unstructured.Unstructured) error { - var c v1alpha1.InnerObject - - if o.CloudProvider == cp.AWS { - c = &v1alpha1.AWSChaos{} - } else if o.CloudProvider == cp.GCP { - c = &v1alpha1.GCPChaos{} - } - - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} - -func (o *NodeChaoOptions) CreateSecret(testEnv bool) error { - if testEnv { - return nil - } - - if o.DryRun != "none" { - return nil - } - - config, err := o.Factory.ToRESTConfig() - if err != nil { - return err - } - - clientSet, err := kubernetes.NewForConfig(config) - if err != nil { - return err - } - - // Check if Secret already exists - secretClient := clientSet.CoreV1().Secrets(o.Namespace) - _, err = secretClient.Get(context.TODO(), o.SecretName, metav1.GetOptions{}) - if err == nil { - fmt.Printf("Secret %s exists under %s namespace.\n", o.SecretName, o.Namespace) - return nil - } else if !k8serrors.IsNotFound(err) { - return err - } - - if err := o.confirmToContinue(); err != nil { - return err - } - - switch o.CloudProvider { - case "aws": - if err := handleAWS(clientSet, o.Namespace, o.SecretName); err != nil { - return err - } - case "gcp": - if err := handleGCP(clientSet, o.Namespace, o.SecretName); err != nil { - return err - } - default: - return fmt.Errorf("unknown cloud provider:%s", o.CloudProvider) - } - return nil -} - -func (o *NodeChaoOptions) confirmToContinue() error { - if !o.AutoApprove { - printer.Warning(o.Out, "A secret will be created for the cloud account to access %s, do you want to continue to create this secret: %s ?\n Only 'yes' will be accepted to confirm.\n\n", o.CloudProvider, o.SecretName) - entered, _ := prompt.NewPrompt("Enter a value:", nil, o.In).Run() - if entered != "yes" { - fmt.Fprintf(o.Out, "\nCancel automatic secert creation. You will not be able to access the nodes on the cluster.\n") - return cmdutil.ErrExit - } - } - fmt.Fprintf(o.Out, "Continue to create secret: %s\n", o.SecretName) - return nil -} - -func handleAWS(clientSet *kubernetes.Clientset, namespace, secretName string) error { - accessKeyID, secretAccessKey, err := readAWSCredentials() - if err != nil { - return err - } - - secret := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: secretName, - Namespace: namespace, - }, - Type: corev1.SecretTypeOpaque, - StringData: map[string]string{ - "aws_access_key_id": accessKeyID, - "aws_secret_access_key": secretAccessKey, - }, - } - - createdSecret, err := clientSet.CoreV1().Secrets(namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) - if err != nil { - return err - } - - fmt.Printf("Secret %s created successfully\n", createdSecret.Name) - return nil -} - -func handleGCP(clientSet *kubernetes.Clientset, namespace, secretName string) error { - home, err := os.UserHomeDir() - if err != nil { - return err - } - - filePath := filepath.Join(home, ".config", "gcloud", "application_default_credentials.json") - data, err := ioutil.ReadFile(filePath) - jsonData := string(data) - fmt.Println(jsonData) - if err != nil { - return err - } - encodedData := base64.StdEncoding.EncodeToString([]byte(jsonData)) - - secret := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: secretName, - Namespace: namespace, - }, - Type: corev1.SecretTypeOpaque, - StringData: map[string]string{ - "service_account": encodedData, - }, - } - - createdSecret, err := clientSet.CoreV1().Secrets(namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) - if err != nil { - return err - } - - fmt.Printf("Secret %s created successfully\n", createdSecret.Name) - return nil -} - -func readAWSCredentials() (string, string, error) { - home, err := os.UserHomeDir() - if err != nil { - return "", "", err - } - filePath := filepath.Join(home, ".aws", "credentials") - file, err := os.Open(filePath) - if err != nil { - return "", "", err - } - defer func(file *os.File) { - err := file.Close() - if err != nil { - fmt.Printf("unable to close file: %s", err) - } - }(file) - - // Read file content line by line using bufio.Scanner - scanner := bufio.NewScanner(file) - accessKeyID := "" - secretAccessKey := "" - - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(line, "aws_access_key_id") { - accessKeyID = strings.TrimSpace(strings.SplitN(line, "=", 2)[1]) - } else if strings.HasPrefix(line, "aws_secret_access_key") { - secretAccessKey = strings.TrimSpace(strings.SplitN(line, "=", 2)[1]) - } - } - - if scanner.Err() != nil { - return "", "", scanner.Err() - } - - if accessKeyID == "" || secretAccessKey == "" { - return "", "", fmt.Errorf("unable to find valid AWS access key information") - } - - return accessKeyID, secretAccessKey, nil -} diff --git a/pkg/cmd/fault/fault_node_test.go b/pkg/cmd/fault/fault_node_test.go deleted file mode 100644 index c07b16c2a..000000000 --- a/pkg/cmd/fault/fault_node_test.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Node", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test fault node", func() { - It("fault node stop", func() { - inputs := [][]string{ - {"-c=aws", "--region=cn-northwest-1", "--dry-run=client"}, - {"-c=aws", "--region=cn-northwest-1", "--secret=test-secret", "--dry-run=client"}, - {"-c=gcp", "--region=us-central1-c", "--project=apecloud-platform-engineering", "--dry-run=client"}, - } - o := NewNodeOptions(tf, streams) - cmd := o.NewCobraCommand(Stop, StopShort) - o.AddCommonFlag(cmd) - - o.Args = []string{"node1", "node2"} - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.Execute(Stop, o.Args, true)).Should(Succeed()) - } - }) - - It("fault node restart", func() { - inputs := [][]string{ - {"-c=aws", "--region=cn-northwest-1", "--dry-run=client"}, - {"-c=aws", "--region=cn-northwest-1", "--secret=test-secret", "--dry-run=client"}, - {"-c=gcp", "--region=us-central1-c", "--project=apecloud-platform-engineering", "--dry-run=client"}, - } - o := NewNodeOptions(tf, streams) - cmd := o.NewCobraCommand(Restart, RestartShort) - o.AddCommonFlag(cmd) - - o.Args = []string{"node1", "node2"} - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.Execute(Restart, o.Args, true)).Should(Succeed()) - } - }) - - It("fault node detach-volume", func() { - inputs := [][]string{ - {"-c=aws", "--region=cn-northwest-1", "--volume-id=v1,v2", "--device-name=/d1,/d2", "--dry-run=client"}, - {"-c=aws", "--region=cn-northwest-1", "--volume-id=v1,v2", "--device-name=/d1,/d2", "--secret=test-secret", "--dry-run=client"}, - {"-c=gcp", "--region=us-central1-c", "--project=apecloud-platform-engineering", "--device-name=/d1,/d2", "--dry-run=client"}, - } - o := NewNodeOptions(tf, streams) - cmd := o.NewCobraCommand(DetachVolume, DetachVolumeShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringSliceVar(&o.VolumeIDs, "volume-id", nil, "The volume id of the ec2.") - cmd.Flags().StringSliceVar(&o.DeviceNames, "device-name", nil, "The device name of the volume.") - - o.Args = []string{"node1", "node2"} - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.Execute(DetachVolume, o.Args, true)).Should(Succeed()) - o.VolumeIDs = nil - o.DeviceNames = nil - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_pod.go b/pkg/cmd/fault/fault_pod.go deleted file mode 100644 index 3bad917a3..000000000 --- a/pkg/cmd/fault/fault_pod.go +++ /dev/null @@ -1,186 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/util" -) - -var faultPodExample = templates.Examples(` - # kill all pods in default namespace - kbcli fault pod kill - - # kill any pod in default namespace - kbcli fault pod kill --mode=one - - # kill two pods in default namespace - kbcli fault pod kill --mode=fixed --value=2 - - # kill 50% pods in default namespace - kbcli fault pod kill --mode=percentage --value=50 - - # kill mysql-cluster-mysql-0 pod in default namespace - kbcli fault pod kill mysql-cluster-mysql-0 - - # kill all pods in default namespace - kbcli fault pod kill --ns-fault="default" - - # --label is required to specify the pods that need to be killed. - kbcli fault pod kill --label statefulset.kubernetes.io/pod-name=mysql-cluster-mysql-2 - - # kill pod under the specified node. - kbcli fault pod kill --node=minikube-m02 - - # kill pod under the specified node-label. - kbcli fault pod kill --node-label=kubernetes.io/arch=arm64 - - # Allow the experiment to last for one minute. - kbcli fault pod failure --duration=1m - - # kill container in pod - kbcli fault pod kill-container mysql-cluster-mysql-0 --container=mysql -`) - -type PodChaosOptions struct { - // GracePeriod waiting time, after which fault injection is performed - GracePeriod int64 `json:"gracePeriod"` - ContainerNames []string `json:"containerNames,omitempty"` - - FaultBaseOptions -} - -func NewPodChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *PodChaosOptions { - o := &PodChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplatePodChaos, - GVR: GetGVR(Group, Version, ResourcePodChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewPodChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{ - Use: "pod", - Short: "Pod chaos.", - } - cmd.AddCommand( - NewPodKillCmd(f, streams), - NewPodFailureCmd(f, streams), - NewContainerKillCmd(f, streams), - ) - return cmd -} - -func NewPodKillCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewPodChaosOptions(f, streams, string(v1alpha1.PodKillAction)) - cmd := o.NewCobraCommand(Kill, KillShort) - - o.AddCommonFlag(cmd) - cmd.Flags().Int64VarP(&o.GracePeriod, "grace-period", "g", 0, "Grace period represents the duration in seconds before the pod should be killed") - - // register flag completion func - registerFlagCompletionFunc(cmd, f) - - return cmd -} - -func NewPodFailureCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewPodChaosOptions(f, streams, string(v1alpha1.PodFailureAction)) - cmd := o.NewCobraCommand(Failure, FailureShort) - - o.AddCommonFlag(cmd) - // register flag completion func - registerFlagCompletionFunc(cmd, f) - - return cmd -} - -func NewContainerKillCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewPodChaosOptions(f, streams, string(v1alpha1.ContainerKillAction)) - cmd := o.NewCobraCommand(KillContainer, KillContainerShort) - - o.AddCommonFlag(cmd) - cmd.Flags().StringArrayVarP(&o.ContainerNames, "container", "c", nil, "the name of the container you want to kill, such as mysql, prometheus.") - - util.CheckErr(cmd.MarkFlagRequired("container")) - - // register flag completion func - registerFlagCompletionFunc(cmd, f) - - return cmd -} - -func (o *PodChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultPodExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *PodChaosOptions) AddCommonFlag(cmd *cobra.Command) { - o.FaultBaseOptions.AddCommonFlag(cmd) -} - -func (o *PodChaosOptions) Validate() error { - return o.BaseValidate() -} - -func (o *PodChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *PodChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.PodChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_pod_test.go b/pkg/cmd/fault/fault_pod_test.go deleted file mode 100644 index a4f2de569..000000000 --- a/pkg/cmd/fault/fault_pod_test.go +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault POD", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test fault pod", func() { - It("fault pod kill", func() { - inputs := [][]string{ - {"--dry-run=client"}, - {"--mode=one", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--dry-run=client"}, - {"--grace-period=5", "--dry-run=client"}, - {"--ns-fault=kb-system", "--dry-run=client"}, - {"--node=minikube-m02", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--dry-run=client"}, - } - o := NewPodChaosOptions(tf, streams, string(v1alpha1.PodKillAction)) - cmd := o.NewCobraCommand(Kill, KillShort) - o.AddCommonFlag(cmd) - cmd.Flags().Int64VarP(&o.GracePeriod, "grace-period", "g", 0, "Grace period represents the duration in seconds before the pod should be killed") - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - - It("fault pod kill-container", func() { - inputs := [][]string{ - {"--container=mysql", "--container=config-manager", "--dry-run=client"}, - } - o := NewPodChaosOptions(tf, streams, string(v1alpha1.ContainerKillAction)) - cmd := o.NewCobraCommand(KillContainer, KillContainerShort) - o.AddCommonFlag(cmd) - cmd.Flags().StringArrayVarP(&o.ContainerNames, "container", "c", nil, "the name of the container you want to kill, such as mysql, prometheus.") - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_stress.go b/pkg/cmd/fault/fault_stress.go deleted file mode 100644 index 252b71303..000000000 --- a/pkg/cmd/fault/fault_stress.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "fmt" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" -) - -var faultStressExample = templates.Examples(` - # Affects the first container in default namespace's all pods.Making CPU load up to 50%, and the memory up to 100MB. - kbcli fault stress --cpu-worker=2 --cpu-load=50 --memory-worker=1 --memory-size=100Mi - - # Affects the first container in mycluster-mysql-0 pod. Making the CPU load up to 50%, and the memory up to 500MB. - kbcli fault stress mycluster-mysql-0 --cpu-worker=2 --cpu-load=50 - - # Affects the mysql container in mycluster-mysql-0 pod. Making the memory up to 500MB. - kbcli fault stress mycluster-mysql-0 --memory-worker=2 --memory-size=500Mi -c=mysql -`) - -type CPU struct { - Workers int `json:"workers"` - Load int `json:"load"` -} - -type Memory struct { - Workers int `json:"workers"` - Size string `json:"size"` -} - -type Stressors struct { - CPU `json:"cpu"` - Memory `json:"memory"` -} - -type StressChaosOptions struct { - Stressors `json:"stressors"` - ContainerNames []string `json:"containerNames,omitempty"` - - FaultBaseOptions -} - -func NewStressChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *StressChaosOptions { - o := &StressChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateStressChaos, - GVR: GetGVR(Group, Version, ResourceStressChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewStressChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewStressChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(Stress, StressShort) - - o.AddCommonFlag(cmd, f) - return cmd -} - -func (o *StressChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultStressExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *StressChaosOptions) AddCommonFlag(cmd *cobra.Command, f cmdutil.Factory) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().IntVar(&o.CPU.Workers, "cpu-worker", 0, `Specifies the number of threads that exert CPU pressure.`) - cmd.Flags().IntVar(&o.CPU.Load, "cpu-load", 0, `Specifies the percentage of CPU occupied. 0 means no extra load added, 100 means full load. The total load is workers * load.`) - cmd.Flags().IntVar(&o.Memory.Workers, "memory-worker", 0, `Specifies the number of threads that apply memory pressure.`) - cmd.Flags().StringVar(&o.Memory.Size, "memory-size", "", `Specify the size of the allocated memory or the percentage of the total memory, and the sum of the allocated memory is size. For example:256MB or 25%`) - cmd.Flags().StringArrayVarP(&o.ContainerNames, "container", "c", nil, "The name of the container, such as mysql, prometheus.If it's empty, the first container will be injected.") - - // register flag completion func - registerFlagCompletionFunc(cmd, f) -} - -func (o *StressChaosOptions) Validate() error { - if o.Memory.Workers == 0 && o.CPU.Workers == 0 { - return fmt.Errorf("the CPU or Memory workers must have at least one greater than 0, Use --cpu-workers or --memory-workers to specify") - } - - return o.BaseValidate() -} - -func (o *StressChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *StressChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.StressChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_stress_test.go b/pkg/cmd/fault/fault_stress_test.go deleted file mode 100644 index 05aa44267..000000000 --- a/pkg/cmd/fault/fault_stress_test.go +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Stress", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - Context("test fault stress", func() { - - It("fault stress", func() { - inputs := [][]string{ - {"--mode=one", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--ns-fault=kb-system", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--node=minikube-m02", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--cpu-worker=2", "--cpu-load=50", "--dry-run=client"}, - {"--memory-worker=2", "--memory-size=500Mi", "-c=mysql", "--dry-run=client"}, - {"--cpu-worker=2", "--cpu-load=50", "--memory-worker=1", "--memory-size=100Mi", "--dry-run=client"}, - {"--cpu-worker=2", "--cpu-load=50", "--memory-worker=1", "--memory-size=100Mi", "--dry-run=client", "--container=mysql"}, - } - o := NewStressChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Stress, StressShort) - o.AddCommonFlag(cmd, tf) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/fault_time.go b/pkg/cmd/fault/fault_time.go deleted file mode 100644 index 9d0de070d..000000000 --- a/pkg/cmd/fault/fault_time.go +++ /dev/null @@ -1,135 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericiooptions" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/action" - "github.com/apecloud/kbcli/pkg/util" -) - -var faultTimeExample = templates.Examples(` - # Affects the first container in default namespace's all pods.Shifts the clock back five seconds. - kbcli fault time --time-offset=-5s - - # Affects the first container in default namespace's all pods. - kbcli fault time --time-offset=-5m5s - - # Affects the first container in mycluster-mysql-0 pod. Shifts the clock forward five seconds. - kbcli fault time mycluster-mysql-0 --time-offset=+5s50ms - - # Affects the mysql container in mycluster-mysql-0 pod. Shifts the clock forward five seconds. - kbcli fault time mycluster-mysql-0 --time-offset=+5s -c=mysql - - # The clock that specifies the effect of time offset is CLOCK_REALTIME. - kbcli fault time mycluster-mysql-0 --time-offset=+5s --clock-id=CLOCK_REALTIME -c=mysql -`) - -type TimeChaosOptions struct { - TimeOffset string `json:"timeOffset"` - - ClockIds []string `json:"clockIds,omitempty"` - - ContainerNames []string `json:"containerNames,omitempty"` - - FaultBaseOptions -} - -func NewTimeChaosOptions(f cmdutil.Factory, streams genericiooptions.IOStreams, act string) *TimeChaosOptions { - o := &TimeChaosOptions{ - FaultBaseOptions: FaultBaseOptions{ - CreateOptions: action.CreateOptions{ - Factory: f, - IOStreams: streams, - CueTemplateName: CueTemplateTimeChaos, - GVR: GetGVR(Group, Version, ResourceTimeChaos), - }, - Action: act, - }, - } - o.CreateOptions.PreCreate = o.PreCreate - o.CreateOptions.Options = o - return o -} - -func NewTimeChaosCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := NewTimeChaosOptions(f, streams, "") - cmd := o.NewCobraCommand(Time, TimeShort) - - o.AddCommonFlag(cmd, f) - return cmd -} - -func (o *TimeChaosOptions) NewCobraCommand(use, short string) *cobra.Command { - return &cobra.Command{ - Use: use, - Short: short, - Example: faultTimeExample, - Run: func(cmd *cobra.Command, args []string) { - o.Args = args - cmdutil.CheckErr(o.CreateOptions.Complete()) - cmdutil.CheckErr(o.Validate()) - cmdutil.CheckErr(o.Complete()) - cmdutil.CheckErr(o.Run()) - }, - } -} - -func (o *TimeChaosOptions) AddCommonFlag(cmd *cobra.Command, f cmdutil.Factory) { - o.FaultBaseOptions.AddCommonFlag(cmd) - - cmd.Flags().StringVar(&o.TimeOffset, "time-offset", "", "Specifies the length of the time offset. For example: -5s, -10m100ns.") - cmd.Flags().StringArrayVar(&o.ClockIds, "clock-id", nil, `Specifies the clock on which the time offset acts.If it's empty, it will be set to ['CLOCK_REALTIME'].See clock_gettime [https://man7.org/linux/man-pages/man2/clock_gettime.2.html] document for details.`) - cmd.Flags().StringArrayVarP(&o.ContainerNames, "container", "c", nil, `Specifies the injected container name. For example: mysql. If it's empty, the first container will be injected.`) - - util.CheckErr(cmd.MarkFlagRequired("time-offset")) - - // register flag completion func - registerFlagCompletionFunc(cmd, f) -} - -func (o *TimeChaosOptions) Validate() error { - return o.BaseValidate() -} - -func (o *TimeChaosOptions) Complete() error { - return o.BaseComplete() -} - -func (o *TimeChaosOptions) PreCreate(obj *unstructured.Unstructured) error { - c := &v1alpha1.TimeChaos{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, c); err != nil { - return err - } - - data, e := runtime.DefaultUnstructuredConverter.ToUnstructured(c) - if e != nil { - return e - } - obj.SetUnstructuredContent(data) - return nil -} diff --git a/pkg/cmd/fault/fault_time_test.go b/pkg/cmd/fault/fault_time_test.go deleted file mode 100644 index e8449abb2..000000000 --- a/pkg/cmd/fault/fault_time_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/cli-runtime/pkg/genericiooptions" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Fault Time", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - ) - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = cmdtesting.NewTestFactory().WithNamespace(testing.Namespace) - tf.Client = &clientfake.RESTClient{} - }) - - AfterEach(func() { - tf.Cleanup() - }) - Context("test fault time", func() { - - It("fault time", func() { - inputs := [][]string{ - {"--mode=one", "--time-offset=-5s", "--dry-run=client"}, - {"--mode=fixed", "--value=2", "--time-offset=-5s", "--dry-run=client"}, - {"--mode=fixed-percent", "--value=50", "--time-offset=-5s", "--dry-run=client"}, - {"--mode=random-max-percent", "--value=50", "--time-offset=-5s", "--dry-run=client"}, - {"--ns-fault=kb-system", "--time-offset=-5s", "--dry-run=client"}, - {"--node=minikube-m02", "--time-offset=-5s", "--dry-run=client"}, - {"--label=app.kubernetes.io/component=mysql", "--time-offset=-5s", "--dry-run=client"}, - {"--node-label=kubernetes.io/arch=arm64", "--time-offset=-5s", "--dry-run=client"}, - {"--annotation=example-annotation=group-a", "--time-offset=-5s", "--dry-run=client"}, - {"--time-offset=-5s", "--dry-run=client"}, - {"--time-offset=+5s", "--clock-id=CLOCK_REALTIME", "-c=mysql", "--dry-run=client"}, - } - o := NewTimeChaosOptions(tf, streams, "") - cmd := o.NewCobraCommand(Time, TimeShort) - o.AddCommonFlag(cmd, tf) - - for _, input := range inputs { - Expect(cmd.Flags().Parse(input)).Should(Succeed()) - Expect(o.CreateOptions.Complete()) - Expect(o.Complete()).Should(Succeed()) - Expect(o.Validate()).Should(Succeed()) - Expect(o.Run()).Should(Succeed()) - } - }) - }) -}) diff --git a/pkg/cmd/fault/list_and_delete.go b/pkg/cmd/fault/list_and_delete.go deleted file mode 100644 index 9fafc8490..000000000 --- a/pkg/cmd/fault/list_and_delete.go +++ /dev/null @@ -1,244 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "context" - "fmt" - "sort" - "strings" - "time" - - "github.com/jedib0t/go-pretty/v6/table" - "github.com/pkg/errors" - "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/cli-runtime/pkg/genericiooptions" - "k8s.io/client-go/dynamic" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "k8s.io/kubectl/pkg/util/templates" - - "github.com/apecloud/kbcli/pkg/printer" - "github.com/apecloud/kbcli/pkg/util" -) - -var listExample = templates.Examples(` - # List all chaos resources - kbcli fault list - - # List all chaos kind - kbcli fault list --kind - - # List specific chaos resources. Use 'kbcli fault list --kind' to get chaos kind. - kbcli fault list podchaos -`) - -var deleteExample = templates.Examples(` - # Delete all chaos resources - kbcli fault delete - - # Delete specific chaos resources - kbcli fault delete podchaos -`) - -type ListAndDeleteOptions struct { - Factory cmdutil.Factory - Dynamic dynamic.Interface - - ResourceKinds []string - AllResourceKinds []string - Kind bool - - genericiooptions.IOStreams -} - -func NewListCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := &ListAndDeleteOptions{Factory: f, IOStreams: streams} - cmd := cobra.Command{ - Use: "list", - Short: "List chaos resources.", - Example: listExample, - Run: func(cmd *cobra.Command, args []string) { - util.CheckErr(o.Validate(args)) - util.CheckErr(o.Complete(args)) - util.CheckErr(o.RunList()) - }, - } - cmd.Flags().BoolVar(&o.Kind, "kind", false, "Print chaos resource kind.") - return &cmd -} - -func NewDeleteCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { - o := &ListAndDeleteOptions{Factory: f, IOStreams: streams} - return &cobra.Command{ - Use: "delete", - Short: "Delete chaos resources.", - Example: deleteExample, - Run: func(cmd *cobra.Command, args []string) { - util.CheckErr(o.Validate(args)) - util.CheckErr(o.Complete(args)) - util.CheckErr(o.RunDelete()) - }, - } -} - -func (o *ListAndDeleteOptions) Validate(args []string) error { - var err error - o.AllResourceKinds, err = getAllChaosResourceKinds(o.Factory, GroupVersion) - if err != nil { - return fmt.Errorf("failed to get all chaos resource kinds: %v", err) - } - kindMap := make(map[string]bool) - for _, kind := range o.AllResourceKinds { - kindMap[kind] = true - } - for _, kind := range args { - if _, ok := kindMap[kind]; !ok { - return fmt.Errorf("invalid chaos resource kind: %s\nUse 'kbcli fault list --kind' to list all chaos resource kinds", kind) - } - } - - return nil -} - -func (o *ListAndDeleteOptions) Complete(args []string) error { - if o.Kind { - for _, resourceKind := range o.AllResourceKinds { - fmt.Fprintf(o.Out, "%s\n", resourceKind) - } - return nil - } - - if len(args) > 0 { - o.ResourceKinds = args - } else { - o.ResourceKinds = o.AllResourceKinds - } - - var err error - o.Dynamic, err = o.Factory.DynamicClient() - if err != nil { - return fmt.Errorf("failed to create dynamic client: %v", err) - } - - return nil -} - -func (o *ListAndDeleteOptions) RunList() error { - if o.Kind { - return nil - } - - tbl := printer.NewTablePrinter(o.Out) - tbl.Tbl.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, WidthMax: 120}, - }) - tbl.SetHeader("NAME", "AGE") - - for _, resourceKind := range o.ResourceKinds { - if err := o.listResources(resourceKind, tbl); err != nil { - return err - } - } - - tbl.Print() - return nil -} - -func (o *ListAndDeleteOptions) RunDelete() error { - for _, resourceKind := range o.ResourceKinds { - if err := o.deleteResources(resourceKind); err != nil { - return err - } - } - return nil -} - -func (o *ListAndDeleteOptions) listResources(resourceKind string, tbl *printer.TablePrinter) error { - gvr := GetGVR(Group, Version, resourceKind) - resourceList, err := o.Dynamic.Resource(gvr).List(context.TODO(), metav1.ListOptions{}) - if err != nil { - return errors.Wrapf(err, "failed to list %s", gvr) - } - - if len(resourceList.Items) == 0 { - return nil - } - - // sort by creation time from old to new - sort.Slice(resourceList.Items, func(i, j int) bool { - t1, _ := time.Parse(time.RFC3339, resourceList.Items[i].GetCreationTimestamp().String()) - t2, _ := time.Parse(time.RFC3339, resourceList.Items[j].GetCreationTimestamp().String()) - return t1.Before(t2) - }) - - for _, obj := range resourceList.Items { - creationTime := obj.GetCreationTimestamp().Time - age := time.Since(creationTime).Round(time.Second).String() - tbl.AddRow(obj.GetName(), age) - } - return nil -} - -func (o *ListAndDeleteOptions) deleteResources(resourceKind string) error { - gvr := GetGVR(Group, Version, resourceKind) - resourceList, err := o.Dynamic.Resource(gvr).List(context.TODO(), metav1.ListOptions{}) - if err != nil { - return errors.Wrapf(err, "failed to list %s", gvr) - } - - if len(resourceList.Items) == 0 { - return nil - } - - for _, obj := range resourceList.Items { - err = o.Dynamic.Resource(gvr).Namespace(obj.GetNamespace()).Delete(context.TODO(), obj.GetName(), metav1.DeleteOptions{}) - if err != nil { - return errors.Wrapf(err, "failed to delete %s", gvr) - } - fmt.Fprintf(o.Out, "delete resource %s/%s\n", obj.GetNamespace(), obj.GetName()) - } - return nil -} - -func getAllChaosResourceKinds(f cmdutil.Factory, groupVersion string) ([]string, error) { - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return nil, errors.Wrap(err, "failed to create discovery client") - } - chaosResources, err := discoveryClient.ServerResourcesForGroupVersion(groupVersion) - if err != nil { - return nil, errors.Wrapf(err, "failed to get server resources for %s", groupVersion) - } - - resourceKinds := make([]string, 0) - for _, resourceKind := range chaosResources.APIResources { - // skip subresources - if len(strings.Split(resourceKind.Name, "/")) > 1 { - continue - } - // skip podhttpchaos and podnetworkchaos etc. - if resourceKind.Name != "podchaos" && strings.HasPrefix(resourceKind.Name, "pod") { - continue - } - resourceKinds = append(resourceKinds, resourceKind.Name) - } - return resourceKinds, nil -} diff --git a/pkg/cmd/fault/list_and_delete_test.go b/pkg/cmd/fault/list_and_delete_test.go deleted file mode 100644 index 8f49ad4c3..000000000 --- a/pkg/cmd/fault/list_and_delete_test.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "net/http" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/cli-runtime/pkg/genericiooptions" - "k8s.io/cli-runtime/pkg/resource" - "k8s.io/client-go/dynamic/fake" - "k8s.io/client-go/kubernetes/scheme" - clientfake "k8s.io/client-go/rest/fake" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - - "github.com/apecloud/kbcli/pkg/testing" -) - -var _ = Describe("Chaos resources list and delete", func() { - var ( - tf *cmdtesting.TestFactory - streams genericiooptions.IOStreams - namespace = "test" - podChaosName = "testPodChaos" - podChaos = testing.FakePodChaos(podChaosName, namespace) - ) - - BeforeEach(func() { - streams, _, _, _ = genericiooptions.NewTestIOStreams() - tf = testing.NewTestFactory(namespace) - codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) - httpResp := func(obj runtime.Object) *http.Response { - return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, obj)} - } - tf.UnstructuredClient = &clientfake.RESTClient{ - GroupVersion: schema.GroupVersion{Group: Group, Version: Version}, - NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, - Client: clientfake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { - urlPrefix := "/apis/" + GroupVersion + "/namespaces/" + namespace - mapping := map[string]*http.Response{ - urlPrefix + "/podchaos/" + podChaos.Name: httpResp(podChaos), - } - return mapping[req.URL.Path], nil - }), - } - - tf.Client = tf.UnstructuredClient - _ = v1alpha1.AddToScheme(scheme.Scheme) - tf.FakeDynamicClient = fake.NewSimpleDynamicClient(scheme.Scheme, podChaos) - }) - - AfterEach(func() { - tf.Cleanup() - }) - - Context("test list and delete chaos resources", func() { - It("test fault list", func() { - args := []string{"podchaoses"} - o := &ListAndDeleteOptions{Factory: tf, IOStreams: streams} - Expect(o.Complete(args)).Should(Succeed()) - Expect(o.RunList()).Should(Succeed()) - }) - - It("test fault delete", func() { - args := []string{"podchaoses"} - o := &ListAndDeleteOptions{Factory: tf, IOStreams: streams} - Expect(o.Complete(args)).Should(Succeed()) - Expect(o.RunDelete()).Should(Succeed()) - }) - }) -}) diff --git a/pkg/cmd/fault/suite_test.go b/pkg/cmd/fault/suite_test.go deleted file mode 100644 index e2fbd82fc..000000000 --- a/pkg/cmd/fault/suite_test.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright (C) 2022-2024 ApeCloud Co., Ltd - -This file is part of KubeBlocks project - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -package fault - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestDashboard(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Fault Suite") -}