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

plugins: Additive updates to services when discovery enabled #2311

Merged

Conversation

ashutosh-narkar
Copy link
Member

Earlier with discovery enabled updates to the 'services' configuration
was not allowed to protect against accidental changes to the discovery service
itself. Since adding new services could be useful, this change allows modifications
to the 'services' configuration. The only exception is that the service used to download
the discovery bundle cannot be modified.

Fixes #2058

Signed-off-by: Ashutosh Narkar anarkar4387@gmail.com

Copy link
Contributor

@patrick-east patrick-east 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!

}

// check for updates to the discovery service
if !reflect.DeepEqual(client, manager.Client(service)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to just have a like Compare() API or something on the clients. We probably just want to compare their config right? We wouldn't really need to compare the other fields on them afaik.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we compare their config only. Added an Equal API on the client.

Comment on lines +346 to +353
if err == nil {
t.Fatal("Expected error but got nil")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Do we need any validation for what error it ran into?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the tests to check the error message.

Earlier with discovery enabled updates to the 'services' configuration
was not allowed to protect against accidental changes to the discovery service
itself. Since adding new services could be useful, this change allows modifications
to the 'services' configuration. The only exception is that the service used to download
the discovery bundle cannot be modified.

Fixes open-policy-agent#2058

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Copy link
Contributor

@patrick-east patrick-east left a comment

Choose a reason for hiding this comment

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

LGTM

@ashutosh-narkar ashutosh-narkar merged commit d67c0f7 into open-policy-agent:master Apr 17, 2020
Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

Just left a couple small comments that I think need to be addresed.

@@ -148,6 +148,11 @@ func (c Client) WithBytes(body []byte) Client {
return c
}

// Equal returns true if this client is equal to the other.
func (c Client) Equal(other Client) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This seems like an odd API to have on an HTTP client--and the comment is misleading since it only checks if the configs are equal. I'd remove this and just expose a way to access the config to perform equality checks when needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Equal API can be removed and added on the rest client config struct.

Copy link
Member

Choose a reason for hiding this comment

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

That should be fine. I guess technically we only care if the discovered configuration is not a subset of the bootstrap configuration because that's where it gets problematic. Strict equality should be fine for now.

}

// check for updates to the discovery configuration
if config.Discovery != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this going to break anyone who is sending OPA a discovery bundle that contains the discovery (and dependent service) configuration unchanged? I think we need to perform a semantic diff on the discovery and dependent service configuration instead of just checking for existence AFAICT.

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the scenario in which a user sends an unchanged discovery configuration in the service bundle ? Given that we already say in the docs that the discovery config cannot be updated, is this something we could be more explicit about in the docs OR Are you proposing we check the discovery config the service bundle and compare with the boot config ?

For the dependent service, we are checking the config of the rest client.

Copy link
Member

Choose a reason for hiding this comment

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

Are you proposing we check the discovery config the service bundle and compare with the boot config ?

Yes, exactly. The current change is backwards incompatible so we need to fix that anyway. From a design perspective, I'd rather not require users special case discovered configuration generation to remove overlap with bootstrap configuration for no reason. As a design principle, it's important to keep APIs idempotent.

Comment on lines +232 to 235
// check for updates to the discovery service
if !client.Equal(manager.Client(service)) {
return nil, fmt.Errorf("updates to the discovery service are not allowed")
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the check on the service config occur before we reconfigure the manager? As is, this means we'll end up with updates being applied inconsistently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I was thinking about that which meant we need to either make parseServicesConfig (plugins/plugins.go) public or copy over the logic or move the function to a common package.

Any preference here ?

Copy link
Member

Choose a reason for hiding this comment

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

A good design principle is to optimize for change--i.e., assume we're going to have to modify the code at some point. Given that, avoid copying logic because it means more maintenance and more bugs. If you're worried about increasing the API surface area outside of OPA consider exporting the function inside of an internal package.

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.

Add support for additive updates to the services configuration when discovery is enabled
3 participants