Refactor GenericMap to prevent managedField issues #2080
Conversation
7de55c1
to
4f584ea
Compare
d7718d0
to
dd3874a
Compare
Looks like I'm still having some issues here. Will update. |
9a8f556
to
4f2c319
Compare
OK -- this is all ready to go |
f8b8850
to
46804c1
Compare
@@ -749,7 +749,7 @@ type Secret struct { | |||
Name string `json:"name,omitempty"` | |||
Description string `json:"description,omitempty"` | |||
Type string `json:"type,omitempty"` | |||
Params GenericMap `json:"params,omitempty"` | |||
Params *GenericMap `json:"params,omitempty"` |
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.
Since this is a pointer everywhere I feel like the chance of panic is extremely high. Like I'm reading all the changes and trying to see if you first checked for nil. What if you add a GetData() to GenericMap
that will first check if the receiver is nil and then return nil. So then existing code that did foo.DeployArgs
and just be changed to foo.DeployArgs.GetData()
and still be safe.
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 like this. Added.
f0d9ab2
to
ab06f9f
Compare
The integration tests are failing in a way that makes it hard to tell what the exact problem is.
when attempting to run an Acorn built earlier in the same test I know that it must be happening client-side since I'm executing the test in my branch against a local instance running |
167448a
to
e0f81b1
Compare
7551be9
to
8bf97b6
Compare
This is all ready for review. Thanks for the patience folks. |
@@ -140,7 +140,7 @@ func ToAppUpdate(ctx context.Context, c Client, name string, opts *AppUpdateOpti | |||
app.Spec.Environment = mergeEnv(app.Spec.Environment, opts.Env) | |||
app.Spec.Labels = mergeLabels(app.Spec.Labels, opts.Labels) | |||
app.Spec.Annotations = mergeLabels(app.Spec.Annotations, opts.Annotations) | |||
app.Spec.DeployArgs = typed.Concat(app.Spec.DeployArgs, opts.DeployArgs) | |||
app.Spec.DeployArgs = app.Spec.DeployArgs.Merge(v1.NewGenericMap(opts.DeployArgs)) |
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 really like the way this looks. Any suggestions?
return a.OriginalImage == b.OriginalImage && | ||
a.Context == b.Context && | ||
a.Acornfile == b.Acornfile && | ||
equality.Semantic.DeepEqual(a.BuildArgs.GetData(), b.BuildArgs.GetData()) |
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 was added to satisfy a preexisting requirement in the code that depends on equality between the zero value of v1.GenericMap
and nil
; when we switched from a named map type to a struct, the default logic provided by equality.Semantic
was no longer sufficient.
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.
Have you tried integrating this into manager and seeing what happens?
I've smoke-tested the backwards and forwards compatibility in runtime, so this should work just fine. A PR for manager using this branch is on its way. |
Switch GenericMap from a named `map[string]interface{}` type to a struct with a Data field. This allows us to override the openapi spec once, at the type level, instead of retroactively at runtime for each new field of type GenericMap added to our API structs. This prevents the "managedFields" log that occurs when we forget to add new fields to the OpenAPI modification logic. Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
This change lets us generate the correct OpenAPI schema for
GenericMap
without the need to mutate the schema for fields, by name, at runtime. It will stop the "managedFields" message from being printed for preexisting usages ofGenericMap
and prevent it for all new usages going forward.