Documentation ¶
Index ¶
- Constants
- func ApplyPatchToUnstructured(obj *unstructured.Unstructured, patch jsondiff.Patch) error
- func GenerateRemovePatch(paths ...string) jsondiff.Patch
- func MaskSecretPatchData(patch jsondiff.Patch) jsondiff.Patch
- type Diff
- type DiffSet
- type DiffType
- type ExclusionSelector
- type FieldOwner
- type Graceful
- type IgnorePaths
- type IgnoreRule
- type IgnoreRules
- type ListOption
- type ListOptions
- type MaskSecrets
- type Rationalize
- type ResourceOption
- type ResourceOptions
- type Selector
- type SelectorRegex
- func (s *SelectorRegex) MatchAnnotationSelector(a map[string]string) bool
- func (s *SelectorRegex) MatchGVK(group, version, kind string) bool
- func (s *SelectorRegex) MatchLabelSelector(l map[string]string) bool
- func (s *SelectorRegex) MatchName(n string) bool
- func (s *SelectorRegex) MatchNamespace(ns string) bool
- func (s *SelectorRegex) MatchUnstructured(obj *unstructured.Unstructured) bool
Constants ¶
const IgnorePathRoot = ""
IgnorePathRoot ignores the root of a JSON document, i.e., the entire document.
Variables ¶
This section is empty.
Functions ¶
func ApplyPatchToUnstructured ¶
func ApplyPatchToUnstructured(obj *unstructured.Unstructured, patch jsondiff.Patch) error
ApplyPatchToUnstructured applies the given JSON patch to the given unstructured object. The patch is applied in-place. It permits the patch to contain "remove" operations that target non-existing paths.
func GenerateRemovePatch ¶
GenerateRemovePatch generates a JSON patch that removes the given JSON pointer paths.
func MaskSecretPatchData ¶
MaskSecretPatchData masks the data and stringData fields of a Secret object in the given JSON patch. It replaces the values with a default mask value if the field is added or removed. Otherwise, it replaces the values with a before/after mask value if the field is modified.
Types ¶
type Diff ¶
type Diff struct { // Type of change detected. Type DiffType // DesiredObject is the client.Object that was used as the desired state to // generate the Patch. DesiredObject client.Object // ClusterObject is the client.Object in the cluster that was used as the // current state to generate the Patch. // It is nil if the resource does not exist in the cluster or has been // excluded, which can be detected by checking the Type field for the // value DiffTypeCreate or DiffTypeExclude. ClusterObject client.Object // Patch with the changes detected for the resource. Patch jsondiff.Patch }
Diff is a change detected by the server-side apply diff operation.
func NewDiffForUnstructured ¶
NewDiffForUnstructured creates a new Diff for the given unstructured object.
func Unstructured ¶
func Unstructured(ctx context.Context, c client.Client, obj *unstructured.Unstructured, opts ...ResourceOption) (*Diff, error)
Unstructured runs a dry-run patch against a Kubernetes cluster and compares the result against the original object. It returns a Diff, which contains differences between the original and the dry-run object.
It accepts a list of ResourceOption, which can be used to exclude an object using an ExclusionSelector, or to ignore specific JSON pointers within the object using IgnorePaths.
The DiffType of the returned Diff is DiffTypeNone if the dry-run object is identical to the original object, DiffTypeCreate if the dry-run object doesn't exist, or DiffTypeUpdate if the dry-run object is different from the original object.
When the object is excluded using an ExclusionSelector or an IgnorePathRoot, the DiffType is DiffTypeExclude.
func (*Diff) GetName ¶ added in v0.35.0
GetName returns the name of the resource the Diff applies to.
func (*Diff) GetNamespace ¶ added in v0.35.0
GetNamespace returns the namespace of the resource the Diff applies to.
func (*Diff) GroupVersionKind ¶
func (d *Diff) GroupVersionKind() schema.GroupVersionKind
GroupVersionKind returns the GroupVersionKind of the resource the Diff applies to.
type DiffSet ¶
type DiffSet []*Diff
DiffSet is a list of changes.
func UnstructuredList ¶
func UnstructuredList(ctx context.Context, c client.Client, objs []*unstructured.Unstructured, opts ...ListOption) (DiffSet, error)
UnstructuredList runs a dry-run patch for a list of Kubernetes resources against a Kubernetes cluster and compares the result against the original objects. It returns a DiffSet, which contains differences between the original and the dry-run objects.
It accepts a list of ListOption, which can be used to exclude an object using an ExclusionSelector, or to ignore specific JSON pointers within an object using an IgnoreRule.
When Graceful is passed as an option, the function will return a DiffSet with the errors that occurred during the dry-run patch, but will not fail.
func (DiffSet) HasChanges ¶
HasChanges returns true if the DiffSet contains a Diff of type DiffTypeCreate or DiffTypeUpdate.
type DiffType ¶
type DiffType string
DiffType is the type of change detected by the server-side apply diff operation.
const ( // DiffTypeCreate indicates that the resource does not exist // and needs to be created. DiffTypeCreate DiffType = "create" // DiffTypeUpdate indicates that the resource exists and needs // to be updated. DiffTypeUpdate DiffType = "update" // DiffTypeExclude indicates that the resource is excluded from // the diff. DiffTypeExclude DiffType = "exclude" // DiffTypeNone indicates that the resource exists and is // identical to the dry-run object. DiffTypeNone DiffType = "none" )
type ExclusionSelector ¶
ExclusionSelector sets the annotations or labels which mark a resource to be excluded from the server-side apply diff.
func (ExclusionSelector) ApplyToList ¶
func (e ExclusionSelector) ApplyToList(_ *ListOptions)
ApplyToList applies this configuration to the given options.
func (ExclusionSelector) ApplyToResource ¶
func (e ExclusionSelector) ApplyToResource(opts *ResourceOptions)
ApplyToResource applies this configuration to the given options.
type FieldOwner ¶
type FieldOwner string
FieldOwner sets the field manager for the server-side apply request.
func (FieldOwner) ApplyToList ¶
func (f FieldOwner) ApplyToList(_ *ListOptions)
ApplyToList applies this configuration to the given options.
func (FieldOwner) ApplyToResource ¶
func (f FieldOwner) ApplyToResource(opts *ResourceOptions)
ApplyToResource applies this configuration to the given options.
type Graceful ¶
type Graceful bool
Graceful enables graceful handling of errors during a server-side apply diff operation. If enabled, the diff operation will continue even if an error occurs for a single resource.
func (Graceful) ApplyToList ¶
func (f Graceful) ApplyToList(opts *ListOptions)
ApplyToList applies this configuration to the given options.
type IgnorePaths ¶
type IgnorePaths []string
IgnorePaths sets the JSON pointers to ignore when comparing objects.
func (IgnorePaths) ApplyToResource ¶
func (i IgnorePaths) ApplyToResource(opts *ResourceOptions)
ApplyToResource applies this configuration to the given options.
type IgnoreRule ¶
type IgnoreRule struct { // Paths is a list of JSON pointers (RFC 6901) to ignore. // To ignore the entire resource, use IgnorePathRoot. Paths []string // Selector is a selector that matches the resources to ignore. Selector *Selector }
IgnoreRule contains the paths to ignore and an optional selector that matches one or more resources.
type IgnoreRules ¶
type IgnoreRules []IgnoreRule
IgnoreRules sets the JSON pointers to ignore when comparing objects.
func (IgnoreRules) ApplyToList ¶
func (i IgnoreRules) ApplyToList(opts *ListOptions)
ApplyToList applies this configuration to the given options.
type ListOption ¶
type ListOption interface {
ApplyToList(options *ListOptions)
}
ListOption is some configuration that modifies the diffing behavior for a set of resources.
type ListOptions ¶
type ListOptions struct { // IgnoreRules is a list of rules that specify which paths to ignore // for which resources. IgnoreRules []IgnoreRule // Graceful enables graceful handling of errors during a server-side // apply diff operation. If enabled, the diff operation will continue // even if an error occurs for a single resource. Graceful bool }
ListOptions holds options for the server-side apply diff operation.
func (*ListOptions) ApplyOptions ¶
func (o *ListOptions) ApplyOptions(opts []ListOption) *ListOptions
ApplyOptions applies the given options on these options, and then returns itself (for convenient chaining).
type MaskSecrets ¶
type MaskSecrets bool
MaskSecrets sets the flag to mask secrets in the diff.
func (MaskSecrets) ApplyToList ¶
func (m MaskSecrets) ApplyToList(_ *ListOptions)
ApplyToList applies this configuration to the given options.
func (MaskSecrets) ApplyToResource ¶
func (m MaskSecrets) ApplyToResource(opts *ResourceOptions)
ApplyToResource applies this configuration to the given options.
type Rationalize ¶
type Rationalize bool
Rationalize enables the rationalization of JSON operations in the server-side apply diff.
func (Rationalize) ApplyToList ¶
func (r Rationalize) ApplyToList(_ *ListOptions)
ApplyToList applies this configuration to the given options.
func (Rationalize) ApplyToResource ¶
func (r Rationalize) ApplyToResource(opts *ResourceOptions)
ApplyToResource applies this configuration to the given options.
type ResourceOption ¶
type ResourceOption interface {
ApplyToResource(options *ResourceOptions)
}
ResourceOption is some configuration that modifies the diffing behavior for a single resource.
type ResourceOptions ¶
type ResourceOptions struct { // FieldManager is the name of the user or component submitting // the server-side apply request. FieldManager string // IgnorePaths is a list of JSON pointers to ignore when comparing objects. IgnorePaths []string // ExclusionSelector is a map of annotations or labels which mark a // resource to be excluded from the server-side apply diff. ExclusionSelector map[string]string // MaskSecrets enables masking of Kubernetes Secrets in the diff. MaskSecrets bool // Rationalize enables rationalization of JSON operations in the diff. Rationalize bool }
ResourceOptions holds options for the server-side apply diff operation.
func (*ResourceOptions) ApplyOptions ¶
func (o *ResourceOptions) ApplyOptions(opts []ResourceOption) *ResourceOptions
ApplyOptions applies the given options on these options, and then returns itself (for convenient chaining).
type Selector ¶
type Selector struct { // Group defines a regular expression to filter resources by their // API group. Group string // Version defines a regular expression to filter resources by their // API version. Version string // Kind defines a regular expression to filter resources by their // API kind. Kind string // Name defines a regular expression to filter resources by their // name. Name string // Namespace defines a regular expression to filter resources by their // namespace. Namespace string // AnnotationSelector defines a selector to filter resources by their // annotations in the format of a label selection expression. // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api AnnotationSelector string // LabelSelector defines a selector to filter resources by their labels // in the format of a label selection expression. // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api LabelSelector string }
Selector is a struct that contains the information needed to select a Kubernetes resource. All fields are optional.
type SelectorRegex ¶
type SelectorRegex struct {
// contains filtered or unexported fields
}
SelectorRegex is a struct that contains the regular expressions needed to select a Kubernetes resource.
func NewSelectorRegex ¶
func NewSelectorRegex(s *Selector) (sr *SelectorRegex, err error)
NewSelectorRegex returns a pointer to a new SelectorRegex which uses the same condition as s.
func (*SelectorRegex) MatchAnnotationSelector ¶
func (s *SelectorRegex) MatchAnnotationSelector(a map[string]string) bool
MatchAnnotationSelector returns true if the annotation selector in selector is empty or the annotation selector matches the annotations in selector. If the selector is nil, it returns true.
func (*SelectorRegex) MatchGVK ¶
func (s *SelectorRegex) MatchGVK(group, version, kind string) bool
MatchGVK returns true if the group, version and kind in selector are empty or the group, version and kind match the group, version and kind in selector. If the selector is nil, it returns true.
func (*SelectorRegex) MatchLabelSelector ¶
func (s *SelectorRegex) MatchLabelSelector(l map[string]string) bool
MatchLabelSelector returns true if the label selector in selector is empty or the label selector matches the labels in selector. If the selector is nil, it returns true.
func (*SelectorRegex) MatchName ¶
func (s *SelectorRegex) MatchName(n string) bool
MatchName returns true if the name in selector is empty or the name matches the name in selector. If the selector is nil, it returns true.
func (*SelectorRegex) MatchNamespace ¶
func (s *SelectorRegex) MatchNamespace(ns string) bool
MatchNamespace returns true if the namespace in selector is empty or the namespace matches the namespace in selector. If the selector is nil, it returns true.
func (*SelectorRegex) MatchUnstructured ¶
func (s *SelectorRegex) MatchUnstructured(obj *unstructured.Unstructured) bool
MatchUnstructured returns true if the unstructured object matches all the conditions in the selector. If the selector is nil, it returns true.