resource

package
v0.0.0-...-35b42f4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DeletionPolicyAnnotation can be set on a resources to control the
	// behaviour of the resource deletion operation.
	DeletionPolicyAnnotation = "kcm/deletion-policy"

	// DeletePersistentVolumeClaimsPolicy will cause the deletion of all PVCs
	// that were created for a StatefulSet.
	DeletePersistentVolumeClaimsPolicy = "delete-pvcs"
)
View Source
const (
	// Kinds of Kubernetes resources that are treated in a special way by kcm.
	Job                   = "Job"
	PersistentVolumeClaim = "PersistentVolumeClaim"
	StatefulSet           = "StatefulSet"
)

Variables

This section is empty.

Functions

func Format

func Format(r *Resource) string

Format formats the resource as string.

func FormatSlice

func FormatSlice(s Slice) string

FormatSlice formats a slice of resources as string. If s is nil or empty the formatted string will also be empty. The formatted output will be prepended with a summary of the counts of different resource hints (e.g. updates).

Types

type Buffer

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

Buffer wraps a bytes.Buffer and delimits the bytes of every write so that the resulting byte slice is valid multi-document yaml.

func (*Buffer) Bytes

func (w *Buffer) Bytes() []byte

Bytes returns the content of the underlying bytes.Buffer.

func (*Buffer) Write

func (w *Buffer) Write(p []byte) (n int, err error)

Write implements io.Writer.

type Head struct {
	Kind     string   `yaml:"kind"`
	Metadata Metadata `yaml:"metadata"`
}

Head defines the yaml structure of a resource head. This is used for parsing metadata from raw yaml documents.

func (Head) String

func (h Head) String() string

String implements fmt.Stringer

type Hint

type Hint int

Hint is the type for resource hints. Hints are used to add context to a resource so that output formatters can make a decision on how to format it.

const (
	// NoChange indicates that the resource has not changed.
	NoChange Hint = iota
	// Addition indicates that the resource was newly added.
	Addition
	// Update indicates that the resource content changed.
	Update
	// Removal indicates that the resource will be removed.
	Removal
)

func (Hint) String

func (h Hint) String() string

String implements fmt.Stringer

type Metadata

type Metadata struct {
	Name        string            `yaml:"name"`
	Namespace   string            `yaml:"namespace"`
	Annotations map[string]string `yaml:"annotations"`
}

Metadata is the resource metadata we are interested in.

type Order

type Order []string

Order is a slice of strings that defines the ordering of resources.

var ApplyOrder Order = []string{
	"Namespace",
	"ResourceQuota",
	"LimitRange",
	"PodSecurityPolicy",
	"PodDisruptionBudget",
	"Secret",
	"ConfigMap",
	"StorageClass",
	"PersistentVolume",
	"PersistentVolumeClaim",
	"ServiceAccount",
	"CustomResourceDefinition",
	"ClusterRole",
	"ClusterRoleBinding",
	"Role",
	"RoleBinding",
	"Service",
	"DaemonSet",
	"Pod",
	"ReplicationController",
	"ReplicaSet",
	"Deployment",
	"StatefulSet",
	"Job",
	"CronJob",
	"Ingress",
	"APIService",
}

ApplyOrder is the resource order for apply operations.

var DeleteOrder Order = []string{
	"APIService",
	"Ingress",
	"Service",
	"CronJob",
	"Job",
	"StatefulSet",
	"Deployment",
	"ReplicaSet",
	"ReplicationController",
	"Pod",
	"DaemonSet",
	"RoleBinding",
	"Role",
	"ClusterRoleBinding",
	"ClusterRole",
	"CustomResourceDefinition",
	"ServiceAccount",
	"PersistentVolumeClaim",
	"PersistentVolume",
	"StorageClass",
	"ConfigMap",
	"Secret",
	"PodDisruptionBudget",
	"PodSecurityPolicy",
	"LimitRange",
	"ResourceQuota",
	"Namespace",
}

DeleteOrder is the resource order for delete operations.

type Printer

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

Printer can print resources in a formatted way.

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter creates a new Printer with w as the backing writer for the formatted output.

func (*Printer) Print

func (p *Printer) Print(r *Resource) error

Print prints the formatted resource.

func (*Printer) PrintSlice

func (p *Printer) PrintSlice(s Slice) error

PrintSlice prints a formatted resource slice.

type Resource

type Resource struct {
	Kind      string
	Name      string
	Namespace string
	Content   []byte

	DeletePersistentVolumeClaims bool
	// contains filtered or unexported fields
}

Resource is a kubernetes resource.

func FindMatching

func FindMatching(haystack []*Resource, needle *Resource) (*Resource, bool)

FindMatching searches haystack for a resource matching needle and returns it if found, nil otherwise.

func New

func New(content []byte, head Head) (*Resource, error)

New creates a new resource value with content and head.

func (*Resource) String

func (r *Resource) String() string

String implements fmt.Stringer

func (*Resource) WithContentHint

func (r *Resource) WithContentHint(content []byte) *Resource

WithContentHint hints the resource with its current content so that diffs can be generated for the new content in formatted output.

func (*Resource) WithHint

func (r *Resource) WithHint(hint Hint) *Resource

WithHint sets a hint on the resource.

type Slice

type Slice []*Resource

Slice is a slice of resources.

func (Slice) Bytes

func (s Slice) Bytes() []byte

Bytes converts the resource slice to raw bytes.

func (Slice) PersistentVolumeClaimsForDeletion

func (s Slice) PersistentVolumeClaimsForDeletion() Slice

PersistentVolumeClaimsForDeletion extracts all PersistentVolumeClaims for StatefulSets that have been annotated with:

kcm/deletion-policy: delete-pvcs

It returns a slice of Head containing name and namespace of every PVC that should be deleted after the StatefulSet is deleted. This is a workaround until a similar feature (https://github.com/kubernetes/kubernetes/issues/55045) is implemented in Kubernetes itself.

func (Slice) Sort

func (s Slice) Sort(order Order) Slice

Sort sorts the slice in the given order.

func (Slice) String

func (s Slice) String() string

String implements fmt.Stringer

func (Slice) WithHint

func (s Slice) WithHint(hint Hint) Slice

WithHint sets a hint on all resources in the slice.

Jump to

Keyboard shortcuts

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