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

adding sidecarEnvJson annotation #726

Merged
merged 4 commits into from
Sep 11, 2023
Merged

adding sidecarEnvJson annotation #726

merged 4 commits into from
Sep 11, 2023

Conversation

dileepng
Copy link
Contributor

Issue #, if available:
#724
Description of changes:
Adding Feature appmesh.k8s.aws/sidecarEnvJson that accepts json list as env for envoy.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -249,6 +259,45 @@ func (m *envoyMutator) getCustomEnv(pod *corev1.Pod) (map[string]string, error)
return customEnv, nil
}

type customEnvJsonType []map[string]string

func (c *customEnvJsonType) UnmarshalJSON(data []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need we make a valid check for bytes before unmarshal if the input is empty or nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw malformed error. so, I didn't make a check for that condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Good to know

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of a sidenote, but a nil array is functionally identical to a empty array in Go, so you generally never need to check for nil arrays. (the same is not always true for maps)

@@ -249,6 +259,45 @@ func (m *envoyMutator) getCustomEnv(pod *corev1.Pod) (map[string]string, error)
return customEnv, nil
}

type customEnvJsonType []map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you not just using a map[string]string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I thought of returning Array of maps, then I changed to returning only one map. I will change the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@@ -249,6 +259,41 @@ func (m *envoyMutator) getCustomEnv(pod *corev1.Pod) (map[string]string, error)
return customEnv, nil
}

type customEnvJsonType map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this custom type still need to exist, or can getCustomEnvJson just deserialize to map[string]string directly?

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 think, it can't be deserialize directly to map[string]string.

we need to have a defined type for methods. Here this method needs some type to a variable to store the deserialized data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place I see this type used is in the getCustomEnvJson function, which immediately unwraps it to a map[string]string.

Generally, you only need to some serialization-time changes between the representative data type and the target data type (for instance, when converting strings to dates). I think that might have been true of the first draft of this where the input data was a list of strings, but now that it's just a map of string->string it's the same as what the target type is. Just passing map[string]string to unmarshal should accomplish this fine without the indirection.

@dileepng dileepng merged commit ed3847a into aws:master Sep 11, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants