func getPlanStepInfo()

in pkg/plan/track_response_builder.go [145:187]


func getPlanStepInfo(workload interface{}, getCurrentPlan bool) ([]*models.ClusterPlanStepInfo, error) {
	var planName = pendingPlanPath
	if getCurrentPlan {
		planName = currentPlanPath
	}

	payloadValue := reflect.ValueOf(workload)
	if !payloadValue.IsValid() {
		return nil, errNoPendingPlan
	}

	// Get either the "Pending" or "Current" plan.
	plan := reflectElemFieldPath(payloadValue, planName)
	if !plan.IsValid() {
		return nil, errNoPendingPlan
	}

	// If the pending plan is nil and getCurrentPlan == false, return an error.
	var noPendingPlanAndWantPendingPlan = plan.IsNil() && !getCurrentPlan
	if noPendingPlanAndWantPendingPlan {
		return nil, errNoPendingPlan
	}

	// When either "Pending" or "Current" aren't nil, obtain the plan log.
	var planLog reflect.Value
	if !plan.IsNil() {
		planLog = plan.Elem().FieldByName(planAttemptLog)
	}

	// When either "Pending" or "Current" are nil, and the current plan needs
	// to be obtained as set by the "getCurrentPlan" bool. Another case is when
	// the planLog is empty, for whichever case, the latest plan in the plan
	// history trail is obtained.
	var currentPlanIsNilAndPlanLogIsNil = plan.IsNil() && getCurrentPlan || planLog.IsNil()
	if currentPlanIsNilAndPlanLogIsNil {
		if history := reflectElemFieldPath(payloadValue, historyPlanPath); history.Len() > 0 {
			var lastPlan = history.Index(history.Len() - 1)
			planLog = lastPlan.Elem().FieldByName(planAttemptLog)
		}
	}

	return getPlanLog(planLog)
}