From c198fad021e40dab2530be33e5fc08df48ecf436 Mon Sep 17 00:00:00 2001 From: David Eads Date: Thu, 26 Sep 2024 16:09:26 -0400 Subject: [PATCH] prevent conditions missing information --- .../dynamic_operator_client.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/operator/genericoperatorclient/dynamic_operator_client.go b/pkg/operator/genericoperatorclient/dynamic_operator_client.go index 665a4af200..477224b05b 100644 --- a/pkg/operator/genericoperatorclient/dynamic_operator_client.go +++ b/pkg/operator/genericoperatorclient/dynamic_operator_client.go @@ -22,6 +22,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + "k8s.io/utils/ptr" ) const defaultConfigName = "cluster" @@ -279,6 +280,18 @@ func (c dynamicOperatorClient) ApplyOperatorStatus(ctx context.Context, fieldMan } func (c dynamicOperatorClient) applyOperatorStatus(ctx context.Context, fieldManager string, desiredConfiguration *applyoperatorv1.StaticPodOperatorStatusApplyConfiguration) (err error) { + if desiredConfiguration != nil { + for i, curr := range desiredConfiguration.Conditions { + // panicking so we can quickly find it and fix the source + if len(ptr.Deref(curr.Type, "")) == 0 { + panic(fmt.Sprintf(".status.conditions[%d].type is missing", i)) + } + if len(ptr.Deref(curr.Status, "")) == 0 { + panic(fmt.Sprintf(".status.conditions[%q].status is missing", *curr.Type)) + } + } + } + uncastOriginal, err := c.informer.Lister().Get(c.configName) switch { case apierrors.IsNotFound(err): @@ -334,6 +347,15 @@ func (c dynamicOperatorClient) applyOperatorStatus(ctx context.Context, fieldMan } } + for _, curr := range desiredConfiguration.Conditions { + if len(ptr.Deref(curr.Reason, "")) == 0 { + klog.Warningf(".status.conditions[%q].reason is missing; this will eventually be fatal", *curr.Type) + } + if len(ptr.Deref(curr.Message, "")) == 0 { + klog.Warningf(".status.conditions[%q].message is missing; this will eventually be fatal", *curr.Type) + } + } + desiredStatus, err := runtime.DefaultUnstructuredConverter.ToUnstructured(desiredConfiguration) if err != nil { return fmt.Errorf("failed to convert to unstructured: %w", err)