Skip to content

Analysis util functions for getting mesh config#19274

Merged
istio-testing merged 11 commits intoistio:masterfrom
sushicw:analysis-istio-system
Dec 9, 2019
Merged

Analysis util functions for getting mesh config#19274
istio-testing merged 11 commits intoistio:masterfrom
sushicw:analysis-istio-system

Conversation

@sushicw
Copy link
Copy Markdown
Contributor

@sushicw sushicw commented Nov 27, 2019

Abstract getting mesh cfg into a util function.
Abstract getting system namespaces (including the istio control plane namespace) into a util function.

Note that this assumes that meshcfg.rootNamespace is the control plane namespace, at least as far as analyzers are concerned. This should do the right thing for our current set of analyzers, and if we need to improve it in the future we now have a better abstraction boundary to do it behind.


Update: Removed abstraction for system namespaces, in favor of refactoring to not have analyzers pay attention. It turns out that "control plane namespace" is not really well defined and best avoided if we can.

Kept other minor refactoring & cleanup.

@sushicw sushicw requested review from a team, howardjohn and selmanj November 27, 2019 22:54
@sushicw sushicw self-assigned this Nov 27, 2019
@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Nov 27, 2019
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 27, 2019
@selmanj
Copy link
Copy Markdown
Contributor

selmanj commented Nov 28, 2019

Would it be more correct to assume that the namespace the MeshConfig configmap resides in is the control-plane namespace, rather than tying it to rootNamespace?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this a utility function rather than a func on analysis.Context? It feels more explicit then that every analyzer should be running on exactly one control-plane/mesh configuration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did fiddle with it briefly but didn't like how it was going, so I was thinking of settling for a smaller incremental improvement. But I agree, it does feel like it should probably end up there.

@sushicw
Copy link
Copy Markdown
Contributor Author

sushicw commented Dec 2, 2019

Would it be more correct to assume that the namespace the MeshConfig configmap resides in is the control-plane namespace, rather than tying it to rootNamespace?

We can't assume that the mesh config is coming via configMap at all. e.g. in the Galley case, it's ingested as a yaml file. (Which, yes, is ultimately provided by a config map, but Galley doesn't know or care about that).

@sushicw sushicw changed the title Analysis util functions for getting system namespaces & mesh config Analysis util functions for getting mesh config Dec 3, 2019
@sushicw sushicw force-pushed the analysis-istio-system branch from 0a21b88 to 5c4f0cd Compare December 4, 2019 16:40
@sushicw
Copy link
Copy Markdown
Contributor Author

sushicw commented Dec 4, 2019

/test unit-tests_istio

@sushicw
Copy link
Copy Markdown
Contributor Author

sushicw commented Dec 4, 2019

/retest

@sushicw sushicw requested a review from ayj December 4, 2019 21:28
@sushicw
Copy link
Copy Markdown
Contributor Author

sushicw commented Dec 4, 2019

@ayj PTAL

// TODO: namespaces can in theory be anything, so we need to make this more configurable
if strings.HasPrefix(r.Metadata.Name.String(), "kube-") || strings.HasPrefix(r.Metadata.Name.String(), "istio-") {
ns := r.Metadata.Name.String()
if util.IsSystemNamespace(ns) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The previous behavior skipped istio-system as well. I didn't see that handled in IsSystemNamespace.

Copy link
Copy Markdown
Contributor Author

@sushicw sushicw Dec 6, 2019

Choose a reason for hiding this comment

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

There's a slight behavior change here. Istio now installs with istio-system labeled istio-injection:disabled, so we aren't going to generate false positives in the normal case and excluding istio-system is redundant. And if someone manually changes that, then I don't feel bad alerting them about it.

The fewer namespace names we need to hardcode, the better.

})

if autoMtlsEnabled {
if mc.GetEnableAutoMtls().GetValue() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this purely a refactor or does it change behavior? Some of the expected test output changed below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. A test was previously broken, and didn't fail even after it should have. Thus the s/istio-policy/istio-telemetry.
  2. There's a behavior change where for the mtls analyzer we look at the istio=annotation to tell us what resources are control plane and should be skipped, instead of relying on the namespace. This has the dual benefit of avoiding needing to know the istio-system namespace, and also lets us detect errors for non-control-plane resources that are bundled in the namespace (like Grafana).
  3. There's some minor test cleanup to add {} to be consistent with what is valid when you kubectl apply it.

@istio-testing istio-testing merged commit 3efa794 into istio:master Dec 9, 2019
antonioberben pushed a commit to antonioberben/istio that referenced this pull request Jan 29, 2024
Signed-off-by: Naseem <naseemkullah@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants