kubernetes

package
v0.0.0-...-830b495 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: BSD-3-Clause, Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelAppKey            = "app"
	LabelAppValue          = "nats"
	LabelClusterNameKey    = "nats_cluster"
	LabelClusterVersionKey = "nats_version"
)
View Source
const (
	TolerateUnreadyEndpointsAnnotation = "service.alpha.kubernetes.io/tolerate-unready-endpoints"
)

Variables

This section is empty.

Functions

func ByCoordinates

func ByCoordinates(namespace, name string) fields.Selector

ByCoordinates returns a field selector that can be used to filter Kubernetes resources based on their name and namespace.

func ClientServiceName

func ClientServiceName(clusterName string) string

ClientServiceName returns the name of the client service based on the specified cluster name.

func ClusterListOpt

func ClusterListOpt(clusterName string) metav1.ListOptions

We are using internal api types for cluster related.

func ConfigSecret

func ConfigSecret(clusterName string) string

ConfigSecret returns the name of the secret that contains the configuration for the NATS cluster with the specified name.

func CreateAndWaitPod

func CreateAndWaitPod(kubecli corev1client.CoreV1Interface, ns string, pod *v1.Pod, timeout time.Duration) (*v1.Pod, error)

CreateAndWaitPod is an util for testing. We should eventually get rid of this in critical code path and move it to test util.

func CreateClientService

func CreateClientService(kubecli corev1client.CoreV1Interface, clusterName, ns string, owner metav1.OwnerReference) error

func CreateConfigSecret

func CreateConfigSecret(kubecli corev1client.CoreV1Interface, operatorcli natsalphav2client.NatsV1alpha2Interface, clusterName, ns string, cluster v1alpha2.ClusterSpec, owner metav1.OwnerReference) error

CreateConfigSecret creates the secret that contains the configuration file for a given NATS cluster..

func CreateMgmtService

func CreateMgmtService(kubecli corev1client.CoreV1Interface, clusterName, clusterVersion, ns string, owner metav1.OwnerReference) error

CreateMgmtService creates an headless service for NATS management purposes.

func CreatePatch

func CreatePatch(o, n, datastruct interface{}) ([]byte, error)

func ExecInContainer

func ExecInContainer(ctx context.Context, kubeClient kubernetes.Interface, kubeCfg *rest.Config, podNamespace, podName, containerName string, args ...string) (int, error)

ExecInContainer runs a command in the specified container, blocking until the command finishes execution or the specified context times out. It returns the command's exit code (if available), its output (stdout and stderr) and the associated error (if any).

func GetClusterList

func GetClusterList(restcli rest.Interface, ns string) (*v1alpha2.NatsClusterList, error)

func GetNATSVersion

func GetNATSVersion(pod *v1.Pod) string

func GetPodNames

func GetPodNames(pods []*v1.Pod) []string

func InClusterConfig

func InClusterConfig() (*rest.Config, error)

func InitCRDs

func InitCRDs(extsClient extsclientset.Interface) error

InitCRDs registers the CRDs for the nats.io/v1alpha2 API and waits for them to become ready.

func IsKubernetesResourceAlreadyExistError

func IsKubernetesResourceAlreadyExistError(err error) bool

func IsKubernetesResourceNotFoundError

func IsKubernetesResourceNotFoundError(err error) bool

func IsPodReady

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns false if the Pod Status is nil

func LabelSelectorForCluster

func LabelSelectorForCluster(clusterName string) labels.Selector

LabelSelectorForCluster returns a label selector that matches resources belonging to the NATS cluster with the specified name.

func LabelsForCluster

func LabelsForCluster(clusterName string) map[string]string

func MakeNATSImage

func MakeNATSImage(version string, serverImage string) string

func ManagementServiceName

func ManagementServiceName(clusterName string) string

func MustNewKubeClientFromConfig

func MustNewKubeClientFromConfig(cfg *rest.Config) kubernetes.Interface

MustNewKubeClientFromConfig builds a Kubernetes client based on the specified configuration object.

func MustNewKubeConfig

func MustNewKubeConfig(kubeconfig string) *rest.Config

MustNewKubeConfig builds a configuration object by either reading from the specified kubeconfig file or by using an in-cluster config.

func MustNewKubeExtClient

func MustNewKubeExtClient(cfg *rest.Config) extsclientset.Interface

MustNewKubeExtClient creates a new client for the apiextensions.k8s.io/v1beta1 API.

func MustNewNatsClientFromConfig

func MustNewNatsClientFromConfig(cfg *rest.Config) natsclient.Interface

MustNewNatsClientFromConfig builds a client for our API based on the specified configuration object.

func NatsServiceRoleLabelSelectorForCluster

func NatsServiceRoleLabelSelectorForCluster(clusterName string) labels.Selector

NatsServiceRoleLabelSelectorForCuster returns a label selector that matches NatsServiceRole resources referencing the NATS cluster with the specified name.

func NewNatsPodSpec

func NewNatsPodSpec(namespace, name, clusterName string, cs v1alpha2.ClusterSpec, owner metav1.OwnerReference) *v1.Pod

NewNatsPodSpec returns a NATS peer pod specification, based on the cluster specification.

func PodSpecToPrettyJSON

func PodSpecToPrettyJSON(pod *v1.Pod) (string, error)

func PodWithAntiAffinity

func PodWithAntiAffinity(pod *v1.Pod, clusterName string) *v1.Pod

PodWithAntiAffinity sets pod anti-affinity with the pods in the same NATS cluster

func PodWithNodeSelector

func PodWithNodeSelector(p *v1.Pod, ns map[string]string) *v1.Pod

func ResourceKey

func ResourceKey(obj interface{}) string

ResourceKey returns the "namespace/name" key that represents the specified resource.

func SetNATSVersion

func SetNATSVersion(pod *v1.Pod, version string)

func UniquePodName

func UniquePodName() string

UniquePodName generates a unique name for the Pod.

func UpdateConfigSecret

func UpdateConfigSecret(
	kubecli corev1client.CoreV1Interface,
	operatorcli natsalphav2client.NatsV1alpha2Interface,
	clusterName, ns string,
	cluster v1alpha2.ClusterSpec,
	owner metav1.OwnerReference,
) error

UpdateConfigSecret applies the new configuration of the cluster, such as modifying the routes available in the cluster.

func WaitCRDs

func WaitCRDs(extsClient extsclientset.Interface) error

WaitCRDs waits for the CRDs to become ready.

func WaitUntilDeploymentCondition

func WaitUntilDeploymentCondition(ctx context.Context, kubeClient kubernetes.Interface, namespace, name string, fn watch.ConditionFunc) error

WaitUntilDeploymentCondition establishes a watch on the specified deployment and blocks until the specified condition function is satisfied.

func WaitUntilPodCondition

func WaitUntilPodCondition(ctx context.Context, kubeClient corev1.CoreV1Interface, pod *v1.Pod, fn watch.ConditionFunc) error

WaitUntilPodCondition establishes a watch on the specified pod and blocks until the specified condition function is satisfied.

func WaitUntilPodReady

func WaitUntilPodReady(ctx context.Context, kubeClient corev1.CoreV1Interface, pod *v1.Pod) error

WaitUntilPodReady establishes a watch on the specified pod and blocks until the pod is running, ready and has its ".status.podIP" field populated.

Types

type NatsClusterCRUpdateFunc

type NatsClusterCRUpdateFunc func(*v1alpha2.NatsCluster)

NatsClusterCRUpdateFunc is a function to be used when atomically updating a Cluster CR.

Jump to

Keyboard shortcuts

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