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

[ws-manager-bridge] Support forced cluster dereg #6682

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/ws-manager-bridge-api/cluster-service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ message UpdateResponse {}

message DeregisterRequest {
string name = 1;
bool force = 2;
}

message DeregisterResponse {}
Expand Down
103 changes: 56 additions & 47 deletions components/ws-manager-bridge-api/go/cluster-service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ export namespace UpdateResponse {
export class DeregisterRequest extends jspb.Message {
getName(): string;
setName(value: string): DeregisterRequest;
getForce(): boolean;
setForce(value: boolean): DeregisterRequest;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): DeregisterRequest.AsObject;
Expand All @@ -437,6 +439,7 @@ export class DeregisterRequest extends jspb.Message {
export namespace DeregisterRequest {
export type AsObject = {
name: string,
force: boolean,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,8 @@ proto.workspacemanagerbridge.DeregisterRequest.prototype.toObject = function(opt
*/
proto.workspacemanagerbridge.DeregisterRequest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, "")
name: jspb.Message.getFieldWithDefault(msg, 1, ""),
force: jspb.Message.getBooleanFieldWithDefault(msg, 2, false)
};

if (includeInstance) {
Expand Down Expand Up @@ -3307,6 +3308,10 @@ proto.workspacemanagerbridge.DeregisterRequest.deserializeBinaryFromReader = fun
var value = /** @type {string} */ (reader.readString());
msg.setName(value);
break;
case 2:
var value = /** @type {boolean} */ (reader.readBool());
msg.setForce(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -3343,6 +3348,13 @@ proto.workspacemanagerbridge.DeregisterRequest.serializeBinaryToWriter = functio
f
);
}
f = message.getForce();
if (f) {
writer.writeBool(
2,
f
);
}
};


Expand All @@ -3364,6 +3376,24 @@ proto.workspacemanagerbridge.DeregisterRequest.prototype.setName = function(valu
};


/**
* optional bool force = 2;
* @return {boolean}
*/
proto.workspacemanagerbridge.DeregisterRequest.prototype.getForce = function() {
return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 2, false));
};


/**
* @param {boolean} value
* @return {!proto.workspacemanagerbridge.DeregisterRequest} returns this
*/
proto.workspacemanagerbridge.DeregisterRequest.prototype.setForce = function(value) {
return jspb.Message.setProto3BooleanField(this, 2, value);
};





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export class ClusterService implements IClusterServiceServer {

const instances = await this.workspaceDB.findRegularRunningInstances();
const relevantInstances = instances.filter(i => i.region === req.name);
if (relevantInstances.length > 0) {
if (!req.force && relevantInstances.length > 0) {
log.info({}, "forced cluster deregistration even though there are still instances running", {cluster: req.name});
throw new GRPCError(grpc.status.FAILED_PRECONDITION, `cluster is not empty (${relevantInstances.length} instances remaining)`);
}

Expand Down
7 changes: 6 additions & 1 deletion dev/gpctl/cmd/clusters-deregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/gitpod-io/gitpod/ws-manager-bridge/api"
)

var clustersDeregisterOpts struct {
Force bool
}

// clustersDeregisterCmd represents the clustersDeregisterCmd command
var clustersDeregisterCmd = &cobra.Command{
Use: "deregister --name [cluster name]",
Expand All @@ -31,7 +35,7 @@ var clustersDeregisterCmd = &cobra.Command{
defer conn.Close()

name := getClusterName()
_, err = client.Deregister(ctx, &api.DeregisterRequest{Name: name})
_, err = client.Deregister(ctx, &api.DeregisterRequest{Name: name, Force: clustersDeregisterOpts.Force})
if err != nil && err != io.EOF {
log.Fatal(err)
}
Expand All @@ -42,4 +46,5 @@ var clustersDeregisterCmd = &cobra.Command{

func init() {
clustersCmd.AddCommand(clustersDeregisterCmd)
clustersDeregisterCmd.Flags().BoolVar(&clustersDeregisterOpts.Force, "force", false, "⚠️💥 force cluster deregistration even if there are still instances running. Use with great caution: this will break people's experience.")
}