Documentation ¶
Index ¶
- Constants
- func DiscoverKubernetesCLI(detailPath string) (string, error)
- func LoadSupportedCLI() []func() (string, error)
- func RegisterClient(name string, client KubernetesClient)
- type CommonCallHandler
- func (r *CommonCallHandler[T]) CheckObjectExist(ctx context.Context, namespace, nodeName, objectName string) (bool, error)
- func (r *CommonCallHandler[T]) Create(t T) error
- func (r *CommonCallHandler[T]) DeleteByNames(namespace string, names ...string) error
- func (r *CommonCallHandler[T]) GetObject(ctx context.Context, namespace, nodeName string, objectName ...string) (T, error)
- func (r *CommonCallHandler[T]) QueryByName(namespace, name string) (T, error)
- func (r *CommonCallHandler[T]) QueryList(namespace string, names ...string) ([]T, error)
- func (r *CommonCallHandler[T]) Update(t T) error
- type CopyType
- type Filter
- type KubernetesCLI
- func (k *KubernetesCLI) CLI() string
- func (k *KubernetesCLI) CheckResourceExist(name, namespace string, resourceType ResourceType) (bool, error)
- func (k *KubernetesCLI) CopyContainerFileToLocal(ctx context.Context, namespace, containerName, src, dst string, ...) ([]byte, error)
- func (k *KubernetesCLI) DeleteFinalizersInResourceByQualifiedNames(qualifiedNames []string, namespace string) error
- func (k *KubernetesCLI) DeleteResourceByQualifiedNames(qualifiedNames []string, namespace string) (string, error)
- func (k *KubernetesCLI) ExecCmdInSpecifiedContainer(ctx context.Context, namespace, containerName, cmd string, podName ...string) ([]byte, error)
- func (k *KubernetesCLI) GetConsoleLogs(ctx context.Context, namespace, containerName string, isHistoryLogs bool, ...) ([]byte, error)
- func (k *KubernetesCLI) GetNameSpace() (string, error)
- func (k *KubernetesCLI) GetObject(ctx context.Context, objectType ObjectType, namespace, nodeName string, ...) error
- func (k *KubernetesCLI) GetResource(name []string, namespace, outputType string, resourceType ResourceType) ([]byte, error)
- func (k *KubernetesCLI) OperateResourceByYaml(yaml, operate string, ignoreNotfound bool) error
- type KubernetesCLIArgs
- func (k *KubernetesCLIArgs) Copy(ctx context.Context, containerPath, localPath string, cpType CopyType) ([]byte, error)
- func (k *KubernetesCLIArgs) Exec(ctx context.Context, cmd string) ([]byte, error)
- func (k *KubernetesCLIArgs) Get(ctx context.Context, data interface{}) error
- func (k *KubernetesCLIArgs) Logs(ctx context.Context) ([]byte, error)
- func (k *KubernetesCLIArgs) SelectObject(objectType ObjectType, objectName ...string) *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithHistoryLogs(isHistoryLog bool) *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithIgnoreNotFound() *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithOutPutFormat(outputType OutputType) *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithSpecifiedContainer(containerName string) *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithSpecifiedNamespace(namespace string) *KubernetesCLIArgs
- func (k *KubernetesCLIArgs) WithSpecifiedNode(nodeName string) *KubernetesCLIArgs
- type KubernetesClient
- type ListResult
- type ObjectType
- type OutputType
- type ResourceType
Constants ¶
const ( CLIKubernetes = "kubectl" CLIOpenShift = "oc" ConfigMap ResourceType = "configmap" Secret ResourceType = "secret" Storagebackendclaim ResourceType = "storagebackendclaim" StoragebackendclaimContent ResourceType = "storagebackendcontent" Create = "create" // used to create resource Delete = "delete" // used to delete resource Apply = "apply" // used to update resource )
const ( Pod ObjectType = "pod" // Operate pod objects. Node ObjectType = "node" // Operate node objects. Namespace ObjectType = "namespace" // Operate namespace objects. Unknown ObjectType = "" // Unknown object JSON OutputType = "-o=json" // Obtains data in JSON format. YAML OutputType = "-o=yaml" // Obtains data in YAML format. LocalToContainer CopyType = 0 // Copy files from the local host to the container. ContainerToLocal CopyType = 1 // Copy files from the container to the local host. IgnoreNode = "" // used to ignore the specified condition of the node when invoking an interface. IgnoreContainer = "" // used to ignore the specified condition of the container when invoking an interface. IgnoreNamespace = "" // used to ignore the specified condition of the namespace when invoking an interface. )
Variables ¶
This section is empty.
Functions ¶
func DiscoverKubernetesCLI ¶
DiscoverKubernetesCLI used to discover kubernetes CLI.
func LoadSupportedCLI ¶
LoadSupportedCLI used to load all supported CLI, e.g. kubectl, oc
func RegisterClient ¶
func RegisterClient(name string, client KubernetesClient)
RegisterClient used to register a client into the clientSet
Types ¶
type CommonCallHandler ¶
type CommonCallHandler[T any] struct { // contains filtered or unexported fields }
CommonCallHandler common call handler
func NewCommonCallHandler ¶
func NewCommonCallHandler[T any](client KubernetesClient) *CommonCallHandler[T]
NewCommonCallHandler init common call handler
func (*CommonCallHandler[T]) CheckObjectExist ¶
func (*CommonCallHandler[T]) Create ¶
func (r *CommonCallHandler[T]) Create(t T) error
Create resource
func (*CommonCallHandler[T]) DeleteByNames ¶
func (r *CommonCallHandler[T]) DeleteByNames(namespace string, names ...string) error
DeleteByNames delete resource by names
func (*CommonCallHandler[T]) QueryByName ¶
func (r *CommonCallHandler[T]) QueryByName(namespace, name string) (T, error)
QueryByName query resource by name
func (*CommonCallHandler[T]) QueryList ¶
func (r *CommonCallHandler[T]) QueryList(namespace string, names ...string) ([]T, error)
QueryList query resource list
func (*CommonCallHandler[T]) Update ¶
func (r *CommonCallHandler[T]) Update(t T) error
Update resource
type KubernetesCLI ¶
type KubernetesCLI struct {
// contains filtered or unexported fields
}
func (*KubernetesCLI) CheckResourceExist ¶
func (k *KubernetesCLI) CheckResourceExist(name, namespace string, resourceType ResourceType) (bool, error)
CheckResourceExist check whether resource exists based on the specified args.
func (*KubernetesCLI) CopyContainerFileToLocal ¶
func (k *KubernetesCLI) CopyContainerFileToLocal(ctx context.Context, namespace, containerName, src, dst string, podName ...string) ([]byte, error)
CopyContainerFileToLocal used to copying a Local File to a Container with Specified Conditions
func (*KubernetesCLI) DeleteFinalizersInResourceByQualifiedNames ¶
func (k *KubernetesCLI) DeleteFinalizersInResourceByQualifiedNames(qualifiedNames []string, namespace string) error
DeleteFinalizersInResourceByQualifiedNames delete finalizers in resource based on the specified qualified names
func (*KubernetesCLI) DeleteResourceByQualifiedNames ¶
func (k *KubernetesCLI) DeleteResourceByQualifiedNames(qualifiedNames []string, namespace string) (string, error)
DeleteResourceByQualifiedNames delete resource based on the specified qualified names
func (*KubernetesCLI) ExecCmdInSpecifiedContainer ¶
func (k *KubernetesCLI) ExecCmdInSpecifiedContainer(ctx context.Context, namespace, containerName, cmd string, podName ...string) ([]byte, error)
ExecCmdInSpecifiedContainer used to executes the specified command in the container with specified conditions.
func (*KubernetesCLI) GetConsoleLogs ¶
func (k *KubernetesCLI) GetConsoleLogs(ctx context.Context, namespace, containerName string, isHistoryLogs bool, podName ...string) ([]byte, error)
GetConsoleLogs used to get the console logs of a specified container.
func (*KubernetesCLI) GetNameSpace ¶
func (k *KubernetesCLI) GetNameSpace() (string, error)
GetNameSpace used to get namespace from service account info.
func (*KubernetesCLI) GetObject ¶
func (k *KubernetesCLI) GetObject(ctx context.Context, objectType ObjectType, namespace, nodeName string, outputType OutputType, data interface{}, objectName ...string) error
GetObject used to get the specified format data of the object with specified conditions and unmarshal to the data.
func (*KubernetesCLI) GetResource ¶
func (k *KubernetesCLI) GetResource(name []string, namespace, outputType string, resourceType ResourceType) ([]byte, error)
GetResource get resources based on the specified resourceType, name and outputType
func (*KubernetesCLI) OperateResourceByYaml ¶
func (k *KubernetesCLI) OperateResourceByYaml(yaml, operate string, ignoreNotfound bool) error
OperateResourceByYaml operate resource by yaml operate supported: Create, Delete, Apply
type KubernetesCLIArgs ¶
type KubernetesCLIArgs struct {
// contains filtered or unexported fields
}
func NewKubernetesCLIArgs ¶
func NewKubernetesCLIArgs(client string) *KubernetesCLIArgs
NewKubernetesCLIArgs get a *KubernetesCLIArgs instance
func (*KubernetesCLIArgs) Copy ¶
func (k *KubernetesCLIArgs) Copy(ctx context.Context, containerPath, localPath string, cpType CopyType) ([]byte, error)
Copy local files and specified container files based on the configured parameters.
func (*KubernetesCLIArgs) Exec ¶
Exec run the command in the specified container based on the configured parameters.
func (*KubernetesCLIArgs) Get ¶
func (k *KubernetesCLIArgs) Get(ctx context.Context, data interface{}) error
Get obtains object data based on the configured parameters and unmarshal to the data.
func (*KubernetesCLIArgs) Logs ¶
func (k *KubernetesCLIArgs) Logs(ctx context.Context) ([]byte, error)
Logs obtains the console logs of a specified container.
func (*KubernetesCLIArgs) SelectObject ¶
func (k *KubernetesCLIArgs) SelectObject(objectType ObjectType, objectName ...string) *KubernetesCLIArgs
SelectObject specifies the type and name of the object to be operated.
func (*KubernetesCLIArgs) WithHistoryLogs ¶
func (k *KubernetesCLIArgs) WithHistoryLogs(isHistoryLog bool) *KubernetesCLIArgs
WithHistoryLogs adds the -p option.
func (*KubernetesCLIArgs) WithIgnoreNotFound ¶
func (k *KubernetesCLIArgs) WithIgnoreNotFound() *KubernetesCLIArgs
WithIgnoreNotFound adds the --ignore-not-found option.
func (*KubernetesCLIArgs) WithOutPutFormat ¶
func (k *KubernetesCLIArgs) WithOutPutFormat(outputType OutputType) *KubernetesCLIArgs
WithOutPutFormat specifies the output format of the object to be manipulated.
func (*KubernetesCLIArgs) WithSpecifiedContainer ¶
func (k *KubernetesCLIArgs) WithSpecifiedContainer(containerName string) *KubernetesCLIArgs
WithSpecifiedContainer specifies the container of the object to be manipulated.
func (*KubernetesCLIArgs) WithSpecifiedNamespace ¶
func (k *KubernetesCLIArgs) WithSpecifiedNamespace(namespace string) *KubernetesCLIArgs
WithSpecifiedNamespace specifies the namespace of the object to be manipulated.
func (*KubernetesCLIArgs) WithSpecifiedNode ¶
func (k *KubernetesCLIArgs) WithSpecifiedNode(nodeName string) *KubernetesCLIArgs
WithSpecifiedNode specifies the node of the object to be manipulated.
type KubernetesClient ¶
type KubernetesClient interface { CLI() string GetNameSpace() (string, error) OperateResourceByYaml(yaml, operate string, ignoreNotfound bool) error DeleteResourceByQualifiedNames(qualifiedNames []string, namespace string) (string, error) DeleteFinalizersInResourceByQualifiedNames(qualifiedNames []string, namespace string) error GetResource(name []string, namespace, outputType string, resourceType ResourceType) ([]byte, error) CheckResourceExist(name, namespace string, resourceType ResourceType) (bool, error) GetObject(ctx context.Context, objectType ObjectType, namespace, nodeName string, outputType OutputType, data interface{}, objectName ...string) error ExecCmdInSpecifiedContainer(ctx context.Context, namespace, containerName, cmd string, podName ...string) ([]byte, error) CopyContainerFileToLocal(ctx context.Context, namespace, containerName, src, dst string, podName ...string) ([]byte, error) GetConsoleLogs(ctx context.Context, namespace, containerName string, isHistoryLogs bool, podName ...string) ([]byte, error) }
KubernetesClient Defines the capabilities that client needs to implement
func LoadSupportedClient ¶
func LoadSupportedClient(name string) (KubernetesClient, error)
LoadSupportedClient used to load supported client. Return a client of type KubernetesClient and nil error if a client with the specified testName exists. If not exists, return an error with not supported.
type ListResult ¶
type ListResult[T any] struct { Items []T `json:"items"` }
ListResult list query result
type ResourceType ¶
type ResourceType string
ResourceType Defines the resource type, e.g. secret, configmap...
func GetResourceTypeByT ¶
func GetResourceTypeByT[T any]() (ResourceType, error)
GetResourceTypeByT get resource type