Skip to content

Commit

Permalink
Merge pull request juju#16353 from hpidcock/merge-3.2-3.3-20230929
Browse files Browse the repository at this point in the history
juju#16353

Forward ports:
- juju#16336
- juju#16339
- juju#16351
- juju#16352

Conflicts:
- .github/workflows/upgrade.yml
  • Loading branch information
jujubot authored Sep 29, 2023
2 parents d668d19 + 85055d1 commit e6b4b19
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 68 deletions.
10 changes: 8 additions & 2 deletions .github/verify-agent-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

set -euxo pipefail

target_version="$1"
model_type="$1"
target_version="$2"
attempt=0
while true; do
UPDATED=$((juju show-controller --format=json || echo "") | jq -r '.c.details."agent-version"')
if [[ "$model_type" == "iaas" ]]; then
UPDATED=$( (juju ssh -mcontroller 0 sudo cat /var/lib/juju/agents/machine-0/agent.conf || echo "") | yq -r '.upgradedToVersion' )
elif [[ "$model_type" == "caas" ]]; then
UPDATED=$( (juju ssh -mcontroller --container api-server 0 cat /var/lib/juju/agents/controller-0/agent.conf || echo "") | yq -r '.upgradedToVersion' )
fi

if [[ $UPDATED == $target_version* ]]; then
break
fi
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/microk8s-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
shell: bash
run: |
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json '.registry-mirrors += ["http://10.0.1.123:80"]' | sudo tee /etc/docker/daemon.json
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json '.insecure-registries += ["10.0.1.123"]' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
docker system info
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
shell: bash
run: |
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json '.registry-mirrors += ["http://10.0.1.123:80"]' | sudo tee /etc/docker/daemon.json
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json '.insecure-registries += ["10.0.1.123"]' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
docker system info
Expand Down
38 changes: 20 additions & 18 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ jobs:
strategy:
fail-fast: false
matrix:
model_type: ["localhost", "microk8s"]
cloud: ["localhost", "microk8s"]
env:
CHARM_localhost: apache2
CHARM_microk8s: prometheus-k8s
DOCKER_REGISTRY: 10.152.183.69
RUN_TEST: RUN
UPGRADE_FLAGS_localhost: --build-agent
UPGRADE_FLAGS_microk8s: --agent-stream=develop
MODEL_TYPE_localhost: iaas
MODEL_TYPE_microk8s: caas

steps:
- name: Install Dependencies
Expand All @@ -51,7 +53,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup LXD
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'localhost'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'localhost'
uses: canonical/setup-lxd@4e959f8e0d9c5feb27d44c5e4d9a330a782edee0

- name: Set some variables
Expand Down Expand Up @@ -82,24 +84,24 @@ jobs:
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Setup Docker Mirror
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'
shell: bash
run: |
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json '.registry-mirrors += ["http://10.0.1.123:80"]' | sudo tee /etc/docker/daemon.json
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json ".insecure-registries += [\"${DOCKER_REGISTRY}\"]" | sudo tee /etc/docker/daemon.json
(cat /etc/docker/daemon.json 2> /dev/null || echo "{}") | yq -o json ".insecure-registries += [\"10.0.1.123\",\"${DOCKER_REGISTRY}\"]" | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
docker system info
- name: Setup k8s
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'
uses: balchua/microk8s-actions@e99a1ffcd3bb2682d941104cf6c1a215c657903f
with:
channel: "1.28-strict/stable"
addons: '["dns", "hostpath-storage"]'
launch-configuration: "$GITHUB_WORKSPACE/.github/microk8s-launch-config-aws.yaml"

- name: Setup local caas registry
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'
run: |
set -euxo pipefail
Expand Down Expand Up @@ -129,7 +131,7 @@ jobs:
curl https://${DOCKER_REGISTRY}/v2/
- name: Mirror docker images required for juju bootstrap
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'
env:
BASE_JUJU_TAG: ${{ steps.vars.outputs.base-juju-version }}
JUJU_DB_TAG: ${{ steps.vars.outputs.juju-db-version }}
Expand Down Expand Up @@ -159,7 +161,7 @@ jobs:
docker push ${DOCKER_REGISTRY}/test-repo/charm-base:${CHARM_BASE}
- name: Bootstrap Juju - localhost
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'localhost'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'localhost'
shell: bash
run: |
set -euxo pipefail
Expand All @@ -173,7 +175,7 @@ jobs:
juju status
- name: Bootstrap Juju - microk8s
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'

