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

Iflib newKO #122

Merged
merged 9 commits into from
Apr 30, 2023
Merged

Iflib newKO #122

merged 9 commits into from
Apr 30, 2023

Conversation

henderiw
Copy link
Contributor

aligned the interface with the new parser implementation
added setters using the real types as this eases validation.

@kispaljr
Copy link
Contributor

My comment for the IPAllocation resource lib, also applies here:
#123 (review)

@gvbalaji
Copy link

Please see my comments on #121 which is base for others. I beleive if we take that path implementation of these individual libraries will be simpler.

@kispaljr
Copy link
Contributor

Just wanted to point out that this PR contains files from #121 (that this PR depends on). This may be fine, but it can also trouble if this is merged after #121.
I am not sure what our policy is in this scenario.

@kispaljr kispaljr mentioned this pull request Apr 20, 2023
@gvbalaji
Copy link

Thanks @kispaljr . Yes a rebase with main needed . In addition as discussed this PR will change in many ways and be simpler as we discussed. This will only have methods directly implemented on KubeObjectEx . Those methods will be only a few handful. All the kubeobject create methods are handled in base parser as well.

@henderiw henderiw requested review from gvbalaji and removed request for tliron April 21, 2023 18:59
Copy link

@gvbalaji gvbalaji left a comment

Choose a reason for hiding this comment

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

Thanks @henderiw . I was hoping we will avoid all "Newfromxxx "methods in this file. Basically instead of creating a new structure, add the interface specific methods directly on KubeObjectEx created in the base parser( few get/set/deletes). Then the usage pattern would be callers first create the object using the base parser and call respective methods based on which function they are implementing. That way these libraries will be simpler. What do you think?

Specifically only these methods

GetAttachmentType
GetCNIType
GetNetworkInstanceName
SetAttachmentType
SetCNIType
SetNetworkInstanceName
SetSpec
DeleteAttachmentType
DeleteCNIType

(Updating comment)
I understand the approach you've taken is cleaner than what I am suggesting as the methods will be scoped to a particular structure and is very definitive. I am thinking since we are on both sides of the library (library consumers and library implementors) probably it's okay to have library methods on the base structure (no interface). Love to hear your thoughts.

@johnbelamaric
Copy link
Member

It's more idiomatic in Go to avoid field setters and getters. So IMO, methods to create from YAML or Go struct, and to convert to Go struct, and to set via Go struct are all we need, as described here: #123 (review)

@nephio-prow nephio-prow bot removed the approved label Apr 28, 2023
@henderiw henderiw changed the title Iflib newparser Iflib SetSpec Apr 28, 2023
@henderiw
Copy link
Contributor Author

Aligned the interface lib with the new setSpec library in kubeobject

@henderiw henderiw changed the title Iflib SetSpec Iflib newKO Apr 28, 2023
Copy link

@gvbalaji gvbalaji left a comment

Choose a reason for hiding this comment

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

Thanks @henderiw . I am on the fence if we really need this with all the changes we made to the base KubeObjectExt. Added a couple of comments.
I think the tests for SetSpec and SetStatus are useful. Even if we decide to do away from this library, I suggest we keep the tests by moving them to the base KubeObjectExt .

cniType = []string{"spec", "cniType"}
networkInstanceName = []string{"spec", "networkInstance", "name"}
)
type Interface struct {

Choose a reason for hiding this comment

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

Is there a need to create this structure? Can the functions developers just directly create the base KubeObjectExt structure? All the methods are used from there anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value is you get explicit type checking for the object and we need this in several libraries. This is the reason to do this. otherwise people need to implement this in each function independently again and again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what I did not do so far is have the explicit SeptSpec and SetStatus with their specific type, so this would add even more type awareness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the way to look at this is a the specific KubeObj extensions for the InterfaceReq CRD

Copy link

@gvbalaji gvbalaji left a comment

Choose a reason for hiding this comment

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

/approve

@henderiw
Copy link
Contributor Author

/approve

@nephio-prow
Copy link
Contributor

nephio-prow bot commented Apr 28, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gvbalaji, henderiw

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:

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 added the approved label Apr 28, 2023
@kispaljr
Copy link
Contributor

kispaljr commented Apr 28, 2023

If I understand correctly, the main reason to have this wrapper at all, is the lack of static type checking in the interface{} type parameter of SetSpec and SetStatus. I agree that this is a valid concern, however I suggest to use the power of Go generics to fix this, as opposed to implementing it one-by-one for each type (avoiding this is the main reason for having generics).
Here s my proposal to add static type checking: #141

@ganchandrasekaran
Copy link
Contributor

/lgtm

@nephio-prow nephio-prow bot added the lgtm label Apr 30, 2023
@nephio-prow nephio-prow bot merged commit 89c76de into nephio-project:main Apr 30, 2023
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.

None yet

5 participants