Skip to content

Commit c2d8e87

Browse files
committed
feat: install cni-plugins
1 parent b6eb4a8 commit c2d8e87

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/__tests__/download.test.js

+45
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,51 @@ describe('download module test suite', () => {
6767
});
6868
});
6969

70+
describe('installCniPlugins', () => {
71+
beforeEach(() => {
72+
axios.mockImplementationOnce(async () => ({
73+
data: {
74+
assets: [
75+
{
76+
name: 'cni-plugins-linux-amd64-v1.2.0.tgz.sha1',
77+
browser_download_url: 'http://invalid'
78+
},
79+
{
80+
name: 'cni-plugins-linux-amd64-v1.2.0.tgz',
81+
browser_download_url: 'http://valid'
82+
},
83+
{
84+
name: 'cni-plugins-linux-amd64-v1.2.0.tgz.sha512',
85+
browser_download_url: 'http://invalid'
86+
},
87+
{
88+
name: 'cni-plugins-windows-amd64-v1.2.0.tgz',
89+
browser_download_url: 'http://invalid'
90+
}
91+
]
92+
}
93+
}));
94+
});
95+
test('with token, should download valid Linux version', async () => {
96+
// Given
97+
tc.downloadTool.mockImplementationOnce(async () => 'file.tar.gz');
98+
// When
99+
await download.installCniPlugins({githubToken: 'secret-token'});
100+
// Then
101+
expect(axios).toHaveBeenCalledWith(
102+
expect.objectContaining({
103+
url: 'https://api.github.com/repos/containernetworking/plugins/releases/tags/v1.2.0',
104+
headers: {Authorization: 'token secret-token'}
105+
})
106+
);
107+
expect(tc.downloadTool).toHaveBeenCalledWith('http://valid');
108+
expect(tc.extractTar).toHaveBeenCalledWith(
109+
'file.tar.gz',
110+
'/opt/cni/bin'
111+
);
112+
});
113+
});
114+
70115
describe('installCriCtl', () => {
71116
beforeEach(() => {
72117
axios.mockImplementationOnce(async () => ({

src/download.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {logExecSync} = require('./exec');
88

99
const isLinux = name => name.indexOf('linux') >= 0;
1010
const isAmd64 = name => name.indexOf('amd64') >= 0;
11-
const isSignature = name => name.indexOf('sha256') >= 0;
11+
const isSignature = name => name.indexOf('sha1') >= 0 || name.indexOf('sha256') >= 0 || name.indexOf('sha512') >= 0;
1212
const isWindows = name => name.indexOf('.win.') >= 0;
1313
const isMac = name => name.indexOf('.darwin.') >= 0;
1414
const isTgz = name => name.endsWith('.tgz');
@@ -43,6 +43,23 @@ const downloadMinikube = async (inputs = {}) => {
4343
});
4444
};
4545

46+
// Required by cri-dockerd and recent Minikube releases
47+
// https://github.com/Mirantis/cri-dockerd/commit/e2666520e25cb302b9b1d231a63699c2338b8567
48+
// https://github.com/kubernetes/minikube/commit/fd549f396dbd39385baefe88dcead0ccf99f1bff
49+
const installCniPlugins = async (inputs = {}) => {
50+
core.info(`Downloading CNI plugins`);
51+
const tag = 'v1.2.0';
52+
const tar = await downloadGitHubArtifact({
53+
inputs,
54+
releaseUrl: `https://api.github.com/repos/containernetworking/plugins/releases/tags/${tag}`,
55+
assetPredicate: asset =>
56+
isLinux(asset.name) && isAmd64(asset.name) && !isSignature(asset.name) && asset.name.indexOf('cni-plugins') === 0
57+
});
58+
const cniBinDirPath = '/opt/cni/bin';
59+
logExecSync(`sudo mkdir -p ${cniBinDirPath}`);
60+
await tc.extractTar(tar, cniBinDirPath);
61+
};
62+
4663
const installCriCtl = async (inputs = {}) => {
4764
core.info(`Downloading cri-ctl`);
4865
const tag = 'v1.25.0';
@@ -96,4 +113,4 @@ const installCriDockerd = async (inputs = {}) => {
96113
logExecSync('sudo systemctl enable --now cri-docker.socket');
97114
};
98115

99-
module.exports = {downloadMinikube, installCriCtl, installCriDockerd};
116+
module.exports = {downloadMinikube, installCniPlugins, installCriCtl, installCriDockerd};

0 commit comments

Comments
 (0)