Skip to content

Commit

Permalink
Merge pull request #2057 from gauravkghildiyal/revert-2043-backend-se…
Browse files Browse the repository at this point in the history
…rvice-log-rate

Revert "Use Patch when syncing GCP BackendService. Linking backend groups still uses Update"
  • Loading branch information
k8s-ci-robot authored Apr 3, 2023
2 parents d772246 + fcccb5b commit 8e31883
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 169 deletions.
19 changes: 0 additions & 19 deletions pkg/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,6 @@ 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: 0 additions & 2 deletions pkg/backends/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ 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
2 changes: 1 addition & 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.Patch(be); err != nil {
if err := s.backendPool.Update(be); err != nil {
return err
}
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/backends/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ 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
47 changes: 0 additions & 47 deletions pkg/composite/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4174,53 +4174,6 @@ func UpdateBackendService(gceCloud *gce.Cloud, key *meta.Key, backendService *Ba
}
}

func PatchBackendService(gceCloud *gce.Cloud, key *meta.Key, backendService *BackendService) error {
ctx, cancel := cloudprovider.ContextWithCallTimeout()
defer cancel()
mc := compositemetrics.NewMetricContext("BackendService", "patch", key.Region, key.Zone, string(backendService.Version))
switch backendService.Version {
case meta.VersionAlpha:
alpha, err := backendService.ToAlpha()
if err != nil {
return err
}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching alpha region BackendService %v", alpha.Name)
return mc.Observe(gceCloud.Compute().AlphaRegionBackendServices().Patch(ctx, key, alpha))
default:
klog.V(3).Infof("Patching alpha BackendService %v", alpha.Name)
return mc.Observe(gceCloud.Compute().AlphaBackendServices().Patch(ctx, key, alpha))
}
case meta.VersionBeta:
beta, err := backendService.ToBeta()
if err != nil {
return err
}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching beta region BackendService %v", beta.Name)
return mc.Observe(gceCloud.Compute().BetaRegionBackendServices().Patch(ctx, key, beta))
default:
klog.V(3).Infof("Patching beta BackendService %v", beta.Name)
return mc.Observe(gceCloud.Compute().BetaBackendServices().Patch(ctx, key, beta))
}
default:
ga, err := backendService.ToGA()
if err != nil {
return err
}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching ga region BackendService %v", ga.Name)
return mc.Observe(gceCloud.Compute().RegionBackendServices().Patch(ctx, key, ga))
default:
klog.V(3).Infof("Patching ga BackendService %v", ga.Name)
return mc.Observe(gceCloud.Compute().BackendServices().Patch(ctx, key, ga))
}
}
}

