Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments to actions operator on ubuntu-24.04 #83

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
os:
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
juju:
- '2.9/stable'
- '3.1/stable'
Expand All @@ -80,6 +81,11 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Python
if: ${{ ! contains(fromJson('["ubuntu-20.04", "ubuntu-22.04"]'), matrix.os) }}
uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: ./
with:
provider: lxd
Expand Down Expand Up @@ -108,12 +114,18 @@ jobs:
os:
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
channel:
- 1.28-strict/stable
- 1.27-strict/stable
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Python
if: ${{ ! contains(fromJson('["ubuntu-20.04", "ubuntu-22.04"]'), matrix.os) }}
uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: ./
with:
provider: microk8s
Expand All @@ -133,12 +145,18 @@ jobs:
os:
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
channel:
- 1.28/stable
- latest/stable
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Python
if: ${{ ! contains(fromJson('["ubuntu-20.04", "ubuntu-22.04"]'), matrix.os) }}
uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: ./
with:
provider: microk8s
Expand Down Expand Up @@ -212,9 +230,15 @@ jobs:
os:
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Python
if: ${{ ! contains(fromJson('["ubuntu-20.04", "ubuntu-22.04"]'), matrix.os) }}
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Setup k8s controller
uses: ./
with:
Expand All @@ -226,7 +250,7 @@ jobs:
# The `CONTROLLER_NAME` envvar is set by this actions
run: echo "name=$CONTROLLER_NAME" >> $GITHUB_OUTPUT
- name: Setup lxd controller
uses: charmed-kubernetes/actions-operator@main
uses: ./
with:
provider: lxd
- name: Save lxd controller name
Expand Down
46 changes: 31 additions & 15 deletions dist/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5492,10 +5492,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const os = __importStar(__nccwpck_require__(2087));
const utils_1 = __nccwpck_require__(2828);
const semver_1 = __importDefault(__nccwpck_require__(1383));
const ts_dedent_1 = __importDefault(__nccwpck_require__(3604));
const ignoreFail = { "ignoreReturnCode": true };
const user = os.userInfo().username;
const os_release = () => __awaiter(void 0, void 0, void 0, function* () {
// Read os-release file into an object
let stdout_buf = '';
Expand All @@ -5512,6 +5514,24 @@ const os_release = () => __awaiter(void 0, void 0, void 0, function* () {
});
return data;
});
const snap_version = (snap_name) => __awaiter(void 0, void 0, void 0, function* () {
let stdout_buf = '';
const options = {
listeners: {
stdout: (data) => { stdout_buf += data.toString(); }
}
};
yield exec.exec("snap", ["list", snap_name], options);
const lines = stdout_buf.split('\n');
if (lines.length < 2) {
throw new Error(`snap ${snap_name} not found`);
}
const snap_line = lines[1].split(/\s+/);
if (snap_line.length < 2) {
throw new Error(`snap ${snap_name} version not found`);
}
return snap_line[1];
});
const docker_lxd_clash = () => __awaiter(void 0, void 0, void 0, function* () {
// Work-around clash between docker and lxd on jammy
// https://github.com/docker/for-linux/issues/1034
Expand All @@ -5537,8 +5557,8 @@ function get_microk8s_group() {
}
function exec_as_microk8s(cmd, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const microk8s_group = get_microk8s_group();
return yield exec.exec('sg', [microk8s_group, '-c', cmd], options);
let group = get_microk8s_group();
return yield exec.exec(`sudo -g ${group} -E ${cmd}`, [], options);
});
}
function retry_until_rc(cmd, expected_rc = 0, maxRetries = 12, timeout = 10000) {
Expand Down Expand Up @@ -5598,15 +5618,10 @@ function microk8s_init(channel, addons, container_registry_url) {
// Add the given addons if any were given.
yield exec_as_microk8s("microk8s status --wait-ready --timeout=600");
if (addons) {
yield exec_as_microk8s("sudo microk8s enable " + addons);
yield exec.exec(`sudo microk8s enable ${addons}`);
}
let stdout_buf = '';
const options = {
listeners: {
stdout: (data) => { stdout_buf += data.toString(); }
}
};
yield exec_as_microk8s("snap list microk8s | grep microk8s | awk '{ print $2 }'", options);
// get microk8s version
const mk8s_ver = yield snap_version("microk8s");
// workarounds for https://bugs.launchpad.net/juju/+bug/1937282
if (!(yield retry_until_rc("microk8s kubectl -n kube-system rollout status deployment/coredns"))) {
core.setFailed("Timed out waiting for CoreDNS");
Expand All @@ -5618,7 +5633,7 @@ function microk8s_init(channel, addons, container_registry_url) {
return false;
}
;
if (semver_1.default.lt(stdout_buf, '1.24.0')) {
if (semver_1.default.lt(mk8s_ver, '1.24.0')) {
yield exec_as_microk8s("microk8s kubectl create serviceaccount test-sa");
if (!(yield retry_until_rc("microk8s kubectl get secrets | grep -q test-sa-token-"))) {
core.setFailed("Timed out waiting for test SA token");
Expand Down Expand Up @@ -5738,7 +5753,7 @@ function run() {
yield exec.exec("sudo lxd init --auto");
yield exec.exec("sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket");
yield exec.exec("lxc network set lxdbr0 ipv6.address none");
yield exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']);
yield exec.exec(`sudo usermod -a -G lxd ${user}`);
core.endGroup();
core.startGroup("Install tox");
yield install_tox(tox_version);
Expand All @@ -5757,7 +5772,8 @@ function run() {
yield snap(`install juju-bundle --classic ${fixed_revision_args("juju-bundle", juju_bundle_channel, arch)}`);
yield snap(`install juju-crashdump --classic ${fixed_revision_args("juju-crashdump", juju_crashdump_channel, arch)}`);
const release = yield os_release();
if (release["VERSION_CODENAME"].includes("jammy")) {
let version_id = semver_1.default.coerce(release["VERSION_ID"], { loose: true });
if (version_id && version_id.compare('22.4.0') >= 0) {
yield docker_lxd_clash();
}
core.endGroup();
Expand All @@ -5783,7 +5799,7 @@ function run() {
}
core.endGroup();
core.startGroup("Initialize microk8s");
yield exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]);
yield exec.exec(`sudo usermod -a -G ${microk8s_group} ${user}`);
if (!(yield microk8s_init(channel, microk8s_addons, container_registry_url))) {
return;
}
Expand Down Expand Up @@ -5835,7 +5851,7 @@ function run() {
core.startGroup("Bootstrap controller");
bootstrap_command = `${bootstrap_command} --bootstrap-constraints="${bootstrap_constraints}"`;
if (group !== "") {
yield exec.exec('sg', [group, '-c', bootstrap_command]);
yield exec.exec(`sudo -g ${group} -E ${bootstrap_command}`);
}
else {
yield exec.exec(bootstrap_command);
Expand Down
48 changes: 33 additions & 15 deletions src/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as os from 'os'
import { retryAsyncDecorator } from 'ts-retry/lib/cjs/retry/utils';
import semver from 'semver';
import dedent from 'ts-dedent';
Expand All @@ -11,6 +12,7 @@ declare var process : {
}

const ignoreFail: exec.ExecOptions = {"ignoreReturnCode": true}
const user = os.userInfo().username

const os_release = async () => {
// Read os-release file into an object
Expand All @@ -29,6 +31,25 @@ const os_release = async () => {
return data
}

const snap_version = async (snap_name: string) => {
let stdout_buf = '';
const options = {
listeners: {
stdout: (data: Buffer) => { stdout_buf += data.toString() }
}
};
await exec.exec("snap", ["list", snap_name], options);
addyess marked this conversation as resolved.
Show resolved Hide resolved
const lines = stdout_buf.split('\n');
if (lines.length < 2) {
throw new Error(`snap ${snap_name} not found`)
}
const snap_line = lines[1].split(/\s+/);
if (snap_line.length < 2) {
throw new Error(`snap ${snap_name} version not found`)
}
return snap_line[1]
}

const docker_lxd_clash = async () => {
// Work-around clash between docker and lxd on jammy
// https://github.com/docker/for-linux/issues/1034
Expand All @@ -54,8 +75,8 @@ function get_microk8s_group() {


async function exec_as_microk8s(cmd: string, options = {}) {
const microk8s_group = get_microk8s_group();
return await exec.exec('sg', [microk8s_group, '-c', cmd], options);
let group = get_microk8s_group();
return await exec.exec(`sudo -g ${group} -E ${cmd}`, [], options);
}

async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout=10000) {
Expand Down Expand Up @@ -120,15 +141,11 @@ async function microk8s_init(channel, addons, container_registry_url:string) {
// Add the given addons if any were given.
await exec_as_microk8s("microk8s status --wait-ready --timeout=600");
if (addons) {
await exec_as_microk8s("sudo microk8s enable " + addons);
await exec.exec(`sudo microk8s enable ${addons}`);
addyess marked this conversation as resolved.
Show resolved Hide resolved
}
let stdout_buf = '';
const options = {
listeners: {
stdout: (data) => { stdout_buf += data.toString() }
}
};
await exec_as_microk8s("snap list microk8s | grep microk8s | awk '{ print $2 }'", options);

// get microk8s version
const mk8s_ver = await snap_version("microk8s")

// workarounds for https://bugs.launchpad.net/juju/+bug/1937282
if (! await retry_until_rc("microk8s kubectl -n kube-system rollout status deployment/coredns")) {
Expand All @@ -139,7 +156,7 @@ async function microk8s_init(channel, addons, container_registry_url:string) {
core.setFailed("Timed out waiting for Storage");
return false;
};
if (semver.lt(stdout_buf, '1.24.0')) {
if (semver.lt(mk8s_ver, '1.24.0')) {
await exec_as_microk8s("microk8s kubectl create serviceaccount test-sa");
if (! await retry_until_rc("microk8s kubectl get secrets | grep -q test-sa-token-")) {
core.setFailed("Timed out waiting for test SA token");
Expand Down Expand Up @@ -261,7 +278,7 @@ async function run() {
await exec.exec("sudo lxd init --auto");
await exec.exec("sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket");
await exec.exec("lxc network set lxdbr0 ipv6.address none");
await exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']);
await exec.exec(`sudo usermod -a -G lxd ${user}`);
core.endGroup();
core.startGroup("Install tox");
await install_tox(tox_version);
Expand All @@ -283,7 +300,8 @@ async function run() {


const release = await os_release();
if (release["VERSION_CODENAME"].includes("jammy")){
let version_id = semver.coerce(release["VERSION_ID"], {loose: true});
if (version_id && version_id.compare('22.4.0') >= 0) {
await docker_lxd_clash();
}

Expand All @@ -308,7 +326,7 @@ async function run() {
}
core.endGroup();
core.startGroup("Initialize microk8s");
await exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]);
await exec.exec(`sudo usermod -a -G ${microk8s_group} ${user}`);
if(!await microk8s_init(channel, microk8s_addons, container_registry_url)) {
return;
}
Expand Down Expand Up @@ -357,7 +375,7 @@ async function run() {
core.startGroup("Bootstrap controller");
bootstrap_command = `${bootstrap_command} --bootstrap-constraints="${bootstrap_constraints}"`
if (group !== "") {
await exec.exec('sg', [group, '-c', bootstrap_command]);
await exec.exec(`sudo -g ${group} -E ${bootstrap_command}`);
} else {
await exec.exec(bootstrap_command);
}
Expand Down
1 change: 1 addition & 0 deletions tests/constraints-2.9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cython<3
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ passenv = HOME
setenv =
PYTHONPATH={toxinidir}/src:{toxinidir}/lib
deps =
macaroonbakery!=1.3.3
pytest
pytest-operator
commands = pytest -v --tb native --show-capture=no --log-cli-level=INFO -s {posargs} {toxinidir}/tests/


[testenv:2.9-tests]
setenv =
PIP_CONSTRAINT={toxinidir}/tests/constraints-2.9.txt
deps =
juju<3.1
{[testenv]deps}
Expand Down
Loading