func()

in internal/readiness/readiness.go [52:84]


func (r *Check) Eval(ctx context.Context, resource *unstructured.Unstructured) (*Status, bool) {
	if resource == nil {
		return nil, false
	}
	val, _, err := r.program.ContextEval(ctx, map[string]any{"self": resource.Object})
	if err != nil {
		return nil, false
	}

	// Support matching on condition structs.
	// This allows us to grab the transition time instead of just using the current time.
	if list, ok := val.Value().([]ref.Val); ok {
		for _, ref := range list {
			if mp, ok := ref.Value().(map[string]any); ok {
				if mp != nil && mp["status"] == "True" && mp["type"] != nil && mp["reason"] != nil {
					ts := metav1.Now()
					if str, ok := mp["lastTransitionTime"].(string); ok {
						parsed, err := time.Parse(time.RFC3339, str)
						if err == nil {
							ts.Time = parsed
						}
					}
					return &Status{ReadyTime: ts, PreciseTime: err == nil}, true
				}
			}
		}
	}

	if val == celtypes.True {
		return &Status{ReadyTime: metav1.Now()}, true
	}
	return nil, false
}