Documentation
¶
Index ¶
- Constants
- Variables
- func GetResource[T any](ctx context.Context, cli *Cli, resourceType ResourceType, resourceName string, ...) (T, error)
- func WaitForResource[T comparable](ctx context.Context, cli *Cli, resourceType ResourceType, ...) (T, error)
- type Cli
- func (cli *Cli) Apply(ctx context.Context, path string, flags *KubeCliFlags) error
- func (cli *Cli) ApplyWithFile(ctx context.Context, filePath string, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) ApplyWithKustomize(ctx context.Context, path string, flags *KubeCliFlags) error
- func (cli *Cli) ApplyWithStdIn(ctx context.Context, input string, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) CheckInstalled(ctx context.Context) error
- func (cli *Cli) ConfigUseContext(ctx context.Context, name string, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) ConfigView(ctx context.Context, merge bool, flatten bool, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) CreateNamespace(ctx context.Context, name string, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) Cwd(cwd string)
- func (cli *Cli) Exec(ctx context.Context, flags *KubeCliFlags, args ...string) (exec.RunResult, error)
- func (cli *Cli) InstallUrl() string
- func (cli *Cli) Name() string
- func (cli *Cli) RolloutStatus(ctx context.Context, deploymentName string, flags *KubeCliFlags) (*exec.RunResult, error)
- func (cli *Cli) SetEnv(envValues map[string]string)
- func (cli *Cli) SetKubeConfig(kubeConfig string)
- type Deployment
- type DeploymentSpec
- type DeploymentStatus
- type DryRunType
- type Ingress
- type IngressPath
- type IngressRule
- type IngressRuleHttp
- type IngressSpec
- type IngressStatus
- type IngressTls
- type KubeCliFlags
- type KubeCluster
- type KubeClusterData
- type KubeConfig
- type KubeConfigManager
- func (kcm *KubeConfigManager) AddOrUpdateContext(ctx context.Context, contextName string, newKubeConfig *KubeConfig) (string, error)
- func (kcm *KubeConfigManager) DeleteKubeConfig(ctx context.Context, configName string) error
- func (kcm *KubeConfigManager) MergeConfigs(ctx context.Context, newConfigName string, path ...string) (string, error)
- func (kcm *KubeConfigManager) SaveKubeConfig(ctx context.Context, configName string, config *KubeConfig) (string, error)
- type KubeContext
- type KubeContextData
- type KubePreferences
- type KubeUser
- type KubeUserData
- type List
- type LoadBalancer
- type LoadBalancerIngress
- type OutputType
- type Port
- type Resource
- type ResourceFilterFn
- type ResourceMetadata
- type ResourceType
- type ResourceWithSpec
- type Service
- type ServiceSpec
- type ServiceStatus
- type ServiceType
Constants ¶
const ( ResourceTypeDeployment ResourceType = "deployment" ResourceTypeIngress ResourceType = "ing" ResourceTypeService ResourceType = "svc" KubeConfigEnvVarName string = "KUBECONFIG" )
Variables ¶
var ( ErrResourceNotFound = errors.New("cannot find resource") ErrResourceNotReady = errors.New("resource is not ready") )
Functions ¶
func GetResource ¶
func GetResource[T any]( ctx context.Context, cli *Cli, resourceType ResourceType, resourceName string, flags *KubeCliFlags, ) (T, error)
func WaitForResource ¶
func WaitForResource[T comparable]( ctx context.Context, cli *Cli, resourceType ResourceType, resourceFilter ResourceFilterFn[T], readyStatusFilter ResourceFilterFn[T], ) (T, error)
Types ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
func (*Cli) ApplyWithFile ¶
func (*Cli) ApplyWithKustomize ¶
Applies the manifests at the specified path using kustomize
func (*Cli) ApplyWithStdIn ¶
func (*Cli) CheckInstalled ¶
Checks whether or not the K8s CLI is installed and available within the PATH
func (*Cli) ConfigUseContext ¶
func (cli *Cli) ConfigUseContext(ctx context.Context, name string, flags *KubeCliFlags) (*exec.RunResult, error)
Sets the k8s context to use for future CLI commands
func (*Cli) ConfigView ¶
func (cli *Cli) ConfigView( ctx context.Context, merge bool, flatten bool, flags *KubeCliFlags, ) (*exec.RunResult, error)
Views the current k8s configuration including available clusters, contexts & users
func (*Cli) CreateNamespace ¶
func (cli *Cli) CreateNamespace(ctx context.Context, name string, flags *KubeCliFlags) (*exec.RunResult, error)
Creates a new k8s namespace with the specified name
func (*Cli) Exec ¶
func (cli *Cli) Exec(ctx context.Context, flags *KubeCliFlags, args ...string) (exec.RunResult, error)
Executes a k8s CLI command from the specified arguments and flags
func (*Cli) InstallUrl ¶
Returns the installation URL to install the K8s CLI
func (*Cli) RolloutStatus ¶
func (cli *Cli) RolloutStatus( ctx context.Context, deploymentName string, flags *KubeCliFlags, ) (*exec.RunResult, error)
Gets the deployment rollout status
func (*Cli) SetKubeConfig ¶
Sets the KUBECONFIG environment variable
type Deployment ¶
type Deployment ResourceWithSpec[DeploymentSpec, DeploymentStatus]
type DeploymentSpec ¶
type DeploymentSpec struct {
Replicas int `json:"replicas" yaml:"replicas"`
}
type DeploymentStatus ¶
type DryRunType ¶
type DryRunType string
const ( DryRunTypeNone DryRunType = "none" // If client strategy, only print the object that would be sent DryRunTypeClient DryRunType = "client" // If server strategy, submit server-side request without persisting the resource. DryRunTypeServer DryRunType = "server" )
type Ingress ¶
type Ingress ResourceWithSpec[IngressSpec, IngressStatus]
type IngressPath ¶
type IngressRule ¶
type IngressRule struct { Host *string `json:"host" yaml:"host"` Http IngressRuleHttp `json:"http" yaml:"http"` }
type IngressRuleHttp ¶
type IngressRuleHttp struct {
Paths []IngressPath `json:"paths" yaml:"paths"`
}
type IngressSpec ¶
type IngressSpec struct { IngressClassName string `json:"ingressClassName" yaml:"ingressClassName"` Tls []IngressTls `json:"tls" yaml:"tls"` Rules []IngressRule `json:"rules" yaml:"rules"` }
type IngressStatus ¶
type IngressStatus struct {
LoadBalancer LoadBalancer `json:"loadBalancer" yaml:"loadBalancer"`
}
type IngressTls ¶
type KubeCliFlags ¶
type KubeCliFlags struct { // The namespace to filter the command or create resources Namespace string // The dry-run type, defaults to empty DryRun DryRunType // The expected output, typically JSON or YAML Output OutputType }
K8s CLI Fags
type KubeCluster ¶
type KubeCluster struct { Name string `yaml:"name"` Cluster KubeClusterData `yaml:"cluster"` }
type KubeClusterData ¶
type KubeConfig ¶
type KubeConfig struct { ApiVersion string `yaml:"apiVersion"` Clusters []*KubeCluster `yaml:"clusters"` Contexts []*KubeContext `yaml:"contexts"` Users []*KubeUser `yaml:"users"` Kind string `yaml:"kind"` CurrentContext string `yaml:"current-context"` Preferences KubePreferences `yaml:"preferences"` }
func ParseKubeConfig ¶
func ParseKubeConfig(ctx context.Context, raw []byte) (*KubeConfig, error)
Parses the raw bytes into a KubeConfig instance
type KubeConfigManager ¶
type KubeConfigManager struct {
// contains filtered or unexported fields
}
Manages k8s configurations available to the k8s CLI
func NewKubeConfigManager ¶
func NewKubeConfigManager(cli *Cli) (*KubeConfigManager, error)
Creates a new instance of the KubeConfigManager
func (*KubeConfigManager) AddOrUpdateContext ¶
func (kcm *KubeConfigManager) AddOrUpdateContext( ctx context.Context, contextName string, newKubeConfig *KubeConfig, ) (string, error)
Adds a new or updates an existing KubeConfig in the main kube config
func (*KubeConfigManager) DeleteKubeConfig ¶
func (kcm *KubeConfigManager) DeleteKubeConfig(ctx context.Context, configName string) error
Deletes the KubeConfig with the specified name
func (*KubeConfigManager) MergeConfigs ¶
func (kcm *KubeConfigManager) MergeConfigs(ctx context.Context, newConfigName string, path ...string) (string, error)
Merges the specified kube configs into the kube config This powers the use of the kubectl config set of commands that allow developers to switch between different k8s cluster contexts
func (*KubeConfigManager) SaveKubeConfig ¶
func (kcm *KubeConfigManager) SaveKubeConfig(ctx context.Context, configName string, config *KubeConfig) (string, error)
Saves the KubeConfig to the kube configuration folder with the specified name
type KubeContext ¶
type KubeContext struct { Name string `yaml:"name"` Context KubeContextData `yaml:"context"` }
type KubeContextData ¶
type KubePreferences ¶
type KubeUser ¶
type KubeUser struct { Name string `yaml:"name"` KubeUserData KubeUserData `yaml:"user"` }
type KubeUserData ¶
type List ¶
func GetResources ¶
func GetResources[T any]( ctx context.Context, cli *Cli, resourceType ResourceType, flags *KubeCliFlags, ) (*List[T], error)
type LoadBalancer ¶
type LoadBalancer struct {
Ingress []LoadBalancerIngress `json:"ingress" yaml:"ingress"`
}
type LoadBalancerIngress ¶
type LoadBalancerIngress struct {
Ip string `json:"ip" yaml:"ip"`
}
type OutputType ¶
type OutputType string
const ( OutputTypeJson OutputType = "json" OutputTypeYaml OutputType = "yaml" )
type Port ¶
type Port struct { Port int `json:"port"` // The target port can be a valid port number or well known service name like 'redis' TargetPort any `json:"targetPort" yaml:"targetPort"` Protocol string `json:"protocol" yaml:"protocol"` }
func (*Port) UnmarshalJSON ¶
type Resource ¶
type Resource struct { ApiVersion string `json:"apiVersion" yaml:"apiVersion"` Kind string `json:"kind" yaml:"kind"` Metadata ResourceMetadata `json:"metadata" yaml:"metadata"` }
type ResourceFilterFn ¶
type ResourceFilterFn[T comparable] func(resource T) bool
type ResourceMetadata ¶
type ResourceType ¶
type ResourceType string
type ResourceWithSpec ¶
type Service ¶
type Service ResourceWithSpec[ServiceSpec, ServiceStatus]
type ServiceSpec ¶
type ServiceSpec struct { Type ServiceType `json:"type" yaml:"type"` ClusterIp string `json:"clusterIP" yaml:"clusterIP"` ClusterIps []string `json:"clusterIPs" yaml:"clusterIPs"` Ports []Port `json:"ports" yaml:"ports"` }
type ServiceStatus ¶
type ServiceStatus struct {
LoadBalancer LoadBalancer `json:"loadBalancer" yaml:"loadBalancer"`
}
type ServiceType ¶
type ServiceType string
const ( ServiceTypeClusterIp ServiceType = "ClusterIP" ServiceTypeLoadBalancer ServiceType = "LoadBalancer" ServiceTypeNodePort ServiceType = "NodePort" ServiceTypeExternalName ServiceType = "ExternalName" )