Skip to content

Commit

Permalink
Use Patch when syncing GCP BackendService. Linking backend groups sti…
Browse files Browse the repository at this point in the history
…ll uses Update
  • Loading branch information
gauravkghildiyal committed Mar 27, 2023
1 parent 62e2af0 commit d3139cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pkg/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ func (b *Backends) Update(be *composite.BackendService) error {
return nil
}

// Patch implements Pool.
func (b *Backends) Patch(be *composite.BackendService) error {
// Ensure the backend service has the proper version before updating.
be.Version = features.VersionFromDescription(be.Description)
scope, err := composite.ScopeFromSelfLink(be.SelfLink)
if err != nil {
return err
}

key, err := composite.CreateKey(b.cloud, be.Name, scope)
if err != nil {
return err
}
if err := composite.PatchBackendService(b.cloud, key, be); err != nil {
return err
}
return nil
}

// Get implements Pool.
func (b *Backends) Get(name string, version meta.Version, scope meta.KeyType) (*composite.BackendService, error) {
key, err := composite.CreateKey(b.cloud, name, scope)
Expand Down
2 changes: 2 additions & 0 deletions pkg/backends/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Pool interface {
Create(sp utils.ServicePort, hcLink string) (*composite.BackendService, error)
// Update a BackendService given the composite type.
Update(be *composite.BackendService) error
// Patch a BackendService given the composite type.
Patch(be *composite.BackendService) error
// Delete a BackendService given its name.
Delete(name string, version meta.Version, scope meta.KeyType) error
// Get the health of a BackendService given its name.
Expand Down
5 changes: 4 additions & 1 deletion pkg/backends/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error {
}

if needUpdate {
if err := s.backendPool.Update(be); err != nil {
if err := s.backendPool.Patch(be); err != nil {
return err
}
}
Expand Down Expand Up @@ -305,6 +305,9 @@ func ensureProtocol(be *composite.BackendService, p utils.ServicePort) (needsUpd
if be.Protocol == string(p.Protocol) {
return false
}

fmt.Printf("protocol needs change; got be = %+v, want protocol = %v\n", be, p.Protocol)

be.Protocol = string(p.Protocol)
return true
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/backends/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func newTestSyncer(fakeGCE *gce.Cloud) *backendSyncer {
(fakeGCE.Compute().(*cloud.MockGCE)).MockAlphaBackendServices.UpdateHook = mock.UpdateAlphaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBetaBackendServices.UpdateHook = mock.UpdateBetaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBackendServices.UpdateHook = mock.UpdateBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockAlphaBackendServices.PatchHook = mock.UpdateAlphaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBetaBackendServices.PatchHook = mock.UpdateBetaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBackendServices.PatchHook = mock.UpdateBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockHealthChecks.UpdateHook = mock.UpdateHealthCheckHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockAlphaHealthChecks.UpdateHook = mock.UpdateAlphaHealthCheckHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockAlphaRegionHealthChecks.UpdateHook = mock.UpdateAlphaRegionHealthCheckHook
Expand Down

0 comments on commit d3139cf

Please sign in to comment.