Skip to content

Commit

Permalink
changed nodeAffinity for preview-environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulf Thimm authored and Wulf Thimm committed Aug 31, 2021
1 parent 8aab84e commit 7258c68
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 54 deletions.
16 changes: 15 additions & 1 deletion .werft/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as semver from 'semver';
import * as util from 'util';
import { sleep } from './util/util';
import * as gpctl from './util/gpctl';
import { createHash } from "crypto";

const readDir = util.promisify(fs.readdir)

Expand Down Expand Up @@ -396,6 +397,12 @@ export async function deployToDev(deploymentConfig: DeploymentConfig, workspaceF
let flags = commonFlags
flags += ` --set components.wsDaemon.servicePort=${wsdaemonPortMeta}`;
flags += ` --set components.registryFacade.ports.registry.servicePort=${registryNodePortMeta}`;

const nodeAffinityValues = [
"values.nodeAffinities_0.yaml",
"values.nodeAffinities_1.yaml"
]

if (k3sWsCluster) {
// we do not need meta cluster ws components when k3s ws is enabled
// TODO: Add flags to disable ws component in the meta cluster
Expand All @@ -406,8 +413,15 @@ export async function deployToDev(deploymentConfig: DeploymentConfig, workspaceF
flags += ` -f ../.werft/values.dev.gcp-storage.yaml`;
}

/* A hash is caclulated from the branch name and a subset of that string is parsed to a number x,
x mod the number of different nodepool-sets defined in the files listed in nodeAffinityValues
is used to generate a pseudo-random number that consistent as long as the branchname persists.
We use it to reduce the number of preview-environments accumulating on a singe nodepool.
*/
const nodepoolIndex = parseInt(createHash('sha256').update(namespace).digest('hex').substring(0,5),16) % nodeAffinityValues.length;

exec(`helm dependencies up`);
exec(`/usr/local/bin/helm3 upgrade --install --timeout 10m -f ../.werft/values.dev.yaml ${flags} ${helmInstallName} .`);
exec(`/usr/local/bin/helm3 upgrade --install --timeout 10m -f ../.werft/${nodeAffinityValues[nodepoolIndex]} -f ../.werft/values.dev.yaml ${flags} ${helmInstallName} .`);
exec(`kubectl apply -f ../.werft/jaeger.yaml`);

werft.log('helm', 'installing Sweeper');
Expand Down
8 changes: 3 additions & 5 deletions .werft/jaeger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ spec:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: dev/workload
operator: In
values:
- workload
- matchExpressions:
- key: workload/meta
operator: Exists
strategy: allInOne
storage:
options:
Expand Down
40 changes: 1 addition & 39 deletions .werft/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ certificatesSecret:
secretName: proxy-config-certificates
version: not-set
imagePullPolicy: Always
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workload_meta
operator: In
values:
- "true"

authProviders: []
tracing:
endoint: http://jaeger-collector:14268/api/traces
Expand Down Expand Up @@ -78,8 +70,6 @@ components:
# configure GCP registry
pullSecret:
secretName: gcp-sa-registry-auth
affinity:
default: "gitpod.io/workload_workspace"
templates:
default:
spec:
Expand Down Expand Up @@ -217,16 +207,6 @@ minio:
serviceAccount:
name: ws-daemon
create: false
# make sure the pod ends up where it's supposed to stay
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: dev/workload
operator: In
values:
- "workload"
resources:
requests:
# in preview envs, we want deployments to push scale-up early
Expand All @@ -235,15 +215,6 @@ minio:
mysql:
primary:
# make sure the pod ends up where it's supposed to stay
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: dev/workload
operator: In
values:
- "workload"
resources:
requests:
# in preview envs, we want deployments to push scale-up early
Expand All @@ -258,15 +229,6 @@ rabbitmq:
username: override-me
password: override-me
# make sure the pod ends up where it's supposed to stay
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: dev/workload
operator: In
values:
- "workload"
resources:
requests:
# in preview envs, we want deployments to push scale-up early
Expand Down
9 changes: 0 additions & 9 deletions .werft/values.k3sWsCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ certificatesSecret:
secretName: proxy-config-certificates
version: not-set
imagePullPolicy: Always
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workload_services
operator: In
values:
- "true"
authProviders: []
tracing:
endoint: http://jaeger-collector:14268/api/traces
Expand Down
62 changes: 62 additions & 0 deletions .werft/values.nodeAffinities_0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

components:

wsDaemon:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workspace_0
operator: Exists

registryFacade:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workspace_0
operator: Exists


workspace:
affinity:
default: gitpod.io/workspace_0

# Sub-Charts

rabbitmq:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

mysql:
primary:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

minio:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists
62 changes: 62 additions & 0 deletions .werft/values.nodeAffinities_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

components:

wsDaemon:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workspace_1
operator: Exists

registryFacade:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gitpod.io/workspace_1
operator: Exists


workspace:
affinity:
default: gitpod.io/workspace_1

# Sub-Charts

rabbitmq:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

mysql:
primary:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

minio:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: workload/meta
operator: Exists

0 comments on commit 7258c68

Please sign in to comment.