kubernetes

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 59 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAllowedContextMap

func CreateAllowedContextMap(contexts []string) map[string]string

CreateAllowedContextMap creates a dummy map from context name to context name

func GetClusterCandidatesFromKubeconfig

func GetClusterCandidatesFromKubeconfig(
	kubeconfig []byte,
	projectID uint,
	local bool,
) ([]*models.ClusterCandidate, error)

GetClusterCandidatesFromKubeconfig parses a kubeconfig for a list of cluster candidates.

The local boolean represents whether the auth mechanism should be designated as "local": if so, the auth mechanism uses local plugins/mechanisms purely from the kubeconfig.

func GetDynamicClientOutOfClusterConfig

func GetDynamicClientOutOfClusterConfig(conf *OutOfClusterConfig) (dynamic.Interface, error)

GetDynamicClientOutOfClusterConfig creates a new dynamic client using the OutOfClusterConfig

func GetRawConfigFromBytes

func GetRawConfigFromBytes(kubeconfig []byte) (*api.Config, error)

GetRawConfigFromBytes returns the clientcmdapi.Config from kubeconfig bytes

func IsInCluster added in v0.3.1

func IsInCluster() bool

IsInCluster returns true if the process is running in a Kubernetes cluster, false otherwise

Types

type Agent

type Agent struct {
	RESTClientGetter genericclioptions.RESTClientGetter
	Clientset        kubernetes.Interface
}

Agent is a Kubernetes agent for performing operations that interact with the api server

func GetAgentInClusterConfig

func GetAgentInClusterConfig() (*Agent, error)

GetAgentInClusterConfig uses the service account that kubernetes gives to pods to connect

func GetAgentOutOfClusterConfig

func GetAgentOutOfClusterConfig(conf *OutOfClusterConfig) (*Agent, error)

GetAgentOutOfClusterConfig creates a new Agent using the OutOfClusterConfig

func GetAgentTesting

func GetAgentTesting(objects ...runtime.Object) *Agent

GetAgentTesting creates a new Agent using an optional existing storage class

func (*Agent) CreateConfigMap

func (a *Agent) CreateConfigMap(name string, namespace string, configMap map[string]string) (*v1.ConfigMap, error)

CreateConfigMap creates the configmap given the key-value pairs and namespace

func (*Agent) CreateImagePullSecrets

func (a *Agent) CreateImagePullSecrets(
	repo repository.Repository,
	namespace string,
	linkedRegs map[string]*models.Registry,
	doAuth *oauth2.Config,
) (map[string]string, error)

CreateImagePullSecrets will create the required image pull secrets and return a map from the registry name to the name of the secret.

func (*Agent) CreateLinkedSecret

func (a *Agent) CreateLinkedSecret(name, namespace, cmName string, data map[string][]byte) (*v1.Secret, error)

CreateLinkedSecret creates a secret given the key-value pairs and namespace. Values are base64 encoded

func (*Agent) CreateNamespace added in v0.3.2

func (a *Agent) CreateNamespace(name string) (*v1.Namespace, error)

CreateNamespace creates a namespace with the given name.

func (*Agent) DeleteConfigMap

func (a *Agent) DeleteConfigMap(name string, namespace string) error

DeleteConfigMap deletes the configmap given its name and namespace

func (*Agent) DeleteLinkedSecret

func (a *Agent) DeleteLinkedSecret(name, namespace string) error

DeleteLinkedSecret deletes the secret given its name and namespace

func (*Agent) DeleteNamespace added in v0.3.2

func (a *Agent) DeleteNamespace(name string) error

DeleteNamespace deletes the namespace given the name.

func (*Agent) DeletePod

func (a *Agent) DeletePod(namespace string, name string) error

DeletePod deletes a pod by name and namespace

func (*Agent) GetConfigMap

func (a *Agent) GetConfigMap(name string, namespace string) (*v1.ConfigMap, error)

GetConfigMap retrieves the configmap given its name and namespace

func (*Agent) GetCronJob

func (a *Agent) GetCronJob(c grapher.Object) (*batchv1beta1.CronJob, error)

GetCronJob gets the CronJob by name and namespace

func (*Agent) GetDaemonSet

func (a *Agent) GetDaemonSet(c grapher.Object) (*appsv1.DaemonSet, error)

GetDaemonSet gets the daemonset by name and namespace

func (*Agent) GetDeployment

func (a *Agent) GetDeployment(c grapher.Object) (*appsv1.Deployment, error)

