Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Spartakus - static container name - #168

Merged
prydonius merged 4 commits into
helm:masterfrom
mgoodness:spartakus
Nov 2, 2016
Merged

prydonius merged 4 commits into
helm:masterfrom
mgoodness:spartakus

Conversation

@mgoodness

Copy link
Copy Markdown
Contributor

My company aggregates container logs by container name, with each stream named after the pod itself. Naming both the pod & the container dynamically based on the release name breaks that pattern between different deployments.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Can a kubernetes member verify that this patch is reasonable to test? If so, please reply with "@k8s-bot ok to test" on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands will still work. Regular contributors should join the org to skip this step.

If you have questions or suggestions related to this bot's behavior, please file an issue against the kubernetes/test-infra repository.

@chrislovecnm

Copy link
Copy Markdown
Contributor

@k8s-bot ok to test

@chrislovecnm chrislovecnm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chrislovecnm

Copy link
Copy Markdown
Contributor

Let me take that back ;) can we make that the default, or when defined is the name??

@chrislovecnm chrislovecnm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we get spartakus, or the template name?

@mgoodness

Copy link
Copy Markdown
Contributor Author

I've created a containerName variable that, if set, will be used as the container's name in the pod. Otherwise, the existing {{ template fullname . }} behavior will be used. @chrislovecnm, I think that's what you requested.

However, I don't really like this default. As I explained in the PR, there is value in having consistent container names between deployments, and I think that should be the out-of-the box behavior. I'm going to propose it as a best practice. Does templating the container name yield any particular benefit?

@viglesiasce

Copy link
Copy Markdown
Contributor

I prefer consistent container names. It helps in live as well as after-the-fact debugging.

@prydonius

Copy link
Copy Markdown
Member

I'm going to propose it as a best practice.

+1, I thinks this makes sense

containers:
- name: {{ template "fullname" . }}
image: "{{ .Values.image }}"
- name: {{ if .Values.containerName }}"{{ .Values.containerName }}"{{ else }}{{ template "fullname" . }}{{ end }}

@sameersbn sameersbn Nov 2, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: add a helper function in templates/_helpers.tpl

@mgoodness

mgoodness commented Nov 2, 2016 •

Copy link
Copy Markdown
Contributor Author

Based on feedback, I've reverted to a static container name (default spartakus) that can be overridden by .Values.containerName. I believe this is the best approach.

Of course, now I'm wondering if the app label shouldn't default to the chart name. Right now the pattern seems to be using the fullname (chart name + release name) template. Here's what I envision instead:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: {{ template "name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
  name: {{ template "fullname" . }}
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ template "name" . }}
        release: "{{ .Release.Name }}"
    spec:
      containers:
        - name: {{ template "name" . }}
          image: "{{ .Values.image }}"
          imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
          args:
            - volunteer
            - --cluster-id={{ uuidv4 | default .Values.uuid | quote }}
          resources:
{{ toYaml .Values.resources | indent 12 }}

This way, resources are still named using fullname, but get both the app=spartakus and release=goofy-gus labels. Future deployments will only affect resources with both tags. However, if a user were to deploy multiple releases of the chart, he/she could view all of the resources with kubectl get dep,po -l app=spartakus. That's not possible using the current app=goofy-gus-spartakus pattern.

containers:
- name: {{ template "fullname" . }}
image: "{{ .Values.image }}"
- name: {{ default "spartakus" .Values.containerName | quote }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could use .Chart.Name? or {{ template "name" . }} which already uses .Values.nameOverride for overriding.

@prydonius

Copy link
Copy Markdown
Member

@mgoodness this is really great feedback. Given that all charts are currently using the current app=goofy-gus-<name> pattern, can you bring it up for discussion in the best practices or a separate issue?

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Jenkins Charts e2e failed for commit 862f5c8. Full PR test history.

The magic incantation to run this job again is @k8s-bot e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@prydonius

Copy link
Copy Markdown
Member

@k8s-bot e2e test this

@prydonius

Copy link
Copy Markdown
Member

thanks @mgoodness, all looks good to me. Ok to merge?

@mgoodness

Copy link
Copy Markdown
Contributor Author

@prydonius please do! I'll take my bigger ideas over to the best-practices issue

@prydonius

Copy link
Copy Markdown
Member

Thanks a lot @mgoodness!

@prydonius
prydonius merged commit 5c096f5 into helm:master Nov 2, 2016
@mgoodness
mgoodness deleted the spartakus branch November 2, 2016 19:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants