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

KDP Reconciler does not set observedGeneration on the managed resource #391

Open
sdowell opened this issue Jun 4, 2024 · 4 comments
Open
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@sdowell
Copy link
Contributor

sdowell commented Jun 4, 2024

What would you like to be added: I would like for the KDP reconciler to have built-in support for setting the observedGeneration on the status of the managed resource.

Why is this needed: This makes it easier to determine when a KDP controller has reconciled the current spec of the managed resource.

@sdowell sdowell added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 4, 2024
@k8s-triage-robot
Copy link

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

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

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 2, 2024
@tomasaschan
Copy link
Member

tomasaschan commented Sep 3, 2024

I agree this would be useful, and shouldn't be terribly hard to implement. I guess the "hard" part is to determine whether the declarative resource definition has status.observedGeneration defined in its schema, to know whether to attempt to set it or not; without that (or an explicit opt-in, which is probably easier to implement), this can never be non-breaking.

@tomasaschan
Copy link
Member

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 3, 2024
@tomasaschan
Copy link
Member

tomasaschan commented Sep 3, 2024

Thinking a bit more about this, it is already possible to do this with the current features of KDP, by utilizing the BuildStatus API of the status builder:

// in your setup code, where you pass all the other options to set up the declarative reconciler

// We use a StatusBuilder to avoid having to implement all of declarative.Status; we only need BuildStatus
// https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/pkg/patterns/declarative/status.go#L80
declarative.WithStatus(&declarative.StatusBuilder{
  BuildStatusImpl: &myCustomStatus{},
})


type myCustomStatus struct {}

func (*myCustomStatus) BuildStatus(ctx context.Context, statusInfo *StatusInfo) error {
    // here, statusInfo has a property Subject which is the declarative object
    // cast that to your custom resource type, so you can mutate the status at will
    subj, ok := statusInfo.Subject.(*MyCustomResource)
    if !ok {
        return errors.New("expected a %T, but got a %T", &MyCustomResource{}, statusInfo.Subject)
    }
    
    // mutations to status here will be saved to the API server by the KDP reconciler
    subj.Status.ObservedGeneration = subj.ObjectMeta.Generation

    return nil
}

This is admittedly quite a bit of ceremony in order to do something very common, but if you also want to do other things (e.g. calculate a set of conditions) you probably already do most of it, and the line that actually sets observed generation is the only new code needed.

It might be interesting to try to simplify this, by e.g. providing a helper feature that removes the need for all the boilerplate, but we'd have to design that a bit carefully to ensure it plays well with the existing status features.

@justinsb Do you have any thoughts on this? In particular, could we make it easier to build helpers for things like this by finally actually removing the old-and-deprecated methods on StatusBuilder (in particular, Reconciled)? (Yes, that would be breaking, but at least in a very compile-time discoverable way.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

4 participants