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 AsVersionedObject to deal with external schema #36066

Closed
wants to merge 1 commit into from

Conversation

mfojtik
Copy link
Contributor

@mfojtik mfojtik commented Nov 2, 2016

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 Reviewable

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2016

@Kargakis @smarterclayton PTAL

@soltysh 🍺

@soltysh
Copy link
Contributor

soltysh commented Nov 2, 2016

LGTM

@0xmichalis
Copy link
Contributor

@kubernetes/sig-api-machinery @kubernetes/sig-cli

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2016

(need to add unit test)

@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Nov 2, 2016
@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 2, 2016

(added unit test)

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 2, 2016
@soltysh soltysh added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Nov 2, 2016
@soltysh
Copy link
Contributor

soltysh commented Nov 2, 2016

@liggitt || @deads2k any objections for merge at this point?

@liggitt
Copy link
Member

liggitt commented Nov 2, 2016

talked with @mfojtik, would like to see a test that fails without the fix in place first

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2016

@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 AsVersionedObject method have api.Schema.ObjectKinds(info.Object) hardcoded, so my custom types will get converted to runtime.Unknown and the test will fail....
This also explains why this fix is working just fine for origin (Origin types are registered in api.Schema?).

To make the test work (I can show you WIP) we will need to add runtime.ObjectTyper to AsVersionedObject (or even runtime.Schema) and plumb this all the way up to factory and all tests...

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?

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2016

@liggitt the WIP of the test is here:

mfojtik@2c351af

I can submit this with the test disabled until we fix the `AsVersionedObject (

if _, _, err := api.Scheme.ObjectKinds(info.Object); runtime.IsNotRegisteredError(err) {
)

@smarterclayton
Copy link
Contributor

The problem here is the use of Get and the structured scheme. Get rid of /
fix either and you fix this issue.

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
mfojtik@2c351af

I can submit this with the test disabled until we fix the
`AsVersionedObject (

if _, _, err := api.Scheme.ObjectKinds(info.Object); runtime.IsNotRegisteredError(err) {

)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#36066 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_pxaRx-m1CcOBE8bHc4y8N8R7fQX1ks5q6eilgaJpZM4KnQq7
.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2016

@smarterclayton i'm not sure I understand what you're suggesting

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2016

@liggitt added typer/encoder into AsVersionedObject and added unit test.

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 3, 2016

@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.
Copy link
Contributor Author

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?)

Copy link
Member

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

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 3, 2016
@mfojtik mfojtik changed the title Use versioned object when recording changes using --record Fix AsVersionedObject to deal with external schema Nov 3, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins GCI GCE e2e failed for commit 5953e45. Full PR test history.

The magic incantation to run this job again is @k8s-bot gci gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit 61720752b222679a27e6ffca4d3f04f7510cb577. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE Node e2e failed for commit 86e6fd6. Full PR test history.

The magic incantation to run this job again is @k8s-bot node e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins Kubemark GCE e2e failed for commit 9b9a3aff2bf2502d79db693c8f650840abc52b33. Full PR test history.

The magic incantation to run this job again is @k8s-bot kubemark e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@soltysh
Copy link
Contributor

soltysh commented Nov 4, 2016

@k8s-bot node e2e test this

@soltysh
Copy link
Contributor

soltysh commented Nov 4, 2016

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) {
Copy link
Member

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?

Copy link
Contributor Author

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()
Copy link
Member

@liggitt liggitt Nov 4, 2016

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)

Copy link
Contributor Author

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)

Copy link
Member

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

Copy link
Member

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 {
Copy link
Member

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 ...
}

Copy link
Contributor Author

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.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2016
@@ -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})
Copy link
Member

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

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 7, 2016

@liggitt I think @deads2k already took care of the "get" here:

#36085

So no plumbing is needed with this PR.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 7, 2016
@soltysh
Copy link
Contributor

soltysh commented Nov 7, 2016

It's possible that this is fixed in #36369 much more cleanly. @mfojtik mind checking that?

@deads2k
Copy link
Contributor

deads2k commented Nov 7, 2016

It's possible that this is fixed in #36369 much more cleanly. @mfojtik mind checking that?

That ended up too big for 1.5

@liggitt
Copy link
Member

liggitt commented Nov 7, 2016

yeah, #36085 fixed the get case

@mfojtik
Copy link
Contributor Author

mfojtik commented Nov 8, 2016

@liggitt @deads2k you OK merging this as it is?

@k8s-github-robot
Copy link

@mfojtik PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2016
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files:

We suggest the following people:
cc @sig-cli-maintainers
You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.