apply

package
v0.27.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: Apache-2.0 Imports: 50 Imported by: 85

Documentation

Index

Constants

View Source
const (
	// ApplySetToolingAnnotation is the key of the label that indicates which tool is used to manage this ApplySet.
	// Tooling should refuse to mutate ApplySets belonging to other tools.
	// The value must be in the format <toolname>/<semver>.
	// Example value: "kubectl/v1.27" or "helm/v3" or "kpt/v1.0.0"
	ApplySetToolingAnnotation = "applyset.kubernetes.io/tooling"

	// ApplySetAdditionalNamespacesAnnotation annotation extends the scope of the ApplySet beyond the parent
	// object's own namespace (if any) to include the listed namespaces. The value is a comma-separated
	// list of the names of namespaces other than the parent's namespace in which objects are found
	// Example value: "kube-system,ns1,ns2".
	ApplySetAdditionalNamespacesAnnotation = "applyset.kubernetes.io/additional-namespaces"

	// ApplySetGRsAnnotation is a list of group-resources used to optimize listing of ApplySet member objects.
	// It is optional in the ApplySet specification, as tools can perform discovery or use a different optimization.
	// However, it is currently required in kubectl.
	// When present, the value of this annotation must be a comma separated list of the group-kinds,
	// in the fully-qualified name format, i.e. <resourcename>.<group>.
	// Example value: "certificates.cert-manager.io,configmaps,deployments.apps,secrets,services"
	ApplySetGRsAnnotation = "applyset.kubernetes.io/contains-group-resources"

	// ApplySetParentIDLabel is the key of the label that makes object an ApplySet parent object.
	// Its value MUST use the format specified in V1ApplySetIdFormat below
	ApplySetParentIDLabel = "applyset.kubernetes.io/id"

	// V1ApplySetIdFormat is the format required for the value of ApplySetParentIDLabel (and ApplysetPartOfLabel).
	// The %s segment is the unique ID of the object itself, which MUST be the base64 encoding
	// (using the URL safe encoding of RFC4648) of the hash of the GKNN of the object it is on, in the form:
	// base64(sha256(<name>.<namespace>.<kind>.<group>)).
	V1ApplySetIdFormat = "applyset-%s-v1"

	// ApplysetPartOfLabel is the key of the label which indicates that the object is a member of an ApplySet.
	// The value of the label MUST match the value of ApplySetParentIDLabel on the parent object.
	ApplysetPartOfLabel = "applyset.kubernetes.io/part-of"

	// ApplysetParentCRDLabel is the key of the label that can be set on a CRD to identify
	// the custom resource type it defines (not the CRD itself) as an allowed parent for an ApplySet.
	ApplysetParentCRDLabel = "applyset.kubernetes.io/is-parent-type"
)

Label and annotation keys from the ApplySet specification. https://git.k8s.io/enhancements/keps/sig-cli/3659-kubectl-apply-prune#design-details-applyset-specification

View Source
const (
	// FieldManagerClientSideApply is the default client-side apply field manager.
	//
	// The default field manager is not `kubectl-apply` to distinguish from
	// server-side apply.
	FieldManagerClientSideApply = "kubectl-client-side-apply"
)

Variables

View Source
var ApplySetToolVersion = version.Get().GitVersion

Functions

func GetApplyFieldManagerFlag added in v0.19.0

func GetApplyFieldManagerFlag(cmd *cobra.Command, serverSide bool) string

GetApplyFieldManagerFlag gets the field manager for kubectl apply if it is not set.

The default field manager is not `kubectl-apply` to distinguish between client-side and server-side apply.

func NewCmdApply

func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command

NewCmdApply creates the `apply` command

func NewCmdApplyEditLastApplied

func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command

NewCmdApplyEditLastApplied created the cobra CLI command for the `apply edit-last-applied` command.

func NewCmdApplySetLastApplied

func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command

NewCmdApplySetLastApplied creates the cobra CLI `apply` subcommand `set-last-applied`.`

func NewCmdApplyViewLastApplied

func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command

NewCmdApplyViewLastApplied creates the cobra CLI `apply` subcommand `view-last-applied`.`

func WarnIfDeleting added in v0.20.0

func WarnIfDeleting(obj runtime.Object, stderr io.Writer)

WarnIfDeleting prints a warning if a resource is being deleted

Types

type ApplyFlags added in v0.23.0

type ApplyFlags struct {
	RecordFlags *genericclioptions.RecordFlags
	PrintFlags  *genericclioptions.PrintFlags

	DeleteFlags *delete.DeleteFlags

	FieldManager   string
	Selector       string
	Prune          bool
	PruneResources []prune.Resource
	ApplySetRef    string
	All            bool
	Overwrite      bool
	OpenAPIPatch   bool

	// DEPRECATED: Use PruneAllowlist instead
	PruneWhitelist []string // TODO: Remove this in kubectl 1.28 or later
	PruneAllowlist []string

	genericclioptions.IOStreams
}

ApplyFlags directly reflect the information that CLI is gathering via flags. They will be converted to Options, which reflect the runtime requirements for the command. This structure reduces the transformation to wiring and makes the logic itself easy to unit test

func NewApplyFlags added in v0.23.0

func NewApplyFlags(streams genericclioptions.IOStreams) *ApplyFlags

NewApplyFlags returns a default ApplyFlags

func (*ApplyFlags) AddFlags added in v0.23.0

func (flags *ApplyFlags) AddFlags(cmd *cobra.Command)

AddFlags registers flags for a cli

func (*ApplyFlags) ToOptions added in v0.23.0

func (flags *ApplyFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, baseName string, args []string) (*ApplyOptions, error)

ToOptions converts from CLI inputs to runtime inputs

type ApplyOptions

type ApplyOptions struct {
	Recorder genericclioptions.Recorder

	PrintFlags *genericclioptions.PrintFlags
	ToPrinter  func(string) (printers.ResourcePrinter, error)

	DeleteOptions *delete.DeleteOptions

	ServerSideApply bool
	ForceConflicts  bool
	FieldManager    string
	Selector        string
	DryRunStrategy  cmdutil.DryRunStrategy
	Prune           bool
	PruneResources  []prune.Resource

	All          bool
	Overwrite    bool
	OpenAPIPatch bool

	ValidationDirective string
	Validator           validation.Schema
	Builder             *resource.Builder
	Mapper              meta.RESTMapper
	DynamicClient       dynamic.Interface
	OpenAPISchema       openapi.Resources

	Namespace        string
	EnforceNamespace bool

	genericclioptions.IOStreams

	// Stores visited objects/namespaces for later use
	// calculating the set of objects to prune.
	VisitedUids       sets.Set[types.UID]
	VisitedNamespaces sets.Set[string]

	// Function run after the objects are generated and
	// stored in the "objects" field, but before the
	// apply is run on these objects.
	PreProcessorFn func() error
	// Function run after all objects have been applied.
	// The standard PostProcessorFn is "PrintAndPrunePostProcessor()".
	PostProcessorFn func() error

	// ApplySet tracks the set of objects that have been applied, for the purposes of pruning.
	// See git.k8s.io/enhancements/keps/sig-cli/3659-kubectl-apply-prune
	ApplySet *ApplySet
	// contains filtered or unexported fields
}

ApplyOptions defines flags and other configuration parameters for the `apply` command

func (*ApplyOptions) GetObjects added in v0.18.0

func (o *ApplyOptions) GetObjects() ([]*resource.Info, error)

GetObjects returns a (possibly cached) version of all the valid objects to apply as a slice of pointer to resource.Info and an error if one or more occurred. IMPORTANT: This function can return both valid objects AND an error, since "ContinueOnError" is set on the builder. This function should not be called until AFTER the "complete" and "validate" methods have been called to ensure that the ApplyOptions is filled in and valid.

func (*ApplyOptions) MarkNamespaceVisited added in v0.18.0

func (o *ApplyOptions) MarkNamespaceVisited(info *resource.Info)

MarkNamespaceVisited keeps track of which namespaces the applied objects belong to. Used for pruning.

func (*ApplyOptions) MarkObjectVisited added in v0.18.0

func (o *ApplyOptions) MarkObjectVisited(info *resource.Info) error

MarkObjectVisited keeps track of UIDs of the applied objects. Used for pruning.

func (*ApplyOptions) PrintAndPrunePostProcessor added in v0.18.0

func (o *ApplyOptions) PrintAndPrunePostProcessor() func() error

PrintAndPrunePostProcessor returns a function which meets the PostProcessorFn function signature. This returned function prints all the objects as a list (if configured for that), and prunes the objects not applied. The returned function is the standard apply post processor.

func (*ApplyOptions) Run

func (o *ApplyOptions) Run() error

Run executes the `apply` command.

func (*ApplyOptions) SetObjects added in v0.18.0

func (o *ApplyOptions) SetObjects(infos []*resource.Info)

SetObjects stores the set of objects (as resource.Info) to be subsequently applied.

func (*ApplyOptions) Validate added in v0.23.0

func (o *ApplyOptions) Validate() error

Validate verifies if ApplyOptions are valid and without conflicts.

type ApplySet added in v0.27.0

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

ApplySet tracks the information about an applyset apply/prune

func NewApplySet added in v0.27.0

func NewApplySet(parent *ApplySetParentRef, tooling ApplySetTooling, mapper meta.RESTMapper, client resource.RESTClient) *ApplySet

NewApplySet creates a new ApplySet object tracked by the given parent object.

func (*ApplySet) AddLabels added in v0.27.0

func (a *ApplySet) AddLabels(objects ...*resource.Info) error

addLabels sets our tracking labels on each object; this should be called as part of loading the objects.

func (*ApplySet) AllPrunableNamespaces added in v0.27.0

func (a *ApplySet) AllPrunableNamespaces() []string

AllPrunableNamespaces returns the list of all namespaces that should be considered for pruning. This is potentially a superset of the namespaces that actually contain resources.

func (*ApplySet) AllPrunableResources added in v0.27.0

func (a *ApplySet) AllPrunableResources() []*meta.RESTMapping

AllPrunableResources returns the list of all resources that should be considered for pruning. This is potentially a superset of the resources types that actually contain resources.

func (*ApplySet) BeforeApply added in v0.27.0

func (a *ApplySet) BeforeApply(objects []*resource.Info, dryRunStrategy cmdutil.DryRunStrategy, validationDirective string) error

BeforeApply should be called before applying the objects. It pre-updates the parent object so that it covers the resources that will be applied. In this way, even if we are interrupted, we will not leak objects.

func (ApplySet) FieldManager added in v0.27.0

func (a ApplySet) FieldManager() string

func (*ApplySet) FindAllObjectsToPrune added in v0.27.0

func (a *ApplySet) FindAllObjectsToPrune(ctx context.Context, dynamicClient dynamic.Interface, visitedUids sets.Set[types.UID]) ([]PruneObject, error)

FindAllObjectsToPrune returns the list of objects that will be pruned. Calling this instead of Prune can be useful for dry-run / diff behaviour.

func (ApplySet) ID added in v0.27.0

func (a ApplySet) ID() string

func (*ApplySet) LabelSelectorForMembers added in v0.27.0

func (a *ApplySet) LabelSelectorForMembers() string

func (*ApplySet) LabelsForMember added in v0.27.0

func (a *ApplySet) LabelsForMember() map[string]string

func (*ApplySet) Prune added in v0.27.0

func (a *ApplySet) Prune(ctx context.Context, o *ApplyOptions) error

Prune deletes any objects from the apiserver that are no longer in the applyset.

func (ApplySet) Validate added in v0.27.0

func (a ApplySet) Validate(ctx context.Context, client dynamic.Interface) error

Validate imposes restrictions on the parent object that is used to track the applyset.

type ApplySetDeleteOptions added in v0.27.0

type ApplySetDeleteOptions struct {
	CascadingStrategy metav1.DeletionPropagation
	DryRunStrategy    cmdutil.DryRunStrategy
	GracePeriod       int

	Printer printers.ResourcePrinter

	IOStreams genericclioptions.IOStreams
}

type ApplySetParentRef added in v0.27.0

type ApplySetParentRef struct {
	Name      string
	Namespace string
	*meta.RESTMapping
}

ApplySetParentRef stores object and type meta for the parent object that is used to track the applyset.

func ParseApplySetParentRef added in v0.27.0

func ParseApplySetParentRef(parentRefStr string, mapper meta.RESTMapper) (*ApplySetParentRef, error)

