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

Function getDaemonsetControllerRevisionHash

controllers/object_controls.go:4093–4126  ·  view source on GitHub ↗
(ctx context.Context, daemonset *appsv1.DaemonSet, n ClusterPolicyController)

Source from the content-addressed store, hash-verified

4091}
4092
4093func getDaemonsetControllerRevisionHash(ctx context.Context, daemonset *appsv1.DaemonSet, n ClusterPolicyController) (string, error) {
4094
4095 // get all revisions for the daemonset
4096 opts := []client.ListOption{
4097 client.MatchingLabels(daemonset.Spec.Selector.MatchLabels),
4098 client.InNamespace(n.operatorNamespace),
4099 }
4100 list := &appsv1.ControllerRevisionList{}
4101 err := n.client.List(ctx, list, opts...)
4102 if err != nil {
4103 return "", fmt.Errorf("error getting controller revision list for daemonset %s: %v", daemonset.Name, err)
4104 }
4105
4106 n.logger.V(2).Info("obtained controller revisions", "Daemonset", daemonset.Name, "len", len(list.Items))
4107
4108 var revisions []appsv1.ControllerRevision
4109 for _, controllerRevision := range list.Items {
4110 if strings.HasPrefix(controllerRevision.Name, daemonset.Name) {
4111 revisions = append(revisions, controllerRevision)
4112 }
4113 }
4114
4115 if len(revisions) == 0 {
4116 return "", fmt.Errorf("no revision found for daemonset %s", daemonset.Name)
4117 }
4118
4119 // sort the revision list to make sure we obtain latest revision always
4120 sort.Slice(revisions, func(i, j int) bool { return revisions[i].Revision < revisions[j].Revision })
4121
4122 currentRevision := revisions[len(revisions)-1]
4123 hash := strings.TrimPrefix(currentRevision.Name, fmt.Sprintf("%s-", daemonset.Name))
4124
4125 return hash, nil
4126}
4127
4128// Deployment creates Deployment resource
4129func Deployment(n ClusterPolicyController) (gpuv1.State, error) {

Callers 1

isDaemonSetReadyFunction · 0.85

Calls 1

ListMethod · 0.65

Tested by

no test coverage detected