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

Pre-install hook for helm #176

Merged
merged 10 commits into from
Sep 6, 2019
4 changes: 2 additions & 2 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -
sudo helm dependency update
cd ../../../

with_files=`ls deploy/helm/sumologic/templates/*.yaml | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\\/g'`
eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl'
with_files=`ls deploy/helm/sumologic/templates/*.yaml | grep -v "setup-job.yaml" | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\\/g'`
eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl --set sumologic.endpoint="bogus" --set sumologic.accessId="bogus" --set sumologic.accessKey="bogus"'

if [[ $(git diff deploy/kubernetes/fluentd-sumologic.yaml.tmpl) ]]; then
echo "Detected changes in 'fluentd-sumologic.yaml.tmpl', committing the updated version to $TRAVIS_BRANCH..."
Expand Down
11 changes: 10 additions & 1 deletion deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ USER root
# Run dependencies
RUN runDeps="sudo libsnappy-dev" \
&& apt-get update \
&& apt-get install -y --no-install-recommends $runDeps
&& apt-get install -y --no-install-recommends $runDeps \
&& apt-get install -y gnupg \
&& apt-get install -y curl \
&& apt-get install -y jq \
&& apt-get install -y wget

# Install kubectl
ADD https://storage.googleapis.com/kubernetes-release/release/v1.6.12/bin/linux/amd64/kubectl /usr/local/bin/kubectl
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this version too low?

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 1.15.0 according to their doc page

RUN chmod +x /usr/local/bin/kubectl
COPY setup/setup.sh /usr/bin/

COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY ./fluent.conf /fluentd/etc/
Expand Down
11 changes: 11 additions & 0 deletions deploy/docker/setup/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:3.9

RUN apk add --no-cache gnupg
RUN apk add --no-cache curl
RUN apk add --no-cache jq

# Install kubectl
ADD https://storage.googleapis.com/kubernetes-release/release/v1.6.12/bin/linux/amd64/kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl
maimaisie marked this conversation as resolved.
Show resolved Hide resolved

COPY setup.sh /usr/bin/
File renamed without changes.
32 changes: 32 additions & 0 deletions deploy/helm/sumologic/templates/setup-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.sumologic.setupEnabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "sumologic.fullname" . }}-init
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels:
app: {{ template "sumologic.labels.app" . }}
{{ template "sumologic.labels.common" . }}
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: setup
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/usr/bin/setup.sh",
"-n", "{{ .Release.Namespace }}",
"-k", "{{ .Values.sumologic.clusterName }}",
{{- if .Values.sumologic.collectorName }}
"-c", "{{ .Values.sumologic.collectorName }}",
{{- end }}
"-d", "false",
"-y", "false",
'{{ required "A valid .Values.sumologic.endpoint entry required!" .Values.sumologic.endpoint }}',
Copy link
Contributor

Choose a reason for hiding this comment

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

What are your thoughts on instead of using the full URL, we let the customer specify the deployment name (e.g. US2)? We then do a conditional block rendering the right URL based on what they selected and can fail if they make an invalid choice. This makes it easier for people, other various open-source Sumo projects work with this way. We have to occasionally update that as we add new deployments, but that seems minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be more maintenance work and I think we generally try to avoid it because it's easily forgotten. What are your thoughts on this @lei-sumo @samjsong @rvmiller89 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with documenting it in our steps for now.

'{{ required "A valid .Values.sumologic.accessId entry required!" .Values.sumologic.accessId }}',
'{{ required "A valid .Values.sumologic.accessKey entry required!" .Values.sumologic.accessKey }}']
{{- end }}
20 changes: 20 additions & 0 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ eventsDeployment:
cpu: "100m"

sumologic:
## Setup

# If enabled, a pre-install hook will create Collector and Sources in Sumo Logic
setupEnabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make the default false since we comment out the values below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are commenting out access id, key and endpoint because they are required values with no defaults. When we reference them here , we use the required function so that if user does not override this value on helm install it will error out. For example:

$ helm install maisie-charts/sumologic --name collection --namespace sumologic --no-crd-hook
Error: render error in "sumologic/templates/setup-job.yaml": template: sumologic/templates/setup-job.yaml:28:14: executing "sumologic/templates/setup-job.yaml" at <required "A valid .Values.sumologic.endpoint entry required!" .Values.sumologic.endpoint>: error calling required: A valid .Values.sumologic.endpoint entry required!

The collector name is commented out because the script has the default value, so we don't need to specify it again here


# Sumo access ID
#accessId: ""

# Sumo access key
#accesskey: ""

# Sumo API endpoint
#endpoint: ""

# Collector name
#collectorName: ""

# Cluster name
clusterName: "kubernetes"


## Format to post logs into Sumo. json, json_merge, or text
logFormat: fields
Expand Down