applygroup

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applier

type Applier struct {
	Kind Kind

	Parent        *Applier
	ApplyDefaults ApplyDefaults
	ErrorPolicy   string

	ResourceApplyOptions  []client.PatchOption
	ResourceDeleteOptions []client.DeleteOption
	Resource              *unstructured.Unstructured

	Group []Applier
}

Applier represents a deeply nested structure of resources to apply or delete. Best used by unmarshalling from JSON.

applier := applygroup.Applier{
	ApplyDefaults: applygroup.ApplyDefaults{FieldManagerFallback: "applier"},
}

err := json.Unmarshal([]byte(rendered), &applier)

func (*Applier) Apply

func (a *Applier) Apply(ctx context.Context, cli client.Writer) error

Apply applies or deletes the resource(s) represented by this Applier using the given client. It returns an error if any operation fails. For groups, it respects the errorPolicy: "Abort" stops on the first error, "Continue" collects all errors.

func (*Applier) UnmarshalJSONFrom

func (a *Applier) UnmarshalJSONFrom(d *jsontext.Decoder) error

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom. It unmarshals a deeply nested structure of resources to apply or delete. The JSON can be: - null: represents a NoopKind - an object: represents a resource to apply or delete - an array: represents a group of resources to apply or delete

If the object is of kind ApplyGroupConfig, it is treated as a configuration for the group. It must not be the root element. If the array contains an ApplyGroupConfig, it must be the first element in the array. The errorPolicy is inherited by child groups and defaults to "Continue".

If the object has the special deletion options, it is treated as a resource to delete. Otherwise, it is treated as a resource to apply.

Example JSON:

[
  null,
  [
    {
      "apiVersion": "internal.espejote.io/v1",
      "kind": "ApplyGroupConfig",
      "spec": {
        "errorPolicy": "Abort"
      }
    },
    {
      "apiVersion": "v1",
      "kind": "ConfigMap"
    },
    {
      "apiVersion": "v1",
      "kind": "ConfigMap"
    }
  ],
  {
    "apiVersion": "apps/v1",
    "kind": "Deployment"
  }
]

func (*Applier) Walk

func (a *Applier) Walk(f func(*Applier) error) error

Walk calls the given function for this Applier and all its children recursively in DFS order. If the function returns an error, the walk is aborted and the error is returned.

type ApplyDefaults

type ApplyDefaults struct {
	espejotev1alpha1.ApplyOptions
	// FieldManagerFallback is the field manager to use if none is specified for the object.
	FieldManagerFallback string
}

ApplyDefaults holds the default options for applying resources.

type Kind

type Kind int
const (
	NoopKind Kind = iota
	ApplyKind
	ApplyGroupConfigKind
	DeleteKind
	GroupKind
)

func (Kind) String

func (i Kind) String() string