Documentation ¶
Overview ¶
Package kube implements a Kubernetes client.
Index ¶
- Constants
- Variables
- func GetObjects(files []string) ([]runtime.Object, error)
- func LoadDefaultKubeConfig() (*clientcmdapi.Config, error)
- func RetrievesDefaultKubeConfig() string
- type Client
- func (c *Client) Apply(files []string) error
- func (c *Client) ApplyConfigMap(ctx context.Context, namespace, name string, data map[string]string) (*corev1.ConfigMap, error)
- func (c *Client) ApplySecret(ctx context.Context, namespace, name string, data map[string]string) (*corev1.Secret, error)
- func (c *Client) ApplySecretBytes(ctx context.Context, namespace, name string, data map[string][]byte) (*corev1.Secret, error)
- func (c *Client) CreateClusterRole(ctx context.Context, role *rbacv1.ClusterRole) (*rbacv1.ClusterRole, error)
- func (c *Client) CreateConfigMap(ctx context.Context, cm *corev1.ConfigMap) (*corev1.ConfigMap, error)
- func (c *Client) CreateCronJob(ctx context.Context, cronjob *v1beta1.CronJob) (*v1beta1.CronJob, error)
- func (c *Client) CreateDaemonSet(ctx context.Context, dsData *v1.DaemonSet) (*v1.DaemonSet, error)
- func (c *Client) CreateDeployment(ctx context.Context, deploy *v1.Deployment) (*v1.Deployment, error)
- func (c *Client) CreateIngress(ctx context.Context, ing *networkv1.Ingress) (*networkv1.Ingress, error)
- func (c *Client) CreateIngressClass(ctx context.Context, ingc *networkv1.IngressClass) (*networkv1.IngressClass, error)
- func (c *Client) CreateJob(ctx context.Context, jobData *batchv1.Job) (*batchv1.Job, error)
- func (c *Client) CreateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (c *Client) CreatePod(ctx context.Context, pod *corev1.Pod) (*corev1.Pod, error)
- func (c *Client) CreateRole(ctx context.Context, role *rbacv1.Role) (*rbacv1.Role, error)
- func (c *Client) CreateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
- func (c *Client) CreateService(ctx context.Context, svc *corev1.Service) (*corev1.Service, error)
- func (c *Client) CreateServiceAccount(ctx context.Context, sa *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
- func (c *Client) CreateStatefulSet(ctx context.Context, statefulSet *v1.StatefulSet) (*v1.StatefulSet, error)
- func (c *Client) Delete(files []string) error
- func (c *Client) DeleteClusterRole(ctx context.Context, name string) error
- func (c *Client) DeleteConfigMap(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteCronJob(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteDaemonSet(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteDeployment(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteIngress(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteIngressClass(ctx context.Context, name string) error
- func (c *Client) DeleteJob(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteNamespace(ctx context.Context, name string) error
- func (c *Client) DeleteNode(ctx context.Context, name string) error
- func (c *Client) DeletePod(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteRole(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteSecret(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteService(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteServiceAccount(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteStatefulSet(ctx context.Context, namespace, name string) error
- func (c *Client) Dial() (kubernetes.Interface, error)
- func (c *Client) DialMetrics() (*versioned.Clientset, error)
- func (c *Client) Exec(pod, container, namespace, command string) (string, string, error)
- func (c *Client) GetClusterRole(ctx context.Context, name string) (*rbacv1.ClusterRole, error)
- func (c *Client) GetClusterRoles(ctx context.Context, label ...string) (*rbacv1.ClusterRoleList, error)
- func (c *Client) GetConfigMap(ctx context.Context, namespace, name string) (*corev1.ConfigMap, error)
- func (c *Client) GetConfigMaps(ctx context.Context, namespace string, label ...string) (*corev1.ConfigMapList, error)
- func (c *Client) GetCronJob(ctx context.Context, namespace, name string) (*v1beta1.CronJob, error)
- func (c *Client) GetCronJobs(ctx context.Context, namespace string, label ...string) (*v1beta1.CronJobList, error)
- func (c *Client) GetDaemonSet(ctx context.Context, namespace, name string) (*v1.DaemonSet, error)
- func (c *Client) GetDaemonSets(ctx context.Context, namespace string, label ...string) (*v1.DaemonSetList, error)
- func (c *Client) GetDeployment(ctx context.Context, namespace, name string) (*v1.Deployment, error)
- func (c *Client) GetDeployments(ctx context.Context, namespace string, label ...string) (*v1.DeploymentList, error)
- func (c *Client) GetIngress(ctx context.Context, namespace, name string) (*networkv1.Ingress, error)
- func (c *Client) GetIngressClass(ctx context.Context, name string) (*networkv1.IngressClass, error)
- func (c *Client) GetIngressClasses(ctx context.Context, label ...string) (*networkv1.IngressClassList, error)
- func (c *Client) GetIngresses(ctx context.Context, namespace string, label ...string) (*networkv1.IngressList, error)
- func (c *Client) GetJob(ctx context.Context, namespace, name string) (*batchv1.Job, error)
- func (c *Client) GetJobs(ctx context.Context, namespace string, label ...string) (*batchv1.JobList, error)
- func (c *Client) GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error)
- func (c *Client) GetNamespaces(ctx context.Context, label ...string) (*corev1.NamespaceList, error)
- func (c *Client) GetNode(ctx context.Context, name string) (*corev1.Node, error)
- func (c *Client) GetNodes(ctx context.Context, label ...string) (*corev1.NodeList, error)
- func (c *Client) GetPod(ctx context.Context, namespace, name string) (*corev1.Pod, error)
- func (c *Client) GetPods(ctx context.Context, namespace string, label ...string) (*corev1.PodList, error)
- func (c *Client) GetRole(ctx context.Context, namespace, name string) (*rbacv1.Role, error)
- func (c *Client) GetRoles(ctx context.Context, namespace string, label ...string) (*rbacv1.RoleList, error)
- func (c *Client) GetSecret(ctx context.Context, namespace, name string) (*corev1.Secret, error)
- func (c *Client) GetSecrets(ctx context.Context, namespace string, label ...string) (*corev1.SecretList, error)
- func (c *Client) GetService(ctx context.Context, namespace, name string) (*corev1.Service, error)
- func (c *Client) GetServiceAccount(ctx context.Context, namespace, name string) (*corev1.ServiceAccount, error)
- func (c *Client) GetServiceAccounts(ctx context.Context, namespace string, label ...string) (*corev1.ServiceAccountList, error)
- func (c *Client) GetServices(ctx context.Context, namespace string, label ...string) (*corev1.ServiceList, error)
- func (c *Client) GetStatefulSet(ctx context.Context, namespace, name string) (*v1.StatefulSet, error)
- func (c *Client) GetStatefulSets(ctx context.Context, namespace string, label ...string) (*v1.StatefulSetList, error)
- func (c *Client) PatchConfigMap(ctx context.Context, namespace, name string, data []byte) (*corev1.ConfigMap, error)
- func (c *Client) PatchSecret(ctx context.Context, namespace, name string, data []byte) (*corev1.Secret, error)
- func (c *Client) ResourceClient(gv schema.GroupVersion) (rest.Interface, error)
- func (c *Client) RestConfig() (*rest.Config, error)
- func (c *Client) UpdateConfigMap(ctx context.Context, cm *corev1.ConfigMap) (*corev1.ConfigMap, error)
- func (c *Client) UpdateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
- func (c *Client) WithProxy(fn func(request *http.Request) (*url.URL, error)) *Client
- type Config
- func (c *Config) ClusterNameFromContext(context string) (string, error)
- func (c *Config) ClusterNames() ([]string, error)
- func (c *Config) ConfigAccess() (clientcmd.ConfigAccess, error)
- func (c *Config) Contexts() (map[string]*clientcmdapi.Context, error)
- func (c *Config) CurrentClusterName() (string, error)
- func (c *Config) CurrentContextName() (string, error)
- func (c *Config) CurrentNamespace() (string, error)
- func (c *Config) CurrentUserName() (string, error)
- func (c *Config) Flags() *genericclioptions.ConfigFlags
- func (c *Config) GetCluster(name string) (*clientcmdapi.Cluster, error)
- func (c *Config) GetContext(n string) (*clientcmdapi.Context, error)
- func (c *Config) GetCredential(name string) (*clientcmdapi.AuthInfo, error)
- func (c *Config) RESTConfig() (*rest.Config, error)
- func (c *Config) RawConfig() (clientcmdapi.Config, error)
- func (c *Config) RemoveCluster(name string) error
- func (c *Config) RemoveContext(n string) error
- func (c *Config) RemoveCredential(name string) error
- func (c *Config) SetCluster(name string, cluster *clientcmdapi.Cluster) error
- func (c *Config) SetContext(name string, ctx *clientcmdapi.Context) error
- func (c *Config) SetCredential(name string, auth *clientcmdapi.AuthInfo) error
- func (c *Config) Timeout() time.Duration
- func (c *Config) UseContext(name string) error
- type Operation
Constants ¶
const ( // DefaultTimeout default request timeout. DefaultTimeout = 10 * time.Second // UsePersistentConfig caches client config to avoid reloads. UsePersistentConfig = true )
const ( // EnvVarKubeConfig The KUBECONFIG environment variable holds a list of kubeconfig files. // For Linux and Mac, the list is colon-delimited. For Windows, the list is semicolon-delimited. EnvVarKubeConfig = "KUBECONFIG" DefaultKubeHomeDir = ".kube" DefaultKubeConfigFileName = "config" )
Variables ¶
var ErrorMissingNamespace = errors.New("missing namespace")
Functions ¶
func GetObjects ¶
GetObjects returns the list of objects parsed from the given files.
func LoadDefaultKubeConfig ¶
func LoadDefaultKubeConfig() (*clientcmdapi.Config, error)
LoadDefaultKubeConfig starts by running the clientcmdapi.MigrationRules and then takes the loading rules and returns a clientcmdapi.Config object.
func RetrievesDefaultKubeConfig ¶
func RetrievesDefaultKubeConfig() string
RetrievesDefaultKubeConfig returns a available kubeconfig file.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents kubernetes Client.
func NewDefault ¶
func NewDefault() *Client
NewDefault returns a new Client with default kubeconfig.
func NewInCluster ¶
func NewInCluster() *Client
NewInCluster returns a new Client with InClusterConfig.
func (*Client) Apply ¶
Apply is like kubectl apply -f references: - https://github.com/kubernetes/client-go/issues/193 - https://stackoverflow.com/questions/58783939/using-client-go-to-kubectl-apply-against-the-kubernetes-api-directly-with-mult
func (*Client) ApplyConfigMap ¶
func (c *Client) ApplyConfigMap(ctx context.Context, namespace, name string, data map[string]string) (*corev1.ConfigMap, error)
ApplyConfigMap updates a ConfigMap, and creates a new ConfigMap if not exist.
func (*Client) ApplySecret ¶
func (c *Client) ApplySecret(ctx context.Context, namespace, name string, data map[string]string) (*corev1.Secret, error)
ApplySecret updates a Secret, and creates a new Secret if not exist.
func (*Client) ApplySecretBytes ¶
func (c *Client) ApplySecretBytes(ctx context.Context, namespace, name string, data map[string][]byte) (*corev1.Secret, error)
ApplySecretBytes is like ApplySecret, but with data map[string][]byte.
func (*Client) CreateClusterRole ¶
func (c *Client) CreateClusterRole(ctx context.Context, role *rbacv1.ClusterRole) (*rbacv1.ClusterRole, error)
CreateClusterRole creates a new ClusterRole.
func (*Client) CreateConfigMap ¶
func (c *Client) CreateConfigMap(ctx context.Context, cm *corev1.ConfigMap) (*corev1.ConfigMap, error)
CreateConfigMap creates a new ConfigMap.
func (*Client) CreateCronJob ¶
func (c *Client) CreateCronJob(ctx context.Context, cronjob *v1beta1.CronJob) (*v1beta1.CronJob, error)
CreateCronJob creates a new CronJob.
func (*Client) CreateDaemonSet ¶
CreateDaemonSet creates a new DaemonSet.
func (*Client) CreateDeployment ¶
func (c *Client) CreateDeployment(ctx context.Context, deploy *v1.Deployment) (*v1.Deployment, error)
CreateDeployment creates a new Deployment.
func (*Client) CreateIngress ¶
func (c *Client) CreateIngress(ctx context.Context, ing *networkv1.Ingress) (*networkv1.Ingress, error)
CreateIngress creates a new Ingress.
func (*Client) CreateIngressClass ¶
func (c *Client) CreateIngressClass(ctx context.Context, ingc *networkv1.IngressClass) (*networkv1.IngressClass, error)
CreateIngressClass creates a new IngressClass.
func (*Client) CreateNamespace ¶
func (c *Client) CreateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
CreateNamespace creates a Namespace.
func (*Client) CreateRole ¶
CreateRole create a new Role.
func (*Client) CreateSecret ¶
CreateSecret creates a new Secret.
func (*Client) CreateService ¶
CreateService creates a new Service.
func (*Client) CreateServiceAccount ¶
func (c *Client) CreateServiceAccount(ctx context.Context, sa *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
CreateServiceAccount creates a new ServiceAccount.
func (*Client) CreateStatefulSet ¶
func (c *Client) CreateStatefulSet(ctx context.Context, statefulSet *v1.StatefulSet) (*v1.StatefulSet, error)
CreateStatefulSet creates a new StatefulSet.
func (*Client) DeleteClusterRole ¶
DeleteClusterRole deletes a ClusterRole.
func (*Client) DeleteConfigMap ¶
DeleteConfigMap deletes a ConfigMap.
func (*Client) DeleteCronJob ¶
DeleteCronJob deletes a CronJob.
func (*Client) DeleteDaemonSet ¶
DeleteDaemonSet deletes a DaemonSet.
func (*Client) DeleteDeployment ¶
DeleteDeployment deletes a Deployment.
func (*Client) DeleteIngress ¶
DeleteIngress deletes a Ingress.
func (*Client) DeleteIngressClass ¶
DeleteIngressClass deletes a IngressClass.
func (*Client) DeleteNamespace ¶
DeleteNamespace deletes a Node.
func (*Client) DeleteNode ¶
DeleteNode deletes a Node.
func (*Client) DeleteRole ¶
DeleteRole deletes a Role.
func (*Client) DeleteSecret ¶
DeleteSecret deletes a Secret.
func (*Client) DeleteService ¶
DeleteService deletes a Service.
func (*Client) DeleteServiceAccount ¶
DeleteServiceAccount deletes a ServiceAccount.
func (*Client) DeleteStatefulSet ¶
DeleteStatefulSet deletes a StatefulSet.
func (*Client) Dial ¶
func (c *Client) Dial() (kubernetes.Interface, error)
Dial returns a client to the kubernetes apiserver.
func (*Client) DialMetrics ¶
DialMetrics returns a client to the metrics server.
func (*Client) GetClusterRole ¶
GetClusterRole returns a ClusterRole with the given name.
func (*Client) GetClusterRoles ¶
func (c *Client) GetClusterRoles(ctx context.Context, label ...string) (*rbacv1.ClusterRoleList, error)
GetClusterRoles returns a ClusterRoleList.
func (*Client) GetConfigMap ¶
func (c *Client) GetConfigMap(ctx context.Context, namespace, name string) (*corev1.ConfigMap, error)
GetConfigMap returns a ConfigMap with the given name.
func (*Client) GetConfigMaps ¶
func (c *Client) GetConfigMaps(ctx context.Context, namespace string, label ...string) (*corev1.ConfigMapList, error)
GetConfigMaps returns a ConfigMapList.
func (*Client) GetCronJob ¶
GetCronJob returns a GetCronJob with given name.
func (*Client) GetCronJobs ¶
func (c *Client) GetCronJobs(ctx context.Context, namespace string, label ...string) (*v1beta1.CronJobList, error)
GetCronJobs returns a CronJobList.
func (*Client) GetDaemonSet ¶
GetDaemonSet returns a DaemonSet with given name.
func (*Client) GetDaemonSets ¶
func (c *Client) GetDaemonSets(ctx context.Context, namespace string, label ...string) (*v1.DaemonSetList, error)
GetDaemonSets returns a DaemonSetList.
func (*Client) GetDeployment ¶
GetDeployment returns a Deployment with the given name.
func (*Client) GetDeployments ¶
func (c *Client) GetDeployments(ctx context.Context, namespace string, label ...string) (*v1.DeploymentList, error)
GetDeployments returns a DeploymentList.
func (*Client) GetIngress ¶
func (c *Client) GetIngress(ctx context.Context, namespace, name string) (*networkv1.Ingress, error)
GetIngress returns an Ingress with the given name.
func (*Client) GetIngressClass ¶
GetIngressClass returns an IngressClass with the given name.
func (*Client) GetIngressClasses ¶
func (c *Client) GetIngressClasses(ctx context.Context, label ...string) (*networkv1.IngressClassList, error)
GetIngressClasses returns a IngressClassList.
func (*Client) GetIngresses ¶
func (c *Client) GetIngresses(ctx context.Context, namespace string, label ...string) (*networkv1.IngressList, error)
GetIngresses returns a IngressList.
func (*Client) GetJobs ¶
func (c *Client) GetJobs(ctx context.Context, namespace string, label ...string) (*batchv1.JobList, error)
GetJobs returns a JobList.
func (*Client) GetNamespace ¶
GetNamespace returns a Namespace with the given name.
func (*Client) GetNamespaces ¶
GetNamespaces returns a NamespaceList.
func (*Client) GetPods ¶
func (c *Client) GetPods(ctx context.Context, namespace string, label ...string) (*corev1.PodList, error)
GetPods returns a PodList.
func (*Client) GetRoles ¶
func (c *Client) GetRoles(ctx context.Context, namespace string, label ...string) (*rbacv1.RoleList, error)
GetRoles returns a RoleList.
func (*Client) GetSecrets ¶
func (c *Client) GetSecrets(ctx context.Context, namespace string, label ...string) (*corev1.SecretList, error)
GetSecrets returns a SecretList.
func (*Client) GetService ¶
GetService returns a Service with the given name.
func (*Client) GetServiceAccount ¶
func (c *Client) GetServiceAccount(ctx context.Context, namespace, name string) (*corev1.ServiceAccount, error)
GetServiceAccount returns a ServiceAccount with the given name.
func (*Client) GetServiceAccounts ¶
func (c *Client) GetServiceAccounts(ctx context.Context, namespace string, label ...string) (*corev1.ServiceAccountList, error)
GetServiceAccounts returns a ServiceAccountList.
func (*Client) GetServices ¶
func (c *Client) GetServices(ctx context.Context, namespace string, label ...string) (*corev1.ServiceList, error)
GetServices returns a ServiceList.
func (*Client) GetStatefulSet ¶
func (c *Client) GetStatefulSet(ctx context.Context, namespace, name string) (*v1.StatefulSet, error)
GetStatefulSet returns a StatefulSet with given name.
func (*Client) GetStatefulSets ¶
func (c *Client) GetStatefulSets(ctx context.Context, namespace string, label ...string) (*v1.StatefulSetList, error)
GetStatefulSets returns a StatefulSetList.
func (*Client) PatchConfigMap ¶
func (c *Client) PatchConfigMap(ctx context.Context, namespace, name string, data []byte) (*corev1.ConfigMap, error)
PatchConfigMap patch a ConfigMap.
func (*Client) PatchSecret ¶
func (c *Client) PatchSecret(ctx context.Context, namespace, name string, data []byte) (*corev1.Secret, error)
PatchSecret patch the given Secret.
func (*Client) ResourceClient ¶
ResourceClient returns a client to the given schema.GroupVersion.
func (*Client) RestConfig ¶
RestConfig returns a complete rest client config.
func (*Client) UpdateConfigMap ¶
func (c *Client) UpdateConfigMap(ctx context.Context, cm *corev1.ConfigMap) (*corev1.ConfigMap, error)
UpdateConfigMap updates a ConfigMap.
func (*Client) UpdateSecret ¶
UpdateSecret updates the given Secret.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents a kubernetes configuration. references: - https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/ - https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
func NewConfig ¶
func NewConfig(f *genericclioptions.ConfigFlags) *Config
NewConfig returns a new kube client configuration.
func (*Config) ClusterNameFromContext ¶
ClusterNameFromContext returns the cluster associated with the given context.
func (*Config) ClusterNames ¶
ClusterNames returns all kubeconfig defined clusters.
func (*Config) ConfigAccess ¶
func (c *Config) ConfigAccess() (clientcmd.ConfigAccess, error)
ConfigAccess returns the current kubeconfig api server access configuration.
func (*Config) Contexts ¶
func (c *Config) Contexts() (map[string]*clientcmdapi.Context, error)
Contexts returns all available contexts.
func (*Config) CurrentClusterName ¶
CurrentClusterName returns the active cluster name.
func (*Config) CurrentContextName ¶
CurrentContextName returns the currently active config context.
func (*Config) CurrentNamespace ¶
CurrentNamespace retrieves the active namespace.
func (*Config) CurrentUserName ¶
CurrentUserName retrieves the active user name.
func (*Config) Flags ¶
func (c *Config) Flags() *genericclioptions.ConfigFlags
Flags returns configuration flags.
func (*Config) GetCluster ¶
func (c *Config) GetCluster(name string) (*clientcmdapi.Cluster, error)
GetCluster returns a cluster with the given name.
func (*Config) GetContext ¶
func (c *Config) GetContext(n string) (*clientcmdapi.Context, error)
GetContext returns a context with the given name.
func (*Config) GetCredential ¶
func (c *Config) GetCredential(name string) (*clientcmdapi.AuthInfo, error)
GetCredential returns a credential with the given name.
func (*Config) RESTConfig ¶
RESTConfig returns a complete rest client config.
func (*Config) RemoveCluster ¶
RemoveCluster remove the given cluster from the configuration.
func (*Config) RemoveContext ¶
RemoveContext remove the given context from the configuration.
func (*Config) RemoveCredential ¶
RemoveCredential remove the given credential from the configuration.
func (*Config) SetCluster ¶
func (c *Config) SetCluster(name string, cluster *clientcmdapi.Cluster) error
SetCluster set k/v of the given cluster or add a new cluster if not exist.
func (*Config) SetContext ¶
func (c *Config) SetContext(name string, ctx *clientcmdapi.Context) error
SetContext set k/v of the given context or add a new context if not exist.
func (*Config) SetCredential ¶
func (c *Config) SetCredential(name string, auth *clientcmdapi.AuthInfo) error
SetCredential set k/v of the given credential or add a new credential if not exist.
func (*Config) UseContext ¶
UseContext changes the current context.