Documentation
¶
Overview ¶
Package ssa contains utilities for managing Kubernetes resources using sever-side apply. Adapted from https://github.com/stefanprodan/kustomizer/tree/v1.1.0/pkg/manager
Index ¶
- func Equals(i, j schema.GroupKind) bool
- func FmtObjMetadata(obj object.ObjMetadata) string
- func FmtUnstructured(obj *unstructured.Unstructured) string
- func FmtUnstructuredList(objects []*unstructured.Unstructured) string
- func IsClusterDefinition(object *unstructured.Unstructured) bool
- func IsKubernetesObject(object *unstructured.Unstructured) bool
- func IsKustomization(object *unstructured.Unstructured) bool
- func IsLessThan(i, j schema.GroupKind) bool
- func MaskSecret(object *unstructured.Unstructured, mask string) (*unstructured.Unstructured, error)
- func ObjectToYAML(object *unstructured.Unstructured) string
- func ObjectsToJSON(objects []*unstructured.Unstructured) (string, error)
- func ObjectsToYAML(objects []*unstructured.Unstructured) (string, error)
- func ReadObject(r io.Reader) (*unstructured.Unstructured, error)
- func ReadObjects(r io.Reader) ([]*unstructured.Unstructured, error)
- func SetNativeKindsDefaults(objects []*unstructured.Unstructured) error
- type Action
- type ChangeSet
- type ChangeSetEntry
- type Owner
- type ResourceManager
- func (m *ResourceManager) Apply(ctx context.Context, object *unstructured.Unstructured, force bool) (*ChangeSetEntry, error)
- func (m *ResourceManager) ApplyAll(ctx context.Context, objects []*unstructured.Unstructured, force bool) (*ChangeSet, error)
- func (m *ResourceManager) ApplyAllStaged(ctx context.Context, objects []*unstructured.Unstructured, force bool, ...) (*ChangeSet, error)
- func (m *ResourceManager) Client() client.Client
- func (m *ResourceManager) Delete(ctx context.Context, object *unstructured.Unstructured, ...) (*ChangeSetEntry, error)
- func (m *ResourceManager) DeleteAll(ctx context.Context, objects []*unstructured.Unstructured, ...) (*ChangeSet, error)
- func (m *ResourceManager) Diff(ctx context.Context, object *unstructured.Unstructured) (*ChangeSetEntry, error)
- func (m *ResourceManager) GetOwnerLabels(name, namespace string) map[string]string
- func (m *ResourceManager) SetOwnerLabels(objects []*unstructured.Unstructured, name, namespace string)
- func (m *ResourceManager) Wait(objects []*unstructured.Unstructured, interval, timeout time.Duration) error
- func (m *ResourceManager) WaitForTermination(objects []*unstructured.Unstructured, interval, timeout time.Duration) error
- type SortableMetas
- type SortableUnstructureds
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FmtObjMetadata ¶
func FmtObjMetadata(obj object.ObjMetadata) string
FmtObjMetadata returns the object ID in the format <kind>/<namespace>/<name>.
func FmtUnstructured ¶
func FmtUnstructured(obj *unstructured.Unstructured) string
FmtUnstructured returns the object ID in the format <kind>/<namespace>/<name>.
func FmtUnstructuredList ¶
func FmtUnstructuredList(objects []*unstructured.Unstructured) string
FmtUnstructuredList returns a line per object in the format <kind>/<namespace>/<name>.
func IsClusterDefinition ¶
func IsClusterDefinition(object *unstructured.Unstructured) bool
IsClusterDefinition checks if the given object is a Kubernetes namespace or a custom resource definition.
func IsKubernetesObject ¶
func IsKubernetesObject(object *unstructured.Unstructured) bool
IsKubernetesObject checks if the given object has the minimum required fields to be a Kubernetes object.
func IsKustomization ¶
func IsKustomization(object *unstructured.Unstructured) bool
IsKustomization checks if the given object is a Kustomize config.
func IsLessThan ¶
func MaskSecret ¶
func MaskSecret(object *unstructured.Unstructured, mask string) (*unstructured.Unstructured, error)
MaskSecret replaces the data key values with the given mask.
func ObjectToYAML ¶
func ObjectToYAML(object *unstructured.Unstructured) string
ObjectToYAML encodes the given Kubernetes API object to YAML.
func ObjectsToJSON ¶
func ObjectsToJSON(objects []*unstructured.Unstructured) (string, error)
ObjectsToJSON encodes the given Kubernetes API objects to a YAML multi-doc.
func ObjectsToYAML ¶
func ObjectsToYAML(objects []*unstructured.Unstructured) (string, error)
ObjectsToYAML encodes the given Kubernetes API objects to a YAML multi-doc.
func ReadObject ¶
func ReadObject(r io.Reader) (*unstructured.Unstructured, error)
ReadObject decodes a YAML or JSON document from the given reader into an unstructured Kubernetes API object.
func ReadObjects ¶
func ReadObjects(r io.Reader) ([]*unstructured.Unstructured, error)
ReadObjects decodes the YAML or JSON documents from the given reader into unstructured Kubernetes API objects.
func SetNativeKindsDefaults ¶ added in v0.0.3
func SetNativeKindsDefaults(objects []*unstructured.Unstructured) error
SetNativeKindsDefaults implements workarounds for server-side apply upstream bugs affecting Kubernetes < 1.22 ContainerPort missing default TCP proto: https://github.com/kubernetes-sigs/structured-merge-diff/issues/130 ServicePort missing default TCP proto: https://github.com/kubernetes/kubernetes/pull/98576 PodSpec resources missing int to string conversion for e.g. 'cpu: 2'
Types ¶
type Action ¶
type Action string
Action represents the action type performed by the reconciliation process.
type ChangeSet ¶
type ChangeSet struct {
Entries []ChangeSetEntry
}
ChangeSet holds the result of the reconciliation of an object collection.
func NewChangeSet ¶
func NewChangeSet() *ChangeSet
NewChangeSet returns a ChangeSet will an empty slice of entries.
func (*ChangeSet) Add ¶
func (c *ChangeSet) Add(e ChangeSetEntry)
Add appends the given entry to the end of the slice.
func (*ChangeSet) Append ¶
func (c *ChangeSet) Append(e []ChangeSetEntry)
Append adds the given ChangeSet entries to end of the slice.
type ChangeSetEntry ¶
type ChangeSetEntry struct {
// Subject represents the Object ID in the format 'kind/namespace/name'.
Subject string
// Action represents the action type taken by the reconciler for this object.
Action string
// Diff contains the YAML diff resulting from server-side apply dry-run.
Diff string
}
ChangeSetEntry defines the result of an action performed on an object.
func (ChangeSetEntry) String ¶
func (e ChangeSetEntry) String() string
type Owner ¶
type Owner struct {
// Field sets the field manager name for the given server-side apply patch.
Field string
// Group sets the owner label key prefix.
Group string
}
Owner contains options for setting the field manager and ownership labels group.
type ResourceManager ¶
type ResourceManager struct {
// contains filtered or unexported fields
}
ResourceManager reconciles Kubernetes resources onto the target cluster using server-side apply.
func NewResourceManager ¶
func NewResourceManager(client client.Client, poller *polling.StatusPoller, owner Owner) *ResourceManager
NewResourceManager creates a ResourceManager for the given Kubernetes client.
func (*ResourceManager) Apply ¶
func (m *ResourceManager) Apply(ctx context.Context, object *unstructured.Unstructured, force bool) (*ChangeSetEntry, error)
Apply performs a server-side apply of the given object if the matching in-cluster object is different or if it doesn't exist. Drift detection is performed by comparing the server-side dry-run result with the existing object. When immutable field changes are detected, the object is recreated if 'force' is set to 'true'.
func (*ResourceManager) ApplyAll ¶
func (m *ResourceManager) ApplyAll(ctx context.Context, objects []*unstructured.Unstructured, force bool) (*ChangeSet, error)
ApplyAll performs a server-side dry-run of the given objects, and based on the diff result, it applies the objects that are new or modified.
func (*ResourceManager) ApplyAllStaged ¶
func (m *ResourceManager) ApplyAllStaged(ctx context.Context, objects []*unstructured.Unstructured, force bool, wait time.Duration) (*ChangeSet, error)
ApplyAllStaged extracts the CRDs and Namespaces, applies them with ApplyAll, waits for CRDs and Namespaces to become ready, then is applies all the other objects. This function should be used when the given objects have a mix of custom resource definition and custom resources, or a mix of namespace definitions with namespaced objects.
func (*ResourceManager) Client ¶
func (m *ResourceManager) Client() client.Client
Client returns the underlying controller-runtime client.
func (*ResourceManager) Delete ¶
func (m *ResourceManager) Delete(ctx context.Context, object *unstructured.Unstructured, labelSelector map[string]string, skipFor map[string]string) (*ChangeSetEntry, error)
Delete deletes the given object (not found errors are ignored).
func (*ResourceManager) DeleteAll ¶
func (m *ResourceManager) DeleteAll(ctx context.Context, objects []*unstructured.Unstructured, labelSelector map[string]string, skipFor map[string]string) (*ChangeSet, error)
DeleteAll deletes the given set of objects (not found errors are ignored). The given objects are filtered based on the metadata present in-cluster.
func (*ResourceManager) Diff ¶
func (m *ResourceManager) Diff(ctx context.Context, object *unstructured.Unstructured) (*ChangeSetEntry, error)
Diff performs a server-side apply dry-un and returns the fields that changed in YAML format. If the diff contains Kubernetes Secrets, the data values are masked.
func (*ResourceManager) GetOwnerLabels ¶
func (m *ResourceManager) GetOwnerLabels(name, namespace string) map[string]string
GetOwnerLabels returns a map of labels for the specified name and namespace.
func (*ResourceManager) SetOwnerLabels ¶
func (m *ResourceManager) SetOwnerLabels(objects []*unstructured.Unstructured, name, namespace string)
SetOwnerLabels adds the ownership labels to the given objects. The ownership labels are in the format:
<owner.group>/name: <name> <owner.group>/namespace: <namespace>
func (*ResourceManager) Wait ¶
func (m *ResourceManager) Wait(objects []*unstructured.Unstructured, interval, timeout time.Duration) error
Wait checks if the given set of objects has been fully reconciled.
func (*ResourceManager) WaitForTermination ¶
func (m *ResourceManager) WaitForTermination(objects []*unstructured.Unstructured, interval, timeout time.Duration) error
WaitForTermination waits for the given objects to be deleted from the cluster.
type SortableMetas ¶
type SortableMetas []object.ObjMetadata
func (SortableMetas) Len ¶
func (a SortableMetas) Len() int
func (SortableMetas) Less ¶
func (a SortableMetas) Less(i, j int) bool
func (SortableMetas) Swap ¶
func (a SortableMetas) Swap(i, j int)
type SortableUnstructureds ¶
type SortableUnstructureds []*unstructured.Unstructured
func (SortableUnstructureds) Len ¶
func (a SortableUnstructureds) Len() int
func (SortableUnstructureds) Less ¶
func (a SortableUnstructureds) Less(i, j int) bool
func (SortableUnstructureds) Swap ¶
func (a SortableUnstructureds) Swap(i, j int)