Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-1835: prevent conditions missing information #1804

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/operator/genericoperatorclient/dynamic_operator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down