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

StatefulSet is sensitive to long names - use a hashed name #2768

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

jlpettersson
Copy link
Member

@jlpettersson jlpettersson commented Jun 6, 2020

Changes

Names in Kubernetes can be up to 253 chars, but labels can only be up to 63 chars.

We are relatively conservative with the two labels we introduce for the Affinity Assistant

app.kubernetes.io/component: affinity-assistant
app.kubernetes.io/instance: ws-parallel-pipelinerun-bbx6w

But apparently, StatefulSets adds a label with the full StatefulSet Name + 10 chars (for a hash) as a label

controller-revision-hash: affinity-assistant-ws-parallel-pipelinerun-bbx6w-dd64c6c8d

This only leave users to use StatefulSet Names up to 53 chars. We use a prefix of 19 chars (affinity-assistant-) on the Affinity Assistant StatefulSet. This leaves Tekton users with only 34 chars for a combination of Workspace Name and the PipelineRun Name.

This commit use a hash of the Workspace Name and the PipelineRun Name to make sure that the name is not too long.
Typical labels after this commit will be:

labels:
  app.kubernetes.io/component: affinity-assistant
  app.kubernetes.io/instance: affinity-assistant-e067465fc0
  controller-revision-hash: affinity-assistant-e067465fc0-b78cb9478
  statefulset.kubernetes.io/pod-name: affinity-assistant-e067465fc0-0
  tekton.dev/pipeline: parallel-pipeline
  tekton.dev/pipelineRun: parallel-pipelinerun-wr9wd

Also the unnecessary name of the PVC in the volumeClaimTemplate-example is removed.

This limitation of StatefulSet is apparently a known problem kubernetes/kubernetes#64023 but I was not aware of it.

/kind bug
Fixes #2766
Fixes #2769
Fixes #2796

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

- There was a problem with long names for WorkspaceName+PipelineRunName, it could only be up to 33 chars. This commit uses a hashed name for the Affinity Assistant with a consistent length. 

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 6, 2020
@tekton-robot tekton-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 6, 2020
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thanks!
/approve

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thanks!
/approve

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2020
@afrittoli afrittoli added the needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch label Jun 6, 2020
@cameronbraid
Copy link

Why not just hash the Workspace Name and the PipelineRun Name so that the length doesn't matter

@jlpettersson
Copy link
Member Author

Why not just hash the Workspace Name and the PipelineRun Name so that the length doesn't matter

Yes, that is also a way to handle it. Hash both names and use a substring of 53 chars. But it is harder to se from where the pod come from - but it is visible in the other labels.

@cameronbraid
Copy link

cameronbraid commented Jun 6, 2020 via email

@jlpettersson
Copy link
Member Author

Yes, we could also keep the prefix and use a 34 chars substring of the hash of workspace+pipelinerun.

E.g. affinity-assistant-bbx6wdd64c6c8dbbx6wdd64c6c8dbbx6wd

That would make it easier to understand when doing kubectl get pods

Would that be a good alternative?
/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 6, 2020
@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 6, 2020
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 91.8% 92.0% 0.2

@jlpettersson jlpettersson changed the title StatefulSet is sensitive to long names - remove prefix StatefulSet is sensitive to long names - use a hashed name Jun 6, 2020
@jlpettersson
Copy link
Member Author

The implementation is now changed to use a hashed name, so that the length of the StatefulSet Name is consistent.

A typical name of the Affinity Assistant will now be:

affinity-assistant-e067465fc0

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 6, 2020
@cameronbraid
Copy link

Cool

One question about the use of a stateful set, why isn't this 'affinity-assistant' just implemented via a single Pod ?

@jlpettersson
Copy link
Member Author

One question about the use of a stateful set, why isn't this 'affinity-assistant' just implemented via a single Pod ?

@cameronbraid I wrote a motivation about why I use StatefulSet in the PR description (a bit down) #2630

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 91.8% 92.0% 0.2

@ghost
Copy link

ghost commented Jun 8, 2020

/lgtm

Thanks for the quick fix!

@tekton-robot tekton-robot assigned ghost Jun 8, 2020
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 8, 2020
@pritidesai
Copy link
Member

Appeared in the integration test logs 😿:

default            1s          Warning   FailedCreate              statefulset/affinity-assistant-shared-workspace-write-and-cleanup-workspace   create Pod affinity-assistant-shared-workspace-write-and-cleanup-workspace-0 in StatefulSet affinity-assistant-shared-workspace-write-and-cleanup-workspace failed error: Pod "affinity-assistant-shared-workspace-write-and-cleanup-workspace-0" is invalid: [metadata.labels: Invalid value: "affinity-assistant-shared-workspace-write-and-cleanup-workspace-55458fdf66": must be no more than 63 characters, metadata.labels: Invalid value: "affinity-assistant-shared-workspace-write-and-cleanup-workspace-0": must be no more than 63 characters, spec.hostname: Invalid value: "affinity-assistant-shared-workspace-write-and-cleanup-workspace-0": must be no more than 63 characters]

@jlpettersson
Copy link
Member Author

jlpettersson commented Jun 9, 2020

@pritidesai from what logs?

The latest is pull-tekton-pipeline-integration-tests

@pritidesai
Copy link
Member

@pritidesai from what logs?

The latest is pull-tekton-pipeline-integration-tests

One of the PRs 😉 #2661, tests

Screen Shot 2020-06-09 at 1 04 22 PM

@bobcatfish
Copy link
Collaborator

Thanks for the excellent commit message @jlpettersson !!!!!

func getAffinityAssistantName(pipelineWorkspaceName string, pipelineRunName string) string {
hashBytes := sha256.Sum256([]byte(pipelineWorkspaceName + pipelineRunName))
hashString := fmt.Sprintf("%x", hashBytes)
return fmt.Sprintf("%s-%s", "affinity-assistant", hashString[:10])
Copy link
Collaborator

Choose a reason for hiding this comment

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

we actually have some existing libs around this that you might be able to use: https://github.com/tektoncd/pipeline/blob/master/pkg/names/generate.go

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I had a look at it, but it is "random"

random suffix

I my use case, I want a consistent hash - from the Workspace Name + PipelineRun Name - so that the same combination always get the same hash.

@bobcatfish
Copy link
Collaborator

@jlpettersson it looks like once the conflicts are resolved this is good to go - don't worry too much about the conflicts, I'm happy to work around them when cherry picking this commit in tomorrow (tho I really appreciate you making it easier to cherry pick!!)

Names in Kubernetes can be up to 253 chars, but labels can only be up to 63 chars.

We are relatively conservative with the two labels we introduce for the Affinity Assistant

    app.kubernetes.io/component: affinity-assistant
    app.kubernetes.io/instance: ws-parallel-pipelinerun-bbx6w

But apparently, StatefulSets adds a label with the full StatefulSet Name + 10 chars (for a hash) as a label

    controller-revision-hash: affinity-assistant-ws-parallel-pipelinerun-bbx6w-dd64c6c8d

This only leave users to use StatefulSet Names up to 53 chars. We use a prefix of 19 chars (affinity-assistant-)
on the Affinity Assistant StatefulSet. This leaves Tekton users with only 34 chars for a combination of
Workspace Name and the PipelineRun Name.

This commit use a hash of the Workspace Name and the PipelineRun Name to make sure that the name is not too long.
Typical labels after this commit will be:

    labels:
      app.kubernetes.io/component: affinity-assistant
      app.kubernetes.io/instance: affinity-assistant-e067465fc0
      controller-revision-hash: affinity-assistant-e067465fc0-b78cb9478
      statefulset.kubernetes.io/pod-name: affinity-assistant-e067465fc0-0
      tekton.dev/pipeline: parallel-pipeline
      tekton.dev/pipelineRun: parallel-pipelinerun-wr9wd

Also the unnecessary name of the PVC in the volumeClaimTemplate-example is removed.

This limitation of StatefulSet is apparently a known problem kubernetes/kubernetes#64023 but I was not aware of it.

/kind bug
Fixes tektoncd#2766
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 10, 2020
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 91.7% 91.8% 0.2

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 10, 2020
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrittoli, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [afrittoli,vdemeester]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot merged commit 7e74e96 into tektoncd:master Jun 10, 2020
@vdemeester vdemeester removed the needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch label Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
7 participants