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

Adds a sidecar Dockerfile and startup script. #22

Merged
merged 1 commit into from Jan 26, 2018
Merged

Adds a sidecar Dockerfile and startup script. #22

merged 1 commit into from Jan 26, 2018

Conversation

jvolkman
Copy link
Contributor

When run as a sidecar container, the following env vars are used:

AGENT_CONFIG_FILE - Required. The path to a file containing the agent's
configuration.

AGENT_STATE_DIR - Optional. The path under which the agent stores state.
If this parameter is not specified, no state will be stored.

AGENT_LOCAL_PORT - Optional. The pod-local port on which the agent's
HTTP API will listen for reports and provide status. If this parameter
is not specified, the agent will not start its HTTP server.

The configuration file is run through envsubst, so it can contain
any additional parameters as well. For example, a service account
key and a servicecontrol consumerId may be stored in a Kubernetes
secret and passed in as environment variables.


COPY --from=build /ubbagent-src/bin/ubbagent /usr/local/bin/ubbagent
COPY docker/ubbagent-start /usr/local/bin/ubbagent-start
CMD ["/usr/local/bin/ubbagent-start"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ubbagent-start sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this form (CMD ["..."]), no shell is required to execute the command. So the full path is needed.

Could change to CMD ubbagent-start, but I'm not sure that there's any benefit in doing so.

Dockerfile Outdated
@@ -0,0 +1,32 @@
# Copyright 2018 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google LLC now :) No need to update existing files I think, but for new files, we should use LLC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks for the heads up.


set -e

if [ -z "$AGENT_CONFIG_FILE" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: you can do [ -v AGENT_CONFIG_FILE ] file instead. This works with -u enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip. I think I'll leave it as -z to catch cases in which the variable is set but is actually an empty string.

fi

cat "$AGENT_CONFIG_FILE" | envsubst > /tmp/ubbagent-envsubst.yaml
exec ubbagent --config /tmp/ubbagent-envsubst.yaml $STATE $HTTP --logtostderr --v=2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"$STATE" "$HTTP"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works since $STATE and $HTTP can expand into multiple parameters?

Example: sh -c 'x="-n foo"; echo $x' outputs "foo" with no newline, whereas sh -c 'x="-n foo"; echo "$x"' actually outputs "-n foo".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use '=' between the parameter and argument, so that the entire arg is a single string. They're now quoted in the final command line.

@huyhg
Copy link
Contributor

huyhg commented Jan 23, 2018

I also wonder if we can add a README file somewhere to capture the env variables.

@jvolkman
Copy link
Contributor Author

Added text to README.md as well.

@jvolkman jvolkman changed the base branch from mockrefactor to flexible January 26, 2018 17:26
@jvolkman jvolkman changed the base branch from flexible to mockrefactor January 26, 2018 17:29
When run as a sidecar container, the following env vars are used:

AGENT_CONFIG_FILE - Required. The path to a file containing the agent's
configuration.

AGENT_STATE_DIR - Optional. The path under which the agent stores state.
If this parameter is not specified, no state will be stored.

AGENT_LOCAL_PORT - Optional. The pod-local port on which the agent's
HTTP API will listen for reports and provide status. If this parameter
is not specified, the agent will not start its HTTP server.

The configuration file is run through envsubst, so it can contain
any additional parameters as well. For example, a service account
key and a servicecontrol consumerId may be stored in a Kubernetes
secret and passed in as environment variables.
@jvolkman jvolkman changed the base branch from mockrefactor to flexible January 26, 2018 17:33
@jvolkman jvolkman merged commit 975a160 into flexible Jan 26, 2018
@jvolkman jvolkman deleted the docker branch January 26, 2018 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants