MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / isDaemonSetReady

Function isDaemonSetReady

controllers/object_controls.go:3989–4065  ·  view source on GitHub ↗
(name string, n ClusterPolicyController)

Source from the content-addressed store, hash-verified

3987}
3988
3989func isDaemonSetReady(name string, n ClusterPolicyController) gpuv1.State {
3990 ctx := n.ctx
3991 ds := &appsv1.DaemonSet{}
3992 n.logger.V(2).Info("checking daemonset for readiness", "name", name)
3993 err := n.client.Get(ctx, types.NamespacedName{Namespace: n.operatorNamespace, Name: name}, ds)
3994 if err != nil {
3995 n.logger.Error(err, "could not get daemonset", "name", name)
3996 }
3997
3998 if ds.Status.DesiredNumberScheduled == 0 {
3999 n.logger.V(2).Info("Daemonset has desired pods of 0", "name", name)
4000 return gpuv1.Ready
4001 }
4002
4003 if ds.Status.NumberUnavailable != 0 {
4004 n.logger.Info("daemonset not ready", "name", name)
4005 return gpuv1.NotReady
4006 }
4007
4008 // if ds is running with "OnDelete" strategy, check if the revision matches for all pods
4009 if ds.Spec.UpdateStrategy.Type != appsv1.OnDeleteDaemonSetStrategyType {
4010 return gpuv1.Ready
4011 }
4012
4013 opts := []client.ListOption{client.MatchingLabels(ds.Spec.Template.Labels)}
4014
4015 n.logger.V(2).Info("Pod", "LabelSelector", fmt.Sprintf("app=%s", name))
4016 list := &corev1.PodList{}
4017 err = n.client.List(ctx, list, opts...)
4018 if err != nil {
4019 n.logger.Info("Could not get PodList", err)
4020 return gpuv1.NotReady
4021 }
4022 n.logger.V(2).Info("Pod", "NumberOfPods", len(list.Items))
4023 if len(list.Items) == 0 {
4024 return gpuv1.NotReady
4025 }
4026
4027 dsPods := getPodsOwnedbyDaemonset(ds, list.Items, n)
4028 daemonsetRevisionHash, err := getDaemonsetControllerRevisionHash(ctx, ds, n)
4029 if err != nil {
4030 n.logger.Error(
4031 err, "Failed to get daemonset template revision hash", "daemonset", ds)
4032 return gpuv1.NotReady
4033 }
4034 n.logger.V(2).Info("daemonset template revision hash", "hash", daemonsetRevisionHash)
4035
4036 for _, pod := range dsPods {
4037 pod := pod
4038 podRevisionHash, err := getPodControllerRevisionHash(ctx, &pod)
4039 if err != nil {
4040 n.logger.Error(
4041 err, "Failed to get pod template revision hash", "pod", pod)
4042 return gpuv1.NotReady
4043 }
4044 n.logger.V(2).Info("pod template revision hash", "hash", podRevisionHash)
4045
4046 // check if the revision hashes are matching and pod is in running state

Callers 1

DaemonSetFunction · 0.85

Calls 6

getPodsOwnedbyDaemonsetFunction · 0.85
ErrorMethod · 0.80
GetMethod · 0.65
ListMethod · 0.65

Tested by

no test coverage detected