Skip to content

Commit

Permalink
feat: install cni-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Apr 6, 2023
1 parent b6eb4a8 commit 802357e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/__tests__/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@ describe('download module test suite', () => {
});
});

describe('installCniPlugins', () => {
beforeEach(() => {
axios.mockImplementationOnce(async () => ({
data: {
assets: [
{
name: 'cni-plugins-linux-amd64-v1.2.0.tgz.sha1',
browser_download_url: 'http://invalid'
},
{
name: 'cni-plugins-linux-amd64-v1.2.0.tgz',
browser_download_url: 'http://valid'
},
{
name: 'cni-plugins-linux-amd64-v1.2.0.tgz.sha512',
browser_download_url: 'http://invalid'
},
{
name: 'cni-plugins-windows-amd64-v1.2.0.tgz',
browser_download_url: 'http://invalid'
}
]
}
}));
});
test('with token, should download valid Linux version', async () => {
// Given
tc.downloadTool.mockImplementationOnce(async () => 'file.tar.gz');
// When
await download.installCniPlugins({githubToken: 'secret-token'});
// Then
expect(axios).toHaveBeenCalledWith(
expect.objectContaining({
url: 'https://api.github.com/repos/containernetworking/plugins/releases/tags/v1.2.0',
headers: {Authorization: 'token secret-token'}
})
);
expect(tc.downloadTool).toHaveBeenCalledWith('http://valid');
expect(tc.extractTar).toHaveBeenCalledWith('file.tar.gz', '/opt/cni/bin');
});
});

describe('installCriCtl', () => {
beforeEach(() => {
axios.mockImplementationOnce(async () => ({
Expand Down
21 changes: 19 additions & 2 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {logExecSync} = require('./exec');

const isLinux = name => name.indexOf('linux') >= 0;
const isAmd64 = name => name.indexOf('amd64') >= 0;
const isSignature = name => name.indexOf('sha256') >= 0;
const isSignature = name => name.indexOf('sha1') >= 0 || name.indexOf('sha256') >= 0 || name.indexOf('sha512') >= 0;
const isWindows = name => name.indexOf('.win.') >= 0;
const isMac = name => name.indexOf('.darwin.') >= 0;
const isTgz = name => name.endsWith('.tgz');
Expand Down Expand Up @@ -43,6 +43,23 @@ const downloadMinikube = async (inputs = {}) => {
});
};

// Required by cri-dockerd and recent Minikube releases
// https://github.com/Mirantis/cri-dockerd/commit/e2666520e25cb302b9b1d231a63699c2338b8567
// https://github.com/kubernetes/minikube/commit/fd549f396dbd39385baefe88dcead0ccf99f1bff
const installCniPlugins = async (inputs = {}) => {
core.info(`Downloading CNI plugins`);
const tag = 'v1.2.0';
const tar = await downloadGitHubArtifact({
inputs,
releaseUrl: `https://api.github.com/repos/containernetworking/plugins/releases/tags/${tag}`,
assetPredicate: asset =>
isLinux(asset.name) && isAmd64(asset.name) && !isSignature(asset.name) && asset.name.indexOf('cni-plugins') === 0
});
const cniBinDirPath = '/opt/cni/bin';
logExecSync(`sudo mkdir -p ${cniBinDirPath}`);
await tc.extractTar(tar, cniBinDirPath);
};

const installCriCtl = async (inputs = {}) => {
core.info(`Downloading cri-ctl`);
const tag = 'v1.25.0';
Expand Down Expand Up @@ -96,4 +113,4 @@ const installCriDockerd = async (inputs = {}) => {
logExecSync('sudo systemctl enable --now cri-docker.socket');
};

module.exports = {downloadMinikube, installCriCtl, installCriDockerd};
module.exports = {downloadMinikube, installCniPlugins, installCriCtl, installCriDockerd};

0 comments on commit 802357e

Please sign in to comment.