func FindRestoreSession(lister v1beta1_listers.RestoreSessionLister, w *wapi.Workload) (*v1beta1_api.RestoreSession, error) {
	// list all RestoreSessions from the lister
	restoreSessions, err := lister.RestoreSessions(w.Namespace).List(labels.Everything())
	if kerr.IsNotFound(err) {
		return nil, nil
	} else if err != nil {
		return nil, err
	}

	result := make([]*v1beta1_api.RestoreSession, 0)
	// keep only those RestoreSession that has this workload as target
	for _, restoreSession := range restoreSessions {
		if restoreSession.DeletionTimestamp == nil && IsRestoreTarget(restoreSession.Spec.Target, w) {
			result = append(result, restoreSession)
		}
	}

	if len(result) == 0 {
		return nil, nil
	}

	// return currently running RestoreSession
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionRunning {
			return r, nil
		}
	}
	// no running RestoreSession. so return pending one
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionPending {
			return r, nil
		}
	}
	// no pending or running restore session so return failed one
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionFailed {
			return r, nil
		}
	}

	// by default return latest RestoreSession
	latestRestoreSession := result[0]
	for _, r := range result {
		if latestRestoreSession.CreationTimestamp.Before(&r.CreationTimestamp) {
			latestRestoreSession = r
		}
	}
	return latestRestoreSession, nil
}
// FindRestoreSession check if there is any pending RestoreSession exist for a particular workload.
// If multiple pending RestoreSessions are found for the workload, it returns error.
FindRestoreSession check if there is any pending RestoreSession exist for a particular workload.
If multiple pending RestoreSessions are found for the workload, it returns error.
// FindRestoreSession check if there is any pending RestoreSession exist for a particular workload . // If multiple pending RestoreSessions are found for the workload it returns error .
func FindRestoreSession(lister v1beta1_listers.RestoreSessionLister, w *wapi.Workload) (*v1beta1_api.RestoreSession, error) {
	restoreSessions, err := lister.RestoreSessions(w.Namespace).List(labels.Everything())
	if kerr.IsNotFound(err) {
		return nil, nil
	} else if err != nil {
		return nil, err
	}
	result := make([]*v1beta1_api.RestoreSession, 0)
	for _, restoreSession := range restoreSessions {
		if restoreSession.DeletionTimestamp == nil && IsRestoreTarget(restoreSession.Spec.Target, w) {
			result = append(result, restoreSession)
		}
	}
	if len(result) == 0 {
		return nil, nil
	}
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionRunning {
			return r, nil
		}
	}
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionPending {
			return r, nil
		}
	}
	for _, r := range result {
		if r.Status.Phase == v1beta1_api.RestoreSessionFailed {
			return r, nil
		}
	}
	latestRestoreSession := result[0]
	for _, r := range result {
		if latestRestoreSession.CreationTimestamp.Before(&r.CreationTimestamp) {
			latestRestoreSession = r
		}
	}
	return latestRestoreSession, nil
}
func FindRestoreSession ( lister v1beta1_listers . RestoreSessionLister , w * wapi . Workload ) ( * v1beta1_api . RestoreSession , error ) { restoreSessions , err := lister . RestoreSessions ( w . Namespace ) . List ( labels . Everything ( ) ) if kerr . IsNotFound ( err ) { return nil , nil } else if err != nil { return nil , err } result := make ( [ ] * v1beta1_api . RestoreSession , 0 ) for _ , restoreSession := range restoreSessions { if restoreSession . DeletionTimestamp == nil && IsRestoreTarget ( restoreSession . Spec . Target , w ) { result = append ( result , restoreSession ) } } if len ( result ) == 0 { return nil , nil } for _ , r := range result { if r . Status . Phase == v1beta1_api . RestoreSessionRunning { return r , nil } } for _ , r := range result { if r . Status . Phase == v1beta1_api . RestoreSessionPending { return r , nil } } for _ , r := range result { if r . Status . Phase == v1beta1_api . RestoreSessionFailed { return r , nil } } latestRestoreSession := result [ 0 ] for _ , r := range result { if latestRestoreSession . CreationTimestamp . Before ( & r . CreationTimestamp ) { latestRestoreSession = r } } return latestRestoreSession , nil }
FindRestoreSession check if there is any pending RestoreSession exist for a particular workload.
FindRestoreSession check if there is any pending RestoreSession exist for a particular workload .
// list all RestoreSessions from the lister // keep only those RestoreSession that has this workload as target // return currently running RestoreSession // no running RestoreSession. so return pending one // no pending or running restore session so return failed one // by default return latest RestoreSession