kubernetes-sigs / cli-utils

This repo contains binaries that built from libraries in cli-runtime.
Apache License 2.0
155 stars 77 forks source link

kstatus: defaults to fail open when no `status` field is available #632

Open jack1902 opened 10 months ago

jack1902 commented 10 months ago

TL;DR - When a resource doesn't yet have a status field does kstatus report unknown ?

When creating a resource which is defined by a CRD which has no status by default, i believe the behaviour of kstatus is to state "unknown". I believe this then enables developers using unknown as a condition to determine if that should be seen as "lets carry on" or "stop here and wait".

If the "unknown" status is indeed what happens when no status field exists on a resource (because it has been freshly applied and the backing controller hasn't had a chance to update the CR' status field yet, i'll close this issue and raise another with the project using this one to add configuration.

Raffo commented 10 months ago

One thing that we have been doing is to patch the logic for every custom CRD that we create. It's not great, but we also don't have a lot of custom CRDs.

aw185176 commented 8 months ago

When a resource doesn't yet have a status field does kstatus report unknown ?

If I am reading the code right (https://github.com/kubernetes-sigs/cli-utils/blob/0b156cb0425fdb29a436d13f840a39039558c10e/pkg/kstatus/status/status.go#L102), it actually falls all the way through to Current if there is no status field.

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

Raffo commented 4 months ago

/remove-lifecycle stale

karlkfi commented 1 month ago

When a resource doesn't yet have a status field does kstatus report unknown ?

If I am reading the code right (

https://github.com/kubernetes-sigs/cli-utils/blob/0b156cb0425fdb29a436d13f840a39039558c10e/pkg/kstatus/status/status.go#L102

), it actually falls all the way through to Current if there is no status field.

This is correct. Objects without status are assumed to be Current. This is how many of the base k8s types are handled, like Role & RoleBinding, which don't have status.

If you want your CRD to not immediately be seen as Current, add status.observedGeneration to the schema with a default of 0. This will cause the API Server to create a default status when the object is created, which kstatus will interpret as InProgress until your controller sets status.observedGeneration = meta.generation.