Skip to content

Introduce inject integration tests#2616

Merged
siggy merged 2 commits intomasterfrom
siggy/inject-integration
Apr 5, 2019
Merged

Introduce inject integration tests#2616
siggy merged 2 commits intomasterfrom
siggy/inject-integration

Conversation

@siggy
Copy link
Member

@siggy siggy commented Apr 2, 2019

This change introduces integration tests for linkerd inject. The tests
perform CLI injection, with and without params, and validates the
output, including annotations.

Also add some known errors in logs to install_test.go.

TODO:

  • deploy uninjected and injected resources to a default and
    auto-injected cluster
  • test creation and update

Part of #2459

Signed-off-by: Andrew Seigner [email protected]

@siggy siggy added the area/test label Apr 2, 2019
@siggy siggy self-assigned this Apr 2, 2019
@siggy siggy force-pushed the siggy/inject-integration branch 3 times, most recently from 851af62 to dd7cacb Compare April 2, 2019 19:49
@siggy siggy changed the title Introduce inject integration tests DO NOT REVIEW: Introduce inject integration tests Apr 2, 2019
@siggy siggy force-pushed the siggy/inject-integration branch from dd7cacb to ce3c160 Compare April 2, 2019 20:56
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 2, 2019

@siggy siggy force-pushed the siggy/inject-integration branch from ce3c160 to cac1276 Compare April 2, 2019 22:04
@linkerd linkerd deleted a comment from l5d-bot Apr 2, 2019
@linkerd linkerd deleted a comment from l5d-bot Apr 2, 2019
@linkerd linkerd deleted a comment from l5d-bot Apr 2, 2019
@linkerd linkerd deleted a comment from l5d-bot Apr 2, 2019
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 2, 2019

@siggy siggy changed the title DO NOT REVIEW: Introduce inject integration tests Introduce inject integration tests Apr 2, 2019
@admc admc mentioned this pull request Apr 2, 2019
25 tasks
@siggy siggy force-pushed the siggy/inject-integration branch from c9e7b2e to 2f77ba3 Compare April 4, 2019 01:15
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 4, 2019

@siggy siggy force-pushed the siggy/inject-integration branch 2 times, most recently from b2e39b3 to f0c441d Compare April 4, 2019 01:49
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 4, 2019

@siggy siggy requested review from alpeb and ihcsim April 4, 2019 17:07
@siggy siggy force-pushed the siggy/inject-integration branch from f0c441d to 9cece5e Compare April 4, 2019 17:15
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 4, 2019

Copy link
Member

@alpeb alpeb left a comment

Choose a reason for hiding this comment

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

According to this

o, err := TestHelper.Kubectl(patchedYAML, "--namespace", ns, "create", "-f", "-")

you're relying on the proxy-injector that one of the install_test.go runs set up to get the pods injected in TestAnnotationPermutations, right?

I got confused by that a little bit. I think it'd be better to disassociate tests more, by having install_test.go clean up the webhook after it's done, and setting a new one for this test (to also be cleaned when finished).

All the other changes looked good to me. I left below a couple of nits.

patchJSON := []byte(`[
{"op": "remove", "path": "/spec/template/metadata/annotations/linkerd.io~1created-by"},
{"op": "remove", "path": "/spec/template/metadata/annotations/linkerd.io~1proxy-version"}
]`)
Copy link
Member

Choose a reason for hiding this comment

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

Nice leverage of json-patch here 😉

@@ -0,0 +1,282 @@
package get
Copy link
Member

Choose a reason for hiding this comment

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

Should be inject

case "", k8s.ProxyInjectDisabled:
switch podAnnotation {
case k8s.ProxyInjectEnabled:
shouldBeInjected = true
Copy link
Member

Choose a reason for hiding this comment

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

Why favoring a switch here instead of a simple if?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's completely subjective. I tried writing this both ways, and I find the switch slightly more readable than the if.

Here they are side-by-side, let me know what you think:

shouldBeInjected := false
if nsAnnotation == "" || nsAnnotation == k8s.ProxyInjectDisabled {
	shouldBeInjected = podAnnotation == k8s.ProxyInjectEnabled
} else if nsAnnotation == k8s.ProxyInjectEnabled {
	shouldBeInjected = (podAnnotation == "" || podAnnotation == k8s.ProxyInjectEnabled)
}
shouldBeInjected := false
switch nsAnnotation {
case "", k8s.ProxyInjectDisabled:
	switch podAnnotation {
	case k8s.ProxyInjectEnabled:
		shouldBeInjected = true
	}
case k8s.ProxyInjectEnabled:
	switch podAnnotation {
	case "", k8s.ProxyInjectEnabled:
		shouldBeInjected = true
	}
}

Copy link
Member

Choose a reason for hiding this comment

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

The outer switch looks good. I was gonna say ifs are better in the inner conditions, but not so much for the second one where an or is involved. But it's definitely more readable keeping all switches for consistency-sake. I'm gonna steal this idiom :shipit:

@alpeb
Copy link
Member

alpeb commented Apr 4, 2019

Actually I'm not sure about my previous comment anymore. All the integration tests rely on the setup done by install_test.go. So in this case a simple comment might suffice, clarifying that the control plane is configured for auto-injection at this point.

@siggy
Copy link
Member Author

siggy commented Apr 4, 2019

@alpeb Yup there's an assumption with the integration tests that install_test.go always runs first: https://github.com/linkerd/linkerd2/blob/38f504beb14cf216443ec7a6bad147d25c0d308e/TEST.md#running-tests

Agree that inject_test.go is still a little special, in that is specifically requires a control-plane with auto-injection. I've added a comment above TestAnnotationPermutations calling this out.

siggy added 2 commits April 4, 2019 14:49
This change introduces integration tests for `linkerd inject`. The tests
perform CLI injection, with and without params, and validates the
output, including annotations.

Also add some known errors in logs to `install_test.go`.

TODO:
- deploy uninjected and injected resources to a default and
  auto-injected cluster
- test creation and update

Part of #2459

Signed-off-by: Andrew Seigner <[email protected]>
Signed-off-by: Andrew Seigner <[email protected]>
@siggy siggy force-pushed the siggy/inject-integration branch from cfbac81 to 88332c8 Compare April 4, 2019 21:49
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 4, 2019

Copy link
Member

@alpeb alpeb left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@siggy siggy merged commit 2f80add into master Apr 5, 2019
@siggy siggy deleted the siggy/inject-integration branch April 5, 2019 18:42
KatherineMelnyk pushed a commit to KatherineMelnyk/linkerd2 that referenced this pull request Apr 5, 2019
This change introduces integration tests for `linkerd inject`. The tests
perform CLI injection, with and without params, and validates the
output, including annotations.

Also add some known errors in logs to `install_test.go`.

TODO:
- deploy uninjected and injected resources to a default and
  auto-injected cluster
- test creation and update

Part of linkerd#2459

Signed-off-by: Andrew Seigner <[email protected]>
Signed-off-by: [email protected] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants