Skip to content

Commit

Permalink
minor fixes, back to spawn, additional packages
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
  • Loading branch information
travisghansen committed Jul 22, 2023
1 parent 809ab5d commit a227436
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 68 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.4.5

Released 2023-07-22

- use `spawn` again for `ip` commands
- additional packages installed in container image

# v0.4.4

Released 2023-07-21
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN echo "I am running on final $BUILDPLATFORM, building for $TARGETPLATFORM"

RUN apt-get update && \
cd ~ && \
apt-get install -y iproute2 xz-utils conntrack ipset iptables wget curl jq && \
apt-get install -y iproute2 xz-utils conntrack ipset iptables wget curl jq less ipvsadm && \
wget -c https://xyne.dev/projects/idemptables/src/idemptables-2012.tar.xz -O - | tar -Jxv && \
install -o root -g root -m 0755 idemptables-2012/idemptables /usr/sbin/idemptables && \
rm -rf idemptables-2012/ && \
Expand Down
2 changes: 1 addition & 1 deletion agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ async function reconcile() {
}
}

logger.verbose('reconcile finished');
logger.info('reconcile finished');
if (process.env.ONESHOT == '1') {
logger.info('exiting due to ONESHOT');
process.exit(0);
Expand Down
103 changes: 37 additions & 66 deletions lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class IpCommand {

if (!options.executor) {
options.executor = {
spawn: cp.spawn,
exec: cp.exec
spawn: cp.spawn
};
}
}
Expand Down Expand Up @@ -214,72 +213,44 @@ class IpCommand {
);

return new Promise((resolve, reject) => {
const use_spawn = false;
if (use_spawn) {
const child = ip.options.executor.spawn(command, args, options);
child.stdout.on('data', function (data) {
stdout = stdout + data;
});

child.stderr.on('data', function (data) {
stderr = stderr + data;
});

child.on('close', function (code) {
const result = {
code,
stdout,
stderr,
timeout: false,
command: `${command} ${args.join(' ')}`
};

ip.options.logger.debug('ip command result:', result);
// timeout scenario
if (code === null) {
result.timeout = true;
reject(result);
}
const child = ip.options.executor.spawn(command, args, options);

child.stdout.on('data', function (data) {
stdout = stdout + data;
});

child.stderr.on('data', function (data) {
stderr = stderr + data;
});

child.on('close', function (code) {
const result = {
code,
stdout,
stderr,
timeout: false,
command: `${command} ${args.join(' ')}`
};

ip.options.logger.debug('ip command result:', result);
// timeout scenario
if (code === null) {
result.timeout = true;
reject(result);
}

try {
result.parsed = JSON.parse(result.stdout);
} catch (e) {
// move along
}
try {
result.parsed = JSON.parse(result.stdout);
} catch (e) {
// move along
}

if (code) {
reject(result);
} else {
resolve(result);
}
});
} else {
ip.options.executor.exec(
`${command} ${args.join(' ')}`,
options,
(error, stdout, stderr) => {
const result = {
stdout,
stderr,
error
};

ip.options.logger.debug('ip command result:', result);

if (error) {
reject(result);
}

try {
result.parsed = JSON.parse(result.stdout);
} catch (e) {
// move along
}

resolve(result);
}
);
}
if (code) {
reject(result);
} else {
resolve(result);
}
});
});
}
}
Expand Down

0 comments on commit a227436

Please sign in to comment.