Closed NikhilSharmaWe closed 2 years ago
Thanks @NikhilSharmaWe - looks like there are some breaking API changes in kubectl / cli-utils. I'll take a look!
cc @seans3
@everettraven I also tried to make the code compatible with the changes made in the versions of kubectl
and cli-runtime
. But I was not able to find a proper approach. I tried to make some changes regarding the changes in the func Validator
. Could you please take a look https://github.com/NikhilSharmaWe/kubebuilder-declarative-pattern/commit/b2da05f0abcd5d05d24726e39228f4b5d540fc6e.
After we can get a reasonable approach for func Validator
, we can move to func NewApplyOptions
.
I also tried to make the code compatible with the changes made in the versions of
kubectl
andcli-runtime
. But I was not able to find a proper approach. I tried to make some changes regarding the changes in the funcValidator
. Could you please take a look NikhilSharmaWe@b2da05f.After we can get a reasonable approach for func
Validator
, we can move to funcNewApplyOptions
.
@NikhilSharmaWe Sure thing, I will take a look and see what I can come up with!
@NikhilSharmaWe I made a draft PR so that I could have the tests run on any changes that I made. I was able to get the tests passing. You should be able to see the changes in the draft PR here: https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/pull/222
I wanted to let you be able to make the changes and have your PR merged in instead of mine since you have already done a bunch of great work on it. I hope the changes in that draft PR helps!
(I am also going to keep the draft open for now in case there is some need for more testing minor changes outside of this PR)
@everettraven Thank you for showing the correct approach for resolving the breaking changes.
In pkg/patterns/declarative/pkg/applier/direct.go
For func NewFactory
: After seeing your approach I think my approach was almost correct but I needed to resource.QueryParamFieldValidation
instead of resource.QueryParamDryRun
in func NewQueryParamVerifier
.
For func NewApplyOptions
: In the future are we thinking to improve this approach in the future by using the new functions added in the package k8s.io/kubectl/pkg/cmd/apply
like https://pkg.go.dev/k8s.io/kubectl@v0.24.0/pkg/cmd/apply#ApplyFlags.ToOptions to produce the desired *apply.ApplyOptions
instead of copying the function NewApplyOptions
which was present in the pkg before.
Or is this unnecessary?
c/c @camilamacedo86
@NikhilSharmaWe
In pkg/patterns/declarative/pkg/applier/direct.go
* For func `NewFactory`: After seeing your approach I think my approach was almost correct but I needed to `resource.QueryParamFieldValidation` instead of `resource.QueryParamDryRun` in func `NewQueryParamVerifier`.
I agree, I think your approach here was pretty much spot on and only required the change to use resource.QueryParamFieldValidation
* For func `NewApplyOptions`: In the future are we thinking to improve this approach in the future by using the new functions added in the package `k8s.io/kubectl/pkg/cmd/apply` like https://pkg.go.dev/k8s.io/kubectl@v0.24.0/pkg/cmd/apply#ApplyFlags.ToOptions to produce the desired `*apply.ApplyOptions` instead of copying the function `NewApplyOptions` which was present in the pkg before. Or is this unnecessary?
This is a great point. I think that this is definitely worth taking a look into and seeing if this would be a better solution than copying the NewApplyOptions
from the previous implementation. I will take a look into this and see if I can come up with a logical way to do this.
@NikhilSharmaWe I was able to get the apply options working using this snippet:
baseName := "declarative-direct"
applyFlags := apply.NewApplyFlags(f, ioStreams)
applyCmd := apply.NewCmdApply(baseName, f, ioStreams)
applyOpts, err := applyFlags.ToOptions(applyCmd, baseName, nil)
if err != nil {
return fmt.Errorf("error getting apply options: %w", err)
}
It also required moving the factory creation outside of the if opt.Validate
block like so:
f := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
if opt.Validate {
// implementation ...
}
Thanks for pointing that out!
@everettraven: changing LGTM is restricted to collaborators
@everettraven Thank you for considering the suggestion. Just wanted to ask how did found out that the base name should be
declarative-direct
.
It could be any string, but when looking into the details of the apply.NewCmdApply
and Apply.ToOptions
the baseName is used when printing messages or warnings (can be seen here: https://github.com/kubernetes/kubectl/blob/9a9633e4515045b45600d2e9cc5f0498c5a4d0d1/pkg/cmd/apply/apply.go#L301-L303).
I felt like declarative-direct
was descriptive enough to point it to this repo and being in the direct.go
file that the setup is being done in.
Now that I think about it, kubebuilder-declarative-applier-direct
would be much more descriptive so feel free to change it to that if you would like, but I think the former is still rather descriptive.
/lgtm
/lgtm
@justinsb Could you check this?
@justinsb could you take a look at this?
We have a couple projects relying on this dependency to be upgraded to support k8s 1.24 before they can be upgraded.
Thanks!
@atoato88 or @justinsb is there anything else that needs to be done to get this merged?
/approve Sorry for my delay. Thank you to create and update PR.
It already looks good for me, and I thinked it is also good to get review from other approver if possible. But I approve this because this PR is getting time.
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: atoato88, camilamacedo86, everettraven, NikhilSharmaWe
The full list of commands accepted by this bot can be found here.
The pull request process is described here
FYI we started to encounter an issue that seems to have been introduced in this PR: https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/issues/224
Wondering if anyone can take a look.
What this PR does / why we need it:
This PR bumps versions of k8s dependencies and controller-runtime and k8s dependencies to be compatible with https://github.com/kubernetes-sigs/kubebuilder.