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

MAISTRA-1071 Add manifest namespace validation #462

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

dgn
Copy link
Contributor

@dgn dgn commented Jun 11, 2020

This is two parts:

  • validatingWebhook code to give users early and comprehensible feedback on why they can't use a namespace
  • reconciler.validateManifests function that makes sure we'll never deploy resources into namespaces that are not part of the mesh

pkg/controller/servicemesh/controlplane/reconciler.go Outdated Show resolved Hide resolved
if err := r.Client.Get(context.TODO(), client.ObjectKey{Namespace: r.Instance.GetNamespace(), Name: common.MemberRollName}, smmr); err != nil {
if !apierrors.IsNotFound(err) {
// log error, but don't fail validation: we'll just assume that the control plane namespace is the only namespace for now
log.Error(err, "failed to retrieve SMMR for SMCP")
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably worth returning the error and letting the reconciliation restart. If there's a gateway that references a namespace that is legitimate, then we'll error when we validate, which will be a false error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you want to restart reconciliation without logging an error in this case?

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 thing is that this will probably only happen rarely, and even if it happens, it will only have an impact if you have a gateway outside the control plane namespace. The idea with just logging and continuing was that 99% of the time it'll be alright, because the gateway is in the cp namespace anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can just return the error from the reconcile loop and let it do its thing. I don't remember if we need to log it and return it, or just return it. @luksa?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it's probably unlikely that it will fail and unlikely that a namespace other than the control plane will be used. Maybe keep track of the fact that the smmr lookup failed and then if there's a validation failure, you can return the smmr error instead. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think that makes sense

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 fixed it now. While at it, I found another issue; I had forgotten to split the manifests (by "---") so was only looking at the first manifest in the output of each helm template (which for the gateways are multiple).

@dgn dgn force-pushed the MAISTRA-1071 branch 3 times, most recently from 733f97e to 5c3beb2 Compare June 16, 2020 11:36
@dgn
Copy link
Contributor Author

dgn commented Jun 16, 2020

FYI I ran the validation function 1k times and it takes 21ms on average on my machine, so should be okay

@dgn dgn requested a review from luksa June 22, 2020 11:48
Copy link
Contributor

@luksa luksa left a comment

Choose a reason for hiding this comment

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

LGTM but I'm wondering why we need to consider the member namespaces when checking the manifests. Aren't all resources deployed in the control plane namespace? If yes, then we could perform the validation when we render the charts.

@dgn
Copy link
Contributor Author

dgn commented Jun 22, 2020

LGTM but I'm wondering why we need to consider the member namespaces when checking the manifests. Aren't all resources deployed in the control plane namespace? If yes, then we could perform the validation when we render the charts.

The gateways are an exception in that they can be deployed to any namespace by providing a
istio.gateways.some-gateway.namespace: someNamespace; this is meant to allow for multiple ingress/egress gateways in separate namespaces.

The reason I added this in a generic fashion is that things like this could come up again in future versions of Istio, and it might not just be restricted to gateways

@dgn
Copy link
Contributor Author

dgn commented Jun 22, 2020

Adding a hold as this will go into 1.1.5

@mergify mergify bot merged commit 5db8548 into maistra:maistra-1.1 Jul 10, 2020
@dgn dgn deleted the MAISTRA-1071 branch July 13, 2020 08:54
@dgn
Copy link
Contributor Author

dgn commented Jul 13, 2020

/cherry-pick maistra-1.2

@maistra-bot
Copy link
Contributor

@dgn: #462 failed to apply on top of branch "maistra-1.2":

Using index info to reconstruct a base tree...
M	pkg/controller/common/util.go
M	pkg/controller/servicemesh/controlplane/reconciler.go
M	pkg/controller/servicemesh/controlplane/reconciler_test.go
M	pkg/controller/servicemesh/webhooks/validation/controlplane_test.go
A	pkg/controller/servicemesh/webhooks/validation/controlplane_util.go
A	pkg/controller/servicemesh/webhooks/validation/controlplane_v1_1.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/controller/versions/util.go
CONFLICT (content): Merge conflict in pkg/controller/versions/util.go
CONFLICT (modify/delete): pkg/controller/servicemesh/webhooks/validation/controlplane_v1_1.go deleted in HEAD and modified in MAISTRA-1071 Add manifest namespace validation. Version MAISTRA-1071 Add manifest namespace validation of pkg/controller/servicemesh/webhooks/validation/controlplane_v1_1.go left in tree.
Auto-merging pkg/controller/servicemesh/webhooks/validation/controlplane_test.go
CONFLICT (content): Merge conflict in pkg/controller/servicemesh/webhooks/validation/controlplane_test.go
Auto-merging pkg/controller/servicemesh/controlplane/reconciler_test.go
CONFLICT (content): Merge conflict in pkg/controller/servicemesh/controlplane/reconciler_test.go
Auto-merging pkg/controller/servicemesh/controlplane/reconciler.go
Auto-merging pkg/controller/common/util.go
CONFLICT (content): Merge conflict in pkg/controller/common/util.go
error: Failed to merge in the changes.
Patch failed at 0001 MAISTRA-1071 Add manifest namespace validation

In response to this:

/cherry-pick maistra-1.2

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.

dgn added a commit to dgn/istio-operator that referenced this pull request Jul 14, 2020
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
dgn added a commit to dgn/istio-operator that referenced this pull request Jul 14, 2020
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.

None yet

5 participants