func DeleteBackendService(gceCloud *gce.Cloud, key *meta.Key, version meta.Version) error {
ctx, cancel := cloudprovider.ContextWithCallTimeout()
defer cancel()
Expand Down
73 changes: 0 additions & 73 deletions pkg/composite/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,79 +365,6 @@ func Update{{.Name}}(gceCloud *gce.Cloud, key *meta.Key, {{.VarName}} *{{.Name}}
}
{{- end}} {{/*HasUpdate*/}}
{{if .HasPatch}}
func Patch{{.Name}}(gceCloud *gce.Cloud, key *meta.Key, {{.VarName}} *{{.Name}}) error {
ctx, cancel := cloudprovider.ContextWithCallTimeout()
defer cancel()
mc := compositemetrics.NewMetricContext("{{.Name}}", "patch", key.Region, key.Zone, string({{.VarName}}.Version))
{{- if $onlyZonalKeySupported}}
switch key.Type() {
case meta.Zonal:
default:
return fmt.Errorf("Key %v not valid for zonal resource {{.Name}} %v", key, key.Name)
}
{{- end}} {{/* $onlyZonalKeySupported*/}}
switch {{.VarName}}.Version {
case meta.VersionAlpha:
alpha, err := {{.VarName}}.ToAlpha()
if err != nil {
return err
}
{{- if $onlyZonalKeySupported}}
klog.V(3).Infof("Patching alpha zonal {{.Name}} %v", alpha.Name)
return mc.Observe(gceCloud.Compute().Alpha{{.GetCloudProviderName}}().Patch(ctx, key, alpha))
{{- else}}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching alpha region {{.Name}} %v", alpha.Name)
return mc.Observe(gceCloud.Compute().Alpha{{$regionalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, alpha))
default:
klog.V(3).Infof("Patching alpha {{.Name}} %v", alpha.Name)
return mc.Observe(gceCloud.Compute().Alpha{{$globalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, alpha))
}
{{- end}} {{/* $onlyZonalKeySupported*/}}
case meta.VersionBeta:
beta, err := {{.VarName}}.ToBeta()
if err != nil {
return err
}
{{- if $onlyZonalKeySupported}}
klog.V(3).Infof("Patching beta zonal {{.Name}} %v", beta.Name)
return mc.Observe(gceCloud.Compute().Beta{{.GetCloudProviderName}}().Patch(ctx, key, beta))
{{- else}}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching beta region {{.Name}} %v", beta.Name)
return mc.Observe(gceCloud.Compute().Beta{{$regionalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, beta))
default:
klog.V(3).Infof("Patching beta {{.Name}} %v", beta.Name)
return mc.Observe(gceCloud.Compute().Beta{{$globalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, beta))
}
{{- end}} {{/* $onlyZonalKeySupported*/}}
default:
ga, err := {{.VarName}}.ToGA()
if err != nil {
return err
}
{{- if $onlyZonalKeySupported}}
klog.V(3).Infof("Patching ga zonal {{.Name}} %v", ga.Name)
return mc.Observe(gceCloud.Compute().{{.GetCloudProviderName}}().Patch(ctx, key, ga))
{{- else}}
switch key.Type() {
case meta.Regional:
klog.V(3).Infof("Patching ga region {{.Name}} %v", ga.Name)
return mc.Observe(gceCloud.Compute().{{$regionalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, ga))
default:
klog.V(3).Infof("Patching ga {{.Name}} %v", ga.Name)
return mc.Observe(gceCloud.Compute().{{$globalKeyFiller}}{{.GetCloudProviderName}}().Patch(ctx, key, ga))
}
{{- end}} {{/* $onlyZonalKeySupported*/}}
}
}
{{- end}} {{/*HasPatch*/}}
func Delete{{.Name}}(gceCloud *gce.Cloud, key *meta.Key, version meta.Version) error {
ctx, cancel := cloudprovider.ContextWithCallTimeout()
defer cancel()
Expand Down
24 changes: 0 additions & 24 deletions pkg/composite/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ var NoUpdate = sets.NewString(
"SignedUrlKey",
)

// Services in NoPatch will not have a Patch() method generated for them.
var NoPatch = sets.NewString(
"Address",
"ForwardingRule",
"HealthCheck",
"HealthStatusForNetworkEndpoint",
"UrlMap",
"TargetHttpProxy",
"TargetHttpsProxy",
"SslCertificate",
"NetworkEndpointGroup",
"NetworkEndpoint",
"NetworkEndpointWithHealthStatus",
"NetworkEndpointGroupsAttachEndpointsRequest",
"NetworkEndpointGroupsDetachEndpointsRequest",
"NetworkEndpointGroupsListEndpointsRequest",
"SignedUrlKey",
)

// Services in NoCRUD will not have Create, Get, Delete, Update, methods generated for them
var NoCRUD = sets.NewString(
"HealthStatusForNetworkEndpoint",
Expand Down Expand Up @@ -177,11 +158,6 @@ func (apiService *ApiService) HasUpdate() bool {
return !NoUpdate.Has(apiService.Name)
}

// HasPatch() returns true if the service name is *not* in the NoPatch() list
func (apiService *ApiService) HasPatch() bool {
return !NoPatch.Has(apiService.Name)
}

// HasCRUD() returns true if the service name is *not* in the NoCRUD() list
func (apiService *ApiService) HasCRUD() bool {
return !NoCRUD.Has(apiService.Name)
Expand Down

0 comments on commit 8e31883

Please sign in to comment.