Skip to content

Commit

Permalink
Merge pull request #14498 from barrettj12/go1.19
Browse files Browse the repository at this point in the history
#14498

## Changes
- update Go version to 1.19 in go.mod
- Set GOROOT before linting to fix golangci/golangci-lint#3107
- update go-macaroon-bakery to fix go-macaroon-bakery/macaroon-bakery#276
- Run Go 1.19's `go fmt` over everything (there have been some changes in 1.19)
- Rebuild facade schema to catch minor formatting change.

Most of the changes are minor formatting tweaks from gofmt. Go 1.18's `gofmt` still passes.

## QA steps

Wait for CI to pass.
  • Loading branch information
jujubot committed Aug 26, 2022
2 parents 584f522 + 46fc34e commit d7e478e
Show file tree
Hide file tree
Showing 139 changed files with 646 additions and 584 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:

- name: "Static Analysis: Go Check"
run: |
# Explicitly set GOROOT to avoid golangci-lint/issues/3107
export "GOROOT=$(go env GOROOT)"
STATIC_ANALYSIS_JOB=test_static_analysis_go make static-analysis
shell: bash

Expand Down
5 changes: 3 additions & 2 deletions api/agent/agent/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ const (
// that currently live in apicaller. This criterion is every bit as
// terrible as it sounds -- surely there should be a new facade at the
// apiserver level somewhere? -- but:
// 1) this feels like a convenient/transitional method grouping, not a
// 1. this feels like a convenient/transitional method grouping, not a
// fundamental *role*; and
// 2) at least it's a narrowed interface, and eschews the object-style
// 2. at least it's a narrowed interface, and eschews the object-style
// sins of *State/*Entity.
//
// Progress not perfection.
type ConnFacade interface {

Expand Down
3 changes: 2 additions & 1 deletion api/agent/upgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (s *machineUpgraderSuite) SetUpTest(c *gc.C) {
}

// Note: This is really meant as a unit-test, this isn't a test that should
// need all of the setup we have for this test suite
//
// need all of the setup we have for this test suite
func (s *machineUpgraderSuite) TestNew(c *gc.C) {
upgrader := upgrader.NewState(s.stateAPI)
c.Assert(upgrader, gc.NotNil)
Expand Down
1 change: 1 addition & 0 deletions api/base/clientfacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type APICallCloser interface {
// They provide two common methods for writing the client side code.
// BestAPIVersion() is used to allow for compatibility testing, and Close() is
// used to indicate when we are done with the connection.
//
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/clientfacade_mock.go github.com/juju/juju/api/base APICallCloser,ClientFacade
type ClientFacade interface {
// BestAPIVersion returns the API version that we were able to
Expand Down
8 changes: 4 additions & 4 deletions api/client/resources/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func setFilename(filename string, req *http.Request) {
// contains the name of the file being uploaded, see mime.FormatMediaType and
// RFC 1867 (http://tools.ietf.org/html/rfc1867):
//
// The original local file name may be supplied as well, either as a
// 'filename' parameter either of the 'content-disposition: form-data'
// header or in the case of multiple files in a 'content-disposition:
// file' header of the subpart.
// The original local file name may be supplied as well, either as a
// 'filename' parameter either of the 'content-disposition: form-data'
// header or in the case of multiple files in a 'content-disposition:
// file' header of the subpart.
const FilenameParamForContentDispositionHeader = "filename"

// HTTPRequest generates a new HTTP request.
Expand Down
26 changes: 13 additions & 13 deletions api/common/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ var logger = loggo.GetLogger("juju.api.common")
// []params.NetworkConfig. In addition to what the source returns, a few
// additional transformations are done:
//
// * On any OS, the state (UP/DOWN) of each interface and the DeviceIndex field,
// will be correctly populated. Loopback interfaces are also properly detected
// and will have InterfaceType set LoopbackInterface.
// * On Linux only, the InterfaceType field will be reliably detected for a few
// types: BondInterface, BridgeInterface, VLAN_8021QInterface.
// * Also on Linux, for interfaces that are discovered to be ports on a bridge,
// the ParentInterfaceName will be populated with the name of the bridge.
// * ConfigType fields will be set to ConfigManual when no address is detected,
// or ConfigStatic when it is.
// * NICs that correspond to the internal port of an OVS-managed switch will
// have their type forced to bridge and their virtual port type set to
// OvsPort.
// * TODO: IPv6 link-local addresses will be ignored and treated as empty ATM.
// - On any OS, the state (UP/DOWN) of each interface and the DeviceIndex field,
// will be correctly populated. Loopback interfaces are also properly detected
// and will have InterfaceType set LoopbackInterface.
// - On Linux only, the InterfaceType field will be reliably detected for a few
// types: BondInterface, BridgeInterface, VLAN_8021QInterface.
// - Also on Linux, for interfaces that are discovered to be ports on a bridge,
// the ParentInterfaceName will be populated with the name of the bridge.
// - ConfigType fields will be set to ConfigManual when no address is detected,
// or ConfigStatic when it is.
// - NICs that correspond to the internal port of an OVS-managed switch will
// have their type forced to bridge and their virtual port type set to
// OvsPort.
// - TODO: IPv6 link-local addresses will be ignored and treated as empty ATM.
func GetObservedNetworkConfig(source network.ConfigSource) ([]params.NetworkConfig, error) {
logger.Tracef("discovering observed machine network config...")

Expand Down
14 changes: 8 additions & 6 deletions api/controller/controller/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
// newHTTPFixture creates and returns an HTTP fixture to be used in order to
// mock controller HTTP requests to the given controller address.
// Use it like in the following example:
// fix := newHTTPFixture("/my/controller/path", func(w http.ResponseWriter, req *http.Request) {
// // Simulate what's returned by the server.
// })
// stub := fix.run(c, func(ac base.APICallCloser) {
// // Do something with the API caller.
// })
//
// fix := newHTTPFixture("/my/controller/path", func(w http.ResponseWriter, req *http.Request) {
// // Simulate what's returned by the server.
// })
// stub := fix.run(c, func(ac base.APICallCloser) {
// // Do something with the API caller.
// })
//
// At this point the stub, if the handler has been called, includes one call
// with the HTTP method requested while running the test function.
func newHTTPFixture(address string, handle func(http.ResponseWriter, *http.Request)) *httpFixture {
Expand Down
8 changes: 5 additions & 3 deletions api/controller/instancepoller/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,13 @@ var entitiesArgs = params.Entities{
// - the Error field is of type *params.Error
//
// Example:
// err := apiservertesting.ServerError("foo")
// r := MakeResultsWithErrors(params.LifeResults{}, err, 2)
//
// err := apiservertesting.ServerError("foo")
// r := MakeResultsWithErrors(params.LifeResults{}, err, 2)
//
// is equvalent to:
// r := params.LifeResults{Results: []params.LifeResult{{Error: err}, {Error: err}}}
//
// r := params.LifeResults{Results: []params.LifeResult{{Error: err}, {Error: err}}}
func MakeResultsWithErrors(resultsRef interface{}, err *params.Error, howMany int) interface{} {
// Make a new instance of the same type as resultsRef.
resultsType := reflect.TypeOf(resultsRef)
Expand Down
1 change: 1 addition & 0 deletions apiserver/common/credentialcommon/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

// At the moment mocks generated here are in use in the apiserver/facades/client/cloud unit tests.
//
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/credentialcommon_mock.go github.com/juju/juju/apiserver/common/credentialcommon Model,PersistentBackend
func TestAll(t *stdtesting.T) {
gc.TestingT(t)
Expand Down
8 changes: 4 additions & 4 deletions apiserver/common/networkingcommon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ type BackingSubnet interface {
// TODO(dimitern): Replace state.SubnetInfo with this and remove
// BackingSubnetInfo, once the rest of state backing methods and the
// following pre-reqs are done:
// * Subnets need a reference count to calculate Status.
// * ensure EC2 and MAAS providers accept empty IDs as Subnets() args
// and return all subnets, including the AvailabilityZones (for EC2;
// empty for MAAS as zones are orthogonal to networks).
// - Subnets need a reference count to calculate Status.
// - ensure EC2 and MAAS providers accept empty IDs as Subnets() args
// and return all subnets, including the AvailabilityZones (for EC2;
// empty for MAAS as zones are orthogonal to networks).
type BackingSubnetInfo struct {
// ProviderId is a provider-specific network id. This may be empty.
ProviderId network.Id
Expand Down
33 changes: 17 additions & 16 deletions apiserver/debuglog.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ func newDebugLogHandler(
// on the apiclient.
//
// Args for the HTTP request are as follows:
// includeEntity -> []string - lists entity tags to include in the response
// - tags may finish with a '*' to match a prefix e.g.: unit-mysql-*, machine-2
// - if none are set, then all lines are considered included
// includeModule -> []string - lists logging modules to include in the response
// - if none are set, then all lines are considered included
// excludeEntity -> []string - lists entity tags to exclude from the response
// - as with include, it may finish with a '*'
// excludeModule -> []string - lists logging modules to exclude from the response
// limit -> uint - show *at most* this many lines
// backlog -> uint
// - go back this many lines from the end before starting to filter
// - has no meaning if 'replay' is true
// level -> string one of [TRACE, DEBUG, INFO, WARNING, ERROR]
// replay -> string - one of [true, false], if true, start the file from the start
// noTail -> string - one of [true, false], if true, existing logs are sent back,
// - but the command does not wait for new ones.
//
// includeEntity -> []string - lists entity tags to include in the response
// - tags may finish with a '*' to match a prefix e.g.: unit-mysql-*, machine-2
// - if none are set, then all lines are considered included
// includeModule -> []string - lists logging modules to include in the response
// - if none are set, then all lines are considered included
// excludeEntity -> []string - lists entity tags to exclude from the response
// - as with include, it may finish with a '*'
// excludeModule -> []string - lists logging modules to exclude from the response
// limit -> uint - show *at most* this many lines
// backlog -> uint
// - go back this many lines from the end before starting to filter
// - has no meaning if 'replay' is true
// level -> string one of [TRACE, DEBUG, INFO, WARNING, ERROR]
// replay -> string - one of [true, false], if true, start the file from the start
// noTail -> string - one of [true, false], if true, existing logs are sent back,
// - but the command does not wait for new ones.
func (h *debugLogHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
handler := func(conn *websocket.Conn) {
socket := &debugLogSocketImpl{conn}
Expand Down
18 changes: 9 additions & 9 deletions apiserver/facades/agent/instancemutater/instancemutater.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ func (api *InstanceMutaterAPI) watchOneEntityApplication(canAccess common.AuthFu

// WatchLXDProfileVerificationForMachine notifies if any of the following happen
// relative to the specified machine:
// 1. A new unit whose charm has an LXD profile is added.
// 2. A unit being removed has a profile and other units
// exist on the machine.
// 3. The LXD profile of an application with a unit on the
// machine is added, removed, or exists. This also includes scenarios
// where the charm is being downloaded asynchronously and its metadata
// gets updated once the download is complete.
// 4. The machine's instanceId is changed, indicating it
// has been provisioned.
// 1. A new unit whose charm has an LXD profile is added.
// 2. A unit being removed has a profile and other units
// exist on the machine.
// 3. The LXD profile of an application with a unit on the
// machine is added, removed, or exists. This also includes scenarios
// where the charm is being downloaded asynchronously and its metadata
// gets updated once the download is complete.
// 4. The machine's instanceId is changed, indicating it
// has been provisioned.
func (w *instanceMutatorWatcher) WatchLXDProfileVerificationForMachine(machine Machine) (state.NotifyWatcher, error) {
return newMachineLXDProfileWatcher(MachineLXDProfileWatcherConfig{
machine: machine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func (s *lxdProfileWatcherSuite) assertAddSubordinate() {
s.unitChanges <- []string{"foo/0"}
}

//
func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherSubordinateWithProfileUpdateUnit(c *gc.C) {
ctrl := s.setup(c)
defer ctrl.Finish()
Expand Down
1 change: 1 addition & 0 deletions apiserver/facades/agent/meterstatus/meterstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type MeterStatus interface {
}

// MeterStatusState represents the state of an model required by the MeterStatus.
//
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/meterstatus_mock.go github.com/juju/juju/apiserver/facades/agent/meterstatus MeterStatusState
type MeterStatusState interface {
ApplyOperation(state.ModelOperation) error
Expand Down
1 change: 0 additions & 1 deletion apiserver/facades/agent/provisioner/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
//
// Version 10+ will consider all supplied positive space constraints when
// making this determination.
//
package provisioner
1 change: 1 addition & 0 deletions apiserver/facades/agent/provisioner/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// Machine is an indirection for use in container provisioning.
// It is an indirection for both containerizer.Machine and
// containerizer.Container as well as state.Machine locally.
//
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/package_mock.go github.com/juju/juju/apiserver/facades/agent/provisioner Machine,BridgePolicy,Unit,Application,Charm
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/containerizer_mock.go github.com/juju/juju/network/containerizer LinkLayerDevice
type Machine interface {
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/agent/unitassigner/unitassigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type API struct {
statusSetter statusSetter
}

// AssignUnits assigns the units with the given ids to the correct machine. The
// error results are returned in the same order as the given entities.
// AssignUnits assigns the units with the given ids to the correct machine. The
// error results are returned in the same order as the given entities.
func (a *API) AssignUnits(args params.Entities) (params.ErrorResults, error) {
result := params.ErrorResults{}

Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/charms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (a *API) List(args params.CharmsList) (params.CharmsListResult, error) {
func (a *APIv2) GetDownloadInfos(_ struct{}) {}

// GetDownloadInfos attempts to get the bundle corresponding to the charm url
//and origin.
// and origin.
func (a *API) GetDownloadInfos(args params.CharmURLAndOrigins) (params.DownloadInfoResults, error) {
logger.Tracef("GetDownloadInfos %+v", args)

Expand Down
50 changes: 32 additions & 18 deletions apiserver/facades/client/client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,32 +337,46 @@ var scenarioStatus = &params.FullStatus{
// user-admin
// user-other
// machine-0
// instance-id="i-machine-0"
// nonce="fake_nonce"
// jobs=manage-environ
// status=started, info=""
//
// instance-id="i-machine-0"
// nonce="fake_nonce"
// jobs=manage-environ
// status=started, info=""
//
// machine-1
// instance-id="i-machine-1"
// nonce="fake_nonce"
// jobs=host-units
// status=started, info=""
// constraints=mem=1G
//
// instance-id="i-machine-1"
// nonce="fake_nonce"
// jobs=host-units
// status=started, info=""
// constraints=mem=1G
//
// machine-2
// instance-id="i-machine-2"
// nonce="fake_nonce"
// jobs=host-units
// status=started, info=""
//
// instance-id="i-machine-2"
// nonce="fake_nonce"
// jobs=host-units
// status=started, info=""
//
// application-wordpress
// application-logging
// unit-wordpress-0
// deployer-name=machine-1
// status=down with error and status data attached
//
// deployer-name=machine-1
// status=down with error and status data attached
//
// unit-logging-0
// deployer-name=unit-wordpress-0
//
// deployer-name=unit-wordpress-0
//
// unit-wordpress-1
// deployer-name=machine-2
//
// deployer-name=machine-2
//
// unit-logging-1
// deployer-name=unit-wordpress-1
//
// deployer-name=unit-wordpress-1
//
// remoteapplication-mediawiki
// applicationoffer-hosted-mysql
//
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ type importedSSHKey struct {
err error
}

// Override for testing
// Override for testing
var RunSSHImportId = runSSHImportId

func runSSHImportId(keyId string) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions apiserver/facades/client/spaces/integrity.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ func (n *affectedNetworks) ensurePositiveConstraintIntegrity(appName string, spa
// ensureBindingsIntegrity checks that moving subnets to the new space does
// not result in inconsistent application endpoint bindings.
// Consistency is considered maintained if:
// 1. Bound spaces remain unchanged by subnet relocation.
// 2. We successfully change affected bindings to a new space that
// preserves consistency across all units of an application.
// 1. Bound spaces remain unchanged by subnet relocation.
// 2. We successfully change affected bindings to a new space that
// preserves consistency across all units of an application.
func (n *affectedNetworks) ensureBindingsIntegrity(allBindings map[string]Bindings) error {
for appName, bindings := range allBindings {
if err := n.ensureApplicationBindingsIntegrity(appName, bindings); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions apiserver/facades/controller/instancepoller/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func (o *mergeMachineLinkLayerOp) Build(attempt int) ([]txn.Op, error) {
// If we locate multiple existing devices with the hardware address,
// such as will be the case for bridged NICs, fallback through the
// following options.
// - If there is a device that already has a provider ID, use that name.
// - If the devices are of different types, choose an ethernet device over
// a bridge (as observed for MAAS).
// - If there is a device that already has a provider ID, use that name.
// - If the devices are of different types, choose an ethernet device over
// a bridge (as observed for MAAS).
func (o *mergeMachineLinkLayerOp) normaliseIncoming() {
incoming := o.Incoming()

Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45212,7 +45212,7 @@
"$ref": "#/definitions/ErrorResults"
}
},
"description": "AssignUnits assigns the units with the given ids to the correct machine. The\n error results are returned in the same order as the given entities."
"description": "AssignUnits assigns the units with the given ids to the correct machine. The\nerror results are returned in the same order as the given entities."
},
"SetAgentStatus": {
"type": "object",
Expand Down
Loading

0 comments on commit d7e478e

Please sign in to comment.