From 94e06ba5ea82895f16b6769c0e2eddb1e68de18f Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Mon, 25 Nov 2024 20:51:37 +0000 Subject: [PATCH] Log error when update is not supported --- .../targettcpproxy/targettcpproxy_controller.go | 10 +++++++--- pkg/controller/direct/directbase/operations.go | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go b/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go index 0969c46ac8..5725445a2f 100644 --- a/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go +++ b/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go @@ -260,11 +260,15 @@ func (a *targetTCPProxyAdapter) Update(ctx context.Context, updateOp *directbase } region := parent.Region + // Regional API does not support Update + if region != "global" { + return updateOp.SkipUpdate(a.id.External) + } + tokens := strings.Split(a.id.External, "/") targetTCPProxy.Name = direct.LazyPtr(tokens[len(tokens)-1]) - // Regional API does not support Update - if !reflect.DeepEqual(targetTCPProxy.ProxyHeader, a.actual.ProxyHeader) && region == "global" { + if !reflect.DeepEqual(targetTCPProxy.ProxyHeader, a.actual.ProxyHeader) { setProxyHeaderReq := &computepb.SetProxyHeaderTargetTcpProxyRequest{ Project: parent.ProjectID, TargetTcpProxiesSetProxyHeaderRequestResource: &computepb.TargetTcpProxiesSetProxyHeaderRequest{ProxyHeader: targetTCPProxy.ProxyHeader}, @@ -283,7 +287,7 @@ func (a *targetTCPProxyAdapter) Update(ctx context.Context, updateOp *directbase log.V(2).Info("successfully updated ComputeTargetTCPProxy proxy header", "name", a.id.External) } - if !reflect.DeepEqual(targetTCPProxy.Service, a.actual.Service) && region == "global" { + if !reflect.DeepEqual(targetTCPProxy.Service, a.actual.Service) { setBackendServiceReq := &computepb.SetBackendServiceTargetTcpProxyRequest{ Project: parent.ProjectID, TargetTcpProxiesSetBackendServiceRequestResource: &computepb.TargetTcpProxiesSetBackendServiceRequest{Service: targetTCPProxy.Service}, diff --git a/pkg/controller/direct/directbase/operations.go b/pkg/controller/direct/directbase/operations.go index 672aca455f..731bfb72d4 100644 --- a/pkg/controller/direct/directbase/operations.go +++ b/pkg/controller/direct/directbase/operations.go @@ -78,6 +78,10 @@ func (o *UpdateOperation) RecordUpdatingEvent() { r.Event(o.object, corev1.EventTypeNormal, k8s.Updating, k8s.UpdatingMessage) } +func (o *UpdateOperation) SkipUpdate(resource string) error { + return fmt.Errorf("update operation does not support for resource %s", resource) +} + var _ Operation = &CreateOperation{} type CreateOperation struct {