From c6bec2b51aae7b5146963001258091861945f024 Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Fri, 20 Sep 2024 21:36:41 +0000 Subject: [PATCH] move resolvers out of adapter --- config/tests/samples/create/harness.go | 2 +- .../compute/forwardingrule_controller.go | 119 ++-------- pkg/controller/direct/compute/refs.go | 108 +++++++++ .../regionalforwardingrulepsc/_http.log | 206 ++++++++++++++---- ...bject_computeserviceattachment.golden.yaml | 2 +- .../computeserviceattachment/_http.log | 86 +++++++- 6 files changed, 376 insertions(+), 147 deletions(-) diff --git a/config/tests/samples/create/harness.go b/config/tests/samples/create/harness.go index a26f699584..0f64ad3245 100644 --- a/config/tests/samples/create/harness.go +++ b/config/tests/samples/create/harness.go @@ -673,7 +673,7 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeNodeGroup"}: case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeNodeTemplate"}: case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeManagedSSLCertificate"}: - //case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeServiceAttachment"}: + case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeServiceAttachment"}: case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeSSLCertificate"}: case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeSubnetwork"}: case schema.GroupKind{Group: "compute.cnrm.cloud.google.com", Kind: "ComputeTargetHTTPProxy"}: diff --git a/pkg/controller/direct/compute/forwardingrule_controller.go b/pkg/controller/direct/compute/forwardingrule_controller.go index 0e422d8c51..dc2da1d4c7 100644 --- a/pkg/controller/direct/compute/forwardingrule_controller.go +++ b/pkg/controller/direct/compute/forwardingrule_controller.go @@ -58,6 +58,7 @@ type forwardingRuleAdapter struct { globalForwardingRulesClient *gcp.GlobalForwardingRulesClient desired *krm.ComputeForwardingRule actual *computepb.ForwardingRule + reader client.Reader } var _ directbase.Adapter = &forwardingRuleAdapter{} @@ -80,109 +81,6 @@ func (m *forwardingRuleModel) AdapterForObject(ctx context.Context, reader clien return nil, err } - // Get network - if obj.Spec.NetworkRef != nil { - networkRef, err := ResolveComputeNetwork(ctx, reader, obj, obj.Spec.NetworkRef) - if err != nil { - return nil, err - - } - obj.Spec.NetworkRef.External = networkRef.External - } - - // Get subnetwork - if obj.Spec.SubnetworkRef != nil { - subnetworkRef, err := ResolveComputeSubnetwork(ctx, reader, obj, obj.Spec.SubnetworkRef) - if err != nil { - return nil, err - - } - obj.Spec.SubnetworkRef.External = subnetworkRef.External - } - - // Get backend service - if obj.Spec.BackendServiceRef != nil { - backendServiceRef, err := ResolveComputeBackendService(ctx, reader, obj, obj.Spec.BackendServiceRef) - if err != nil { - return nil, err - - } - obj.Spec.BackendServiceRef.External = backendServiceRef.External - } - - // Get ip address, ip address is optional - if obj.Spec.IpAddress != nil && obj.Spec.IpAddress.AddressRef != nil { - computeAddressRef, err := ResolveComputeAddress(ctx, reader, obj, obj.Spec.IpAddress.AddressRef) - if err != nil { - return nil, err - - } - obj.Spec.IpAddress.AddressRef.External = computeAddressRef.External - } - - // Get target, target is optional - if obj.Spec.Target != nil { - // Get target ServiceAttachment - if obj.Spec.Target.ServiceAttachmentRef != nil { - serviceAttachmentRef, err := ResolveComputeServiceAttachment(ctx, reader, obj, obj.Spec.Target.ServiceAttachmentRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.ServiceAttachmentRef.External = serviceAttachmentRef.External - } - - // Get target ComputeTargetHTTPProxy - if obj.Spec.Target.TargetHTTPProxyRef != nil { - targetHTTPProxyRef, err := ResolveComputeTargetHTTPProxy(ctx, reader, obj, obj.Spec.Target.TargetHTTPProxyRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.TargetHTTPProxyRef.External = targetHTTPProxyRef.External - } - - // Get target ComputeTargetHTTPSProxy - if obj.Spec.Target.TargetHTTPSProxyRef != nil { - targetHTTPSProxyRef, err := ResolveComputeTargetHTTPSProxy(ctx, reader, obj, obj.Spec.Target.TargetHTTPSProxyRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.TargetHTTPSProxyRef.External = targetHTTPSProxyRef.External - } - - // Get target TargetVPNGateway - if obj.Spec.Target.TargetVPNGatewayRef != nil { - targetVPNGatewayRef, err := ResolveComputeTargetVPNGateway(ctx, reader, obj, obj.Spec.Target.TargetVPNGatewayRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.TargetVPNGatewayRef.External = targetVPNGatewayRef.External - } - - // Get target SSLProxy - if obj.Spec.Target.TargetSSLProxyRef != nil { - targetSSLProxyRef, err := ResolveComputeTargetSSLProxy(ctx, reader, obj, obj.Spec.Target.TargetSSLProxyRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.TargetSSLProxyRef.External = targetSSLProxyRef.External - } - - // Get target TCPProxy - if obj.Spec.Target.TargetTCPProxyRef != nil { - targetTCPProxyRef, err := ResolveComputeTargetTCPProxy(ctx, reader, obj, obj.Spec.Target.TargetTCPProxyRef) - if err != nil { - return nil, err - - } - obj.Spec.Target.TargetTCPProxyRef.External = targetTCPProxyRef.External - } - } - // Get location location := obj.Spec.Location @@ -223,6 +121,7 @@ func (m *forwardingRuleModel) AdapterForObject(ctx context.Context, reader clien forwardingRuleAdapter := &forwardingRuleAdapter{ id: id, desired: obj, + reader: reader, } // Get GCP client @@ -274,6 +173,7 @@ func (a *forwardingRuleAdapter) Find(ctx context.Context) (bool, error) { func (a *forwardingRuleAdapter) Create(ctx context.Context, createOp *directbase.CreateOperation) error { u := createOp.GetUnstructured() + var err error if a.id.project == "" { return fmt.Errorf("project is empty") @@ -282,6 +182,11 @@ func (a *forwardingRuleAdapter) Create(ctx context.Context, createOp *directbase return fmt.Errorf("resourceID is empty") } + err = resolveDependencies(ctx, a.reader, a.desired) + if err != nil { + return err + } + log := klog.FromContext(ctx).WithName(ctrlName) log.V(2).Info("creating ComputeForwardingRule", "name", a.id.forwardingRule) mapCtx := &direct.MapContext{} @@ -296,7 +201,6 @@ func (a *forwardingRuleAdapter) Create(ctx context.Context, createOp *directbase forwardingRule.Labels = desired.Labels // Create forwarding rule(labels are not set during Insert) - var err error op := &gcp.Operation{} if a.id.location == "global" { req := &computepb.InsertGlobalForwardingRuleRequest{ @@ -362,11 +266,17 @@ func (a *forwardingRuleAdapter) Create(ctx context.Context, createOp *directbase func (a *forwardingRuleAdapter) Update(ctx context.Context, updateOp *directbase.UpdateOperation) error { u := updateOp.GetUnstructured() + var err error if a.id.forwardingRule == "" { return fmt.Errorf("resourceID is empty") } + err = resolveDependencies(ctx, a.reader, a.desired) + if err != nil { + return err + } + log := klog.FromContext(ctx).WithName(ctrlName) log.V(2).Info("updating ComputeForwardingRule", "name", a.id.forwardingRule) mapCtx := &direct.MapContext{} @@ -381,7 +291,6 @@ func (a *forwardingRuleAdapter) Update(ctx context.Context, updateOp *directbase // Patch only support update on networkTier field, which KCC does not support yet. // Use setTarget and setLabels to update target and labels fields. - var err error op := &gcp.Operation{} updated := &computepb.ForwardingRule{} if !reflect.DeepEqual(forwardingRule.Labels, a.actual.Labels) { diff --git a/pkg/controller/direct/compute/refs.go b/pkg/controller/direct/compute/refs.go index b4ad9d062d..77e3a07ef5 100644 --- a/pkg/controller/direct/compute/refs.go +++ b/pkg/controller/direct/compute/refs.go @@ -18,6 +18,8 @@ import ( "context" "fmt" + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/compute/v1beta1" + refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -521,3 +523,109 @@ func resolveResourceName(ctx context.Context, reader client.Reader, key client.O return resource, nil } + +func resolveDependencies(ctx context.Context, reader client.Reader, obj *krm.ComputeForwardingRule) error { + // Get network + if obj.Spec.NetworkRef != nil { + networkRef, err := ResolveComputeNetwork(ctx, reader, obj, obj.Spec.NetworkRef) + if err != nil { + return err + + } + obj.Spec.NetworkRef.External = networkRef.External + } + + // Get subnetwork + if obj.Spec.SubnetworkRef != nil { + subnetworkRef, err := ResolveComputeSubnetwork(ctx, reader, obj, obj.Spec.SubnetworkRef) + if err != nil { + return err + + } + obj.Spec.SubnetworkRef.External = subnetworkRef.External + } + + // Get backend service + if obj.Spec.BackendServiceRef != nil { + backendServiceRef, err := ResolveComputeBackendService(ctx, reader, obj, obj.Spec.BackendServiceRef) + if err != nil { + return err + + } + obj.Spec.BackendServiceRef.External = backendServiceRef.External + } + + // Get ip address, ip address is optional + if obj.Spec.IpAddress != nil && obj.Spec.IpAddress.AddressRef != nil { + computeAddressRef, err := ResolveComputeAddress(ctx, reader, obj, obj.Spec.IpAddress.AddressRef) + if err != nil { + return err + + } + obj.Spec.IpAddress.AddressRef.External = computeAddressRef.External + } + + // Get target, target is optional + if obj.Spec.Target != nil { + // Get target ServiceAttachment + if obj.Spec.Target.ServiceAttachmentRef != nil { + serviceAttachmentRef, err := ResolveComputeServiceAttachment(ctx, reader, obj, obj.Spec.Target.ServiceAttachmentRef) + if err != nil { + return err + + } + obj.Spec.Target.ServiceAttachmentRef.External = serviceAttachmentRef.External + } + + // Get target ComputeTargetHTTPProxy + if obj.Spec.Target.TargetHTTPProxyRef != nil { + targetHTTPProxyRef, err := ResolveComputeTargetHTTPProxy(ctx, reader, obj, obj.Spec.Target.TargetHTTPProxyRef) + if err != nil { + return err + + } + obj.Spec.Target.TargetHTTPProxyRef.External = targetHTTPProxyRef.External + } + + // Get target ComputeTargetHTTPSProxy + if obj.Spec.Target.TargetHTTPSProxyRef != nil { + targetHTTPSProxyRef, err := ResolveComputeTargetHTTPSProxy(ctx, reader, obj, obj.Spec.Target.TargetHTTPSProxyRef) + if err != nil { + return err + + } + obj.Spec.Target.TargetHTTPSProxyRef.External = targetHTTPSProxyRef.External + } + + // Get target TargetVPNGateway + if obj.Spec.Target.TargetVPNGatewayRef != nil { + targetVPNGatewayRef, err := ResolveComputeTargetVPNGateway(ctx, reader, obj, obj.Spec.Target.TargetVPNGatewayRef) + if err != nil { + return err + + } + obj.Spec.Target.TargetVPNGatewayRef.External = targetVPNGatewayRef.External + } + + // Get target SSLProxy + if obj.Spec.Target.TargetSSLProxyRef != nil { + targetSSLProxyRef, err := ResolveComputeTargetSSLProxy(ctx, reader, obj, obj.Spec.Target.TargetSSLProxyRef) + if err != nil { + return err + + } + obj.Spec.Target.TargetSSLProxyRef.External = targetSSLProxyRef.External + } + + // Get target TCPProxy + if obj.Spec.Target.TargetTCPProxyRef != nil { + targetTCPProxyRef, err := ResolveComputeTargetTCPProxy(ctx, reader, obj, obj.Spec.Target.TargetTCPProxyRef) + if err != nil { + return err + + } + obj.Spec.Target.TargetTCPProxyRef.External = targetTCPProxyRef.External + } + } + return nil +} diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalforwardingrulepsc/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalforwardingrulepsc/_http.log index 1ce772e0c4..32090f6413 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalforwardingrulepsc/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalforwardingrulepsc/_http.log @@ -506,7 +506,7 @@ X-Xss-Protection: 0 --- -GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -527,11 +527,11 @@ X-Xss-Protection: 0 "errors": [ { "domain": "global", - "message": "address \"projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}\" not found", + "message": "address \"projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}\" not found", "reason": "notFound" } ], - "message": "address \"projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}\" not found" + "message": "address \"projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}\" not found" } } @@ -574,8 +574,8 @@ X-Xss-Protection: 0 "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", "status": "RUNNING", - "targetId": "1725556260292294180", - "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "targetId": "${addressesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "user": "user@example.com" } @@ -607,14 +607,14 @@ X-Xss-Protection: 0 "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", "status": "DONE", - "targetId": "1725556260292294180", - "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "targetId": "${addressesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "user": "user@example.com" } --- -GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -641,13 +641,13 @@ X-Xss-Protection: 0 }, "name": "computeaddress-${uniqueId}", "region": "projects/${projectId}/global/regions/us-central1", - "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "subnetwork": "projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-1-${uniqueId}" } --- -POST https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}/setLabels?alt=json +POST https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}/setLabels?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -683,7 +683,7 @@ X-Xss-Protection: 0 --- -GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -710,7 +710,7 @@ X-Xss-Protection: 0 }, "name": "computeaddress-${uniqueId}", "region": "projects/${projectId}/global/regions/us-central1", - "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "subnetwork": "projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-1-${uniqueId}" } @@ -1275,11 +1275,11 @@ X-Xss-Protection: 0 "errors": [ { "domain": "global", - "message": "forwardingRule \"projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}\" not found", + "message": "The resource 'projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}' was not found", "reason": "notFound" } ], - "message": "forwardingRule \"projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}\" not found" + "message": "The resource 'projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}' was not found" } } @@ -1384,6 +1384,86 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 +{ + "IPProtocol": "TCP", + "allPorts": true, + "backendService": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/backendServices/computebackendservice-${uniqueId}", + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "A test forwarding rule with internal load balancing scheme", + "fingerprint": "abcdef0123A=", + "id": "000000000000000000000", + "kind": "compute#forwardingRule", + "labelFingerprint": "abcdef0123A=", + "loadBalancingScheme": "INTERNAL", + "name": "computeforwardingrule-1-${uniqueId}", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-2-${uniqueId}", + "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}", + "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-2-${uniqueId}" +} + +--- + +POST https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID}/setLabels +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&resource=computeforwardingrule-1-${uniqueId} + +{ + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "managed-by-cnrm": "true" + } +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "endTime": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "setLabels", + "progress": 100, + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&forwarding_rule=computeforwardingrule-1-${uniqueId} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + { "IPProtocol": "TCP", "allPorts": true, @@ -1402,6 +1482,7 @@ X-Xss-Protection: 0 "name": "computeforwardingrule-1-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-2-${uniqueId}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}", "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-2-${uniqueId}" } @@ -1571,11 +1652,11 @@ X-Xss-Protection: 0 "errors": [ { "domain": "global", - "message": "forwardingRule \"projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}\" not found", + "message": "The resource 'projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}' was not found", "reason": "notFound" } ], - "message": "forwardingRule \"projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}\" not found" + "message": "The resource 'projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}' was not found" } } @@ -1587,7 +1668,7 @@ User-Agent: kcc/controller-manager x-goog-request-params: project=${projectId}®ion=us-central1 { - "IPAddress": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", + "IPAddress": "8.8.8.8", "allowPscGlobalAccess": true, "description": "A VPC private service connect forwarding rule", "labels": { @@ -1682,7 +1763,7 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { - "IPAddress": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", + "IPAddress": "8.8.8.8", "IPProtocol": "TCP", "allowPscGlobalAccess": true, "creationTimestamp": "2024-04-01T12:34:56.123456Z", @@ -1691,15 +1772,11 @@ X-Xss-Protection: 0 "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", - "labels": { - "cnrm-test": "true", - "label-one": "value-one", - "managed-by-cnrm": "true" - }, "loadBalancingScheme": "", "name": "computeforwardingrule-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-1-${uniqueId}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-central1/serviceAttachments/computeserviceattachment-${uniqueId}" } @@ -1715,7 +1792,7 @@ x-goog-request-params: project=${projectId}®ion=us-central1&resource=computef "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", - "label-one": "value-two", + "label-one": "value-one", "managed-by-cnrm": "true" } } @@ -1737,12 +1814,12 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", - "operationType": "SetLabels", - "progress": 0, + "operationType": "setLabels", + "progress": 100, "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "RUNNING", + "status": "DONE", "targetId": "${forwardingRulesId}", "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}", "user": "user@example.com" @@ -1750,10 +1827,61 @@ X-Xss-Protection: 0 --- -GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID} +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} Content-Type: application/json User-Agent: kcc/controller-manager -x-goog-request-params: project=${projectId}®ion=us-central1&operation=${operationID} +x-goog-request-params: project=${projectId}®ion=us-central1&forwarding_rule=computeforwardingrule-${uniqueId} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "IPAddress": "8.8.8.8", + "IPProtocol": "TCP", + "allowPscGlobalAccess": true, + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "A VPC private service connect forwarding rule", + "fingerprint": "abcdef0123A=", + "id": "000000000000000000000", + "kind": "compute#forwardingRule", + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "label-one": "value-one", + "managed-by-cnrm": "true" + }, + "loadBalancingScheme": "", + "name": "computeforwardingrule-${uniqueId}", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-1-${uniqueId}", + "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}", + "target": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-central1/serviceAttachments/computeserviceattachment-${uniqueId}" +} + +--- + +POST https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID}/setLabels +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&resource=computeforwardingrule-${uniqueId} + +{ + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "label-one": "value-two", + "managed-by-cnrm": "true" + } +} 200 OK Cache-Control: private @@ -1772,7 +1900,7 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", - "operationType": "SetLabels", + "operationType": "setLabels", "progress": 100, "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", @@ -1802,7 +1930,7 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { - "IPAddress": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", + "IPAddress": "8.8.8.8", "IPProtocol": "TCP", "allowPscGlobalAccess": true, "creationTimestamp": "2024-04-01T12:34:56.123456Z", @@ -1820,6 +1948,7 @@ X-Xss-Protection: 0 "name": "computeforwardingrule-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-1-${uniqueId}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-central1/serviceAttachments/computeserviceattachment-${uniqueId}" } @@ -2059,6 +2188,7 @@ X-Xss-Protection: 0 "name": "computeforwardingrule-1-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/computenetwork-2-${uniqueId}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeforwardingrule-1-${uniqueId}", "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-2-${uniqueId}" } @@ -2501,7 +2631,7 @@ X-Xss-Protection: 0 --- -GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -2528,13 +2658,13 @@ X-Xss-Protection: 0 }, "name": "computeaddress-${uniqueId}", "region": "projects/${projectId}/global/regions/us-central1", - "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "subnetwork": "projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-1-${uniqueId}" } --- -DELETE https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/${networkID}?alt=json +DELETE https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}?alt=json Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -2560,8 +2690,8 @@ X-Xss-Protection: 0 "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", "status": "RUNNING", - "targetId": "1725556260292294180", - "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "targetId": "${addressesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "user": "user@example.com" } @@ -2593,8 +2723,8 @@ X-Xss-Protection: 0 "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", "status": "DONE", - "targetId": "1725556260292294180", - "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/networks/computeaddress-${uniqueId}", + "targetId": "${addressesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/addresses/computeaddress-${uniqueId}", "user": "user@example.com" } diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_generated_object_computeserviceattachment.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_generated_object_computeserviceattachment.golden.yaml index 87bf45bf95..91d53931e8 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_generated_object_computeserviceattachment.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_generated_object_computeserviceattachment.golden.yaml @@ -3,7 +3,7 @@ kind: ComputeServiceAttachment metadata: annotations: cnrm.cloud.google.com/management-conflict-prevention-policy: none - cnrm.cloud.google.com/state-into-spec: merge + cnrm.cloud.google.com/state-into-spec: absent finalizers: - cnrm.cloud.google.com/finalizer - cnrm.cloud.google.com/deletion-defender diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log index e747b74b14..557d759910 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log @@ -1077,11 +1077,11 @@ X-Xss-Protection: 0 "errors": [ { "domain": "global", - "message": "forwardingRule \"projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}\" not found", + "message": "The resource 'projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}' was not found", "reason": "notFound" } ], - "message": "forwardingRule \"projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}\" not found" + "message": "The resource 'projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}' was not found" } } @@ -1187,6 +1187,86 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 +{ + "IPProtocol": "TCP", + "allPorts": true, + "backendService": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/backendServices/computebackendservice-${uniqueId}", + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "A test forwarding rule with internal load balancing scheme", + "fingerprint": "abcdef0123A=", + "id": "000000000000000000000", + "kind": "compute#forwardingRule", + "labelFingerprint": "abcdef0123A=", + "loadBalancingScheme": "INTERNAL", + "name": "computeforwardingrule-${uniqueId}", + "network": "https://www.googleapis.com/compute/v1/projects/example-project-01/global/networks/${networkID}", + "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}", + "subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/subnetworks/computesubnetwork-3-${uniqueId}" +} + +--- + +POST https://compute.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/${forwardingRuleID}/setLabels +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: project=example-project-01®ion=us-west1&resource=computeforwardingrule-${uniqueId} + +{ + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "managed-by-cnrm": "true" + } +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "endTime": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "setLabels", + "progress": 100, + "region": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/${forwardingRuleID} +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: project=example-project-01®ion=us-west1&forwarding_rule=computeforwardingrule-${uniqueId} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + { "IPProtocol": "TCP", "allPorts": true, @@ -1205,6 +1285,7 @@ X-Xss-Protection: 0 "name": "computeforwardingrule-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/example-project-01/global/networks/${networkID}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}", "subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/subnetworks/computesubnetwork-3-${uniqueId}" } @@ -2191,6 +2272,7 @@ X-Xss-Protection: 0 "name": "computeforwardingrule-${uniqueId}", "network": "https://www.googleapis.com/compute/v1/projects/example-project-01/global/networks/${networkID}", "networkTier": "PREMIUM", + "region": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/forwardingRules/computeforwardingrule-${uniqueId}", "subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/subnetworks/computesubnetwork-3-${uniqueId}" }