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

ca: isolate more of the CA logic in CAManager #10445

Merged
merged 8 commits into from
Jul 12, 2021
Merged

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Jun 21, 2021

Best viewed by individual commit.

This is in preparation for documenting the CA provider flows, and fixing some bugs related to CA provider in secondary DCs.

@dnephin dnephin added theme/internal-cleanup Used to identify tech debt, testing improvements, code refactoring, and non-impactful optimization theme/certificates Related to creating, distributing, and rotating certificates in Consul pr/no-changelog PR does not need a corresponding .changelog entry labels Jun 21, 2021
@github-actions github-actions bot added theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies and removed theme/certificates Related to creating, distributing, and rotating certificates in Consul labels Jun 21, 2021
@dnephin
Copy link
Contributor Author

dnephin commented Jun 22, 2021

Looks like there is a lint error and a couple test failures to fix.

@dnephin dnephin marked this pull request as draft June 22, 2021 00:16
@dnephin dnephin force-pushed the dnephin/ca-provider-explore branch from 1d6d6a9 to 1d69937 Compare June 22, 2021 21:42
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 22, 2021 21:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 22, 2021 21:42 Inactive
Comment on lines 25 to +29
caStateUninitialized caState = "UNINITIALIZED"
caStateInitializing = "INITIALIZING"
caStateInitialized = "INITIALIZED"
caStateRenewIntermediate = "RENEWING"
caStateReconfig = "RECONFIGURING"
caStateInitializing caState = "INITIALIZING"
caStateInitialized caState = "INITIALIZED"
caStateRenewIntermediate caState = "RENEWING"
caStateReconfig caState = "RECONFIGURING"
Copy link
Contributor Author

@dnephin dnephin Jun 22, 2021

Choose a reason for hiding this comment

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

Implicit using the type in a const block only works with iota. In blocks like this without iota the type has to be explicit. This was changed so that tests can use require.Equal , instead of require.EqualValue

@dnephin dnephin marked this pull request as ready for review June 22, 2021 22:31
@dnephin dnephin requested a review from a team June 30, 2021 18:05
Comment on lines -105 to -94
c.primaryRoots = structs.IndexedCARoots{}
c.actingSecondaryCA = false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: check to see if this should be done in Stop, should primaryRoots and actingSecondarCA be called to zero things out on leader loss.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked and I'm pretty sure it's needed to clean up the struc and the state. I added them as part of the stop

Copy link
Contributor

Choose a reason for hiding this comment

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

How was reset() being used originally? I can't find where it was being called from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't, which is why 7dae65c was able to remove the method without any other changes. While reviewing this I thought it might be worth checking to see if the Stop method was missing any of this logic, and I guess it was.

I believe an earlier change must have removed the call to reset, but I haven't looked into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reset seems like it was added in 0bfda44 (#9009) but never used.

Copy link
Contributor

@freddygv freddygv Jul 12, 2021

Choose a reason for hiding this comment

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

Got it. I just saw that when reset was added it wasn't being called then either, looks like a stray change.

The important parts of reset were to set the state to uninitialized and set the provider to nil, and those were being handled directly in revokeLeadership.

It's definitely clearer to move those down into caManager.Stop() rather than spread around.

dnephin and others added 7 commits July 12, 2021 09:27
Reducing the coupling between Server and CAManager
This further decouples the CAManager from Server. It reduces the interface between them and
removes the need for the SetLogger method on providers.
This method on Server was only used by the caDelegateWithState, so move it there
until we can move it entirely into CAManager.
After moving ca.ConsulProviderStateDelegate into the interface we now
have the ApplyCARequest method which does the same thing. Use this more
specific method instead of raftApply.
and small refactor to getCAProvider so that GoLand is less confused about what it is doing.
Previously it was reporting that the for condition was always true, which was not the case.
raftApply was removed so ApplyCARequest needs to handle all the possible operations

Also set the providerShim to use the mock provider.

other changes are small test improvements that were necessary to debug the failures.
@dhiaayachi dhiaayachi force-pushed the dnephin/ca-provider-explore branch from 1d69937 to 0475378 Compare July 12, 2021 13:33
@vercel vercel bot temporarily deployed to Preview – consul July 12, 2021 13:33 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 12, 2021 13:33 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

This mostly looks good to me, left a couple questions/comments.

The main one being the question about CAManager.reset()

agent/connect/ca/provider_aws_test.go Outdated Show resolved Hide resolved
agent/connect/ca/provider_consul.go Outdated Show resolved Hide resolved
agent/consul/leader_connect_ca.go Outdated Show resolved Hide resolved
@@ -473,7 +473,7 @@ func NewServer(config *Config, flat Deps) (*Server, error) {
return nil, fmt.Errorf("Failed to start Raft: %v", err)
}

s.caManager = NewCAManager(&caDelegateWithState{s}, s.leaderRoutineManager, s.loggers.Named(logging.Connect), s.config)
s.caManager = NewCAManager(&caDelegateWithState{s}, s.leaderRoutineManager, s.logger.ResetNamed("connect.ca"), s.config)
Copy link
Contributor

@freddygv freddygv Jul 12, 2021

Choose a reason for hiding this comment

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

There's a logging.CA constant, "ca", that could be used here. I'm not sure how much value is added by the "connect." prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to keep it consistent with the previous logger name.

IMO, the logging constants are not really valuable. I think we should aim to only create a logger with a given name in one place, which makes the name constants in some far away package more of a nuisance than something helpful. If we want a constant it could be un-exported in the local package.

Comment on lines -105 to -94
c.primaryRoots = structs.IndexedCARoots{}
c.actingSecondaryCA = false
Copy link
Contributor

Choose a reason for hiding this comment

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

How was reset() being used originally? I can't find where it was being called from

Adds a contructor for the one provider that did not have one.
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 12, 2021 18:04 Inactive
@vercel vercel bot temporarily deployed to Preview – consul July 12, 2021 18:04 Inactive
@dnephin
Copy link
Contributor Author

dnephin commented Jul 12, 2021

Pushed another commit which makes the provider constructors more consistent.

Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

LGTM, solid improvement!

@dnephin dnephin merged commit b89ec82 into main Jul 12, 2021
@dnephin dnephin deleted the dnephin/ca-provider-explore branch July 12, 2021 19:26
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/407297.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-changelog PR does not need a corresponding .changelog entry theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies theme/internal-cleanup Used to identify tech debt, testing improvements, code refactoring, and non-impactful optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants