diff --git a/.github/workflows/terraform-smoke.yml b/.github/workflows/terraform-smoke.yml index 096292e95af..8357c8f77d1 100644 --- a/.github/workflows/terraform-smoke.yml +++ b/.github/workflows/terraform-smoke.yml @@ -17,7 +17,7 @@ jobs: smoke: name: Terraform Smoke - runs-on: [self-hosted, linux, x64, aws, xlarge] + runs-on: [self-hosted, linux, x64, aws, xxlarge] if: github.event.pull_request.draft == false steps: diff --git a/apiserver/common/charms/appcharminfo_test.go b/apiserver/common/charms/appcharminfo_test.go index e6312ea3519..0359a90a9ff 100644 --- a/apiserver/common/charms/appcharminfo_test.go +++ b/apiserver/common/charms/appcharminfo_test.go @@ -18,7 +18,6 @@ import ( facademocks "github.com/juju/juju/apiserver/facade/mocks" "github.com/juju/juju/core/permission" "github.com/juju/juju/rpc/params" - "github.com/juju/juju/state" ) type appCharmInfoSuite struct{} @@ -47,7 +46,7 @@ func (s *appCharmInfoSuite) TestBasic(c *gc.C) { ch.EXPECT().Actions().Return(&charm.Actions{}) ch.EXPECT().Metrics().Return(&charm.Metrics{}) ch.EXPECT().Manifest().Return(&charm.Manifest{}) - ch.EXPECT().LXDProfile().Return(&state.LXDProfile{}) + ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{}) authorizer := facademocks.NewMockAuthorizer(ctrl) authorizer.EXPECT().AuthController().Return(true) @@ -134,7 +133,7 @@ func (s *appCharmInfoSuite) TestSidecarCharm(c *gc.C) { ch.EXPECT().Actions().Return(&charm.Actions{}) ch.EXPECT().Metrics().Return(&charm.Metrics{}) ch.EXPECT().Manifest().Return(&charm.Manifest{}) - ch.EXPECT().LXDProfile().Return(&state.LXDProfile{}) + ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{}) authorizer := facademocks.NewMockAuthorizer(ctrl) authorizer.EXPECT().AuthController().Return(true) diff --git a/apiserver/common/charms/charminfo_test.go b/apiserver/common/charms/charminfo_test.go index fab55a3138a..a3dcc19a621 100644 --- a/apiserver/common/charms/charminfo_test.go +++ b/apiserver/common/charms/charminfo_test.go @@ -17,7 +17,6 @@ import ( facademocks "github.com/juju/juju/apiserver/facade/mocks" "github.com/juju/juju/core/permission" "github.com/juju/juju/rpc/params" - "github.com/juju/juju/state" ) type charmInfoSuite struct{} @@ -41,7 +40,7 @@ func (s *charmInfoSuite) TestBasic(c *gc.C) { ch.EXPECT().Actions().Return(&charm.Actions{}) ch.EXPECT().Metrics().Return(&charm.Metrics{}) ch.EXPECT().Manifest().Return(&charm.Manifest{}) - ch.EXPECT().LXDProfile().Return(&state.LXDProfile{}) + ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{}) ch.EXPECT().URL().Return("ch:foo-1") authorizer := facademocks.NewMockAuthorizer(ctrl) diff --git a/apiserver/common/charms/common.go b/apiserver/common/charms/common.go index 8bed1ea0652..e3b0ebb2225 100644 --- a/apiserver/common/charms/common.go +++ b/apiserver/common/charms/common.go @@ -33,7 +33,7 @@ type Charm interface { Manifest() *charm.Manifest Metrics() *charm.Metrics Actions() *charm.Actions - LXDProfile() *state.LXDProfile + LXDProfile() *charm.LXDProfile } type Model interface { @@ -335,7 +335,7 @@ func convertCharmExtraBindingMap(bindings map[string]charm.ExtraBinding) map[str return result } -func convertCharmLXDProfile(profile *state.LXDProfile) *params.CharmLXDProfile { +func convertCharmLXDProfile(profile *charm.LXDProfile) *params.CharmLXDProfile { return ¶ms.CharmLXDProfile{ Description: profile.Description, Config: convertCharmLXDProfileConfig(profile.Config), diff --git a/apiserver/common/charms/mocks/mocks.go b/apiserver/common/charms/mocks/mocks.go index 40d68419b3a..efce25c124b 100644 --- a/apiserver/common/charms/mocks/mocks.go +++ b/apiserver/common/charms/mocks/mocks.go @@ -14,7 +14,6 @@ import ( charm "github.com/juju/charm/v12" charms "github.com/juju/juju/apiserver/common/charms" - state "github.com/juju/juju/state" names "github.com/juju/names/v5" gomock "go.uber.org/mock/gomock" ) @@ -178,10 +177,10 @@ func (mr *MockCharmMockRecorder) Config() *gomock.Call { } // LXDProfile mocks base method. -func (m *MockCharm) LXDProfile() *state.LXDProfile { +func (m *MockCharm) LXDProfile() *charm.LXDProfile { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LXDProfile") - ret0, _ := ret[0].(*state.LXDProfile) + ret0, _ := ret[0].(*charm.LXDProfile) return ret0 } diff --git a/apiserver/facades/client/application/application_test.go b/apiserver/facades/client/application/application_test.go index 4dfd8fd8f65..0172c017fdc 100644 --- a/apiserver/facades/client/application/application_test.go +++ b/apiserver/facades/client/application/application_test.go @@ -303,7 +303,7 @@ func (s *applicationSuite) TestApplicationDeployToMachineWithLXDProfile(c *gc.C) c.Assert(expected.Config(), gc.DeepEquals, ch.Config()) expectedProfile := ch.(charm.LXDProfiler).LXDProfile() - c.Assert(expected.LXDProfile(), gc.DeepEquals, &state.LXDProfile{ + c.Assert(expected.LXDProfile(), gc.DeepEquals, &charm.LXDProfile{ Description: expectedProfile.Description, Config: expectedProfile.Config, Devices: expectedProfile.Devices, @@ -357,7 +357,7 @@ func (s *applicationSuite) TestApplicationDeployToMachineWithInvalidLXDProfileAn c.Assert(expected.Config(), gc.DeepEquals, ch.Config()) expectedProfile := ch.(charm.LXDProfiler).LXDProfile() - c.Assert(expected.LXDProfile(), gc.DeepEquals, &state.LXDProfile{ + c.Assert(expected.LXDProfile(), gc.DeepEquals, &charm.LXDProfile{ Description: expectedProfile.Description, Config: expectedProfile.Config, Devices: expectedProfile.Devices, diff --git a/cmd/juju/application/refresh.go b/cmd/juju/application/refresh.go index af0949b735e..99fa5ee0cfc 100644 --- a/cmd/juju/application/refresh.go +++ b/cmd/juju/application/refresh.go @@ -229,8 +229,8 @@ is determined by the contents of the charm at the specified path. --switch and --revision are mutually exclusive. Use of the --force-units option is not generally recommended; units upgraded -while in an error state will not have refreshed hooks executed, and may cause -unexpected behavior. +while in an error state will not have upgrade-charm hooks executed, and may +cause unexpected behavior. --force option for LXD Profiles is not generally recommended when upgrading an application; overriding profiles on the container may cause unexpected diff --git a/cmd/juju/caas/add.go b/cmd/juju/caas/add.go index e2c54061155..1facdcb85e2 100644 --- a/cmd/juju/caas/add.go +++ b/cmd/juju/caas/add.go @@ -876,34 +876,28 @@ func (c *AddCAASCommand) getClusterMetadataFunc(ctx *cmd.Context) provider.GetCl } func (c *AddCAASCommand) verifyName(name string) error { - public, _, err := c.cloudMetadataStore.PublicCloudMetadata() - if err != nil { - return err + if name == k8s.K8sCloudMicrok8s { + return fmt.Errorf(`%q is the name of a built-in cloud. +If you want to use Juju with microk8s, the recommended way is to install the strictly confined microk8s snap. +Using the strictly confined microk8s snap means that Juju and microk8s will work together out of the box.`, name) } - msg, err := nameExists(name, public) + + public, _, err := c.cloudMetadataStore.PublicCloudMetadata() if err != nil { return errors.Trace(err) } - if msg != "" { - return errors.Errorf(msg) - } - return nil -} -// nameExists returns either an empty string if the name does not exist, or a -// non-empty string with an error message if it does exist. -func nameExists(name string, public map[string]jujucloud.Cloud) (string, error) { if _, ok := public[name]; ok { - return fmt.Sprintf("%q is the name of a public cloud", name), nil + return fmt.Errorf("%q is the name of a public cloud", name) } builtin, err := common.BuiltInClouds() if err != nil { - return "", errors.Trace(err) + return errors.Trace(err) } if _, ok := builtin[name]; ok { - return fmt.Sprintf("%q is the name of a built-in cloud", name), nil + return fmt.Errorf("%q is the name of a built-in cloud", name) } - return "", nil + return nil } func addCloudToLocal(cloudMetadataStore CloudMetadataStore, newCloud jujucloud.Cloud) error { diff --git a/cmd/juju/caas/add_test.go b/cmd/juju/caas/add_test.go index 8f402ca0d67..0e666d499be 100644 --- a/cmd/juju/caas/add_test.go +++ b/cmd/juju/caas/add_test.go @@ -510,6 +510,15 @@ func (s *addCAASSuite) TestMissingName(c *gc.C) { c.Assert(err, gc.ErrorMatches, `missing k8s name.`) } +func (s *addCAASSuite) TestInvalidName(c *gc.C) { + command := s.makeCommand(c, true, true, true) + _, err := s.runCommand(c, nil, command, "microk8s") + c.Assert(err, gc.ErrorMatches, ` +"microk8s" is the name of a built-in cloud. +If you want to use Juju with microk8s, the recommended way is to install the strictly confined microk8s snap. +Using the strictly confined microk8s snap means that Juju and microk8s will work together out of the box.`[1:]) +} + func (s *addCAASSuite) TestMissingArgs(c *gc.C) { command := s.makeCommand(c, true, true, true) _, err := s.runCommand(c, nil, command) diff --git a/cmd/output/progress/mocks/clock_mock.go b/cmd/output/progress/mocks/clock_mock.go index ed358ce8281..0714dba0978 100644 --- a/cmd/output/progress/mocks/clock_mock.go +++ b/cmd/output/progress/mocks/clock_mock.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/container/lxd/mocks/clock_mock.go b/container/lxd/mocks/clock_mock.go index d7c49f0a5e2..584d53b5f49 100644 --- a/container/lxd/mocks/clock_mock.go +++ b/container/lxd/mocks/clock_mock.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/go.mod b/go.mod index 49c48883ed9..c726ddeea6b 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/juju/ansiterm v1.0.0 github.com/juju/blobstore/v3 v3.0.2 github.com/juju/charm/v12 v12.0.2 - github.com/juju/clock v1.0.3 + github.com/juju/clock v1.1.1 github.com/juju/cmd/v3 v3.0.14 github.com/juju/collections v1.0.4 github.com/juju/description/v5 v5.0.4 diff --git a/go.sum b/go.sum index 50f8b748137..57ec867c74a 100644 --- a/go.sum +++ b/go.sum @@ -475,8 +475,8 @@ github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c/go.mod h1:nD0vlnrUjcjJh github.com/juju/clock v0.0.0-20220202072423-1b0f830854c4/go.mod h1:zDZCPSgCJQINeZtQwHx2/cFk4seaBC8Yiqe8V82xiP0= github.com/juju/clock v0.0.0-20220203021603-d9deb868a28a/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= github.com/juju/clock v1.0.0/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= -github.com/juju/clock v1.0.3 h1:yJHIsWXeU8j3QcBdiess09SzfiXRRrsjKPn2whnMeds= -github.com/juju/clock v1.0.3/go.mod h1:HIBvJ8kiV/n7UHwKuCkdYL4l/MDECztHR2sAvWDxxf0= +github.com/juju/clock v1.1.1 h1:NvgHG9DQmOpBevgt6gzkyimdWBooLXDy1cQn89qJzBI= +github.com/juju/clock v1.1.1/go.mod h1:HIBvJ8kiV/n7UHwKuCkdYL4l/MDECztHR2sAvWDxxf0= github.com/juju/cmd v0.0.0-20171107070456-e74f39857ca0/go.mod h1:yWJQHl73rdSX4DHVKGqkAip+huBslxRwS8m9CrOLq18= github.com/juju/cmd/v3 v3.0.0-20220202061353-b1cc80b193b0/go.mod h1:EoGJiEG+vbMwO9l+Es0SDTlaQPjH6nLcnnc4NfZB3cY= github.com/juju/cmd/v3 v3.0.14 h1:KuuamArSH7vQ6SdQKEHYK2scEMkJTEZKLs8abrlW3XE= diff --git a/service/snap/clock_mock_test.go b/service/snap/clock_mock_test.go index 74cedcff667..41f43ca5d21 100644 --- a/service/snap/clock_mock_test.go +++ b/service/snap/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/state/charm.go b/state/charm.go index 42836132d8e..9ac1c6b0810 100644 --- a/state/charm.go +++ b/state/charm.go @@ -251,7 +251,7 @@ func insertCharmOps(mb modelBackend, info CharmInfo) ([]txn.Op, error) { } lpc, ok := info.Charm.(charm.LXDProfiler) if !ok { - return nil, errors.New("charm does no implement LXDProfiler") + return nil, errors.New("charm does not implement LXDProfiler") } doc.LXDProfile = safeLXDProfile(lpc.LXDProfile()) @@ -490,6 +490,8 @@ type Charm struct { charmURL *charm.URL } +var _ charm.LXDProfiler = (*Charm)(nil) + func newCharm(st *State, cdoc *charmDoc) *Charm { // Because we probably just read the doc from state, make sure we // unescape any config option names for "$" and ".". See @@ -678,8 +680,15 @@ func (c *Charm) Actions() *charm.Actions { } // LXDProfile returns the lxd profile definition of the charm. -func (c *Charm) LXDProfile() *LXDProfile { - return c.doc.LXDProfile +func (c *Charm) LXDProfile() *charm.LXDProfile { + if c.doc.LXDProfile == nil { + return nil + } + return &charm.LXDProfile{ + Config: c.doc.LXDProfile.Config, + Description: c.doc.LXDProfile.Description, + Devices: c.doc.LXDProfile.Devices, + } } // StoragePath returns the storage path of the charm bundle. diff --git a/state/mocks/clock_mock.go b/state/mocks/clock_mock.go index d7c49f0a5e2..584d53b5f49 100644 --- a/state/mocks/clock_mock.go +++ b/state/mocks/clock_mock.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/changestream/clock_mock_test.go b/worker/changestream/clock_mock_test.go index 742d9f45e59..b6b9935775c 100644 --- a/worker/changestream/clock_mock_test.go +++ b/worker/changestream/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/changestream/stream/clock_mock_test.go b/worker/changestream/stream/clock_mock_test.go index 4e7d7252e1a..c09ed3ae8ba 100644 --- a/worker/changestream/stream/clock_mock_test.go +++ b/worker/changestream/stream/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/dbaccessor/clock_mock_test.go b/worker/dbaccessor/clock_mock_test.go index ff381a8b095..9245b2a2863 100644 --- a/worker/dbaccessor/clock_mock_test.go +++ b/worker/dbaccessor/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/filenotifywatcher/clock_mock_test.go b/worker/filenotifywatcher/clock_mock_test.go index 95f5f134bf6..178a564b3f6 100644 --- a/worker/filenotifywatcher/clock_mock_test.go +++ b/worker/filenotifywatcher/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/leaseexpiry/clock_mock_test.go b/worker/leaseexpiry/clock_mock_test.go index aefba1d79d0..11968220c6f 100644 --- a/worker/leaseexpiry/clock_mock_test.go +++ b/worker/leaseexpiry/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/querylogger/clock_mock_test.go b/worker/querylogger/clock_mock_test.go index c6f6992462f..0ace0dc732a 100644 --- a/worker/querylogger/clock_mock_test.go +++ b/worker/querylogger/clock_mock_test.go @@ -68,6 +68,48 @@ func (mr *MockClockMockRecorder) AfterFunc(arg0, arg1 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterFunc", reflect.TypeOf((*MockClock)(nil).AfterFunc), arg0, arg1) } +// At mocks base method. +func (m *MockClock) At(arg0 time.Time) <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "At", arg0) + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// At indicates an expected call of At. +func (mr *MockClockMockRecorder) At(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "At", reflect.TypeOf((*MockClock)(nil).At), arg0) +} + +// AtFunc mocks base method. +func (m *MockClock) AtFunc(arg0 time.Time, arg1 func()) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtFunc", arg0, arg1) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// AtFunc indicates an expected call of AtFunc. +func (mr *MockClockMockRecorder) AtFunc(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtFunc", reflect.TypeOf((*MockClock)(nil).AtFunc), arg0, arg1) +} + +// NewAlarm mocks base method. +func (m *MockClock) NewAlarm(arg0 time.Time) clock.Alarm { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAlarm", arg0) + ret0, _ := ret[0].(clock.Alarm) + return ret0 +} + +// NewAlarm indicates an expected call of NewAlarm. +func (mr *MockClockMockRecorder) NewAlarm(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAlarm", reflect.TypeOf((*MockClock)(nil).NewAlarm), arg0) +} + // NewTimer mocks base method. func (m *MockClock) NewTimer(arg0 time.Duration) clock.Timer { m.ctrl.T.Helper() diff --git a/worker/secretexpire/secretexpire.go b/worker/secretexpire/secretexpire.go index 9b9098e2cb6..9e1386c99d2 100644 --- a/worker/secretexpire/secretexpire.go +++ b/worker/secretexpire/secretexpire.go @@ -103,7 +103,7 @@ type Worker struct { secretRevisions map[string]secretRevisionExpiryInfo - timer clock.Timer + alarm clock.Alarm nextTrigger time.Time } @@ -127,8 +127,8 @@ func (w *Worker) loop() (err error) { } for { var timeout <-chan time.Time - if w.timer != nil { - timeout = w.timer.Chan() + if w.alarm != nil { + timeout = w.alarm.Chan() } select { case <-w.catacomb.Dying(): @@ -206,7 +206,7 @@ func (w *Worker) computeNextExpireTime() { w.config.Logger.Debugf("computing next expire time for secret revisions %#v", w.secretRevisions) if len(w.secretRevisions) == 0 { - w.timer = nil + w.alarm = nil return } @@ -225,29 +225,28 @@ func (w *Worker) computeNextExpireTime() { } soonestExpireTime = info.expireTime } - // There's no need to start or reset the timer if there's no changes to make. + // There's no need to start or reset the alarm if there's no changes to make. if soonestExpireTime.IsZero() || w.nextTrigger == soonestExpireTime { return } - nextDuration := soonestExpireTime.Sub(now) - w.config.Logger.Debugf("next secret revision for %q will expire in %v at %s", w.config.SecretOwners, nextDuration, soonestExpireTime) + w.config.Logger.Debugf("next secret revision for %q will expire at %s", w.config.SecretOwners, soonestExpireTime) w.nextTrigger = soonestExpireTime - if w.timer == nil { - w.timer = w.config.Clock.NewTimer(nextDuration) + if w.alarm == nil { + w.alarm = w.config.Clock.NewAlarm(w.nextTrigger) } else { - // See the docs on Timer.Reset() that says it isn't safe to call + // See the docs on (*time.Timer).Reset() that says it isn't safe to call // on a non-stopped channel, and if it is stopped, you need to check // if the channel needs to be drained anyway. It isn't safe to drain // unconditionally in case another goroutine has already noticed, // but make an attempt. - if !w.timer.Stop() { + if !w.alarm.Stop() { select { - case <-w.timer.Chan(): + case <-w.alarm.Chan(): default: } } - w.timer.Reset(nextDuration) + w.alarm.Reset(w.nextTrigger) } } diff --git a/worker/storageprovisioner/mock_test.go b/worker/storageprovisioner/mock_test.go index f058a1b8b9a..35d19931a67 100644 --- a/worker/storageprovisioner/mock_test.go +++ b/worker/storageprovisioner/mock_test.go @@ -856,6 +856,7 @@ func newMockMachineAccessor(c *gc.C) *mockMachineAccessor { } type mockClock struct { + clock.Clock gitjujutesting.Stub now time.Time onNow func() time.Time