Skip to content

Commit

Permalink
Merge pull request #3604 from GoogleCloudPlatform/fix_managedkaflaclu…
Browse files Browse the repository at this point in the history
…ster_update

fix: fix the update diff in ManagedKaflaCluster
  • Loading branch information
google-oss-prow[bot] authored Feb 5, 2025
2 parents 90ab42d + 79b372b commit 1569b32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions pkg/controller/direct/managedkafka/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (a *ClusterAdapter) Update(ctx context.Context, updateOp *directbase.Update
return mapCtx.Err()
}

// Set the name field to ensure the GCP API can identity the resource during UpdateCluster().
// This also prevents incorrect diffs, as the name field is not populated by ManagedKafkaClusterSpec_ToProto.
desiredPb.Name = a.id.String()

paths, err := common.CompareProtoMessage(desiredPb, a.actual, common.BasicDiff)
if err != nil {
return err
Expand All @@ -194,13 +198,11 @@ func (a *ClusterAdapter) Update(ctx context.Context, updateOp *directbase.Update
}
return updateOp.UpdateStatus(ctx, status, nil)
}
updateMask := &fieldmaskpb.FieldMask{
Paths: sets.List(paths)}

desiredPb.Name = a.id.String() // populate the name field so that the GCP API can identify the resource
req := &pb.UpdateClusterRequest{
UpdateMask: updateMask,
Cluster: desiredPb,
UpdateMask: &fieldmaskpb.FieldMask{
Paths: sets.List(paths)},
Cluster: desiredPb,
}
op, err := a.gcpClient.UpdateCluster(ctx, req)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ X-Xss-Protection: 0

---

PATCH https://managedkafka.googleapis.com/v1/projects/${projectId}/locations/us-central1/clusters/managedkafkacluster-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=capacityConfig.memoryBytes%2CcapacityConfig.vcpuCount%2CgcpConfig.accessConfig.networkConfigs%2Cname%2CrebalanceConfig.mode
PATCH https://managedkafka.googleapis.com/v1/projects/${projectId}/locations/us-central1/clusters/managedkafkacluster-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=capacityConfig.memoryBytes%2CcapacityConfig.vcpuCount%2CgcpConfig.accessConfig.networkConfigs%2CrebalanceConfig.mode
Content-Type: application/json
User-Agent: kcc/${kccVersion} (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/${kccVersion}
X-Goog-Request-Params: cluster.name=projects%2F${projectId}%2Flocations%2Fus-central1%2Fclusters%2Fmanagedkafkacluster-${uniqueId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ X-Xss-Protection: 0

---

PATCH https://managedkafka.googleapis.com/v1/projects/${projectId}/locations/us-central1/clusters/managedkafkacluster-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=capacityConfig.memoryBytes%2CcapacityConfig.vcpuCount%2Cname%2CrebalanceConfig.mode
PATCH https://managedkafka.googleapis.com/v1/projects/${projectId}/locations/us-central1/clusters/managedkafkacluster-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=capacityConfig.memoryBytes%2CcapacityConfig.vcpuCount%2CrebalanceConfig.mode
Content-Type: application/json
User-Agent: kcc/${kccVersion} (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/${kccVersion}
X-Goog-Request-Params: cluster.name=projects%2F${projectId}%2Flocations%2Fus-central1%2Fclusters%2Fmanagedkafkacluster-${uniqueId}
Expand Down

0 comments on commit 1569b32

Please sign in to comment.