Skip to content

Commit

Permalink
Log error when update is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Nov 25, 2024
1 parent fa8b789 commit 0a8389e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down
15 changes: 15 additions & 0 deletions pkg/k8s/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Check failure on line 244 in pkg/k8s/errors.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Sprintf format %s reads arg #3, but call has 2 args (govet)
e.resourceGVK.Kind, e.resource)
}

func NewUpdateNotSupportedError(resourceGVK schema.GroupVersionKind, namespace types.NamespacedName, resource string) *UpdateNotSupportedError {
return &UpdateNotSupportedError{resourceGVK, namespace, resource}
}

0 comments on commit 0a8389e

Please sign in to comment.