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

Refactor apiserver ToolsFinder() and ToolsGetter() to take a newEnviron func #11291

Merged
merged 2 commits into from Mar 10, 2020

Conversation

wallyworld
Copy link
Member

Description of change

The apiserver ToolsGetter and ToolsFnder helpers were constructing an IAAS Environ directly. This change refactors them to take a newEnviron func so that the relevant instance for the model can be constructed. The change allows a k8s model to ask for agent binary metadata even though the agent binaries are not used directly.

Part of the change involved fixing the situation where EnvironConfigGetter had both a State and a Model. Only a model is used now (and an interface at that). As more methods are moved/copied to Model from State, we can eventually avoid using State other than to wrap mgo connections.

QA steps

bootstrap an aws controller with --agent-version=2.7.2
deploy postgresql with an ebs volume
(ensures storage registry in state works)
run upgrade-controller --dry-run
(check that 2.7.3 is suggested)
upgrade controller
run upgrade-model --dry-run
(check that 2.7.3 is suggested)
upgrade model

@wallyworld
Copy link
Member Author

Copy link
Contributor

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

This looks great, but the names for the new Model methods are a bit awkward.

func NewToolsGetter(f state.EntityFinder, c environs.EnvironConfigGetter, s ToolsStorageGetter, t ToolsURLGetter, getCanRead GetAuthFunc) *ToolsGetter {
return &ToolsGetter{f, c, s, t, getCanRead}
func NewToolsGetter(f state.EntityFinder, c environs.EnvironConfigGetter, s ToolsStorageGetter, t ToolsURLGetter, getCanRead GetAuthFunc, newEnviron NewEnvironFunc) *ToolsGetter {
return &ToolsGetter{newEnviron, f, c, s, t, getCanRead}
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this multiline?

Copy link
Member Author

Choose a reason for hiding this comment

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

also added struct attr names

@@ -56,8 +57,8 @@ type ToolsGetter struct {

// NewToolsGetter returns a new ToolsGetter. The GetAuthFunc will be
// used on each invocation of Tools to determine current permissions.
func NewToolsGetter(f state.EntityFinder, c environs.EnvironConfigGetter, s ToolsStorageGetter, t ToolsURLGetter, getCanRead GetAuthFunc) *ToolsGetter {
return &ToolsGetter{f, c, s, t, getCanRead}
func NewToolsGetter(f state.EntityFinder, c environs.EnvironConfigGetter, s ToolsStorageGetter, t ToolsURLGetter, getCanRead GetAuthFunc, newEnviron NewEnvironFunc) *ToolsGetter {
Copy link
Contributor

Choose a reason for hiding this comment

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

This takes too many args - maybe just make the fields public and construct a struct? Depends on how important it is that the fields aren't monkeyable-with I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

it does but prefer to keep the struct fields private, and also, this ToolsGetter / ToolsFinder stuff needs more extensive refactoring at some point

@@ -18,7 +19,7 @@ import (
)

type Backend interface {
state.CloudAccessor
//state.CloudAccessor
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove me? Or reinstate I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

no longer needed

state/model.go Outdated
@@ -589,6 +589,11 @@ func (m *Model) Cloud() string {
return m.doc.Cloud
}

// CloudValue returns the cloud to which the model is deployed.
func (m *Model) CloudValue() (jujucloud.Cloud, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise this is probably a bit more work but it would make more sense to call this Cloud() and change the existing Cloud() method to CloudName(), and similarly for CloudCredential[Value]. I guess Goland can do that pretty easily right?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

…udCredential()->CloudCredentialTag(), CloudCredentialValue()->CloudCredntial()
@wallyworld
Copy link
Member Author

$$merge$$

@jujubot jujubot merged commit d9d8aa3 into juju:2.7 Mar 10, 2020
This was referenced Mar 11, 2020
jujubot added a commit that referenced this pull request Mar 13, 2020
#11314

## Description of change

Merge 2.7 bringing in these PRs:

#11286 speed up juju status by handling units better
#11296 fix LP:1860083 machine availability zone
#11291 various refactorings (method renames, tools finder/getter handle k8s broker)
#11297 juju show-action-status not listing all
#11300 k8s controllers can start lxd containers
#11304 protect against nil profile from the charm
#11310 speed up processing of machines in juju status
#11306 ensure k8s juju upgrades select correct agent version
#11313 fix watcher race in ControllerAddressSuite
#11302 fix LP:1866658 jujud called in makefile before it is built

## QA steps

Run unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants