-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Force using versioned objects in apply's patch #35688
Conversation
Great! It works. |
Ha! Fixes #25106 (i was right) |
@@ -220,7 +230,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App | |||
helper := resource.NewHelper(info.Client, info.Mapping) | |||
patcher := NewPatcher(encoder, decoder, info.Mapping, helper, overwrite) | |||
|
|||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name) | |||
infos := []*resource.Info{info} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... you should have info.VersionedObject set here. Can you verify that you do (it should be the external version)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I'll check, but from what I see kubectl edit is using the same approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that's where I copied it from 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info.VersionedObject
to my surprise is of type interface {}
and might be nil
as well, so I'd have to cast it to runtime.Object
and if that fails fall back to resource.AsVersionedObject
. Or stay with current solution? Which one you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Apply has VersionedObject as nil, other things will fail. VersionedObject was added in order to solve the Apply use case, so it's expected to work in general.
This LGTM, but I defer to @smarterclayton for the final call. |
Grrrr.... after using |
|
Please open a follow up issue for it. If versioned object doesn't work, we On Nov 1, 2016, at 4:08 AM, Maciej Szulik notifications@github.com wrote: .VersionedObject doesn't work with lists, it looks like the code does not — |
Tell me about it 😉 I've created #35999 and assigned it to myself. Can we merge this as is in that case? |
@@ -220,7 +230,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App | |||
helper := resource.NewHelper(info.Client, info.Mapping) | |||
patcher := NewPatcher(encoder, decoder, info.Mapping, helper, overwrite) | |||
|
|||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name) | |||
infos := []*resource.Info{info} | |||
originalObj, err := resource.AsVersionedObject(infos, false, defaultVersion, encoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if you try to apply two objects in different API versions, it looks like. Is there a test that proves it doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll verify that and add a proper test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the reason this doesn't have VersionedObject is because you are calling Get() up above. Why are you calling Get() up above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defending I didn't write that part won't probably help 😜 . I'll test proposed approaches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped Get, but that still suffers from list not having VersionedObject set :/ I think I'll leave that for later in that case. Hopefully when we enter codefreeze I'll find some time to dig into this.
This is a bug so it can be worked post feature freeze. |
Jenkins unit/integration failed for commit 9cafc7e. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE etcd3 e2e failed for commit 9cafc7e. Full PR test history. The magic incantation to run this job again is |
Jenkins GCI GCE e2e failed for commit 9cafc7e. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE e2e failed for commit 9cafc7e. Full PR test history. The magic incantation to run this job again is |
Do we have an ETA for this? Also, what version will this be fixed in? Thanks! |
No strict ETA, rather wishful thinking of mine to have it in for 1.5 |
@soltysh please rebase this, I think this has blocked users using HPA. |
@adohe rebase is one thing, most importantly this needs final solution :/ |
@soltysh Ok, I will take a look. |
if !dryRun { | ||
overwrite := cmdutil.GetFlagBool(cmd, "overwrite") | ||
helper := resource.NewHelper(info.Client, info.Mapping) | ||
patcher := NewPatcher(encoder, decoder, info.Mapping, helper, overwrite) | ||
|
||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right... VersionedObject is what the client provided, Object came from the server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
against master, I'm seeing an error inside patchSimple
, where this line is returning an internal object:
versionedObject, _, err := p.decoder.Decode(current, nil, nil)
using the info from the mapping instead let the apply unit tests pass for me:
versionedObject, err := api.Scheme.New(p.mapping.GroupVersionKind)
edit: I take it back... that may only work for types registered into the scheme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt thx for the feedback, it's on my list for this week, hopefully.
@@ -182,45 +182,17 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App | |||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving modified configuration from:\n%v\nfor:", info), info.Source, err) | |||
} | |||
|
|||
if err := info.Get(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not remove all of this. Otherwise, we can't use kubectl apply
to create non-existing resource.
if !dryRun { | ||
overwrite := cmdutil.GetFlagBool(cmd, "overwrite") | ||
helper := resource.NewHelper(info.Client, info.Mapping) | ||
patcher := NewPatcher(encoder, decoder, info.Mapping, helper, overwrite) | ||
|
||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name) | ||
originalObj, ok := info.VersionedObject.(runtime.Object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info.VersionedObject is no longer a interface. Don't need to cast.
@soltysh PR needs rebase |
I'm not sure this is needed anymore. Can you double check with the tests you added and see if this is already fixed in master? |
The problem still persists. I just checked on lastest master and I'm getting following error:
I'll try to fix it this week. |
Here's the current state. I can't use @deads2k @liggitt @caesarxuchao @kubernetes/sig-api-machinery-misc any ideas how this could be fixed? I'm thinking about two possible approaches:
Are there other options I'm missing here? |
Btw, am I the only one who finds this confusing. I've always thought |
At Box we're hitting an issue like this trying to apply (update an already created one, first time apply works just fine) instances of a thirdpartyresource after upgrading to 1.4.8. I can't tell if this or #38982 will fix this problem for instances of a ThirdPartyResource. Our error message looks like:
|
@huggsboson This is the PR #39396 merged in 1.4 branch. But the patch is not for fixing TPR. |
I think #40260 is more likely to be what we want, switching apply to use unstructured and not do any conversion or defaulting from the input the user gives |
I'll check, thx for the pointer. |
[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files: We suggest the following people: |
Fixes #35149 and #34413.
Until now
kubectl apply
was working with internal version and manually invoking encoding, which resulted in problems converting object to versioned counterpart. It worked until now mostly because each group had only single version, but with multiple versions usually the first/preferred is chosen, which in case of ScheduledJobs isn't true. (ScheduledJobs exists inbatch/v2alpha1
, but preferred version isbatch/v1
). Resource helper has all the necessary information to perform necessary conversion so I've added conversion before actually calling the patch method and passing it as versioned to that method.@janetkuo or anyone from @kubernetes/kubectl ptal
This change is