Skip to content

Commit

Permalink
feat: CBWP update with ETag
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed Jun 14, 2024
1 parent 0dc2dd0 commit 27efa03
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apis/cloudbuild/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func Convert_WorkerPool_API_v1_To_KRM_status(in *cloudbuildpb.WorkerPool, out *C
return nil
}
out.ObservedState = &CloudBuildWorkerPoolObservedState{}

out.ObservedState.ETag = &in.Etag
if err := Convert_PrivatePoolV1Config_API_v1_To_KRM(in.GetPrivatePoolV1Config(), out.ObservedState); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions apis/cloudbuild/v1alpha1/workerpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type CloudBuildWorkerPoolObservedState struct {
// +required
WorkerConfig *WorkerConfig `json:"workerConfig,omitempty"`
NetworkConfig *NetworkConfigState `json:"networkConfig,omitempty"`

ETag *string `json:"eTag,omitempty"`
}

type NetworkConfigState struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/cloudbuild/v1alpha1/zz_generated.deepcopy.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 @@ -180,6 +180,8 @@ spec:
description: The creation timestamp of the workerpool.
format: date-time
type: string
eTag:
type: string
networkConfig:
properties:
egressOption:
Expand Down
4 changes: 3 additions & 1 deletion mockgcp/mockcloudbuild/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *CloudBuildV1) CreateWorkerPool(ctx context.Context, req *pb.CreateWorke
result.CreateTime = now
result.UpdateTime = now
result.State = pb.WorkerPool_RUNNING
result.Etag = "W/11111111111111111111111111111111"
return result, nil
})
}
Expand All @@ -99,7 +100,7 @@ func (s *CloudBuildV1) UpdateWorkerPool(ctx context.Context, req *pb.UpdateWorke
f := target.FieldByName(path)
if f.IsValid() && f.CanSet() {
switch f.Kind() {
case reflect.Int:
case reflect.Int, reflect.Int64:
intVal := source.FieldByName(path).Int()
f.SetInt(intVal)
case reflect.String:
Expand All @@ -122,6 +123,7 @@ func (s *CloudBuildV1) UpdateWorkerPool(ctx context.Context, req *pb.UpdateWorke
result := proto.Clone(obj).(*pb.WorkerPool)
result.UpdateTime = now
result.State = pb.WorkerPool_RUNNING
result.Etag = "W/22222222222222222222222222222222"
return result, nil
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/direct/cloudbuild/workerpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) erro

wp := &cloudbuildpb.WorkerPool{
Name: a.fullyQualifiedName(),
Etag: a.actual.Etag,
}
desired := a.desired.DeepCopy()
err := krm.Convert_WorkerPool_KRM_To_API_v1(desired, wp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ status:
observedGeneration: 2
observedState:
createTime: "1970-01-01T00:00:00Z"
eTag: W/22222222222222222222222222222222
networkConfig:
egressOption: NO_PUBLIC_EGRESS
peeredNetwork: projects/${projectId}/global/networks/computenetwork-${uniqueId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ X-Xss-Protection: 0
"@type": "type.googleapis.com/google.devtools.cloudbuild.v1.WorkerPool",
"createTime": "2024-04-01T12:34:56.123456Z",
"displayName": "New CloudBuild WorkerPool",
"etag": "abcdef0123A=",
"name": "projects/${projectId}/locations/us-central1/workerPools/cloudbuildworkerpool-${uniqueId}",
"privatePoolV1Config": {
"networkConfig": {
Expand Down Expand Up @@ -715,6 +716,7 @@ X-Xss-Protection: 0
"response": {
"@type": "type.googleapis.com/google.devtools.cloudbuild.v1.WorkerPool",
"displayName": "New CloudBuild WorkerPool",
"etag": "abcdef0123A=",
"name": "projects/${projectId}/locations/us-central1/workerPools/cloudbuildworkerpool-${uniqueId}",
"privatePoolV1Config": {
"networkConfig": {
Expand Down

0 comments on commit 27efa03

Please sign in to comment.