ParseApplySetParentRef creates a new ApplySetParentRef from a parent reference in the format [RESOURCE][.GROUP]/NAME

func (ApplySetParentRef) IsNamespaced added in v0.27.0

func (p ApplySetParentRef) IsNamespaced() bool

func (ApplySetParentRef) String added in v0.27.0

func (p ApplySetParentRef) String() string

String returns the string representation of the parent object using the same format that we expect to receive in the --applyset flag on the CLI.

type ApplySetTooling added in v0.27.0

type ApplySetTooling struct {
	Name    string
	Version string
}

func (ApplySetTooling) String added in v0.27.0

func (t ApplySetTooling) String() string

type ApplySetUpdateMode added in v0.27.0

type ApplySetUpdateMode string

type PatchBuffer

type PatchBuffer struct {
	Patch     []byte
	PatchType types.PatchType
}

PatchBuffer caches changes that are to be applied.

type Patcher

type Patcher struct {
	Mapping *meta.RESTMapping
	Helper  *resource.Helper

	Overwrite bool
	BackOff   clockwork.Clock

	Force             bool
	CascadingStrategy metav1.DeletionPropagation
	Timeout           time.Duration
	GracePeriod       int

	// If set, forces the patch against a specific resourceVersion
	ResourceVersion *string

	// Number of retries to make if the patch fails with conflict
	Retries int

	OpenapiSchema openapi.Resources
}

Patcher defines options to patch OpenAPI objects.

func (*Patcher) Patch

func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespace, name string, errOut io.Writer) ([]byte, runtime.Object, error)

Patch tries to patch an OpenAPI resource. On success, returns the merge patch as well the final patched object. On failure, returns an error.

type PruneObject added in v0.27.0

type PruneObject struct {
	Name      string
	Namespace string
	Mapping   *meta.RESTMapping
	Object    runtime.Object
}

PruneObject is an apiserver object that should be deleted as part of prune.

func (*PruneObject) String added in v0.27.0

func (p *PruneObject) String() string

String returns a human-readable name of the object, for use in debug messages.

type SetLastAppliedOptions

type SetLastAppliedOptions struct {
	CreateAnnotation bool

	PrintFlags *genericclioptions.PrintFlags
	PrintObj   printers.ResourcePrinterFunc

	FilenameOptions resource.FilenameOptions

	genericclioptions.IOStreams
	// contains filtered or unexported fields
}

SetLastAppliedOptions defines options for the `apply set-last-applied` command.`

func NewSetLastAppliedOptions

func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastAppliedOptions

NewSetLastAppliedOptions takes option arguments from a CLI stream and returns it at SetLastAppliedOptions type.

func (*SetLastAppliedOptions) Complete

func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error

Complete populates dry-run and output flag options.

func (*SetLastAppliedOptions) RunSetLastApplied

func (o *SetLastAppliedOptions) RunSetLastApplied() error

RunSetLastApplied executes the `set-last-applied` command according to SetLastAppliedOptions.

func (*SetLastAppliedOptions) Validate

func (o *SetLastAppliedOptions) Validate() error

Validate checks SetLastAppliedOptions for validity.

type ViewLastAppliedOptions

type ViewLastAppliedOptions struct {
	FilenameOptions              resource.FilenameOptions
	Selector                     string
	LastAppliedConfigurationList []string
	OutputFormat                 string
	All                          bool
	Factory                      cmdutil.Factory

	genericclioptions.IOStreams
}

ViewLastAppliedOptions defines options for the `apply view-last-applied` command.`

func NewViewLastAppliedOptions

func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastAppliedOptions

NewViewLastAppliedOptions takes option arguments from a CLI stream and returns it at ViewLastAppliedOptions type.

func (*ViewLastAppliedOptions) Complete

func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args []string) error

Complete checks an object for last-applied-configuration annotations.

func (*ViewLastAppliedOptions) RunApplyViewLastApplied

func (o *ViewLastAppliedOptions) RunApplyViewLastApplied(cmd *cobra.Command) error

RunApplyViewLastApplied executes the `view-last-applied` command according to ViewLastAppliedOptions.

func (*ViewLastAppliedOptions) Validate

func (o *ViewLastAppliedOptions) Validate() error

Validate checks ViewLastAppliedOptions for validity.

Jump to

Keyboard shortcuts

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