-
Notifications
You must be signed in to change notification settings - Fork 40k
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 AsVersionedObject to deal with external schema #36066
Conversation
@Kargakis @smarterclayton PTAL @soltysh 🍺 |
LGTM |
@kubernetes/sig-api-machinery @kubernetes/sig-cli |
(need to add unit test) |
(added unit test) |
talked with @mfojtik, would like to see a test that fails without the fix in place first |
@liggitt now that I spend couple hours making that test working, I think I would defer this as making this work in kube will require more work. Basically, when I register new schema and add my types there, the To make the test work (I can show you WIP) we will need to add So what I suggest is to merge this as it is now and open a follow up to refactor this post-mortem. We also need this for Origin to fix the regression bug which is due to tomorrow. WDYT? |
@liggitt the WIP of the test is here: I can submit this with the test disabled until we fix the `AsVersionedObject ( kubernetes/pkg/kubectl/resource/result.go Line 254 in 56bbfd2
|
The problem here is the use of Get and the structured scheme. Get rid of / On Nov 3, 2016, at 9:59 AM, Michal Fojtik notifications@github.com wrote: @liggitt https://github.com/liggitt the WIP of the test is here: mfojtik/kubernetes@2c351af I can submit this with the test disabled until we fix the kubernetes/pkg/kubectl/resource/result.go Line 254 in 56bbfd2
) — |
@smarterclayton i'm not sure I understand what you're suggesting |
@liggitt added typer/encoder into AsVersionedObject and added unit test. |
@liggitt PTAL |
s.AddKnownTypes(externalGV, &ExternalTestType{}) | ||
s.AddKnownTypeWithName(externalGV.WithKind("TestType"), &ExternalTestType{}) | ||
s.AddKnownTypeWithName(internalGV.WithKind("TestType"), &TestType{}) | ||
// TODO: Use AddToScheme(s) here instead of explicitely calling the conversion function. |
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 if I do this I will get:
unexpected error: converting (util.TestType).CreationTimestamp.Time.sec to (util.ExternalTestType).CreationTimestamp.Time.sec: Cannot set dest. (Tried to deep copy something with unexported fields?)
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.
#35728 will fix it so that runtime.NewScheme() will get you the deep copies needed for objectmeta, so this is fine for now
Jenkins GCI GCE e2e failed for commit 5953e45. Full PR test history. The magic incantation to run this job again is |
Jenkins unit/integration failed for commit 61720752b222679a27e6ffca4d3f04f7510cb577. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE Node e2e failed for commit 86e6fd6. Full PR test history. The magic incantation to run this job again is |
Jenkins Kubemark GCE e2e failed for commit 9b9a3aff2bf2502d79db693c8f650840abc52b33. Full PR test history. The magic incantation to run this job again is |
@k8s-bot node e2e test this |
Still LGTM |
@@ -340,10 +340,10 @@ func getPrinter(cmd *cobra.Command) (*editPrinterOptions, error) { | |||
} | |||
} | |||
|
|||
func getMapperAndResult(f cmdutil.Factory, args []string, options *resource.FilenameOptions, editMode EditMode) (meta.RESTMapper, *resource.Mapper, *resource.Result, string, error) { | |||
func getMapperAndResult(f cmdutil.Factory, args []string, options *resource.FilenameOptions, editMode EditMode) (meta.RESTMapper, *resource.Mapper, runtime.ObjectTyper, *resource.Result, string, error) { |
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.
don't you already return the typer in resourceMapper.ObjectTyper
?
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.
you're right! will fix it
@@ -150,6 +150,9 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ | |||
allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces") | |||
showKind := cmdutil.GetFlagBool(cmd, "show-kind") | |||
mapper, typer := f.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.
when is this returning nil? (I assume it was nil or you wouldn't have added options.Typer
)
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 need to expose typer in GetOptions for a unit 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.
it's possible the test typer we mocked up in NewMixedFactory is wrong, or it's possible something else is wrong, but we need to figure out the problem there and fix it, not swap in a fake typer here for 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.
the test MixedFactory was actually returning a typer that would recognize the test types, but the point of TestGetUnknownSchemaObjectListGeneric
is to test serialization of objects the compiled-in typer doesn't recognize. Because you plumbed the typer correctly, we needed a way to simulate the typer not recognizing the test type.
fixed in mfojtik#1, and removed this field and test-only hack
@@ -225,10 +225,10 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) { | |||
} | |||
arr := out["items"].([]interface{}) | |||
if arr[0].(map[string]interface{})["apiVersion"] != test.testtypeVersion { |
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.
save locally and reuse, rather than repeating the index+cast:
if version := arr[0].(map[string]interface{})["apiVersion"]; version != test.testtypeVersion {
... 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.
i can drop this change, just something I encountered and was hard to debug.
@@ -210,7 +210,7 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) { | |||
cmd.Flags().Set("output", "json") | |||
|
|||
cmd.Flags().Set("output-version", test.outputVersion) | |||
err := RunGet(f, buf, errBuf, cmd, []string{"type/foo", "replicationcontrollers/foo"}, &GetOptions{}) | |||
err := RunGet(f, buf, errBuf, cmd, []string{"type/foo", "replicationcontrollers/foo"}, &GetOptions{Typer: api.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.
we need to revert this change and figure out whether the problem is in the typer returned from NewMixedFactory, or in AsVersionedObject, or elsewhere
yeah, #36085 fixed the get case |
@mfojtik PR needs rebase |
[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files: We suggest the following people: |
This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review. cc @adohe @deads2k @fabianofranz @mfojtik You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days |
This fixes errors where the internal object omits json tags or has a different field structure than the versioned object
At also add typer and encoder to
AsVersionedObject()
to deal with custom schemes.This change is