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 ¶
func IsHealthy ¶
func IsHealthy(u *unstructured.Unstructured) (bool, string, error)
IsHealthy reports whether the object should be considered "healthy"
Types ¶
type ApplyResults ¶
type ApplyResults struct { Objects []ObjectStatus // 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 (*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 ¶
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 ComputeHealthCallback ¶
type ComputeHealthCallback func(*unstructured.Unstructured) (bool, string, error)
type HealthInfo ¶
type ObjectStatus ¶
type ObjectStatus struct { GVK schema.GroupVersionKind NameNamespace types.NamespacedName Apply ApplyInfo Health HealthInfo LastApplied *unstructured.Unstructured }
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 ComputeHealth ComputeHealthCallback }
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 ¶
NewParentRef initialize a ParentRef object.
func (*ParentRef) GetSubject ¶
GetSubject returns the parent runtime.Object
func (*ParentRef) GroupVersionKind ¶
func (p *ParentRef) GroupVersionKind() schema.GroupVersionKind
GroupVersionKind returns the parent GroupVersionKind
func (*ParentRef) RESTMapping ¶
func (p *ParentRef) RESTMapping() *meta.RESTMapping
RESTMapping returns the parent RESTMapping