Skip to content

Commit

Permalink
fix: cannot update cluster since clustername is not set (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcarver authored Sep 9, 2024
1 parent 6cb614a commit b5f0226
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
7 changes: 6 additions & 1 deletion internal/cloudsdk/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (acc *FakeCloudClient) IsTenantNameExist(ctx context.Context, region string
func (acc *FakeCloudClient) CreateClusterAwait(ctx context.Context, region string, req apigen_mgmt.TenantRequestRequestBody) (*apigen_mgmt.Tenant, error) {
debugFuncCaller()

clusterName := req.ClusterName
if clusterName == nil {
clusterName = ptr.Ptr("default-control-plane")
}

r := state.GetRegionState(region)
t := &apigen_mgmt.Tenant{
Id: uint64(len(r.GetClusters()) + 1),
Expand All @@ -98,7 +103,7 @@ func (acc *FakeCloudClient) CreateClusterAwait(ctx context.Context, region strin
Resources: reqResouceToClusterResource(req.Resources),
NsId: uuid.New(),
Tier: *req.Tier,
ClusterName: req.ClusterName,
ClusterName: clusterName,
}
cluster := NewClusterState(t)
r.AddCluster(cluster)
Expand Down
37 changes: 24 additions & 13 deletions internal/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,24 +814,35 @@ func (r *ClusterResource) Update(ctx context.Context, req resource.UpdateRequest
}

// immutable fields
if previous.ClusterName == nil && updated.ClusterName != nil {
if previous.Tier != updated.Tier {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous is not set, now is %s", *updated.ClusterName),
"Tier cannot be changed",
)
}
if previous.ClusterName != nil && updated.ClusterName == nil {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous is %s, now is not set", *previous.ClusterName),
)
}
if (previous.ClusterName != nil && updated.ClusterName != nil) && (*previous.ClusterName != *updated.ClusterName) {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous: %s, updated: %s", *previous.ClusterName, *updated.ClusterName),
)

// only check clusterName for BYOC
if previous.Tier == apigen_mgmt.BYOC {
if previous.ClusterName == nil && updated.ClusterName != nil {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous is not set, now is %s", *updated.ClusterName),
)
}
if previous.ClusterName != nil && updated.ClusterName == nil {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous is %s, now is not set", *previous.ClusterName),
)
}
if (previous.ClusterName != nil && updated.ClusterName != nil) && (*previous.ClusterName != *updated.ClusterName) {
resp.Diagnostics.AddError(
"Cannot update immutable field",
fmt.Sprintf("Cluster name cannot be changed, previous: %s, updated: %s", *previous.ClusterName, *updated.ClusterName),
)
}
}

if previous.TenantName != updated.TenantName {
resp.Diagnostics.AddError(
"Cannot update immutable field",
Expand Down

0 comments on commit b5f0226

Please sign in to comment.