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

[wsman-bridge] Introduce admission preferences #6164

Merged
merged 1 commit into from
Oct 14, 2021
Merged

Conversation

csweichel
Copy link
Contributor

@csweichel csweichel commented Oct 11, 2021

Description

This PR adds admission preferences to the workspace cluster selection mechanism. While admission constraints limit the set of clusters a workspace can be started on, admission preferences express a preference for a set of cluster but still allow fall-back to clusters that do not match that preference.

With this change, we first try and choose a cluster from the preferred clusters (green circle below) following the usual score mechanism. If there are no preferred cluster, we'll fall back to all clusters matching the admission constraints.

image

Use-cases this addition is helpful for:

  • give paying customers their own cluster (original motivation for this change): this PR introduces a single admission preference named user-level. This in-descriptive level can be used for a variety of purposes, e.g. express "paying customer" status. In a follow-up PR (once I've figured out if a user is actually paying), we would set this level to paying-customer. All workspace cluster with an admission preference user-level=paying-customer and the (new) admission constraint has-user-level=paying-customer would then become exclusive for paying users.
  • explicitly select a cluster to start a workspace one: suppose we want to test a new workspace cluster, right now we add the has-permission=workspace-cluster constraint and a high score, hoping that after so many attempts we land on the new cluster. We could introduce a prefix context parser which takes a cluster name, and add an admission preference for that name.
  • hyper-local workspace clusters: if we added an admission preference with network locality or some other information we could use to predict quality of service, we could give regional/likely performant clusters preference. The admission preference need not be static, but can be negotiated on a per-user basis.

How to test

image

Release Notes

Add admission constraints to support fine-grained cluster selection

@csweichel
Copy link
Contributor Author

/approve no-issue

@aledbf
Copy link
Member

aledbf commented Oct 12, 2021

/werft run

👍 started the job as gitpod-build-cw-admission-prefs.2

@aledbf
Copy link
Member

aledbf commented Oct 12, 2021

/werft run

👍 started the job as gitpod-build-cw-admission-prefs.3

@csweichel
Copy link
Contributor Author

csweichel commented Oct 12, 2021

/werft run

👍 started the job as gitpod-build-cw-admission-prefs.4

@meysholdt
Copy link
Member

great stuff!

explicitly select a cluster to start a workspace on

sounds like #4809

hyper-local workspace clusters

sounds like #5596

@csweichel csweichel force-pushed the cw/admission-prefs branch 4 times, most recently from 7fabcce to 3d3f2a1 Compare October 12, 2021 11:20
@csweichel csweichel marked this pull request as ready for review October 12, 2021 11:20
public async up(queryRunner: QueryRunner): Promise<any> {
if (await tableExists(queryRunner, "d_b_workspace_cluster")) {
if (!(await columnExists(queryRunner, "d_b_workspace_cluster", "admissionPreferences"))) {
await queryRunner.query("ALTER TABLE d_b_workspace_cluster ADD COLUMN admissionPreferences TEXT");
Copy link
Member

Choose a reason for hiding this comment

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

Why not make this a JSON column?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to follow the same pattern as for admissionConstraints


function admissionPreferencesFilter(user: ExtendedUser): (c: WorkspaceClusterWoTLS) => boolean {
return (c: WorkspaceClusterWoTLS) => {
if (!c.admissionPreferences) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: superfluous

* See License-AGPL.txt in the project root for license information.
*/

import {MigrationInterface, QueryRunner} from "typeorm";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting, no space

@@ -46,6 +47,13 @@ message AdmissionConstraint {
oneof constraint {
FeaturePreview has_feature_preview = 1;
HasPermission has_permission = 2;
string has_user_level = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason not to have this as a message type instad of a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The message was a bad choice to beging with :) but for now we're stuck with it for backwards compatibility reasons.

@princerachit
Copy link
Contributor

Overall lgtm other than a few clarifying questions. Also, there are no unit tests, given that we don't have them for any other file this is not a blocker, but we, should definitely discuss this.

let availableCluster = await this.getAvailableStartCluster(user, workspace, instance);
if (!!exceptInstallations) {
availableCluster = availableCluster.filter(c => !exceptInstallations?.includes(c.name));
}
const chosenCluster = chooseCluster(availableCluster);

let chosenCluster = chooseCluster(availableCluster.filter(admissionPreferencesFilter(user)))
Copy link
Member

Choose a reason for hiding this comment

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

👍

@geropl
Copy link
Member

geropl commented Oct 13, 2021

/werft run

👍 started the job as gitpod-build-cw-admission-prefs.14

@geropl
Copy link
Member

geropl commented Oct 14, 2021

/werft run

👍 started the job as gitpod-build-cw-admission-prefs.15

return JSON.stringify(value);
},
from(value: any): any {
if (!value) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Should return defaultValue.

{{- range .Status }}
{{ .Name }} {{ .Url }} {{ .Static }} {{ .State }} {{ .Score }} {{ .Governed }} {{ .AdmissionConstraints -}}
{{ .Name }} {{ .Url }} {{ .Static }} {{ .State }} {{ .Score }} {{ .Governed }} {{ .AdmissionConstraint -}} {{ .AdmissionPreference -}}
Copy link
Member

Choose a reason for hiding this comment

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

nit: the {{ .AdmissionConstraint -}} should be {{ .AdmissionConstraint }} (without the dash) to avoid the output to be skewed:
image

@@ -164,8 +167,8 @@ export class ClusterService implements IClusterServiceServer {
if (call.request.hasCordoned()) {
cluster.state = mapCordoned(req.cordoned);
}
if (call.request.hasAdmissionConstraints()) {
Copy link
Member

Choose a reason for hiding this comment

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

Bumped into this while testing: A few lines up (L158/159) the error ALREADY_EXISTS is wrong. Not introduce with this PR, but worth fixing.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Finally found the time for testing: works as advertised!

There are a couple of things which are worth fixing, but am fine with doing those in a followup PR:

👍

@roboquat
Copy link
Contributor

LGTM label has been added.

Git tree hash: 929e1e57a57fb0be37107c119e84af17325dd1ed

@roboquat
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: csweichel, geropl

Associated issue requirement bypassed by: csweichel

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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants