-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.7' into merge-2.7-20200408
- Loading branch information
Showing
19 changed files
with
332 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
date=`date` | ||
status-set waiting "Hello from install, it is $date." | ||
juju-log -l INFO "Hello from install." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
application-version-set $(grep DISTRIB_RELEASE /etc/lsb-release | cut -d= -sf2) | ||
juju-log -l INFO "Hello from start." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
date=`date` | ||
status-set active "Hello from update-status, it is $date." | ||
juju-log -l INFO "Hello from update-status." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: ubuntu-k8s | ||
summary: "ubuntu operating system" | ||
description: "A popular operating system" | ||
provides: | ||
ubuntu: | ||
interface: ubuntu | ||
resources: | ||
ubuntu_image: | ||
type: "oci-image" | ||
description: "Image used for ubuntu pod." | ||
series: | ||
- kubernetes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2020 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package upgrades | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/juju/errors" | ||
"github.com/juju/utils" | ||
"gopkg.in/juju/names.v3" | ||
|
||
"github.com/juju/juju/worker/uniter/operation" | ||
) | ||
|
||
// stateStepsFor276 returns upgrade steps for Juju 2.7.6. | ||
func stepsFor276() []Step { | ||
return []Step{ | ||
&upgradeStep{ | ||
description: "add remote-application key to hooks in uniter state files", | ||
targets: []Target{HostMachine}, | ||
run: AddRemoteApplicationToRunningHooks(uniterStateGlob), | ||
}, | ||
} | ||
} | ||
|
||
const uniterStateGlob = `/var/lib/juju/agents/unit-*/state/uniter` | ||
|
||
// AddRemoteApplicationToRunningHooks finds any uniter state files on | ||
// the machine with running hooks, and makes sure that they contain a | ||
// remote-application key. | ||
func AddRemoteApplicationToRunningHooks(pattern string) func(Context) error { | ||
return func(_ Context) error { | ||
matches, err := filepath.Glob(pattern) | ||
if err != nil { | ||
return errors.Annotate(err, "finding uniter state files") | ||
} | ||
for _, path := range matches { | ||
// First, check whether the file needs rewriting. | ||
stateFile := operation.NewStateFile(path) | ||
_, err := stateFile.Read() | ||
if err == nil { | ||
// This one's fine, leave it alone. | ||
logger.Debugf("state file valid: %q", path) | ||
continue | ||
} | ||
|
||
err = AddRemoteApplicationToHook(path) | ||
if err != nil { | ||
return errors.Annotatef(err, "fixing %q", path) | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// AddRemoteApplicationToHook takes a the path to a uniter state file | ||
// that doesn't validate, and sets hook.remote-application to the | ||
// remote application so that it does. (If it doesn't validate for | ||
// some other reason we won't change the file.) | ||
func AddRemoteApplicationToHook(path string) error { | ||
var uniterState map[string]interface{} | ||
err := utils.ReadYaml(path, &uniterState) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
hookUnconverted, found := uniterState["hook"] | ||
if !found { | ||
logger.Warningf("no hook found in %q, unable to fix", path) | ||
return nil | ||
} | ||
|
||
hook, ok := hookUnconverted.(map[interface{}]interface{}) | ||
if !ok { | ||
logger.Warningf("fixing %q: expected hook to be a map[interface{}]interface{}, got %T", path, hookUnconverted) | ||
return nil | ||
} | ||
|
||
if val, found := hook["remote-application"]; found { | ||
logger.Debugf("remote-application in %q set to %v already", path, val) | ||
return nil | ||
} | ||
|
||
unitUnconverted, found := hook["remote-unit"] | ||
if !found { | ||
logger.Warningf("fixing %q: remote-unit not found") | ||
return nil | ||
} | ||
|
||
unit, ok := unitUnconverted.(string) | ||
if !ok { | ||
logger.Warningf("fixing %q: expected remote-unit to be string, got %T", path, unitUnconverted) | ||
return nil | ||
} | ||
|
||
appName, err := names.UnitApplication(unit) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
logger.Debugf("setting remote-application to %q in %q", appName, path) | ||
hook["remote-application"] = appName | ||
return errors.Annotatef(utils.WriteYaml(path, uniterState), | ||
"writing updated state to %q", path) | ||
} |
Oops, something went wrong.