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

Add redirect params as annotations to pod resolves issue #12906 #14171

Merged
merged 9 commits into from Jun 9, 2019

Conversation

john-a-joyce
Copy link
Contributor

When Helm is used to specify additional redirection parameters they are passed to the istio_init container via command line args. When the CNI is used there is normally not an istio_init container and these redirection parameters are lost. The CNI already has logic to handle all of these additional redirection parameters when applied directly to the pod spec. This PR enhances the istio kube injection logic so any parameters specified via Helm values are added to the pod spec during the injection process (only when cni is enabled) so Istio CNI will perform the proper actions.

@@ -947,3 +957,27 @@ func potentialPodName(metadata *metav1.ObjectMeta) string {
}
return ""
}

// rewriteCniPodSPec will check if values from the sidecar injector Helm
// values need to be inserted as Pod annotations so the CNI will apply
Copy link
Contributor

Choose a reason for hiding this comment

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

File is not gofmt-ed with -s (from gofmt)

if len(spec.CniExtraConfig) == 0 {
return nil
}
for k, _ := range annotationRegistry {
Copy link
Contributor

Choose a reason for hiding this comment

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

File is not gofmt-ed with -s (from gofmt)

@tiswanso
Copy link
Contributor

Could you change the subject to something like "Add redirect params as annotations to pod" or something more descriptive?

{{- end }}
{{- if .Values.istio_cni.enabled }}
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should always add these values as annotations if they exist in the proxyConfig.

Copy link
Member

Choose a reason for hiding this comment

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

Agree, I don't think there is anything wrong with additional annotations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well from a quick check if we add the annotations to the pods for all cases then I have to modify 90% of the test cases. I don't have a ton of time in the next week due to kubecon so wondering if it is worth the effort.

Copy link
Member

Choose a reason for hiding this comment

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

set REFRESH_GOLDEN=1 in your env does it automatically if it is the tests I am thinking of. Just use with caution, don't blindly accept the output our the tests are really testing anything.

I don't care too much one way or another though

if annotations[k] == spec.CniExtraConfig[k] {
continue
} else if annotations[k] != "" {
err = fmt.Errorf("Helm redirection inconsistent with pod spec annotation %s", annotations[k])
Copy link
Contributor

Choose a reason for hiding this comment

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

error strings should not be capitalized or end with punctuation or a newline (from golint)

{{- end }}
{{- if .Values.istio_cni.enabled }}
Copy link
Member

Choose a reason for hiding this comment

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

Agree, I don't think there is anything wrong with additional annotations?

// rewriteCniPodSPec will check if values from the sidecar injector Helm
// values need to be inserted as Pod annotations so the CNI will apply
// the proper redirection rules.
func rewriteCniPodSPec(annotations map[string]string, spec *SidecarInjectionSpec) error {
Copy link
Member

Choose a reason for hiding this comment

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

Need some tests. Should be as simple as adding a couple yamls using cni to the testdata directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Starting looking to add some tests, but I don't see an example for how to make things conditional in the current test cases based helm values. I didn't search that hard yet but if there is another case or parameter to use as a recipe let me know. I might not get to this for a few days due to kubecon travel.

@john-a-joyce john-a-joyce changed the title This PR is to resolve issue #12906 Add redirect params as annotations to pod resolves issue #12906 May 17, 2019
@howardjohn howardjohn added this to the 1.2 milestone May 17, 2019
// rewriteCniPodSPec will check if values from the sidecar injector Helm
// values need to be inserted as Pod annotations so the CNI will apply
// the proper redirection rules.
func rewriteCniPodSPec(annotations map[string]string, spec *SidecarInjectionSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

File is not gofmt-ed with -s (from gofmt)

{{- end }}
podRedirectAnnot:
Copy link
Contributor

Choose a reason for hiding this comment

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

With merge of #13970 need to add traffic.sidecar.istio.io/excludeOutboundPorts as well.

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 can add here, but the change is missing on the CNI side so it won't change any behavior until that change goes in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right... it will just help so when we do add the functionality to istio/cni this will already be in place.

@tiswanso
Copy link
Contributor

looks good but need to incorporate: traffic.sidecar.istio.io/excludeOutboundPorts (#13970)

This change resolves issue 12906 by adding support
for include and exclude CIDRs and ports that are
specified via Helm options when the CNI is enabled.
Tests are updated to reflect the annotations
being added regardless of cni being enabled.
sidecar.istio.io/status: '{"version":"","initContainers":["istio-init"],"containers":["istio-proxy"],"volumes":["istio-envoy","istio-certs"],"imagePullSecrets":null}'
traffic.sidecar.istio.io/excludeInboundPorts: 4,5,6
traffic.sidecar.istio.io/excludeInboundPorts: 4,5,6,15020
Copy link
Member

Choose a reason for hiding this comment

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

This will not impact non-CNI users, right? This annotation is read at inject time only, so this change does nothing (unless using CNI)?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, this is the post-injected app yaml under test so it's just validating that the annotation is getting added with the correct value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current template logic merges the helm values and the annotations and sends that as parameters to the istio_init container. This PR will merge the helm and annotation and write back to annotation so CNI can use. So it doesn't change the non-CNI case in anyway

@john-a-joyce
Copy link
Contributor Author

/test istio-pilot-e2e-envoyv2-v1alpha3-master

@john-a-joyce
Copy link
Contributor Author

@tiswanso @howardjohn - i think this is ready to go after a rebase. Please have a look if you can.

Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

/lgtm

traffic.sidecar.istio.io/includeInboundPorts: "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeInboundPorts` (includeInboundPorts .Spec.Containers) }}"
traffic.sidecar.istio.io/excludeInboundPorts: "{{ excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }}"
{{ if or (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeOutboundPorts`) (ne .Values.global.proxy.excludeOutboundPorts "") }}
Copy link
Member

Choose a reason for hiding this comment

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

Any reason that this is wrapped in the if but the others are not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@howardjohn - I was matching the logic that is used when setting the parameters passed to the init container when the init container is doing the redirection. On reflection it was done that way for the init container to set up the extra option flag and you are correct I didn't really need the if here.

@istio-testing
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: howardjohn, john-a-joyce

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@howardjohn
Copy link
Member

/test e2e-simpleTests-master

@istio-testing istio-testing merged commit 6b43aad into istio:master Jun 9, 2019
@istio-testing
Copy link
Collaborator

@john-a-joyce: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
prow/integ-pilot-k8s-presubmit-tests.sh 7a87d08 link /test integ-pilot-k8s-presubmit-tests-master
prow/integ-mixer-k8s-presubmit-tests.sh 7a87d08 link /test integ-mixer-k8s-presubmit-tests-master
prow/integ-security-k8s-presubmit-tests.sh 7a87d08 link /test integ-security-k8s-presubmit-tests-master

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. I understand the commands that are listed here.

@john-a-joyce john-a-joyce deleted the iss-12906 branch June 13, 2019 19:13
mergify bot pushed a commit that referenced this pull request Jun 14, 2019
* Add support for annotations when CNI enabled

This change resolves issue 12906 by adding support
for include and exclude CIDRs and ports that are
specified via Helm options when the CNI is enabled.

* Fix some issues found during testing

* Fix lint

* More lint

* Improve corner case

* Add annotations do the pods for all cases

Tests are updated to reflect the annotations
being added regardless of cni being enabled.

* Remove error as return value

* Lint fixes

* Add support for outbound exclude ports.

(cherry picked from commit 6b43aad)
howardjohn added a commit to howardjohn/istio that referenced this pull request Jan 12, 2020
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.

None yet

6 participants