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

fix: restore binary replacement in cri-dockerd.service file #81

Merged
merged 1 commit into from
Dec 23, 2022
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
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