Skip to content

Inject warns on UDP ports#1617

Merged
siggy merged 1 commit intomasterfrom
siggy/inject-udp
Sep 11, 2018
Merged

Inject warns on UDP ports#1617
siggy merged 1 commit intomasterfrom
siggy/inject-udp

Conversation

@siggy
Copy link
Member

@siggy siggy commented Sep 10, 2018

linkerd only routes TCP data, but linkerd inject does not warn when it
injects into pods with ports set to protocol: UDP.

Modify linkerd inject to warn when injected into a pod with
protocol: UDP. The Linkerd sidecar will still be injected, but the
stderr output will include a warning.

Also add stderr checking on all inject unit tests.

Part of #1516.

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

Copy link
Contributor

@dadjeibaah dadjeibaah left a comment

Choose a reason for hiding this comment

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

Like the new flag! thanks for adding this. Left a few comments.

func injectPodSpec(t *v1.PodSpec, identity k8s.TLSIdentity, controlPlaneDNSNameOverride string, options *injectOptions, report *injectReport) bool {
// Pods with `hostNetwork=true` share a network namespace with the host. The
// check for ports with `protocol: udp`, which will not be routed by Linkerd
for _, container := range t.Containers {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get away with making this loop a function and then returning true as soon as we encounter a port with using UDP protocol. Something like:

func checkUDPPorts(t *v1.PodSpec) bool{
	// check for ports with `protocol: udp`, which will not be routed by Linkerd
	for _, container := range t.Containers {
		for _, port := range container.Ports {
			if port.Protocol == v1.ProtocolUDP {
				return true
			}
		}
	}
	return false
}

func injectPodSpec(t *v1.PodSpec, identity k8s.TLSIdentity, controlPlaneDNSNameOverride string, options *injectOptions, report *injectReport) bool {
...
report.udp = checkUDPPorts(t)

// for inject reports
hostNetworkDesc = "hostNetwork: pods do not use host networking"
unsupportedDesc = "supported: at least one resource injected"
udpDesc = "udp: pods do not use UDP protocol"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if this should be a statement like all pods using TCP protocol.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, i went back and forth on this one. i'm a bit hesitant to use a phrase like all pods, because whether a pod has zero, one, or all pods set as UDP, we're still going to inject. the intent is more just a warning to the user that at least one pod is using UDP.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, how about "pod specs do not include UDP ports"? I'd like to avoid "UDP protocol", since protocol is redundant.

{"inject_emojivoto_deployment.input.yml", "inject_emojivoto_deployment_tls.golden.yml", tlsOptions},
{"inject_emojivoto_pod.input.yml", "inject_emojivoto_pod_tls.golden.yml", tlsOptions},
{
inputFileName: "inject_emojivoto_deployment.input.yml",
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this formatting intended? I do like that the test cases are now readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup! since i was adding a new reportFileName field, it felt a bit more readable to call explicitly call out the key names.

Copy link
Contributor

@klingerf klingerf left a comment

Choose a reason for hiding this comment

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

⭐️ Great, thanks for all the test improvements as well. I just had a small copy edit, but otherwise looks good to me.

// for inject reports
hostNetworkDesc = "hostNetwork: pods do not use host networking"
unsupportedDesc = "supported: at least one resource injected"
udpDesc = "udp: pods do not use UDP protocol"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, how about "pod specs do not include UDP ports"? I'd like to avoid "UDP protocol", since protocol is redundant.

linkerd only routes TCP data, but `linkerd inject` does not warn when it
injects into pods with ports set to `protocol: UDP`.

Modify `linkerd inject` to warn when injected into a pod with
`protocol: UDP`. The Linkerd sidecar will still be injected, but the
stderr output will include a warning.

Also add stderr checking on all inject unit tests.

Part of #1516.

Signed-off-by: Andrew Seigner <[email protected]>
@siggy siggy merged commit 7eec5f1 into master Sep 11, 2018
@siggy siggy deleted the siggy/inject-udp branch September 11, 2018 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants