Skip to content

Commit

Permalink
feat: add capability to disable a stack
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed May 26, 2023
1 parent 223d66b commit fcf3e13
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 51 deletions.
32 changes: 32 additions & 0 deletions components/agent/internal/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ func (client *client) Start(ctx context.Context) error {
if err := client.k8sClient.Delete(ctx, msg.DeletedStack.ClusterName); err != nil {
sharedlogging.FromContext(ctx).Errorf("creating deleting cluster side: %s", err)
}
case *generated.ConnectResponse_DisabledStack:
existingStack, err := client.k8sClient.Get(ctx, msg.DisabledStack.ClusterName, metav1.GetOptions{})
if err != nil {
if controllererrors.IsNotFound(err) {
sharedlogging.FromContext(ctx).Infof("cannot disable not existing stack: %s", msg.DisabledStack.ClusterName)
continue
}
sharedlogging.FromContext(ctx).Errorf("reading stack cluster side: %s", err)
continue
}
existingStack.Spec.Disabled = true
if _, err := client.k8sClient.Update(ctx, existingStack); err != nil {
sharedlogging.FromContext(ctx).Errorf("updating stack cluster side: %s", err)
continue
}
sharedlogging.FromContext(ctx).Infof("stack %s updated", msg.DisabledStack.ClusterName)
case *generated.ConnectResponse_EnabledStack:
existingStack, err := client.k8sClient.Get(ctx, msg.EnabledStack.ClusterName, metav1.GetOptions{})
if err != nil {
if controllererrors.IsNotFound(err) {
sharedlogging.FromContext(ctx).Infof("cannot enable not existing stack: %s", msg.EnabledStack.ClusterName)
continue
}
sharedlogging.FromContext(ctx).Errorf("reading stack cluster side: %s", err)
continue
}
existingStack.Spec.Disabled = false
if _, err := client.k8sClient.Update(ctx, existingStack); err != nil {
sharedlogging.FromContext(ctx).Errorf("updating stack cluster side: %s", err)
continue
}
sharedlogging.FromContext(ctx).Infof("stack %s updated", msg.EnabledStack.ClusterName)
case *generated.ConnectResponse_UpdateUsageReport:
total, err := CountDocument(msg.UpdateUsageReport.ClusterName)
if err != nil {
Expand Down
266 changes: 216 additions & 50 deletions components/agent/internal/grpc/generated/server.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions components/agent/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ message ConnectResponse {
DeletedStack deletedStack = 3;
Ping ping = 4;
UpdateUsageReport updateUsageReport = 5;
DisabledStack disabledStack = 6;
EnabledStack enabledStack = 7;
}
}

Expand All @@ -46,6 +48,14 @@ message DeletedStack {
string clusterName = 1;
}

message DisabledStack {
string clusterName = 1;
}

message EnabledStack {
string clusterName = 1;
}

message UpdateUsageReport {
string clusterName = 1;
string stripeKey = 2;
Expand Down
2 changes: 1 addition & 1 deletion components/operator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ garden/local-registries.yaml
garden.default.env
ca.crt
helm/operator/charts
helm/operator/templates/rbac/kustomization.yaml
helm/templates/rbac/kustomization.yaml
operator
3 changes: 3 additions & 0 deletions components/operator/apis/stack/v1beta3/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type StackSpec struct {
// +optional
// +kubebuilder:default:="http"
Scheme string `json:"scheme"`

// +optional
Disabled bool `json:"disabled"`
}

type ControlAuthentication struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,8 @@ spec:
type: boolean
dev:
type: boolean
disabled:
type: boolean
host:
type: string
scheme:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,8 @@ spec:
type: boolean
dev:
type: boolean
disabled:
type: boolean
host:
type: string
scheme:
Expand Down
12 changes: 12 additions & 0 deletions components/operator/internal/modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ import (

func HandleStack(ctx Context, deployer *ResourceDeployer) error {

if ctx.Stack.Spec.Disabled {
if err := deployer.client.DeleteAllOf(ctx, &v1.Deployment{},
client.InNamespace(ctx.Stack.Name),
client.MatchingLabels{
"stack": "true",
},
); err != nil {
return err
}
return nil
}

var (
portAllocator PortAllocator = StaticPortAllocator(8080)
podDeployer PodDeployer = NewDefaultPodDeployer(deployer)
Expand Down

0 comments on commit fcf3e13

Please sign in to comment.