Skip to content

Commit

Permalink
fix: istio-connection
Browse files Browse the repository at this point in the history
- wait for istio-proxy container to be ready before starting producer
  container
- stop istio-proxy container after producer completes execution
  • Loading branch information
karanwadhwa authored and sydrawat01 committed Dec 8, 2023
1 parent 7a4b43e commit 80ad843
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
FROM node:lts-alpine

WORKDIR /

COPY package*.json ./

RUN apk --no-cache add curl

RUN npm install

COPY . .

ENTRYPOINT ["node", "index.js"]
# ENTRYPOINT ["node", "index.js"]
CMD [ "/bin/sh", "-c", "until curl --head localhost:15000 ; do echo Waiting for Sidecar; sleep 3 ; done ; echo Sidecar available; node index.js"]
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ const kafka = new Kafka({
brokers,
})

const quitIstioProxy = async () => {
fetch('http://localhost:15000/quitquitquit', {
method: 'POST',
})
.then((res) => {
logger.info('Sent quit message to istio-proxy', { res })
})
.catch((err) => {
logger.error('Could not send quit request to istio-proxy', { err })
})
}

const init = async () => {
try {
// https://kafka.js.org/docs/producing#default-partitioners
Expand Down Expand Up @@ -54,10 +66,12 @@ const init = async () => {
})
.catch((err) => logger.error(`Message not sent`, { err }))
.finally(async () => {
quitIstioProxy()
await producer.disconnect() // performs clean exit
})
} catch (error) {
logger.error(`Kafka producer error`, { error })
quitIstioProxy()
process.exit(1)
}
}
Expand Down

0 comments on commit 80ad843

Please sign in to comment.