Skip to content

Commit

Permalink
bump k8s.io and controller-runtime dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Jun 25, 2024
1 parent deedefa commit 4870d7c
Show file tree
Hide file tree
Showing 409 changed files with 42,145 additions and 11,603 deletions.
10 changes: 10 additions & 0 deletions bundle/manifests/nvidia.com_nvidiadrivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchFields:
description: A list of node selector requirements by
node's fields.
Expand Down Expand Up @@ -389,11 +391,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
weight:
Expand All @@ -406,6 +410,7 @@ spec:
- weight
type: object
type: array
x-kubernetes-list-type: atomic
requiredDuringSchedulingIgnoredDuringExecution:
description: |-
If the affinity requirements specified by this field are not met at
Expand Down Expand Up @@ -450,11 +455,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchFields:
description: A list of node selector requirements by
node's fields.
Expand Down Expand Up @@ -482,14 +489,17 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
type: array
x-kubernetes-list-type: atomic
required:
- nodeSelectorTerms
type: object
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/nvidia.com_nvidiadrivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchFields:
description: A list of node selector requirements by
node's fields.
Expand Down Expand Up @@ -389,11 +391,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
weight:
Expand All @@ -406,6 +410,7 @@ spec:
- weight
type: object
type: array
x-kubernetes-list-type: atomic
requiredDuringSchedulingIgnoredDuringExecution:
description: |-
If the affinity requirements specified by this field are not met at
Expand Down Expand Up @@ -450,11 +455,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchFields:
description: A list of node selector requirements by
node's fields.
Expand Down Expand Up @@ -482,14 +489,17 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
type: array
x-kubernetes-list-type: atomic
required:
- nodeSelectorTerms
type: object
Expand Down
39 changes: 27 additions & 12 deletions controllers/clusterpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ func updateCRState(ctx context.Context, r *ClusterPolicyReconciler, namespacedNa
}
}

func addWatchNewGPUNode(ctx context.Context, r *ClusterPolicyReconciler, c controller.Controller, mgr ctrl.Manager) error {
func addWatchNewGPUNode(r *ClusterPolicyReconciler, c controller.Controller, mgr ctrl.Manager) error {
// Define a mapping from the Node object in the event to one or more
// ClusterPolicy objects to Reconcile
mapFn := func(ctx context.Context, a client.Object) []reconcile.Request {
mapFn := func(ctx context.Context, n *corev1.Node) []reconcile.Request {
// find all the ClusterPolicy to trigger their reconciliation
opts := []client.ListOption{} // Namespace = "" to list across all namespaces.
list := &gpuv1.ClusterPolicyList{}
Expand All @@ -280,13 +280,13 @@ func addWatchNewGPUNode(ctx context.Context, r *ClusterPolicyReconciler, c contr
return cpToRec
}

p := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
p := predicate.TypedFuncs[*corev1.Node]{
CreateFunc: func(e event.TypedCreateEvent[*corev1.Node]) bool {
labels := e.Object.GetLabels()

return hasGPULabels(labels)
},
UpdateFunc: func(e event.UpdateEvent) bool {
UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Node]) bool {
newLabels := e.ObjectNew.GetLabels()
oldLabels := e.ObjectOld.GetLabels()
nodeName := e.ObjectNew.GetName()
Expand Down Expand Up @@ -324,7 +324,7 @@ func addWatchNewGPUNode(ctx context.Context, r *ClusterPolicyReconciler, c contr
}
return needsUpdate
},
DeleteFunc: func(e event.DeleteEvent) bool {
DeleteFunc: func(e event.TypedDeleteEvent[*corev1.Node]) bool {
// if an RHCOS GPU node is deleted, trigger a
// reconciliation to ensure that there is no dangling
// OpenShift Driver-Toolkit (RHCOS version-specific)
Expand All @@ -341,9 +341,12 @@ func addWatchNewGPUNode(ctx context.Context, r *ClusterPolicyReconciler, c contr
}

err := c.Watch(
source.Kind(mgr.GetCache(), &corev1.Node{}),
handler.EnqueueRequestsFromMapFunc(mapFn),
p)
source.Kind(mgr.GetCache(),
&corev1.Node{},
handler.TypedEnqueueRequestsFromMapFunc[*corev1.Node](mapFn),
p,
),
)

return err
}
Expand All @@ -360,20 +363,32 @@ func (r *ClusterPolicyReconciler) SetupWithManager(ctx context.Context, mgr ctrl
r.conditionUpdater = conditions.NewClusterPolicyUpdater(mgr.GetClient())

// Watch for changes to primary resource ClusterPolicy
err = c.Watch(source.Kind(mgr.GetCache(), &gpuv1.ClusterPolicy{}), &handler.EnqueueRequestForObject{}, predicate.GenerationChangedPredicate{})
err = c.Watch(source.Kind(
mgr.GetCache(),
&gpuv1.ClusterPolicy{},
&handler.TypedEnqueueRequestForObject[*gpuv1.ClusterPolicy]{},
predicate.TypedGenerationChangedPredicate[*gpuv1.ClusterPolicy]{},
),
)
if err != nil {
return err
}

// Watch for changes to Node labels and requeue the owner ClusterPolicy
err = addWatchNewGPUNode(ctx, r, c, mgr)
err = addWatchNewGPUNode(r, c, mgr)
if err != nil {
return err
}

// TODO(user): Modify this to be the types you create that are owned by the primary resource
// Watch for changes to secondary resource Daemonsets and requeue the owner ClusterPolicy
err = c.Watch(source.Kind(mgr.GetCache(), &appsv1.DaemonSet{}), handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &gpuv1.ClusterPolicy{}, handler.OnlyControllerOwner()))
err = c.Watch(
source.Kind(mgr.GetCache(),
&appsv1.DaemonSet{},
handler.TypedEnqueueRequestForOwner[*appsv1.DaemonSet](mgr.GetScheme(), mgr.GetRESTMapper(), &gpuv1.ClusterPolicy{},
handler.OnlyControllerOwner()),
),
)
if err != nil {
return err
}
Expand Down
73 changes: 50 additions & 23 deletions controllers/nvidiadriver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,47 @@ func (r *NVIDIADriverReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
}

// Watch for changes to the primary resource NVIDIaDriver
err = c.Watch(source.Kind(mgr.GetCache(), &nvidiav1alpha1.NVIDIADriver{}), &handler.EnqueueRequestForObject{}, predicate.GenerationChangedPredicate{})
err = c.Watch(source.Kind(
mgr.GetCache(),
&nvidiav1alpha1.NVIDIADriver{},
&handler.TypedEnqueueRequestForObject[*nvidiav1alpha1.NVIDIADriver]{},
predicate.TypedGenerationChangedPredicate[*nvidiav1alpha1.NVIDIADriver]{},
),
)
if err != nil {
return err
}

// Watch for changes to ClusterPolicy. Whenever an event is generated for ClusterPolicy, enqueue
// a reconcile request for all NVIDIADriver instances.
mapFn := func(ctx context.Context, a client.Object) []reconcile.Request {
mapFn := func(ctx context.Context, cp *gpuv1.ClusterPolicy) []reconcile.Request {
logger := log.FromContext(ctx)
opts := []client.ListOption{}
list := &nvidiav1alpha1.NVIDIADriverList{}

err := mgr.GetClient().List(ctx, list, opts...)
if err != nil {
logger.Error(err, "Unable to list NVIDIADriver resources")
return []reconcile.Request{}
}

reconcileRequests := []reconcile.Request{}
for _, nvidiaDriver := range list.Items {
reconcileRequests = append(reconcileRequests,
reconcile.Request{
NamespacedName: types.NamespacedName{
Name: nvidiaDriver.ObjectMeta.GetName(),
Namespace: nvidiaDriver.ObjectMeta.GetNamespace(),
},
})
}

return reconcileRequests
}

// Watch for changes to the Nodes. Whenever an event is generated for ClusterPolicy, enqueue
// a reconcile request for all NVIDIADriver instances.
nodeMapFn := func(ctx context.Context, cp *corev1.Node) []reconcile.Request {
logger := log.FromContext(ctx)
opts := []client.ListOption{}
list := &nvidiav1alpha1.NVIDIADriverList{}
Expand All @@ -296,20 +329,23 @@ func (r *NVIDIADriverReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
}

err = c.Watch(
source.Kind(mgr.GetCache(), &gpuv1.ClusterPolicy{}),
handler.EnqueueRequestsFromMapFunc(mapFn),
predicate.GenerationChangedPredicate{},
source.Kind(
mgr.GetCache(),
&gpuv1.ClusterPolicy{},
handler.TypedEnqueueRequestsFromMapFunc[*gpuv1.ClusterPolicy](mapFn),
predicate.TypedGenerationChangedPredicate[*gpuv1.ClusterPolicy]{},
),
)
if err != nil {
return err
}

nodePredicate := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
nodePredicate := predicate.TypedFuncs[*corev1.Node]{
CreateFunc: func(e event.TypedCreateEvent[*corev1.Node]) bool {
labels := e.Object.GetLabels()
return hasGPULabels(labels)
},
UpdateFunc: func(e event.UpdateEvent) bool {
UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Node]) bool {
logger := log.FromContext(ctx)
newLabels := e.ObjectNew.GetLabels()
oldLabels := e.ObjectOld.GetLabels()
Expand All @@ -324,38 +360,29 @@ func (r *NVIDIADriverReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
}
return needsUpdate
},
DeleteFunc: func(e event.DeleteEvent) bool {
DeleteFunc: func(e event.TypedDeleteEvent[*corev1.Node]) bool {
labels := e.Object.GetLabels()
return hasGPULabels(labels)
},
}

// Watch for changes to node labels
err = c.Watch(
source.Kind(mgr.GetCache(), &corev1.Node{}),
handler.EnqueueRequestsFromMapFunc(mapFn),
nodePredicate,
source.Kind(mgr.GetCache(),
&corev1.Node{},
handler.TypedEnqueueRequestsFromMapFunc[*corev1.Node](nodeMapFn),
nodePredicate,
),
)
if err != nil {
return err
}

// Watch for changes to secondary resources which each state manager manages
watchSources := stateManager.GetWatchSources(mgr)
nvDriverPredicate, err := predicate.LabelSelectorPredicate(metav1.LabelSelector{MatchLabels: map[string]string{AppComponentLabelKey: AppComponentLabelValue}})
if err != nil {
return fmt.Errorf("failed to create labelSelector predicate: %w", err)
}
for _, watchSource := range watchSources {
err = c.Watch(
watchSource,
handler.EnqueueRequestForOwner(
mgr.GetScheme(),
mgr.GetRESTMapper(),
&nvidiav1alpha1.NVIDIADriver{},
handler.OnlyControllerOwner(),
),
nvDriverPredicate,
)
if err != nil {
return fmt.Errorf("error setting up Watch for source type %v: %w", watchSource, err)
Expand Down
Loading

0 comments on commit 4870d7c

Please sign in to comment.