kube

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindOrder []string = []string{
	"Namespace",
	"NetworkPolicy",
	"ResourceQuota",
	"LimitRange",
	"PodSecurityPolicy",
	"PodDisruptionBudget",
	"Secret",
	"ConfigMap",
	"ConfigMapList",
	"StorageClass",
	"PersistentVolume",
	"PersistentVolumeClaim",
	"ServiceAccount",
	"CustomResourceDefinition",
	"ClusterRole",
	"ClusterRoleList",
	"ClusterRoleBinding",
	"ClusterRoleBindingList",
	"Role",
	"RoleList",
	"RoleBinding",
	"RoleBindingList",
	"Service",
	"DaemonSet",
	"Pod",
	"ReplicationController",
	"ReplicaSet",
	"Deployment",
	"HorizontalPodAutoscaler",
	"StatefulSet",
	"Job",
	"CronJob",
	"Ingress",
	"APIService",
}

KindOrder specifies the order in which Kubernetes resource types should be applied. Adapted from the list in https://github.com/helm/helm/blob/master/pkg/releaseutil/kind_sorter.go.

View Source
var KindithoutMetadata []string = []string{
	"ConfigMapList",
	"RoleBindingList",
	"RoleList",
}

KindithoutMetadata lists out Kubernetes manifest types that don't have metadata.

Functions

func CreateKubeconfigFromClusterData

func CreateKubeconfigFromClusterData(
	clusterName string,
	serverURL string,
	caData string,
	region string,
	path string,
) error

CreateKubeconfigFromClusterData generates a kubeconfig from the raw components in KubeconfigTemplateData.

func CreateKubeconfigViaAPI

func CreateKubeconfigViaAPI(
	ctx context.Context,
	sess *session.Session,
	clusterName string,
	region string,
	path string,
) error

CreateKubeconfigViaAPI generates a kubeconfig by hitting the EKS API.

func KubeconfigMatchesCluster

func KubeconfigMatchesCluster(path string, clusterName string) bool

KubeconfigMatchesCluster determines (roughly) whether a kubeconfig matches the provided cluster name. Currently, it just looks for the latter string in the config.

func SortManifests

func SortManifests(manifests []Manifest)

SortManifests sorts the provided manifest slice using the KindOrder above. Ties within the same type are broken by (namespace, name).

Types

type KubeconfigTemplateData

type KubeconfigTemplateData struct {
	Name      string
	ServerURL string
	CAData    string
	Region    string
}

KubeconfigTemplateData stores the data necessary to generate a kubeconfig.

type Manifest

type Manifest struct {
	Path     string
	Head     SimpleHeader
	Contents string
}

Manifest is a wrapper around a Kubernetes resource manifest on local disk.

func GetManifests

func GetManifests(paths []string) ([]Manifest, error)

GetManifests recursively parses all of the manifests in the argument path.

type OrderedClient

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

OrderedClient is a kubectl-wrapped client that tries to be clever about the order in which resources are created or destroyed.

func NewOrderedClient

func NewOrderedClient(
	kubeConfigPath string,
	keepConfigs bool,
	extraEnv []string,
	debug bool,
	serverSide bool,
) *OrderedClient

NewOrderedClient returns a new OrderedClient instance.

func (*OrderedClient) Apply

func (k *OrderedClient) Apply(
	ctx context.Context,
	applyPaths []string,
	output bool,
	format string,
	dryRun bool,
) ([]byte, error)

Apply runs kubectl apply on the manifests in the argument path. The apply is done in the optimal order based on resource type.

func (*OrderedClient) Diff

func (k *OrderedClient) Diff(
	ctx context.Context,
	configPaths []string,
	structured bool,
	diffCommand string,
	spinner *spinner.Spinner,
) ([]byte, error)

Diff runs kubectl diff for the configs at the argument path.

func (*OrderedClient) GetNamespaceUID

func (k *OrderedClient) GetNamespaceUID(ctx context.Context, namespace string) (string, error)

GetNamespaceUID returns the kubernetes identifier for a given namespace in this cluster.

func (*OrderedClient) Summary

func (k *OrderedClient) Summary(
	ctx context.Context,
) (string, error)

Summary returns a pretty summary of the current cluster state.

type SimpleHeader

type SimpleHeader struct {
	Version  string `json:"apiVersion"`
	Kind     string `json:"kind,omitempty"`
	Metadata *struct {
		Name        string            `json:"name"`
		Namespace   string            `json:"namespace"`
		Annotations map[string]string `json:"annotations"`
	} `json:"metadata,omitempty"`
}

SimpleHeader is a simplified header used to getting basic metadata from Kubernetes YAML files. Adapted from same struct in Helm repo.

Jump to

Keyboard shortcuts

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