Skip to content

Commit

Permalink
bigtable: workaround for autoscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Jul 30, 2024
1 parent 2b0f384 commit c3ce784
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 427 deletions.
71 changes: 71 additions & 0 deletions pkg/resourceoverrides/bigtable_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package resourceoverrides

import (
"context"
"fmt"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides/operations"
)

func GetBigtableInstanceOverrides() ResourceOverrides {
ro := ResourceOverrides{
Kind: "BigtableInstance",
}
ro.Overrides = append(ro.Overrides, noNodesWhereAutoscaling())
return ro
}

func noNodesWhereAutoscaling() ResourceOverride {
o := ResourceOverride{}

// When we are applying a cluster which has autoscaling, we should not specify num_nodes (serve_nodes in GCP)
o.PreTerraformApply = func(ctx context.Context, op *operations.PreTerraformApply) error {
removeNumNodesIfAutoscaling := func(clusters []any) {
for i, clusterAny := range clusters {
cluster, ok := clusterAny.(map[string]any)
if !ok {
continue
}

autoscalingConfig := cluster["autoscaling_config"]
if autoscalingConfig == nil {
continue
}

delete(cluster, "num_nodes")

// Delete from liveState also, otherwise it gets merged?
if op.LiveState != nil {
k := fmt.Sprintf("cluster.%d.num_nodes", i)
delete(op.LiveState.Attributes, k)
}
}
}

if clusters, ok := op.TerraformConfig.Config["cluster"].([]any); ok {
removeNumNodesIfAutoscaling(clusters)
}

if clusters, ok := op.TerraformConfig.Raw["cluster"].([]any); ok {
removeNumNodesIfAutoscaling(clusters)
}

return nil
}

return o
}
1 change: 1 addition & 0 deletions pkg/resourceoverrides/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func (h *ROHandler) Register(ro ResourceOverrides) {
}

func init() {
Handler.Register(GetBigtableInstanceOverrides())
Handler.Register(GetStorageBucketResourceOverrides())
Handler.Register(GetSQLInstanceResourceOverrides())
Handler.Register(GetContainerClusterResourceOverrides())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ spec:
maxNodes: 20
minNodes: 2
storageTarget: 2560
clusterId: cluster-2-${uniqueId}
numNodes: 2
storageType: SSD
zone: us-west1-b
- autoscalingConfig:
cpuTarget: 70
maxNodes: 20
minNodes: 2
clusterId: cluster-3-${uniqueId}
numNodes: 2
storageType: SSD
Expand Down
Loading

0 comments on commit c3ce784

Please sign in to comment.