Skip to content

Commit 723a397

Browse files
feat: add an option to pass --agent-version when bootstrapping (#111)
Adds a new config option in `juju`, `agent-version`. When specified, this is passed as `--agent-version` when bootstrapping Juju. This is particularly useful when there is an issue with the latest agent version and users want to restrict the agent version to one without the issue, but otherwise use the latest Juju.
1 parent 6c6f2cb commit 723a397

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ juju:
147147
disable: true | false
148148
# (Optional): Channel from which to install Juju.
149149
channel: <channel>
150+
# (Optional): Juju agent version to use when bootstrapping (e.g. "3.5.2").
151+
agent-version: <version>
150152
# (Optional): A map of model-defaults to set when bootstrapping *all* Juju controllers.
151153
model-defaults:
152154
<model-default>: <value>
@@ -300,6 +302,7 @@ An example config file can be seen below:
300302
```yaml
301303
juju:
302304
channel: 3.5/stable
305+
agent-version: "3.5.2"
303306
model-defaults:
304307
test-mode: "true"
305308
automatically-retry-hooks: "false"

internal/config/config_format.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type jujuConfig struct {
3434
Disable bool `mapstructure:"disable"`
3535
// The Snap Store channel from which to install Juju
3636
Channel string `mapstructure:"channel"`
37+
// The Juju agent version to use during bootstrap
38+
AgentVersion string `mapstructure:"agent-version"`
3739
// The set of model-defaults to be passed to Juju during bootstrap
3840
ModelDefaults map[string]string `mapstructure:"model-defaults"`
3941
// The set of bootstrap constraints to be passed to Juju

internal/juju/juju.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func NewJujuHandler(config *config.Config, r system.Worker, providers []provider
2929

3030
return &JujuHandler{
3131
channel: channel,
32+
agentVersion: config.Juju.AgentVersion,
3233
bootstrapConstraints: config.Juju.BootstrapConstraints,
3334
modelDefaults: config.Juju.ModelDefaults,
3435
providers: providers,
@@ -40,6 +41,7 @@ func NewJujuHandler(config *config.Config, r system.Worker, providers []provider
4041
// JujuHandler represents a Juju installation on the system.
4142
type JujuHandler struct {
4243
channel string
44+
agentVersion string
4345
bootstrapConstraints map[string]string
4446
modelDefaults map[string]string
4547
providers []providers.Provider
@@ -201,6 +203,11 @@ func (j *JujuHandler) bootstrapProvider(provider providers.Provider) error {
201203
"--verbose",
202204
}
203205

206+
// Add agent version if specified.
207+
if j.agentVersion != "" {
208+
bootstrapArgs = append(bootstrapArgs, "--agent-version", j.agentVersion)
209+
}
210+
204211
// Combine the global and provider-local model-defaults and bootstrap-constraints.
205212
modelDefaults := config.MergeMaps(j.modelDefaults, provider.ModelDefaults())
206213
bootstrapConstraints := config.MergeMaps(j.bootstrapConstraints, provider.BootstrapConstraints())

internal/juju/juju_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,41 @@ func TestJujuRestoreKillController(t *testing.T) {
218218
t.Fatalf("expected: %v, got: %v", expectedCommands, system.ExecutedCommands)
219219
}
220220
}
221+
222+
func TestJujuHandlerWithAgentVersion(t *testing.T) {
223+
cfg := &config.Config{}
224+
cfg.Juju.AgentVersion = "3.5.2"
225+
cfg.Providers.LXD.Enable = true
226+
cfg.Providers.LXD.Bootstrap = true
227+
228+
cfg.Juju.ModelDefaults = map[string]string{
229+
"test-mode": "true",
230+
"automatically-retry-hooks": "false",
231+
}
232+
233+
system := system.NewMockSystem()
234+
system.MockCommandReturn(
235+
"sudo -u test-user juju show-controller concierge-lxd",
236+
[]byte("ERROR controller concierge-lxd not found"),
237+
fmt.Errorf("Test error"),
238+
)
239+
240+
provider := providers.NewLXD(system, cfg)
241+
handler := NewJujuHandler(cfg, system, []providers.Provider{provider})
242+
243+
err := handler.Prepare()
244+
if err != nil {
245+
t.Fatal(err.Error())
246+
}
247+
248+
expectedCommands := []string{
249+
"snap install juju",
250+
"sudo -u test-user juju show-controller concierge-lxd",
251+
"sudo -u test-user -g lxd juju bootstrap localhost concierge-lxd --verbose --agent-version 3.5.2 --model-default automatically-retry-hooks=false --model-default test-mode=true",
252+
"sudo -u test-user juju add-model -c concierge-lxd testing",
253+
}
254+
255+
if !reflect.DeepEqual(expectedCommands, system.ExecutedCommands) {
256+
t.Fatalf("expected: %v, got: %v", expectedCommands, system.ExecutedCommands)
257+
}
258+
}

0 commit comments

Comments
 (0)