dependency

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Copyright 2024 The ORC 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureFinalizer

func EnsureFinalizer(ctx context.Context, k8sClient client.Client, obj client.Object, finalizer string, fieldOwner client.FieldOwner) error

EnsureFinalizer adds a finalizer to the given object if it is not already present. It does nothing if the finalizer is already present.

func OverrideDependencyName

func OverrideDependencyName(name string) deletionGuardOpt

Types

type DeletionGuardDependency

type DeletionGuardDependency[
	objectTP ObjectType[objectT],
	objectListTP ObjectListType[objectListT, objectT],
	depTP DependencyType[depT],

	objectT any, objectListT any, depT any,
] struct {
	Dependency[objectTP, objectListTP, depTP, objectT, objectListT, depT]
	// contains filtered or unexported fields
}

func NewDeletionGuardDependency

func NewDeletionGuardDependency[
	objectListTP ObjectListType[objectListT, objectT],
	depTP DependencyType[depT],

	objectTP ObjectType[objectT],
	objectT any, objectListT any, depT any,
](indexName string, getDependencyRefs func(objectTP) []string, finalizer string, fieldOwner client.FieldOwner, opts ...deletionGuardOpt) DeletionGuardDependency[objectTP, objectListTP, depTP, objectT, objectListT, depT]

NewDeletionGuardDependency returns a Dependency which can additionally create a deletion guard for the dependency. See NewDependency for a discussion of the base functionality.

In addition to the arguments required by NewDependency, NewDeletionGuardDependency requires: - finalizer: the string to add to Finalizers in objects that we depend on - fieldOwner: a client.FieldOwner identifying this controller when adding a finalizer to objects we depend on

func (*DeletionGuardDependency[objectTP, objectListTP, depTP, objectT, objectListT, depT]) AddToManager

func (d *DeletionGuardDependency[objectTP, objectListTP, depTP, objectT, objectListT, depT]) AddToManager(ctx context.Context, mgr ctrl.Manager) error

func (*DeletionGuardDependency[objectTP, _, depTP, _, _, depT]) GetDependencies

func (d *DeletionGuardDependency[objectTP, _, depTP, _, _, depT]) GetDependencies(ctx context.Context, k8sClient client.Client, obj objectTP, readyFilter func(depTP) bool) (map[string]depTP, progress.ReconcileStatus)

GetDependencies returns the dependencies of the given object, ensuring that all returned dependencies have the required finalizer. It returns: - a map of name -> object containing all objects which exist and are ready - a list of progressStatus for all dependencies which are not yet ready - an error

Dependencies are filtered by the readyFilter argument. Dependencies which are not ready will be in progressStatus but not in the returned object map.

func (*DeletionGuardDependency[objectTP, _, depTP, _, _, depT]) GetDependency

func (d *DeletionGuardDependency[objectTP, _, depTP, _, _, depT]) GetDependency(ctx context.Context, k8sClient client.Client, obj objectTP, readyFilter func(depTP) bool) (depTP, progress.ReconcileStatus)

GetDependency is a convenience wrapper around GetDependencies when the caller only expects a single result.

type Dependency

type Dependency[
	objectTP ObjectType[objectT],
	objectListTP ObjectListType[objectListT, objectT],
	depTP DependencyType[depT],

	objectT any, objectListT any, depT any,
] struct {
	// contains filtered or unexported fields
}

func NewDependency

func NewDependency[
	objectListTP ObjectListType[objectListT, objectT],
	depTP DependencyType[depT],

	objectTP ObjectType[objectT],
	objectT any, objectListT any, depT any,
](indexName string, getDependencyRefs func(objectTP) []string) Dependency[objectTP, objectListTP, depTP, objectT, objectListT, depT]

NewDependency returns a new Dependency, which can perform tasks necessary to manage a dependency between 2 object types. The 2 object types are:

  • Object: this is the 'source' object.
  • Dependency: this is the object that a 'source' object may depend on.

For example, a Port may depend on a Subnet, because it references one or more Subnets in its Addresses. In this case 'Object' is the Port, and 'Dependency' is the subnet.

NewDependency has several type parameters, but only the first 2 are required as all the rest can be inferred. The 2 required parameters are:

  • pointer to the List type of Object
  • pointer to the Dependency type

NewDependency takes the following arguments:

  • indexName: a name representing the path to the Dependency reference in Object.
  • getDependencyRefs: a function that takes a pointer to Object and returns a slice of strings containing the names of Dependencies

Taking the Port -> Subnet example, the required type parameter is:

  • *PortList: pointer to the list type of Port

and the arguments are:

  • indexName: "spec.resource.addresses[].subnetRef" - a symbolic path to the subnet reference in a Port
  • getDependencyRefs: func(object *Port) []string{ ... returns a slice containing all subnetRefs in this Port's addresses ... }

func (*Dependency[_, _, _, _, _, _]) AddToManager

func (d *Dependency[_, _, _, _, _, _]) AddToManager(ctx context.Context, mgr ctrl.Manager) error

func (*Dependency[_, objectListTP, depTP, objectT, objectListT, _]) GetObjectsForDependency

func (d *Dependency[_, objectListTP, depTP, objectT, objectListT, _]) GetObjectsForDependency(ctx context.Context, k8sClient client.Client, dep depTP) ([]objectT, error)

GetObjectsForDependency returns a slice of all Objects which depend on the given Dependency.

func (*Dependency[objectTP, _, depTP, _, _, depT]) WatchEventHandler

func (d *Dependency[objectTP, _, depTP, _, _, depT]) WatchEventHandler(log logr.Logger, k8sClient client.Client) (handler.EventHandler, error)

WatchEventHandler returns an EventHandler which maps a Dependency to all Objects which depend on it

type DependencyType

type DependencyType[depT any] interface {
	client.Object
	// contains filtered or unexported methods
}

type ObjectListType

type ObjectListType[objectListT any, objectT any] interface {
	client.ObjectList

	GetItems() []objectT
	// contains filtered or unexported methods
}

type ObjectType

type ObjectType[objectT any] interface {
	client.Object
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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