func (dsc *DaemonSetsController) constructHistory(ds *apps.DaemonSet) (cur *apps.ControllerRevision, old []*apps.ControllerRevision, err error) {
	var histories []*apps.ControllerRevision
	var currentHistories []*apps.ControllerRevision
	histories, err = dsc.controlledHistories(ds)
	if err != nil {
		return nil, nil, err
	}
	for _, history := range histories {
		// Add the unique label if it's not already added to the history
		// We use history name instead of computing hash, so that we don't need to worry about hash collision
		if _, ok := history.Labels[apps.DefaultDaemonSetUniqueLabelKey]; !ok {
			toUpdate := history.DeepCopy()
			toUpdate.Labels[apps.DefaultDaemonSetUniqueLabelKey] = toUpdate.Name
			history, err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
			if err != nil {
				return nil, nil, err
			}
		}
		// Compare histories with ds to separate cur and old history
		found := false
		found, err = Match(ds, history)
		if err != nil {
			return nil, nil, err
		}
		if found {
			currentHistories = append(currentHistories, history)
		} else {
			old = append(old, history)
		}
	}

	currRevision := maxRevision(old) + 1
	switch len(currentHistories) {
	case 0:
		// Create a new history if the current one isn't found
		cur, err = dsc.snapshot(ds, currRevision)
		if err != nil {
			return nil, nil, err
		}
	default:
		cur, err = dsc.dedupCurHistories(ds, currentHistories)
		if err != nil {
			return nil, nil, err
		}
		// Update revision number if necessary
		if cur.Revision < currRevision {
			toUpdate := cur.DeepCopy()
			toUpdate.Revision = currRevision
			_, err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
			if err != nil {
				return nil, nil, err
			}
		}
	}
	return cur, old, err
}
// constructHistory finds all histories controlled by the given DaemonSet, and
// update current history revision number, or create current history if need to.
// It also deduplicates current history, and adds missing unique labels to existing histories.
constructHistory finds all histories controlled by the given DaemonSet, and
update current history revision number, or create current history if need to.
It also deduplicates current history, and adds missing unique labels to existing histories.
// constructHistory finds all histories controlled by the given DaemonSet and // update current history revision number or create current history if need to . // It also deduplicates current history and adds missing unique labels to existing histories .
func (dsc *DaemonSetsController) constructHistory(ds *apps.DaemonSet) (cur *apps.ControllerRevision, old []*apps.ControllerRevision, err error) {
	var histories []*apps.ControllerRevision
	var currentHistories []*apps.ControllerRevision
	histories, err = dsc.controlledHistories(ds)
	if err != nil {
		return nil, nil, err
	}
	for _, history := range histories {
		if _, ok := history.Labels[apps.DefaultDaemonSetUniqueLabelKey]; !ok {
			toUpdate := history.DeepCopy()
			toUpdate.Labels[apps.DefaultDaemonSetUniqueLabelKey] = toUpdate.Name
			history, err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
			if err != nil {
				return nil, nil, err
			}
		}
		found := false
		found, err = Match(ds, history)
		if err != nil {
			return nil, nil, err
		}
		if found {
			currentHistories = append(currentHistories, history)
		} else {
			old = append(old, history)
		}
	}
	currRevision := maxRevision(old) + 1
	switch len(currentHistories) {
	case 0:
		cur, err = dsc.snapshot(ds, currRevision)
		if err != nil {
			return nil, nil, err
		}
	default:
		cur, err = dsc.dedupCurHistories(ds, currentHistories)
		if err != nil {
			return nil, nil, err
		}
		if cur.Revision < currRevision {
			toUpdate := cur.DeepCopy()
			toUpdate.Revision = currRevision
			_, err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
			if err != nil {
				return nil, nil, err
			}
		}
	}
	return cur, old, err
}
func ( dsc * DaemonSetsController ) constructHistory ( ds * apps . DaemonSet ) ( cur * apps . ControllerRevision , old [ ] * apps . ControllerRevision , err error ) { var histories [ ] * apps . ControllerRevision var currentHistories [ ] * apps . ControllerRevision histories , err = dsc . controlledHistories ( ds ) if err != nil { return nil , nil , err } for _ , history := range histories { if _ , ok := history . Labels [ apps . DefaultDaemonSetUniqueLabelKey ] ; ! ok { toUpdate := history . DeepCopy ( ) toUpdate . Labels [ apps . DefaultDaemonSetUniqueLabelKey ] = toUpdate . Name history , err = dsc . kubeClient . AppsV1 ( ) . ControllerRevisions ( ds . Namespace ) . Update ( context . TODO ( ) , toUpdate , metav1 . UpdateOptions { } ) if err != nil { return nil , nil , err } } found := false found , err = Match ( ds , history ) if err != nil { return nil , nil , err } if found { currentHistories = append ( currentHistories , history ) } else { old = append ( old , history ) } } currRevision := maxRevision ( old ) + 1 switch len ( currentHistories ) { case 0 : cur , err = dsc . snapshot ( ds , currRevision ) if err != nil { return nil , nil , err } default : cur , err = dsc . dedupCurHistories ( ds , currentHistories ) if err != nil { return nil , nil , err } if cur . Revision < currRevision { toUpdate := cur . DeepCopy ( ) toUpdate . Revision = currRevision _ , err = dsc . kubeClient . AppsV1 ( ) . ControllerRevisions ( ds . Namespace ) . Update ( context . TODO ( ) , toUpdate , metav1 . UpdateOptions { } ) if err != nil { return nil , nil , err } } } return cur , old , err }
constructHistory finds all histories controlled by the given DaemonSet, and
update current history revision number, or create current history if need to.
constructHistory finds all histories controlled by the given DaemonSet and update current history revision number or create current history if need to .
// Add the unique label if it's not already added to the history // We use history name instead of computing hash, so that we don't need to worry about hash collision // Compare histories with ds to separate cur and old history // Create a new history if the current one isn't found // Update revision number if necessary