forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifold.go
50 lines (41 loc) · 1.49 KB
/
manifold.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package toolsversionchecker
import (
"time"
"github.com/juju/errors"
"gopkg.in/juju/names.v3"
"gopkg.in/juju/worker.v1"
"gopkg.in/juju/worker.v1/dependency"
"github.com/juju/juju/agent"
apiagent "github.com/juju/juju/api/agent"
"github.com/juju/juju/api/agenttools"
"github.com/juju/juju/api/base"
"github.com/juju/juju/cmd/jujud/agent/engine"
)
// ManifoldConfig defines the names of the manifolds on which a Manifold will depend.
type ManifoldConfig engine.AgentAPIManifoldConfig
// Manifold returns a dependency manifold that runs a toolsversionchecker worker,
// using the api connection resource named in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {
typedConfig := engine.AgentAPIManifoldConfig(config)
return engine.AgentAPIManifold(typedConfig, newWorker)
}
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
tag := a.CurrentConfig().Tag()
if tag.Kind() != names.MachineTagKind {
return nil, errors.New("this manifold may only be used inside a machine agent")
}
isController, err := apiagent.IsController(apiCaller, tag)
if err != nil {
return nil, errors.Trace(err)
}
if !isController {
return nil, dependency.ErrMissing
}
// 4 times a day seems a decent enough amount of checks.
checkerParams := VersionCheckerParams{
CheckInterval: time.Hour * 6,
}
return New(agenttools.NewFacade(apiCaller), &checkerParams), nil
}