kubernetes

package
v1.1.2-2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationSpinnakerArtifactLocation   = `artifact.spinnaker.io/location`
	AnnotationSpinnakerArtifactName       = `artifact.spinnaker.io/name`
	AnnotationSpinnakerArtifactType       = `artifact.spinnaker.io/type`
	AnnotationSpinnakerMonikerApplication = `moniker.spinnaker.io/application`
	AnnotationSpinnakerMonikerCluster     = `moniker.spinnaker.io/cluster`
	AnnotationSpinnakerMonikerDetail      = `moniker.spinnaker.io/detail`
	AnnotationSpinnakerMonikerStack       = `moniker.spinnaker.io/stack`
	AnnotationSpinnakerStrategyVersioned  = `strategy.spinnaker.io/versioned`
)
View Source
const (
	// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
	LabelKubernetesName           = `app.kubernetes.io/name`
	LabelKubernetesManagedBy      = `app.kubernetes.io/managed-by`
	LabelSpinnakerMonikerSequence = `moniker.spinnaker.io/sequence`
)
View Source
const (
	AnnotationSpinnakerMaxVersionHistory = "strategy.spinnaker.io/max-version-history"
	AnnotationSpinnakerRecreate          = "strategy.spinnaker.io/recreate"
	AnnotationSpinnakerReplaced          = "strategy.spinnaker.io/replace"
	AnnotationSpinnakerUseSourceCapacity = "strategy.spinnaker.io/use-source-capacity"
)
View Source
const (
	// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
	AnnotationSpinnakerArtifactVersion = `artifact.spinnaker.io/version`
	AnnotationSpinnakerMonikerSequence = `moniker.spinnaker.io/sequence`
)
View Source
const (
	AnnotationSpinnakerTrafficLoadBalancers = "traffic.spinnaker.io/load-balancers"
)

Variables

This section is empty.

Functions

func AddSpinnakerAnnotations

func AddSpinnakerAnnotations(u *unstructured.Unstructured, application string) error

AddSpinnakerAnnotations adds Spinnaker-defined annotations to a given unstructured resource.

func AddSpinnakerLabels

func AddSpinnakerLabels(u *unstructured.Unstructured, application string) error

AddSpinnakerLabels labels a given unstructured Kubernetes resource with Spinnaker defined labels.

func AddSpinnakerVersionAnnotations

func AddSpinnakerVersionAnnotations(u *unstructured.Unstructured, version SpinnakerVersion) error

AddSpinnakerVersionAnnotations adds the following annotations: `artifact.spinnaker.io/version` `moniker.spinnaker.io/sequence` to the manifest to identify the version number of that resource.

func AddSpinnakerVersionLabels

func AddSpinnakerVersionLabels(u *unstructured.Unstructured, version SpinnakerVersion) error

AddSpinnakerVersionLabels adds the `moniker.spinnaker.io/sequence` label to the manifest to identify the version number of that resource.

func AnnotateTemplate

func AnnotateTemplate(u *unstructured.Unstructured, key, value string) error

AnnotateTemplate annotates the nested string map located at .spec.template.metadata.annotations.

func AnnotationMatches added in v0.24.0

func AnnotationMatches(u unstructured.Unstructured, annotationKey, value string) bool

AnnotationMatches returns true if the value of annotation matches the given value.

If value is "", then match when annotation is missing or also "". If value is "*", then always match. If value is "something", then match only when annotation value is "something".

See https://github.com/spinnaker/clouddriver/blob/96755fec0c04b6e361efb6d1c19a7afc3926e302/clouddriver-core/src/main/java/com/netflix/spinnaker/clouddriver/core/ProjectClustersService.java#L197

func BindArtifacts

func BindArtifacts(u *unstructured.Unstructured,
	artifacts []clouddriver.Artifact, account string)

BindArtifacts takes in an unstructured Kubernetes object and a slice of artifacts then binds these artifacts to any applicable JSON path for the given artifact.

For example, take the following manifest that references a configMap with name 'replace-me':

apiVersion: v1 kind: Pod metadata:

name: dapi-test-pod

spec:

containers:
  - name: test-container
    image: k8s.gcr.io/busybox
    volumeMounts:
    - name: my-volume
      mountPath: /etc/config
volumes:
  - name: my-volume
    configMap:
      # Provide the name of the ConfigMap containing the files you want
      # to add to the container
      name: replace-me
restartPolicy: Never

Now let's say we pass in the following Clouddriver Artifact:

{
  "name": "replace-me",
  "reference": "my-config-map-v000"
}

This would result in the JSON path '.spec.volumes[0].configMap.name' changing from 'replace-me' to 'my-config-map-v000'.

The source code for these Replacers can be found here: https://github.com/spinnaker/clouddriver/blob/4d4e01084ac5259792020e419b1af7686ab38019/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/artifact/Replacer.java#L150

func Cluster added in v0.20.0

func Cluster(kind, name string) string

Generate the cluster that a kind is a part of. A Kubernetes cluster is of kind deployment, statefulSet, replicaSet, ingress, service, and daemonSet so only generate a cluster for these kinds.

func DefaultLabelSelector added in v0.19.0

func DefaultLabelSelector() string

DefaultLabelSelector returns the label selector `app.kubernetes.io/managed-by in (spinnaker,spinnaker-operator)`, which allows us to list all resources with a label selector managed by Spinnaker or Spinnaker Operator.

func FilterOnAnnotation added in v0.19.0

func FilterOnAnnotation(items []unstructured.Unstructured,
	annotationKey, annotationValue string) []unstructured.Unstructured

FilterOnAnnotations takes a slice of unstructured and returns the filtered slice based on a given annotation key and value.

func FilterOnLabelExists added in v0.19.0

func FilterOnLabelExists(items []unstructured.Unstructured,
	label string) []unstructured.Unstructured

FilterOnLabelExists takes a slice of unstructured and returns a filtered slice where a given label exists in each of the unstructured objects.

func FindArtifacts added in v0.24.0

func FindArtifacts(u *unstructured.Unstructured) []clouddriver.Artifact

FindArtifacts lists all artifacts found in a given manifest. It is expected to be used only for Kubernetes kind Deployment, so non-Deployment kind paths are omitted.

func GetCurrentVersion

func GetCurrentVersion(ul *unstructured.UnstructuredList, kind, name string) string

GetCurrentVersion returns the latest "Spinnaker version" from an unstructured list of Kubernetes resources.

func IsVersioned

func IsVersioned(u unstructured.Unstructured) bool

IsVersioned returns true is a given Kubernetes unstructured resource is "versioned". A resource is version if its annotation `strategy.spinnaker.io/versioned` is set to "true" or if it is of kind Pod, ReplicaSet, ConfigMap, or Secret.

See https://spinnaker.io/reference/providers/kubernetes-v2/#workloads for more info.

func LoadBalancers added in v0.20.0

func LoadBalancers(u unstructured.Unstructured) ([]string, error)

LoadBalancers returns a slice of load balancers from the annotation `traffic.spinnaker.io/load-balancers`. It errors if this annotation is not a string slice format like '["service my-service", "service my-service2"]'.

See https://spinnaker.io/docs/reference/providers/kubernetes-v2/#traffic for more info.

func MaxVersionHistory

func MaxVersionHistory(u unstructured.Unstructured) (maxVersionHistory int, err error)

MaxVersionHistory returns the value as an int of the annotation `strategy.spinnaker.io/max-version-history` of the given Kubernetes unstructured resource, or 0 if annotation is not present.

See https://spinnaker.io/docs/reference/providers/kubernetes-v2/#strategy for more info.

func NameWithoutVersion added in v0.20.0

func NameWithoutVersion(name string) string

NameWithVersion removes the Spinnaker version (trailing '-v###) from the name.

func NewRequirement

func NewRequirement(op string, key string, values []string) (*labels.Requirement, error)

func Recreate

func Recreate(u unstructured.Unstructured) bool

Recreate returns true if the given Kubernetes unstructured resource has the annotation `strategy.spinnaker.io/recreate` set to "true".

See https://spinnaker.io/docs/reference/providers/kubernetes-v2/#strategy for more info.

func Replace

func Replace(u unstructured.Unstructured) bool

Replace returns true if the given Kubernetes unstructured resource has the annotation `strategy.spinnaker.io/replace` set to "true".

See https://spinnaker.io/docs/reference/providers/kubernetes-v2/#strategy for more info.

func SetDefaultNamespaceIfScopedAndNoneSet

func SetDefaultNamespaceIfScopedAndNoneSet(u *unstructured.Unstructured, helper *resource.Helper)

func SetNamespaceIfScoped

func SetNamespaceIfScoped(namespace string, u *unstructured.Unstructured, helper *resource.Helper)

func SetNamespaceOnManifest added in v0.24.0

func SetNamespaceOnManifest(u *unstructured.Unstructured, namespaceOverride string)

SetNamespaceOnManifest updates the namespace on the given manifest.

If no namespace is set on the manifest and no namespace override is passed in then we set the namespace to 'default'.

If namespaceOverride is empty it will NOT override the namespace set on the manifest.

We only override the namespace if the manifest is NOT cluster scoped (i.e. a ClusterRole) and namespaceOverride is NOT an empty string.

func SortManifests

func SortManifests(manifests []unstructured.Unstructured) []unstructured.Unstructured

SortManifests takes in a list of manifests and sorts them by the priority of their kind. The kind's priorities are defined above in the var 'priorities'. Lower numbered priorities should be deployed first.

func SpinnakerMonikerApplication added in v0.20.0

func SpinnakerMonikerApplication(u unstructured.Unstructured) string

SpinnakerMonikerApplication returns the value the annotation `moniker.spinnaker.io/application` of the given Kubernetes unstructured resource, or an empty string if not present.

func ToUnstructured

func ToUnstructured(manifest map[string]interface{}) (unstructured.Unstructured, error)

ToUnstructured converts a map[string]interface{} to a kubernetes unstructured.Unstructured object. An unstructured's "Object" field is technically just a map[string]interface{}, so we could do the following:

return unstructured.Unstructured{ Object: manifest }

and not have this function return an error, but we miss out on some validation that happens during `kubectl`, such as when you attempt to apply a bad manifest, like something without "kind" specified. Example:

$ k apply -f bad.yaml --validate=false error: unable to decode "bad.yaml": Object 'Kind' is missing in '{}'

If we decide to not cycle through the encoding/decoding process, these errors will be deferred to when the manifest gets applied, and will fail with some error like

error applying manifest (kind: , apiVersion: v1, name: bad-gke): no matches for kind "" in version "apps/v1"

For now, we are not deferring the error.

func UseDiskCache added in v0.25.0

func UseDiskCache()

UseDiskCache sets the controller to generate clients that use disk cache instead of memory cache for discovery and HTTP responses.

func UseSourceCapacity

func UseSourceCapacity(u unstructured.Unstructured) bool

UseSourceCapacity returns true is a given Kubernetes unstructured resource has the annotation `strategy.spinnaker.io/use-source-capacity` set to "true" and it is of kind Deployment, ReplicaSet, or StatefulSet.

See https://spinnaker.io/docs/reference/providers/kubernetes-v2/#strategy for more info.

Types

type Clientset

type Clientset interface {
	PodLogs(string, string, string) (string, error)
	Events(context.Context, string, string, string) ([]v1.Event, error)
}

type Controller

type Controller interface {
	NewClient(*rest.Config) (Client, error)
	NewClientset(*rest.Config) (Clientset, error)
}

Controller holds the ability to generate a new dynamic kubernetes client.

func NewController

func NewController() Controller

NewController returns an instance of Controller.

type DaemonSet

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

func NewDaemonSet

func NewDaemonSet(m map[string]interface{}) *DaemonSet

func (*DaemonSet) Object

func (ds *DaemonSet) Object() *v1.DaemonSet

func (*DaemonSet) Status

func (ds *DaemonSet) Status() manifest.Status

type Deployment

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

func NewDeployment

func NewDeployment(m map[string]interface{}) *Deployment

func (*Deployment) Object

func (d *Deployment) Object() *v1.Deployment

func (*Deployment) Status

func (d *Deployment) Status() manifest.Status

type HorizontalPodAutoscaler

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

func NewHorizontalPodAutoscaler

func NewHorizontalPodAutoscaler(m map[string]interface{}) *HorizontalPodAutoscaler

func (*HorizontalPodAutoscaler) Object

func (*HorizontalPodAutoscaler) Status

func (hpa *HorizontalPodAutoscaler) Status() manifest.Status

type Job

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

func NewJob

func NewJob(m map[string]interface{}) *Job

func (*Job) Object

func (j *Job) Object() *v1.Job

func (*Job) Status

func (j *Job) Status() manifest.Status

type Metadata

type Metadata struct {
	Name      string
	Namespace string
	Group     string
	Version   string
	Resource  string
	Kind      string
}

type Pod

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

func NewPod

func NewPod(m map[string]interface{}) *Pod

func (*Pod) Object

func (p *Pod) Object() *v1.Pod

func (*Pod) Status

func (p *Pod) Status() manifest.Status

type Provider

type Provider struct {
	Name          string              `json:"name" gorm:"primary_key"`
	Host          string              `json:"host"`
	CAData        string              `json:"caData" gorm:"type:text"`
	BearerToken   string              `json:"bearerToken,omitempty" gorm:"size:2048"`
	TokenProvider string              `json:"tokenProvider,omitempty" gorm:"size:128;not null;default:'google'"`
	Namespace     *string             `json:"namespace,omitempty" gorm:"size:253"`
	Namespaces    []string            `json:"namespaces,omitempty" gorm:"-"`
	Permissions   ProviderPermissions `json:"permissions" gorm:"-"`
	// Providers can hold instances of clients.
	Client    Client    `json:"-" gorm:"-"`
	Clientset Clientset `json:"-" gorm:"-"`
}

func (Provider) TableName

func (Provider) TableName() string

func (*Provider) ValidateKindStatus

func (p *Provider) ValidateKindStatus(kind string) error

ValidateKindStatus verifies that this provider can access the given kind. This begins to support `omitKinds`, but only in the context of namespace-scoped providers.

When a provider is limited to namespace, then it cannot access these kinds:

  • apiService
  • clusterRole
  • clusterRoleBinding
  • customResourceDefinition
  • mutatingWebhookConfiguration
  • namespace
  • persistentVolume
  • podSecurityPolicy
  • storageClass
  • validatingWebhookConfiguration

See https://github.com/spinnaker/clouddriver/blob/58ab154b0ec0d62772201b5b319af349498a4e3f/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/description/manifest/KubernetesKindProperties.java#L31 for clouddriver OSS namespace-scoped kinds.

func (*Provider) ValidateNamespaceAccess added in v1.1.0

func (p *Provider) ValidateNamespaceAccess(namespace string) error

ValidateNamespaceAccess verifies that this provider can access the given namespace

func (*Provider) WithClient

func (p *Provider) WithClient(client Client)

WithClient sets the kubernetes client for this provider.

func (*Provider) WithClientset

func (p *Provider) WithClientset(clientset Clientset)

WithClientset sets the kubernetes clientset for this provider.

type ProviderNamespaces added in v1.1.0

type ProviderNamespaces struct {
	//ID          string `json:"-" gorm:"primary_key"`
	AccountName string `json:"accountName"`
	Namespace   string `json:"namespace,omitempty"`
}

func (ProviderNamespaces) TableName added in v1.1.0

func (ProviderNamespaces) TableName() string

type ProviderPermissions

type ProviderPermissions struct {
	Read  []string `json:"read" gorm:"-"`
	Write []string `json:"write" gorm:"-"`
}

type ReplicaSet

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

func NewReplicaSet

func NewReplicaSet(m map[string]interface{}) *ReplicaSet

func (*ReplicaSet) Object

func (rs *ReplicaSet) Object() *v1.ReplicaSet

func (*ReplicaSet) Status

func (rs *ReplicaSet) Status() manifest.Status

type Resource

type Resource struct {
	AccountName  string    `json:"accountName"`
	ID           string    `json:"id" gorm:"primary_key"`
	Timestamp    time.Time `json:"timestamp,omitempty" gorm:"type:timestamp;DEFAULT:current_timestamp"`
	TaskID       string    `json:"taskId"`
	TaskType     string    `json:"-"`
	APIGroup     string    `json:"apiGroup"`
	Name         string    `json:"name"`
	ArtifactName string    `json:"-"`
	Namespace    string    `json:"namespace"`
	Resource     string    `json:"resource"`
	Version      string    `json:"version"`
	Kind         string    `json:"kind"`
	SpinnakerApp string    `json:"spinnakerApp"`
	Cluster      string    `json:"-"`
}

func (Resource) TableName

func (Resource) TableName() string

type SpinnakerVersion

type SpinnakerVersion struct {
	Long  string
	Short string
}

func IncrementVersion

func IncrementVersion(currentVersion string) SpinnakerVersion

type StatefulSet

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

func NewStatefulSet

func NewStatefulSet(m map[string]interface{}) *StatefulSet

func (*StatefulSet) Object

func (ss *StatefulSet) Object() *v1.StatefulSet

func (*StatefulSet) Status

func (ss *StatefulSet) Status() manifest.Status

Directories

Path Synopsis
cached
disk/diskfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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