# TODO: Enabling developer-mode is a bit of a hack to get this working for now.
# Ideally, we would mock our own simplestream, similar to Jenkins, to select
Expand Down Expand Up @@ -201,15 +203,15 @@ jobs:
# On k8s, we have to grant the app access to the cluster.
DEPLOY_FLAGS=''
if [[ ${{ matrix.model_type }} == 'microk8s' ]]; then
if [[ ${{ matrix.cloud }} == 'microk8s' ]]; then
DEPLOY_FLAGS='--trust'
fi
juju deploy ${CHARM_${{ matrix.model_type }}} $DEPLOY_FLAGS
juju deploy ${CHARM_${{ matrix.cloud }}} $DEPLOY_FLAGS
juju wait-for application ${CHARM_${{ matrix.model_type }}}
juju wait-for application ${CHARM_${{ matrix.cloud }}}
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.model_type }}}.sh 30
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.cloud }}}.sh 30
- name: Update Juju
if: env.RUN_TEST == 'RUN'
Expand All @@ -219,7 +221,7 @@ jobs:
make go-install
- name: Build jujud image
if: env.RUN_TEST == 'RUN' && matrix.model_type == 'microk8s'
if: env.RUN_TEST == 'RUN' && matrix.cloud == 'microk8s'
env:
UPSTREAM_JUJU_TAG: ${{ steps.vars.outputs.upstream-juju-version }}
CURRENT_STABLE_JUJU_TAG: ${{ steps.vars.outputs.current-stable-juju-version }}
Expand Down Expand Up @@ -270,11 +272,11 @@ jobs:
run: |
set -euxo pipefail
OUTPUT=$(juju upgrade-controller --debug ${UPGRADE_FLAGS_${{ matrix.model_type }}})
OUTPUT=$(juju upgrade-controller --debug ${UPGRADE_FLAGS_${{ matrix.cloud }}})
if [[ $OUTPUT == 'no upgrades available' ]]; then
exit 1
fi
.github/verify-agent-version.sh ${UPSTREAM_JUJU_TAG}
.github/verify-agent-version.sh ${MODEL_TYPE_${{ matrix.cloud }}} ${UPSTREAM_JUJU_TAG}
PANIC=$(juju debug-log --replay --no-tail -m controller | grep "panic" || true)
if [ "$PANIC" != "" ]; then
Expand All @@ -283,7 +285,7 @@ jobs:
exit 1
fi
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.model_type }}}.sh 30
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.cloud }}}.sh 30
- name: Test upgrade model
if: env.RUN_TEST == 'RUN'
Expand Down Expand Up @@ -322,7 +324,7 @@ jobs:
exit 1
fi
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.model_type }}}.sh 30
$GITHUB_WORKSPACE/.github/verify-${CHARM_${{ matrix.cloud }}}.sh 30
- name: Wrap up
if: env.RUN_TEST == 'RUN'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ microk8s-operator-update: host-install operator-image
.PHONY: k3s-operator-update
k3s-operator-update: host-install operator-image
## k3s-operator-update: Push up the newly built operator image for use with k3s
docker save "$(shell ${OPERATOR_IMAGE_PATH})" | k3s ctr images import -
docker save "$(shell ${OPERATOR_IMAGE_PATH})" | sudo k3s ctr images import -

.PHONY: check-k8s-model
check-k8s-model:
Expand Down
9 changes: 3 additions & 6 deletions cmd/juju/ssh/debughooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,9 @@ func (c *debugHooksCommand) getValidHooks(ch charm.Charm) (set.Strings, error) {

func (c *debugHooksCommand) decideEntryPoint(ctx *cmd.Context) string {
if c.modelType == model.CAAS {
c.provider.setArgs([]string{"which", "sudo"})
if err := c.sshCommand.Run(ctx); err != nil {
return "/bin/bash -c '%s'"
}
return "exec /bin/bash -c '%s'"
}
return "sudo /bin/bash -c '%s'"
return "exec sudo /bin/bash -c '%s'"
}

// commonRun is shared between debugHooks and debugCode
Expand All @@ -275,7 +272,7 @@ func (c *debugHooksCommand) commonRun(
debugctx := unitdebug.NewHooksContext(resolvedTargetName)
clientScript := unitdebug.ClientScript(debugctx, hooks, debugAt)
b64Script := base64.StdEncoding.EncodeToString([]byte(clientScript))
innercmd := fmt.Sprintf(`F=$(mktemp); echo %s | base64 -d > $F; . $F`, b64Script)
innercmd := fmt.Sprintf(`F=$(mktemp); echo %s | base64 -d > $F; chmod +x $F; exec $F`, b64Script)
args := []string{fmt.Sprintf(c.decideEntryPoint(ctx), innercmd)}
c.provider.setArgs(args)
return c.sshCommand.Run(ctx)
Expand Down
6 changes: 3 additions & 3 deletions cmd/juju/ssh/debughooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var debugHooksTests = []struct {
expected: &argsSpec{
hostKeyChecking: "yes",
knownHosts: "0",
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) sudo .+`, // can be any of the 3
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) exec sudo .+`, // can be any of the 3
},
}, {
info: "proxy",
Expand All @@ -54,7 +54,7 @@ var debugHooksTests = []struct {
hostKeyChecking: "yes",
knownHosts: "0",
withProxy: true,
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) sudo .+`, // can be any of the 3
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) exec sudo .+`, // can be any of the 3
},
}, {
info: "pty enabled",
Expand All @@ -64,7 +64,7 @@ var debugHooksTests = []struct {
hostKeyChecking: "yes",
knownHosts: "0",
enablePty: true,
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) sudo .+`, // can be any of the 3
argsMatch: `ubuntu@0\.(private|public|1\.2\.3) exec sudo .+`, // can be any of the 3
},
}, {
info: `"*" is a valid hook name: it means hook everything`,
Expand Down
9 changes: 8 additions & 1 deletion cmd/juju/ssh/ssh_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,16 @@ type Context interface {
func (c *sshContainer) ssh(ctx Context, enablePty bool, target *resolvedTarget) (err error) {
args := c.args
if len(args) == 0 {
args = []string{"sh"}
args = []string{"exec", "sh"}
}
cancel, stop := getInterruptAbortChan(ctx)
defer stop()
var env []string
if enablePty {
if term := os.Getenv("TERM"); term != "" {
env = append(env, "TERM="+term)
}
}
return c.execClient.Exec(
k8sexec.ExecParams{
PodName: target.entity,
Expand All @@ -319,6 +325,7 @@ func (c *sshContainer) ssh(ctx Context, enablePty bool, target *resolvedTarget)
Stderr: ctx.GetStderr(),
Stdin: ctx.GetStdin(),
TTY: enablePty,
Env: env,
},
cancel,
)
Expand Down
Loading

0 comments on commit e6b4b19

Please sign in to comment.