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

Fix api generation #35

Merged
merged 12 commits into from
Mar 28, 2024
Merged

Conversation

efiacor
Copy link
Collaborator

@efiacor efiacor commented Mar 21, 2024

Upgrade code gen to latest and use the provided script to generate the api.
Bump versions to align with the code-gen version.
Fix cli e2e test suite.

The following files are auto generated and therefore do not require a "full" review:

  • api/generated/*
  • all files with a zz_* prefix
  • controllers/config/bases/crds
  • controller/**/config/*

@nephio-prow nephio-prow bot requested review from henderiw and s3wong March 21, 2024 15:34
@nephio-prow nephio-prow bot added the approved label Mar 21, 2024
@efiacor efiacor requested review from johnbelamaric and liamfallon and removed request for s3wong and henderiw March 21, 2024 15:34
Copy link
Collaborator

@kispaljr kispaljr left a comment

Choose a reason for hiding this comment

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

As far as I can tell by looking through it:
/lgtm

Trigger CLI e2e
@liamfallon
Copy link
Member

It also looks fine to me. Also I have built it locally and run the tests locally and they pass. I have also manually ran through the Porch tutorial locally, testing PVSs and VPs and it all works fine. However, let's leave the PR open for another day or so to get more reviews on it given that it is such a big PR.

Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

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

It also looks fine to me. Also I have built it locally and run the tests locally and they pass. I have also manually ran through the Porch tutorial locally, testing PVSs and VPs and it all works fine. However, let's leave the PR open for another day or so to get more reviews on it given that it is such a big PR.

@liamfallon
Copy link
Member

/assign @johnbelamaric @s3wong @henderiw

@@ -38,8 +38,8 @@ var (

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Package{},
&PackageList{},
&PorchPackage{},

Choose a reason for hiding this comment

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

Curious as to why the renaming is needed? Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It uses kube-codegen to generate the api code.

With naming the CR Package, the code generator didn't like that apparently as package is a keyword in golang, so they forked it and customised it here. Didn't dig into what they did really.

As part of the migration/clean up plan, the Package and Function CRs will be removed, so the idea here is to provide a stop gap solution (hopefully without breaking anything), by renaming to "PorchPackage.."

Copy link
Member

Choose a reason for hiding this comment

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

Curious as to why the renaming is needed? Thanks

@vjayaramrh Are you OK with this?

Copy link

@vjayaramrh vjayaramrh Mar 26, 2024

Choose a reason for hiding this comment

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

@efiacor @liamfallon , Thanks for the response, I am good.

@@ -1,24 +1,9 @@
# Copyright 2023 The kpt and Nephio Authors
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these getting removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good spot. Not sure how they were getting added before. I have update the controller-gen directives to add the header now.

func mapObjectsToRequests(mgrClient client.Reader) handler.MapFunc {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
attachedPackageVariants := &api.PackageVariantList{}
err := mgrClient.List(context.TODO(), attachedPackageVariants, &client.ListOptions{
Copy link
Contributor

@nagygergo nagygergo Mar 26, 2024

Choose a reason for hiding this comment

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

With the new function signature, you get the associated context as a param of the function, that should be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

func mapObjectsToRequests(mgrClient client.Reader) handler.MapFunc {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
attachedPackageVariants := &api.PackageVariantSetList{}
err := mgrClient.List(context.TODO(), attachedPackageVariants, &client.ListOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, use the provided context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

o.RecommendedOptions.Etcd.StorageConfig.Paging = utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
}
// if o.RecommendedOptions.Etcd != nil {
// o.RecommendedOptions.Etcd.StorageConfig.Paging = utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you just remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Possibly but my knowledge of the Paging functionality in etcd is limited.
They removed it in the latest version. Plan was maybe to reintroduce it once I have the know how.
Can remove if it's cleaner. Don't think we are losing much.

if err != nil {
return nil, err
}
return resources, nil
}

func loadResourcesFromTar(ctx context.Context, tarReader *tar.Reader) (*repository.PackageResources, error) {
func loadResourcesFromTar(tarReader *tar.Reader) (*repository.PackageResources, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why dropping context here? If anything, context cancelation should be part of the for loop at #195.

Copy link
Collaborator Author

@efiacor efiacor Mar 26, 2024

Choose a reason for hiding this comment

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

Slightly lazy one but it shows up as an unused param. There is a few of them in the code which prob should be cleaned up. Unless my understanding of how the context is passed/used in k8s is incorrect.

@@ -0,0 +1,39 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really a bash expert, I couldn't figure out what this is used for. Could you add 1-2 lines to explain it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nor am I :D
I borrowed this from another project. From my understanding, it catches the exit codes if any and gives some nice output to the user.

@efiacor efiacor requested review from kispaljr, nagygergo, vjayaramrh, liamfallon and tliron and removed request for nagygergo March 26, 2024 20:41
@vjayaramrh
Copy link

@efiacor any specific files that you would recommend a newbie porch reviewer to get familar with while reviewing this PR. Thanks

Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

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

The updates all look fine @efiacor

@efiacor
Copy link
Collaborator Author

efiacor commented Mar 27, 2024

@efiacor any specific files that you would recommend a newbie porch reviewer to get familar with while reviewing this PR. Thanks

Hi @vjayaramrh .
To be honest I am still working my way around the code myself.
For this PR, the main objective was to fix the api code generation. Then I looked to upgrade as many dependencies as possible.
Most of the stuff under the api dir can be skimmed over really. All of the code-gen stuff is now handed off to the scripts generate-api and kube_code_gen. Also, we prob need to decide whether the auto gen code is checked in or not. For me it shouldn't be in the repo.
The relevant changes to the "controllers" are mostly related to upgrading in the dependencies. controller-runtime, etc. Some code gen stuff too but minimal.
The pkg dir contains most/all the business logic so should really be the main focus. Again, with the dependencies bump, there were some minor required changes.
Finally, I needed to fix an issue with the cli e2e test run where the ns delete was hanging due to Finalizers on the PackageRev resources in the NameSpace.

@efiacor efiacor requested a review from nagygergo March 27, 2024 09:06
@@ -174,6 +176,40 @@ func KubectlDeleteNamespace(t *testing.T, name string) {
t.Logf("output: %v", string(out))
}

func RemovePackagerevFinalizers(t *testing.T, namespace string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the test case not failing before because of finalizers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Intermittently yes.
See the history here - https://github.com/nephio-project/porch/actions/workflows/porchctl-cli-e2e.yaml
I believe there is some timing/race condition on how the PackageRev api-resource gets updated. If the Finalizers remain, it blocks the NameSpace deletion.

Copy link
Contributor

@nagygergo nagygergo Mar 27, 2024

Choose a reason for hiding this comment

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

Ok, that's fine, I'll open a separate issue on this one. Seems strange that porch-server is sometimes able to delete the packagerevs and sometimes not.

@efiacor efiacor requested a review from nagygergo March 27, 2024 14:52
@johnbelamaric
Copy link
Member

Nice work, @efiacor! I know how gnarly this problem was, I spent a fair bit of time on it myself and gave up in frustration :) - thanks for sticking through it.

/approve

@liamfallon
Copy link
Member

/approve
/lgtm

Copy link
Contributor

nephio-prow bot commented Mar 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: efiacor, johnbelamaric, liamfallon, nagygergo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [efiacor,johnbelamaric,liamfallon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nephio-prow nephio-prow bot merged commit 8a84339 into nephio-project:main Mar 28, 2024
6 checks passed
@efiacor efiacor deleted the upgrade_code_gen branch March 28, 2024 09:15
@liamfallon liamfallon mentioned this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants