func getConditionMessage()

in operatortrace-go/pkg/client/conditions.go [47:73]


func getConditionMessage(conditionType string, obj client.Object, scheme *runtime.Scheme) (string, error) {
	conditions, err := getConditionsAsMap(obj, scheme)
	if err != nil {
		return "", err
	}

	for _, condition := range conditions {
		// Check if "Type" key exists
		conType, exists := condition["Type"]
		if !exists {
			return "", fmt.Errorf("condition does not contain a 'Type' field")
		}

		// Convert conType to string using reflection
		conTypeStr, err := convertToString(conType)
		if err != nil {
			return "", fmt.Errorf("failed to convert 'Type' field to string: %v", err)
		}

		if conTypeStr == conditionType {
			message := condition["Message"].(string)
			return message, nil
		}
	}

	return "", fmt.Errorf("condition of type %s not found", conditionType)
}