-
Notifications
You must be signed in to change notification settings - Fork 263
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
feature(service create/update): Register list of EnvVars in alphabetical order #389
Conversation
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.
@toVersus: 0 warnings.
In response to this:
Proposed Changes
In current logic of handling user input of Environment variables, list of EnvVars are registered in random order because we convert user input string to Golang map and append them into slice of corev1.EnvVars, which has no guarantee of stable order as follows:
$ ./kn service create hello --image="gcr.io/knative-samples/helloworld-go" -e FOO=foo -e BAR=bar -e BAZ=baz -e QUX=qux -e EMPTY= Service 'hello' successfully created in namespace 'default'. Waiting for service 'hello' to become ready ... OK Service URL: http://hello-default.example.com $ ./kn service describe hello -o yaml (...) spec: containers: - env: - name: BAZ value: baz - name: QUX value: qux - name: EMPTY - name: FOO value: foo - name: BAR value: barWe need to fix this for passing mock test without flakiness as well as GitOps deployment without causing any bothering diffs.
- Register list of EnvVars in the same order as user input when creating new kservice
- Keep the original order of EnvVars when updating existing kservice
- Add mock test for create/update service with EnvVars
After:
$ ./kn service create hello --image="gcr.io/knative-samples/helloworld-go" -e FOO=foo -e BAR=bar -e BAZ=baz -e QUX=qux -e EMPTY= Service 'hello' successfully created in namespace 'default'. Waiting for service 'hello' to become ready ... OK Service URL: http://hello-default.example.com $ ./kn service describe hello -o yaml (...) spec: containers: - env: - name: FOO value: foo - name: BAR value: bar - name: BAZ value: baz - name: QUX value: qux - name: EMPTY (...) $ ./kn service update hello -e FOO=foov2 -e BAR- Waiting for service 'hello' to become ready ... OK Service 'hello' updated in namespace 'default'. $ ./kn service describe hello -o yaml (...) spec: containers: - env: - name: FOO value: foov2 - name: BAZ value: baz - name: QUX value: qux - name: EMPTY (...)Part of: #358
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Hi @toVersus. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Is there a flakiness in tests due to order of env?
Interesting, are resource template files stored using |
/ok-to-test |
Sorry, currently not in tests. However, when I try to add TestServiceCreateEnvMock mock test, it would emerge due to this assert.DeepEqual as follows: === RUN TestServiceCreateEnvMock
--- FAIL: TestServiceCreateEnvMock (0.00s)
client_mock.go:292: assertion failed:
--- call.args[i]
+++ arg
&v1alpha1.Service{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{Name: "foo", Namespace: "default"},
Spec: v1alpha1.ServiceSpec{
... // 3 identical fields
DeprecatedManual: nil,
DeprecatedRelease: nil,
ConfigurationSpec: v1alpha1.ConfigurationSpec{
DeprecatedGeneration: 0,
DeprecatedBuild: nil,
DeprecatedRevisionTemplate: nil,
Template: &v1alpha1.RevisionTemplateSpec{
ObjectMeta: v1.ObjectMeta{},
Spec: v1alpha1.RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1.PodSpec{
Volumes: nil,
InitContainers: nil,
Containers: []v1.Container{
{
... // 5 identical fields
Ports: nil,
EnvFrom: nil,
Env: []v1.EnvVar{
- {Name: "a", Value: "mouse"},
{Name: "b", Value: "cookie"},
{Name: "empty"},
+ {Name: "a", Value: "mouse"},
},
Resources: v1.ResourceRequirements{Limits: v1.ResourceList{}, Requests: v1.ResourceList{}},
VolumeMounts: nil,
... // 11 identical fields
},
},
RestartPolicy: "",
TerminationGracePeriodSeconds: nil,
... // 24 identical fields
},
ContainerConcurrency: 0,
TimeoutSeconds: nil,
},
DeprecatedGeneration: 0,
DeprecatedServingState: "",
... // 4 identical fields
},
},
},
RouteSpec: v1alpha1.RouteSpec{},
},
Status: v1alpha1.ServiceStatus{},
}
Yeah, I assume to use |
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 is now green, is this passing? What was the change?
@maximilien, sorry for confusing you. The tests included in this PR are always green without a flakiness from the beginning. OK, I summarize. When I first introduced the mock test for service create with env vars, I encountered the error described above. Therefore, I fixed some internal logic and made mock test green, then raised this PR. |
ad8a26a
to
fff4bfe
Compare
@toVersus : During last WG PR rodeo, its discussed that simply sort the env vars before updating the service. |
@navidshaikh Ah okay, but should we sort env vars in order of user input or env key name? |
Env key name. User input is a lot harder to get consistent
… On Aug 31, 2019, at 1:03 AM, Tsubasa Nagasawa ***@***.***> wrote:
@navidshaikh Ah okay, but should we sort env vars in order of user input or env key name?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@sixolet, Thanks for clarifying, I fixed! (Also updated both the title and description of this PR.) |
30507f2
to
56a0178
Compare
It's ready for review :) |
90b7c31
to
e3a6395
Compare
I agree, that env vars should not be listed in random order, but why should the order be alphabetically and not the order as defined in the Service (env vars are registered as an array) ? |
In my initial proposal below, I tried to sort the env vars in the order of user input.
However, the ordering logic became complicated given the consistency in the order when updating/deleting existing ones. See #389 (comment). client/pkg/kn/commands/service/configuration_edit_flags.go Lines 298 to 326 in 2ca3980
client/pkg/serving/config_changes.go Lines 238 to 275 in 2ca3980
I'm not sure what was discussed in the last WG PR rodeo, but they decided to register the env vars alphabetically. See #389 (comment). |
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.
few nits on naming of functions and variables
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.
@toVersus lets squash the commits
@navidshaikh I think Prow robot will squash the commits when a PR is merged. Should I manually squash the commits? |
@toVersus : There are commits in this PR for the initial approach taken, then we changed to alphabetical order, I asked explicitly to squash to reflect the approach we're taking. |
5c7b441
to
220576d
Compare
The following is the coverage report on pkg/.
|
@navidshaikh I'm not sure I could take the action you asked me to do, but I removed the commit messages regarding the initial approach from this PR. |
@rhuss :
The actual order of env doesn't impact and maintaining the alphabetically order is simpler and consistent than maintaining the user provided env order. |
ok, convinced. let's go with the alphabetical order (assuming that duplicate keys in the env-list is already treated properly by the env handling as the later key overrides a former key) |
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: navidshaikh, toVersus The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
They break the authentication if present.
Proposed Changes
In current logic of handling user input of Environment variables, list of EnvVars are registered in random order because we convert user input string to Golang map and append them into slice of corev1.EnvVars, which has no guarantee of stable order as follows:
We need to fix this for passing mock test without flakiness as well as GitOps deployment without causing any bothering diffs.
After:
Part of: #358
/lint