GetDeployment gets the deployment given the name and namespace

func (*Agent) GetIngress

func (a *Agent) GetIngress(namespace string, name string) (*v1beta1.Ingress, error)

GetIngress gets ingress given the name and namespace

func (*Agent) GetJob

func (a *Agent) GetJob(c grapher.Object) (*batchv1.Job, error)

GetJob gets the job by name and namespace

func (*Agent) GetJobPods

func (a *Agent) GetJobPods(namespace, jobName string) ([]v1.Pod, error)

GetJobPods lists all pods belonging to a job in a namespace

func (*Agent) GetPodLogs

func (a *Agent) GetPodLogs(namespace string, name string, conn *websocket.Conn) error

GetPodLogs streams real-time logs from a given pod.

func (*Agent) GetPodsByLabel

func (a *Agent) GetPodsByLabel(selector string, namespace string) (*v1.PodList, error)

GetPodsByLabel retrieves pods with matching labels

func (*Agent) GetReplicaSet

func (a *Agent) GetReplicaSet(c grapher.Object) (*appsv1.ReplicaSet, error)

GetReplicaSet gets the replicaset given the name and namespace

func (*Agent) GetStatefulSet

func (a *Agent) GetStatefulSet(c grapher.Object) (*appsv1.StatefulSet, error)

GetStatefulSet gets the statefulset given the name and namespace

func (*Agent) ListConfigMaps

func (a *Agent) ListConfigMaps(namespace string) (*v1.ConfigMapList, error)

ListConfigMaps simply lists namespaces

func (*Agent) ListEvents added in v0.3.0

func (a *Agent) ListEvents(name string, namespace string) (*v1.EventList, error)

ListEvents lists the events of a given object.

func (*Agent) ListJobsByLabel

func (a *Agent) ListJobsByLabel(namespace string, labels ...Label) ([]batchv1.Job, error)

func (*Agent) ListNamespaces

func (a *Agent) ListNamespaces() (*v1.NamespaceList, error)

ListNamespaces simply lists namespaces

func (*Agent) ProvisionDOCR

func (a *Agent) ProvisionDOCR(
	projectID uint,
	doConf *integrations.OAuthIntegration,
	doAuth *oauth2.Config,
	repo repository.Repository,
	docrName, docrSubscriptionTier string,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionDOCR spawns a new provisioning pod that creates a DOCR instance

func (*Agent) ProvisionDOKS

func (a *Agent) ProvisionDOKS(
	projectID uint,
	doConf *integrations.OAuthIntegration,
	doAuth *oauth2.Config,
	repo repository.Repository,
	doRegion, doksClusterName string,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionDOKS spawns a new provisioning pod that creates a DOKS instance

func (*Agent) ProvisionECR

func (a *Agent) ProvisionECR(
	projectID uint,
	awsConf *integrations.AWSIntegration,
	ecrName string,
	repo repository.Repository,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionECR spawns a new provisioning pod that creates an ECR instance

func (*Agent) ProvisionEKS

func (a *Agent) ProvisionEKS(
	projectID uint,
	awsConf *integrations.AWSIntegration,
	eksName, machineType string,
	repo repository.Repository,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionEKS spawns a new provisioning pod that creates an EKS instance

func (*Agent) ProvisionGCR

func (a *Agent) ProvisionGCR(
	projectID uint,
	gcpConf *integrations.GCPIntegration,
	repo repository.Repository,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionGCR spawns a new provisioning pod that creates a GCR instance

func (*Agent) ProvisionGKE

func (a *Agent) ProvisionGKE(
	projectID uint,
	gcpConf *integrations.GCPIntegration,
	gkeName string,
	repo repository.Repository,
	infra *models.Infra,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionGKE spawns a new provisioning pod that creates a GKE instance

func (*Agent) ProvisionTest

func (a *Agent) ProvisionTest(
	projectID uint,
	infra *models.Infra,
	repo repository.Repository,
	operation provisioner.ProvisionerOperation,
	pgConf *config.DBConf,
	redisConf *config.RedisConf,
	provImageTag string,
) (*batchv1.Job, error)

ProvisionTest spawns a new provisioning pod that tests provisioning

func (*Agent) StopJobWithJobSidecar added in v0.3.0

func (a *Agent) StopJobWithJobSidecar(namespace, name string) error

StopJobWithJobSidecar sends a termination signal to a job running with a sidecar

func (*Agent) StreamControllerStatus

func (a *Agent) StreamControllerStatus(conn *websocket.Conn, kind string) error

StreamControllerStatus streams controller status. Supports Deployment, StatefulSet, ReplicaSet, and DaemonSet TODO: Support Jobs

func (*Agent) UpdateConfigMap

func (a *Agent) UpdateConfigMap(name string, namespace string, configMap map[string]string) error

UpdateConfigMap updates the configmap given its name and namespace

func (*Agent) UpdateLinkedSecret

func (a *Agent) UpdateLinkedSecret(name, namespace, cmName string, data map[string][]byte) error

UpdateLinkedSecret updates the secret given its name and namespace

type ErrConnection added in v0.3.2

type ErrConnection struct {
	// contains filtered or unexported fields
}

For ECONNREFUSED and errors.IsTimeout

func (*ErrConnection) Error added in v0.3.2

func (e *ErrConnection) Error() string

func (*ErrConnection) Externalize added in v0.3.2

func (e *ErrConnection) Externalize() *ErrExternalized

type ErrExternalized added in v0.3.2

type ErrExternalized struct {
	Message string `json:"message"`
	Details string `json:"error"`
	// contains filtered or unexported fields
}

type ErrUnauthorized added in v0.3.2

type ErrUnauthorized struct {
	// contains filtered or unexported fields
}

For errors.IsForbidden and errors.IsUnauthorized

func (*ErrUnauthorized) Error added in v0.3.2

func (e *ErrUnauthorized) Error() string

func (*ErrUnauthorized) Externalize added in v0.3.2

func (e *ErrUnauthorized) Externalize() *ErrExternalized

type ErrUnknown added in v0.3.2

type ErrUnknown struct {
	// contains filtered or unexported fields
}

func (*ErrUnknown) Error added in v0.3.2

func (e *ErrUnknown) Error() string

func (*ErrUnknown) Externalize added in v0.3.2

func (e *ErrUnknown) Externalize() *ErrExternalized

type K8sConnectionError added in v0.3.2

type K8sConnectionError interface {
	Externalize() *ErrExternalized
	Error() string
}

func CatchK8sConnectionError added in v0.3.2

func CatchK8sConnectionError(err error) K8sConnectionError

type Label

type Label struct {
	Key string
	Val string
}

ListJobsByLabel lists jobs in a namespace matching a label

type ListOptions

type ListOptions struct {
	FieldSelector string
}

type Message

type Message struct {
	EventType string `json:"event_type"`
	Object    interface{}
	Kind      string
}

type OutOfClusterConfig

type OutOfClusterConfig struct {
	Cluster          *models.Cluster
	Repo             *repository.Repository
	DefaultNamespace string // optional

	// Only required if using DigitalOcean OAuth as an auth mechanism
	DigitalOceanOAuth *oauth2.Config
}

OutOfClusterConfig is the set of parameters required for an out-of-cluster connection. This implements RESTClientGetter

func (*OutOfClusterConfig) CreateRawConfigFromCluster

func (conf *OutOfClusterConfig) CreateRawConfigFromCluster() (*api.Config, error)

func (*OutOfClusterConfig) GetClientConfigFromCluster

func (conf *OutOfClusterConfig) GetClientConfigFromCluster() (clientcmd.ClientConfig, error)

GetClientConfigFromCluster will construct new clientcmd.ClientConfig using the configuration saved within a Cluster model

func (*OutOfClusterConfig) ToDiscoveryClient

func (conf *OutOfClusterConfig) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

ToDiscoveryClient returns a CachedDiscoveryInterface using a computed RESTConfig It's required to implement the interface genericclioptions.RESTClientGetter

func (*OutOfClusterConfig) ToRESTConfig

func (conf *OutOfClusterConfig) ToRESTConfig() (*rest.Config, error)

ToRESTConfig creates a kubernetes REST client factory -- it calls ClientConfig on the result of ToRawKubeConfigLoader, and also adds a custom http transport layer if necessary (required for GCP auth)

func (*OutOfClusterConfig) ToRESTMapper

func (conf *OutOfClusterConfig) ToRESTMapper() (meta.RESTMapper, error)

ToRESTMapper returns a mapper

func (*OutOfClusterConfig) ToRawKubeConfigLoader

func (conf *OutOfClusterConfig) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader creates a clientcmd.ClientConfig from the raw kubeconfig found in the OutOfClusterConfig. It does not implement loading rules or overrides.

Directories

Path Synopsis
aws
do
gcp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL