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

Package conditions #3614

Merged
merged 1 commit into from
Oct 14, 2022
Merged

Package conditions #3614

merged 1 commit into from
Oct 14, 2022

Conversation

mortent
Copy link
Contributor

@mortent mortent commented Oct 12, 2022

This adds support for readiness gates and conditions to kpt packages through new fields in the Kptfile, and exposes those fields in Porch through the PackageRevision resource.

The two most important aspects about this PR is:

  • Is the fields we add to the Kptfile the correct ones? The patterns mirrors the podReadinessGates pretty closely, so it aligns well with prior art in Kubernetes.
  • Should we expose fields in the Kptfile through the Porch API? We already expose the UpstreamLock read-only through the status object, but this allows for updates too by creating patches for the changes to the Kptfile. So in the git history for the Kptfile, it shows up identical to what it looks like if someone updates the Kptfile through PackageRevisionResources. Allowing updates through the Porch API directly simplifies updates with controllers.

One aspect of the current implementation that is a bit surprising, is that kpt updates both the conditions and the readiness gates as non-associative lists. This doesn't seem correct, but unfortunately the kyaml library can't identify the merge key and therefore falls back to treating it as a non-associative list. We could handle this either by adding custom merge logic for these fields, or provide a schema that provide this information to kyaml.

@mortent mortent changed the title Package conditions [WIP] Package conditions Oct 12, 2022
@mortent mortent force-pushed the PackageConditions branch 3 times, most recently from 1ad77b7 to 0310af8 Compare October 13, 2022 04:08
@mortent mortent changed the title [WIP] Package conditions Package conditions Oct 13, 2022
@mortent mortent marked this pull request as ready for review October 13, 2022 04:41
@mortent mortent force-pushed the PackageConditions branch 2 times, most recently from 5769fba to 1e5a45b Compare October 13, 2022 04:44

Status ConditionStatus `yaml:"type" json:"status"`

Reason string `yaml:"type,omitempty" json:"reason,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: yaml:"type" -> reason

We also should just remove the yaml annotations - they aren't needed by the yaml libraries that apimachinery supports - but we can do that separately!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the incorrect names, but we can clean up the tags in a separate PR.

draft, err := repo.UpdatePackageRevision(ctx, oldPackage)
if err != nil {
return nil, err
}

// If any of the fields in the API that are projections from the Kptfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to try this, but I suspect we won't be able to maintain this in the Kptfile going forwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that projecting fields from the Kptfile into the API here? If so, why? I had some concerns about it, but it actually seems to work a bit better than I feared.

resources := map[string]string{}

tree, err := r.repo.TreeObject(hash)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We should warn if the hash isn't found, and we should also check the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to treat hash not found different from other errors, other than perhaps trying to get a better message to the user? It seems like almost no matter what goes wrong here, an error would be a better than returning an empty map.

key := p.Key()

kf, _ := p.GetKptfile(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we shouldn't drop errors without checking them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant to clean this up but forgot about it. Fixed now.

@justinsb
Copy link
Contributor

A few nits, but LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants