Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(examples): add labels and antiAffinity to k8s example #5763

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

Merged
merged 4 commits into from
Jan 18, 2023

Conversation

coadler
Copy link
Contributor

@coadler coadler commented Jan 17, 2023

No description provided.

@coadler coadler requested a review from deansheather January 17, 2023 23:43
@coadler coadler self-assigned this Jan 17, 2023
Comment on lines +110 to +112
"app.kubernetes.io/name" = "coder-workspace"
"app.kubernetes.io/instance" = "coder-workspace-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
"app.kubernetes.io/part-of" = "coder"
Copy link
Member

Choose a reason for hiding this comment

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

Should add some more labels similar to what we do in v1 for workspace details. Should add these to the PVC too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the labels I could from v1

$ kdpo coder-colin-gea
Name:             coder-colin-gea
Namespace:        colin-coder
Priority:         0
Service Account:  default
Node:             gke-dev-4-2-coder-node-pool-8b0aaa9c-wfg6/10.1.0.102
Start Time:       Wed, 18 Jan 2023 10:49:01 -0600
Labels:           app.kubernetes.io/instance=coder-workspace-colin-gea
                  app.kubernetes.io/name=coder-workspace
                  app.kubernetes.io/part-of=coder
                  com.coder.resource=true
                  com.coder.user=b851db54-9827-45bc-b453-72138b46f99c
                  com.coder.username=colin
                  com.coder.workspace.id=8118ca50-2edc-4b7c-8b70-61b3c7c3673d
                  com.coder.workspace.name=gea
$ kd pvc coder-colin-gea-home
Name:          coder-colin-gea-home
Namespace:     colin-coder
StorageClass:  standard
Status:        Bound
Volume:        pvc-d6612185-b553-459a-9c85-acce9bf33cc2
Labels:        app.kubernetes.io/instance=coder-pvc-colin-gea
               app.kubernetes.io/name=coder-pvc
               app.kubernetes.io/part-of=coder
               com.coder.resource=true
               com.coder.workspace.id=8118ca50-2edc-4b7c-8b70-61b3c7c3673d
               com.coder.workspace.name=gea

Comment on lines 146 to 161
affinity {
pod_anti_affinity {
preferred_during_scheduling_ignored_during_execution {
weight = 1
pod_affinity_term {
topology_key = "kubernetes.io/hostname"
label_selector {
match_expressions {
key = "app.kubernetes.io/name"
operator = "In"
values = ["coder-workspace"]
}
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused, because wouldn't this fail for the defaults on most Kubernetes cluster that don't have the hostname of coder-workspace?

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's matching pods that have app.kubernetes.io/name: coder-workspace, summing the amount partitioned by hostname. Our helm chart has something similar

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, I see. So even if you didn't deploy Coder with Kubernetes, this would still work? We should add a comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of the spec, so I imagine any k8s-like apis would also implement this. I found some references to it in the openshift docs: https://docs.openshift.com/container-platform/4.8/nodes/scheduling/nodes-scheduler-node-selectors.html#nodes-scheduler-node-selectors-about_nodes-scheduler-node-selectors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I think I understand your question. This doesn't have anything to do with how Coder itself is deployed.

@coadler coadler enabled auto-merge (squash) January 18, 2023 16:55
"com.coder.workspace.id" = data.coder_workspace.me.id
"com.coder.workspace.name" = data.coder_workspace.me.name
"com.coder.user.id" = data.coder_workspace.me.owner_id
"com.coder.user.username" = data.coder_workspace.me.owner
Copy link
Member

Choose a reason for hiding this comment

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

email too, we provide email as owner_email

@coadler coadler merged commit 6ed4e21 into main Jan 18, 2023
@coadler coadler deleted the colin/k8s-example-anti-affinity branch January 18, 2023 17:01
@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2023
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.

3 participants