From 0a8389e1c2fa1709dfb0c469c6a2d12f678d1004 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 | 13 ++++++++++--- pkg/k8s/errors.go | 15 +++++++++++++++ 2 files changed, 25 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..a346eb9985 100644 --- a/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go +++ b/pkg/controller/direct/compute/targettcpproxy/targettcpproxy_controller.go @@ -20,6 +20,8 @@ import ( "reflect" "strings" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" + "google.golang.org/api/option" gcp "cloud.google.com/go/compute/apiv1" @@ -260,11 +262,16 @@ func (a *targetTCPProxyAdapter) Update(ctx context.Context, updateOp *directbase } region := parent.Region + // Regional API does not support Update + if region != "global" { + return k8s.NewUpdateNotSupportedError(a.desired.GroupVersionKind(), + k8s.GetNamespacedName(a.desired), 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 +290,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/k8s/errors.go b/pkg/k8s/errors.go index 21bb05c215..c3fcc3c3af 100644 --- a/pkg/k8s/errors.go +++ b/pkg/k8s/errors.go @@ -233,3 +233,18 @@ func (e *ImmutableFieldsMutationError) Error() string { func NewImmutableFieldsMutationError(immutableFields []string) *ImmutableFieldsMutationError { return &ImmutableFieldsMutationError{immutableFields} } + +type UpdateNotSupportedError struct { + resourceGVK schema.GroupVersionKind + namespace types.NamespacedName + resource string +} + +func (e *UpdateNotSupportedError) Error() string { + return fmt.Sprintf("update operation not supported for resource %v %v: %s", + e.resourceGVK.Kind, e.resource) +} + +func NewUpdateNotSupportedError(resourceGVK schema.GroupVersionKind, namespace types.NamespacedName, resource string) *UpdateNotSupportedError { + return &UpdateNotSupportedError{resourceGVK, namespace, resource} +}