Skip to content

Commit

Permalink
fix: restore binary replacement in cri-dockerd.service file
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Dec 23, 2022
1 parent 00480f2 commit 17fbbaa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
80 changes: 53 additions & 27 deletions src/__tests__/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,33 +177,59 @@ describe('download module test suite', () => {
'sudo ln -sf /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd'
);
});
test('should install cri-dockerd service', async () => {
// Given
fs.readFileSync.mockImplementation(
() =>
'ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://'
);
// When
await download.installCriDockerd({githubToken: 'secret-token'});
// Then
expect(fs.writeFileSync).toHaveBeenCalledWith(
'/etc/systemd/system/cri-docker.service',
'ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --container-runtime-endpoint fd://'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
expect.stringMatching(
/sudo cp -a .+\/packaging\/systemd\/\* \/etc\/systemd\/system/
)
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl daemon-reload'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl enable cri-docker.service'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl enable --now cri-docker.socket'
);
describe('should install cri-dockerd service', () => {
test('should copy systemd service files', async () => {
// When
await download.installCriDockerd();
// Then
expect(exec.logExecSync).toHaveBeenCalledWith(
expect.stringMatching(
/sudo cp -a .+\/packaging\/systemd\/\* \/etc\/systemd\/system/
)
);
});
test('should add --network-plugin=cni to systemd service file', async () => {
// Given
fs.readFileSync.mockImplementation(
() =>
'ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://'
);
// When
await download.installCriDockerd();
// Then
expect(fs.writeFileSync).toHaveBeenCalledWith(
'/etc/systemd/system/cri-docker.service',
'ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --container-runtime-endpoint fd://'
);
});
test('should replace binary location in systemd service file', async () => {
// Given
fs.readFileSync.mockImplementation(
() =>
'ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://'
);
// When
await download.installCriDockerd();
// Then
expect(fs.writeFileSync).toHaveBeenCalledWith(
'/etc/systemd/system/cri-docker.service',
'ExecStart=/usr/local/bin/cri-dockerd --container-runtime-endpoint fd://'
);
});
test('should enable and start service', async () => {
// When
await download.installCriDockerd();
// Then
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl daemon-reload'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl enable cri-docker.service'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo systemctl enable --now cri-docker.socket'
);
});
});
});
});
4 changes: 4 additions & 0 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const installCriDockerd = async (inputs = {}) => {
fs.writeFileSync(serviceFile, fs.readFileSync(serviceFile).toString()
.replace(/cri-dockerd --/g, 'cri-dockerd --network-plugin=cni --')
);
// There's a soft link and shouldn't be needed
fs.writeFileSync(serviceFile, fs.readFileSync(serviceFile).toString()
.replace(/\/usr\/bin\/cri-dockerd/g, '/usr/local/bin/cri-dockerd')
);
const socketFile = '/etc/systemd/system/cri-docker.socket';
fs.writeFileSync(socketFile, fs.readFileSync(socketFile).toString()
.replace(/cri-docker.sock/g, 'cri-dockerd.sock')
Expand Down

0 comments on commit 17fbbaa

Please sign in to comment.