applyset

package
v0.0.0-...-83bd9c0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This package provides Parent object related methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyResults

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

ApplyResults contains the results of an Apply operation.

func (*ApplyResults) AllApplied

func (r *ApplyResults) AllApplied() bool

AllApplied is true if the desired state has been successfully applied for all objects. Note: you likely also want to check AllHealthy, if you want to be sure the objects are "ready".

func (*ApplyResults) AllHealthy

func (r *ApplyResults) AllHealthy() bool

AllHealthy is true if all the objects have been applied and have converged to a "ready" state. Note that this is only meaningful if AllApplied is true.

type ApplySet

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

ApplySet is a set of objects that we want to apply to the cluster.

An ApplySet has a few cases which it tries to optimize for: * We can change the objects we're applying * We want to watch the objects we're applying / be notified of changes * We want to know when the objects we apply are "healthy" * We expose a "try once" method to better support running from a controller.

TODO: Pluggable health functions.

func New

func New(options Options) (*ApplySet, error)

New constructs a new ApplySet

func (*ApplySet) ApplyOnce

func (a *ApplySet) ApplyOnce(ctx context.Context) (*ApplyResults, error)

ApplyOnce will make one attempt to apply all objects and observe their health. It does not wait for the objects to become healthy, but will report their health.

TODO: Limit the amount of time this takes, particularly if we have thousands of objects.

We don't _have_ to try to apply all objects if it is taking too long.

TODO: We re-apply every object every iteration; we should be able to do better.

func (*ApplySet) SetDesiredObjects

func (a *ApplySet) SetDesiredObjects(objects []ApplyableObject) error

SetDesiredObjects is used to replace the desired state of all the objects. Any objects not specified are removed from the "desired" set.

func (*ApplySet) WithParent

func (a *ApplySet) WithParent(ctx context.Context, kapplyset *kubectlapply.ApplySet) error

WithParent guarantees the parent has the right applyset labels. It uses "superset" mode to determine the "applyset.kubernetes.io/contains-group-resources" which contains both

previous manifests GVRs and the current manifests GVRs.

type ApplyableObject

type ApplyableObject interface {
	// GroupVersionKind returns the GroupVersionKind structure describing the type of the object
	GroupVersionKind() schema.GroupVersionKind
	// GetNamespace returns the namespace of the object
	GetNamespace() string
	// GetName returns the name of the object
	GetName() string

	// The object should implement json marshalling
	json.Marshaler
}

ApplyableObject is implemented by objects that can be applied to the cluster. We don't need much, so this might allow for more efficient implementations in future.

type Options

type Options struct {
	// Client is the dynamic kubernetes client used to apply objects to the k8s cluster.
	Client dynamic.Interface
	// ParentClient is the controller runtime client used to apply parent.
	ParentClient client.Client
	// RESTMapper is used to map object kind to resources, and to know if objects are cluster-scoped.
	RESTMapper meta.RESTMapper
	// PatchOptions holds the options used when applying, in particular the fieldManager
	PatchOptions  metav1.PatchOptions
	DeleteOptions metav1.DeleteOptions
	Prune         bool
	Parent        Parent
	Tooling       string
}

Options holds the parameters for building an ApplySet.

type Parent

type Parent interface {
	GroupVersionKind() schema.GroupVersionKind
	Name() string
	Namespace() string
	RESTMapping() *meta.RESTMapping
	GetSubject() runtime.Object
}

Parent is aimed for adaption. We want users to us Parent rather than the third-party/forked ParentRef directly. This gives us more flexibility to change the third-party/forked without introducing breaking changes to users.

type ParentRef

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

ParentRef defines the Parent object information

func NewParentRef

func NewParentRef(object runtime.Object, name, namespace string, rest *meta.RESTMapping) *ParentRef

NewParentRef initialize a ParentRef object.

func (*ParentRef) GetSubject

func (p *ParentRef) GetSubject() runtime.Object

GetSubject returns the parent runtime.Object

func (*ParentRef) GroupVersionKind

func (p *ParentRef) GroupVersionKind() schema.GroupVersionKind

GroupVersionKind returns the parent GroupVersionKind

func (*ParentRef) Name

func (p *ParentRef) Name() string

Name returns the parent Name

func (*ParentRef) Namespace

func (p *ParentRef) Namespace() string

Namespace returns the parent Namespace

func (*ParentRef) RESTMapping

func (p *ParentRef) RESTMapping() *meta.RESTMapping

RESTMapping returns the parent RESTMapping

Jump to

Keyboard shortcuts

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