controller_common

package
v0.0.0-...-21a03b3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0, Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NvidiaAnnotationHashKey indicates annotation name for last applied hash by the operator
	NvidiaAnnotationHashKey = "nvidia.com/last-applied-hash"
)

Variables

This section is empty.

Functions

func AddFinalizer

func AddFinalizer(obj client.Object)

func CanonicalizePodCliqueSet

func CanonicalizePodCliqueSet(gangSet *grovev1alpha1.PodCliqueSet) *grovev1alpha1.PodCliqueSet

func CanonicalizePodSpec

func CanonicalizePodSpec(podSpec *corev1.PodSpec) *corev1.PodSpec

CanonicalizePodSpec sorts the pod spec in a way that is deterministic and easy to reason about.

func ContainsFinalizer

func ContainsFinalizer(obj client.Object) bool

func CopySpec

func CopySpec(source, destination client.Object) error

CopySpec copies only the Spec field from source to destination using Unstructured

func DetectGroveAvailability

func DetectGroveAvailability(ctx context.Context, mgr ctrl.Manager) bool

DetectGroveAvailability checks if Grove is available by checking if the Grove API group is registered This approach uses the discovery client which is simpler and more reliable

func DetectKaiSchedulerAvailability

func DetectKaiSchedulerAvailability(ctx context.Context, mgr ctrl.Manager) bool

DetectKaiSchedulerAvailability checks if Kai-scheduler is available by checking if the scheduling.run.ai API group is registered This approach uses the discovery client which is simpler and more reliable

func DetectLWSAvailability

func DetectLWSAvailability(ctx context.Context, mgr ctrl.Manager) bool

DetectLWSAvailability checks if LWS is available by checking if the LWS API group is registered This approach uses the discovery client which is simpler and more reliable

func DetectVolcanoAvailability

func DetectVolcanoAvailability(ctx context.Context, mgr ctrl.Manager) bool

detectVolcanoAvailability checks if Volcano is available by checking if the Volcano API group is registered This approach uses the discovery client which is simpler and more reliable

func EphemeralDeploymentEventFilter

func EphemeralDeploymentEventFilter(config Config) predicate.Predicate

func GetResourceHash

func GetResourceHash(obj any) (string, error)

GetResourceHash returns a consistent hash for the given object spec

func GetResourcesConfig

func GetResourcesConfig(resources *v1alpha1.Resources) (*corev1.ResourceRequirements, error)

func GetSpecHash

func GetSpecHash(obj client.Object) (string, error)

func HandleFinalizer

func HandleFinalizer[T client.Object](ctx context.Context, obj T, writer client.Writer, finalizer Finalizer[T]) (bool, error)

func IsSpecChanged

func IsSpecChanged(current client.Object, desired client.Object) (*string, error)

IsSpecChanged returns the new hash if the spec has changed between the existing one It compares the actual current spec hash with the desired spec hash to detect manual edits

func RemoveFinalizer

func RemoveFinalizer(obj client.Object)

func ScaleResource

func ScaleResource(ctx context.Context, scaleClient scale.ScalesGetter, gvr schema.GroupVersionResource, namespace, name string, replicas int32) error

ScaleResource scales any Kubernetes resource using the Scale subresource

func SortKeys

func SortKeys(obj interface{}) interface{}

SortKeys recursively sorts the keys of a map to ensure consistent serialization

func SyncResource

func SyncResource[T client.Object](ctx context.Context, r Reconciler, parentResource client.Object, generateResource ResourceGenerator[T]) (modified bool, res T, err error)

Types

type Config

type Config struct {
	// Enable resources filtering, only the resources belonging to the given namespace will be handled.
	RestrictedNamespace string
	Grove               GroveConfig
	LWS                 LWSConfig
	KaiScheduler        KaiSchedulerConfig
	EtcdAddress         string
	NatsAddress         string
	IngressConfig       IngressConfig
	// ModelExpressURL is the URL of the Model Express server to inject into all pods
	ModelExpressURL string
	// PrometheusEndpoint is the URL of the Prometheus endpoint to use for metrics
	PrometheusEndpoint string
	MpiRun             MpiRunConfig
	// RBAC configuration for cross-namespace resource management
	RBAC RBACConfig
	// ExcludedNamespaces is a thread-safe set of namespaces to exclude (cluster-wide mode only)
	ExcludedNamespaces ExcludedNamespacesInterface

	// DiscoveryBackend is the discovery backend to use. By default, will rely on ETCD for discovery. Can be set to "kubernetes" to use Kubernetes API for service discovery.
	DiscoveryBackend string

	// WebhooksEnabled indicates whether admission webhooks are enabled
	// When true, controllers skip validation (webhooks handle it)
	// When false, controllers perform validation (defense in depth)
	WebhooksEnabled bool
}

func (Config) GetDiscoveryBackend

func (c Config) GetDiscoveryBackend(annotations map[string]string) string

func (Config) IsK8sDiscoveryEnabled

func (c Config) IsK8sDiscoveryEnabled(annotations map[string]string) bool

For DGD, pass in the meta annotations For DCD, pass in the spec annotations

type ExcludedNamespacesInterface

type ExcludedNamespacesInterface interface {
	Contains(namespace string) bool
}

ExcludedNamespacesInterface defines the interface for checking namespace exclusions

type Finalizer

type Finalizer[T client.Object] interface {
	FinalizeResource(ctx context.Context, obj T) error
}

type GroveConfig

type GroveConfig struct {
	// Enabled is automatically determined by checking if Grove CRDs are installed in the cluster
	Enabled bool
	// TerminationDelay configures the termination delay for Grove PodCliqueSets
	TerminationDelay time.Duration
}

type IngressConfig

type IngressConfig struct {
	VirtualServiceGateway      string
	IngressControllerClassName string
	IngressControllerTLSSecret string
	IngressHostSuffix          string
}

func (*IngressConfig) UseVirtualService

func (i *IngressConfig) UseVirtualService() bool

type KaiSchedulerConfig

type KaiSchedulerConfig struct {
	// Enabled is automatically determined by checking if Kai-scheduler CRDs are installed in the cluster
	Enabled bool
}

type LWSConfig

type LWSConfig struct {
	// Enabled is automatically determined by checking if LWS CRDs are installed in the cluster
	Enabled bool
}

type MpiRunConfig

type MpiRunConfig struct {
	// SecretName is the name of the secret containing the SSH key for MPI Run
	SecretName string
}

type RBACConfig

type RBACConfig struct {
	// PlannerClusterRoleName is the name of the ClusterRole for planner (cluster-wide mode only)
	PlannerClusterRoleName string
	// DGDRProfilingClusterRoleName is the name of the ClusterRole for DGDR profiling jobs (cluster-wide mode only)
	DGDRProfilingClusterRoleName string
}

RBACConfig holds configuration for RBAC management

type Reconciler

type Reconciler interface {
	client.Client
	GetRecorder() record.EventRecorder
}

type Resource

type Resource struct {
	client.Object
	// contains filtered or unexported fields
}

func WrapResource

func WrapResource[T client.Object](resource T, isReady func() (bool, string)) *Resource

func (*Resource) GetName

func (r *Resource) GetName() string

func (*Resource) IsReady

func (r *Resource) IsReady() (bool, string)

type ResourceGenerator

type ResourceGenerator[T client.Object] func(ctx context.Context) (T, bool, error)

ResourceGenerator is a function that generates a resource. it must return the resource, a boolean indicating if the resource should be deleted, and an error if the resource should be deleted, the returned resource must contain the necessary information to delete it (name and namespace)

Jump to

Keyboard shortcuts

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