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
state: pass in mgo.Session when opening State #8056
state: pass in mgo.Session when opening State #8056
Conversation
@@ -15,7 +17,7 @@ import ( | |||
// controller addresses and the CA public certificate. | |||
type AddressAndCertGetter interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface name is now a bit inaccurate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed it, although the types in this file aren't very well scoped anyway. CA certs have bugger all to do with addresses, and what's the ModelUUID doing in there? Anyway.
@@ -492,8 +493,8 @@ func (m *mockState) APIHostPorts() ([][]network.HostPort, error) { | |||
}, nil | |||
} | |||
|
|||
func (m *mockState) CACert() string { | |||
return testing.CACert | |||
func (m *mockState) ControllerConfig() (controller.Config, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used for the backend of the APIAddresser. I've updated the PR with a commit to remove CACert from that interface.
} | ||
caCert, ok := controllerConfig.CACert() | ||
if !ok { | ||
return nil, errors.New("CA certificate missing from controller config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's define NoCACertErr or something instead of the same string in several places.
Perhaps CACert() method itself on controllerConfig should return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it would return neither a bool nor an error, since it's not possible to have controller config without a CA certificate past bootstrap. I'm ignoring the bool now, will add a card to change the controller.Config method.
@@ -79,6 +79,7 @@ func newAPIHandler(srv *Server, st *state.State, rpcConn *rpc.Conn, modelUUID st | |||
modelUUID: modelUUID, | |||
serverHost: serverHost, | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need what? whitespace? accidentally snuck in as I added a resource, then removed it again - reverted
state/initialize.go
Outdated
MongoInfo *mongo.MongoInfo | ||
// MongoSession is the mgo.Session to use for storing and | ||
// accessing state data. The caller remains responsible | ||
// for closing the session. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for closing this session ??
(to distinguish from the copy that is made)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
state/open.go
Outdated
MongoDialOpts mongo.DialOpts | ||
// MongoSession is the mgo.Session to use for storing and | ||
// accessing state data. The caller remains responsible | ||
// for closing the session; Open will copy it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the/the passed in session?
Not sure if that clarification is needed? Makes sense to make the change to me anyway. YMMV
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the/this/ like in the other case
} `bson:"authenticatedUsers"` | ||
} `bson:"authInfo"` | ||
} | ||
if err := st.session.DB(jujuDB).Run(bson.D{{"connectionStatus", 1}}, &connectionStatus); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here? I don't quite grok this at first read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup - sorry, done
We shouldn't need to know about how to connect to MongoDB given a State object, we just need a connection.
This is a property of controller config, so use that where necessary, rather than relying on the CACert value in the mongo info.
No longer needed, so stop storing it. Next step is to stop passing it into State altogether, and instead just pass in a mgo.Session.
be835f8
to
32673f8
Compare
Functions in the State package that create State objects now accept an mgo.Session, rather than the mongo connection info and dial options. For now at least, they copy the session.
469bbed
to
d90d7f7
Compare
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju |
Build failed: Tests failed |
Remove CACert from the APIAddresser type, which is embedded and exposed by various facades. Add CACert as a method directly to those facades that require it. Also remove CACert method from client-side APIAddresser type, and move to clients that require it.
d90d7f7
to
67aba93
Compare
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju |
Build failed: Tests failed |
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju |
Build failed: it's a mystery |
|
Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju |
|
Description of change
QA steps
Smoke test: bootstrap, destroy.
Documentation changes
None.
Bug reference
None.