Documentation ¶
Index ¶
- Constants
- func AddSpinnakerAnnotations(u *unstructured.Unstructured, application string) error
- func AddSpinnakerLabels(u *unstructured.Unstructured, application string) error
- func AddSpinnakerVersionAnnotations(u *unstructured.Unstructured, version SpinnakerVersion) error
- func AddSpinnakerVersionLabels(u *unstructured.Unstructured, version SpinnakerVersion) error
- func AnnotateTemplate(u *unstructured.Unstructured, key, value string) error
- func AnnotationMatches(u unstructured.Unstructured, annotationKey, value string) bool
- func BindArtifacts(u *unstructured.Unstructured, artifacts []clouddriver.Artifact)
- func Cluster(kind, name string) string
- func DefaultLabelSelector() string
- func FilterOnAnnotation(items []unstructured.Unstructured, annotationKey, annotationValue string) []unstructured.Unstructured
- func FilterOnLabelExists(items []unstructured.Unstructured, label string) []unstructured.Unstructured
- func FindArtifacts(u *unstructured.Unstructured) []clouddriver.Artifact
- func GetCurrentVersion(ul *unstructured.UnstructuredList, kind, name string) string
- func GetStatus(kind string, m map[string]interface{}) manifest.Status
- func IsVersioned(u unstructured.Unstructured) bool
- func LoadBalancers(u unstructured.Unstructured) ([]string, error)
- func MaxVersionHistory(u unstructured.Unstructured) (maxVersionHistory int, err error)
- func NameWithoutVersion(name string) string
- func NewRequirement(op string, key string, values []string) (*labels.Requirement, error)
- func Recreate(u unstructured.Unstructured) bool
- func Replace(u unstructured.Unstructured) bool
- func SetDefaultNamespaceIfScopedAndNoneSet(u *unstructured.Unstructured, helper *resource.Helper)
- func SetNamespaceIfScoped(namespace string, u *unstructured.Unstructured, helper *resource.Helper)
- func SetNamespaceOnManifest(u *unstructured.Unstructured, namespaceOverride string)
- func SortManifests(manifests []unstructured.Unstructured) []unstructured.Unstructured
- func SpinnakerMonikerApplication(u unstructured.Unstructured) string
- func ToUnstructured(manifest map[string]interface{}) (unstructured.Unstructured, error)
- func UseDiskCache()
- func UseSourceCapacity(u unstructured.Unstructured) bool
- type Client
- type Clientset
- type Controller
- type DaemonSet
- type Deployment
- type HorizontalPodAutoscaler
- type Job
- type Metadata
- type Pod
- type Provider
- type ProviderPermissions
- type ReplicaSet
- type Resource
- type SpinnakerVersion
- type StatefulSet
Constants ¶
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` )
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` )
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" )
const ( // https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/ AnnotationSpinnakerArtifactVersion = `artifact.spinnaker.io/version` AnnotationSpinnakerMonikerSequence = `moniker.spinnaker.io/sequence` )
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".
func BindArtifacts ¶
func BindArtifacts(u *unstructured.Unstructured, artifacts []clouddriver.Artifact)
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
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 GetStatus ¶
Status definitions of kinds can be found at https://github.com/spinnaker/clouddriver/tree/master/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/op/handler
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
NameWithVersion removes the Spinnaker version (trailing '-v###) from the name.
func NewRequirement ¶
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 Client ¶
type Client interface { Apply(*unstructured.Unstructured) (Metadata, error) DeleteResourceByKindAndNameAndNamespace(string, string, string, metav1.DeleteOptions) error Discover() error GVRForKind(string) (schema.GroupVersionResource, error) Get(string, string, string) (*unstructured.Unstructured, error) ListByGVR(schema.GroupVersionResource, metav1.ListOptions) (*unstructured.UnstructuredList, error) ListByGVRWithContext(context.Context, schema.GroupVersionResource, metav1.ListOptions) (*unstructured.UnstructuredList, error) ListResource(string, metav1.ListOptions) (*unstructured.UnstructuredList, error) ListResourceWithContext(context.Context, string, metav1.ListOptions) (*unstructured.UnstructuredList, error) Patch(string, string, string, []byte) (Metadata, *unstructured.Unstructured, error) PatchUsingStrategy(string, string, string, []byte, types.PatchType) (Metadata, *unstructured.Unstructured, error) ListResourcesByKindAndNamespace(string, string, metav1.ListOptions) (*unstructured.UnstructuredList, error) ListResourcesByKindAndNamespaceWithContext(context.Context, string, string, metav1.ListOptions) (*unstructured.UnstructuredList, 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 ¶
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 (hpa *HorizontalPodAutoscaler) Object() *v1.HorizontalPodAutoscaler
func (*HorizontalPodAutoscaler) Status ¶
func (hpa *HorizontalPodAutoscaler) 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:32;not null;default:'google'"` Namespace *string `json:"namespace,omitempty" gorm:"size:253"` Permissions ProviderPermissions `json:"permissions" gorm:"-"` // Providers can hold instances of clients. Client Client `json:"-" gorm:"-"` Clientset Clientset `json:"-" gorm:"-"` }
func (*Provider) ValidateKindStatus ¶
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) WithClient ¶
WithClient sets the kubernetes client for this provider.
func (*Provider) WithClientset ¶
WithClientset sets the kubernetes clientset for this provider.
type ProviderPermissions ¶
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:"-"` }
type SpinnakerVersion ¶
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
Source Files ¶
- annotation.go
- artifact.go
- client.go
- clientset.go
- cluster.go
- controller.go
- daemonset.go
- deployment.go
- filter.go
- horizontalpodautoscaler.go
- job.go
- label.go
- label_selector.go
- namespace.go
- pod.go
- provider.go
- replicaset.go
- resource.go
- sort.go
- statefulset.go
- status.go
- strategy.go
- traffic.go
- unstructured.go
- version.go
Directories ¶
Path | Synopsis |
---|---|
cached
|
|
disk/diskfakes
Code generated by counterfeiter.
|
Code generated by counterfeiter. |
Code generated by counterfeiter.
|
Code generated by counterfeiter. |