From c6132a4df23a128be39190cf64e0a0188a96bdfe Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Thu, 19 Sep 2024 22:11:12 +0000 Subject: [PATCH] update regional forwarding rule --- .../mockcompute/globalforwardingrulesv1.go | 46 +++ .../mockcompute/regionalforwardingrulev1.go | 49 ++- .../compute/forwardingrule_controller.go | 31 +- pkg/controller/direct/compute/refs.go | 27 +- ...ionalcomputeforwardingrulefull.golden.yaml | 11 +- .../_http.log | 306 ++++++------------ .../create.yaml | 7 +- .../dependencies.yaml | 30 +- .../update.yaml | 11 +- .../regionalforwardingrulepsc/_http.log | 2 +- .../computeserviceattachment/_http.log | 2 +- 11 files changed, 273 insertions(+), 249 deletions(-) diff --git a/mockgcp/mockcompute/globalforwardingrulesv1.go b/mockgcp/mockcompute/globalforwardingrulesv1.go index 355bd06ac0..9751bf1fd5 100644 --- a/mockgcp/mockcompute/globalforwardingrulesv1.go +++ b/mockgcp/mockcompute/globalforwardingrulesv1.go @@ -118,6 +118,14 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) } + if obj.Subnetwork != nil { + subnetworkName, err := s.parseSubnetName(obj.GetSubnetwork()) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "subnetwork %q is not valid", obj.GetSubnetwork()) + } + obj.Subnetwork = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", subnetworkName.Project.ID, subnetworkName.Region, subnetworkName.Name)) + } + // output only field. This field is only used for internal load balancing. if obj.LoadBalancingScheme != nil && *obj.LoadBalancingScheme == "INTERNAL" { if obj.ServiceLabel != nil { @@ -147,6 +155,44 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob }) } +func (s *GlobalForwardingRulesV1) Patch(ctx context.Context, req *pb.PatchGlobalForwardingRuleRequest) (*pb.Operation, error) { + reqName := "projects/" + req.GetProject() + "/global" + "/forwardingRules/" + req.GetForwardingRule() + name, err := s.parseGlobalForwardingRuleName(reqName) + if err != nil { + return nil, err + } + + fqn := name.String() + + obj := &pb.ForwardingRule{} + if err := s.storage.Get(ctx, fqn, obj); err != nil { + if status.Code(err) == codes.NotFound { + return nil, status.Errorf(codes.NotFound, "The resource '%s' was not found", fqn) + } + return nil, err + } + + proto.Merge(obj, req.GetForwardingRuleResource()) + // checked GCP log, when AllowGlobalAccess is false, the field will be ignored + if obj.AllowGlobalAccess != nil && *obj.AllowGlobalAccess == false { + obj.AllowGlobalAccess = nil + } + + if err := s.storage.Update(ctx, fqn, obj); err != nil { + return nil, err + } + + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("patch"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) +} + func (s *GlobalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteGlobalForwardingRuleRequest) (*pb.Operation, error) { reqName := "projects/" + req.GetProject() + "/global" + "/forwardingRules/" + req.GetForwardingRule() name, err := s.parseGlobalForwardingRuleName(reqName) diff --git a/mockgcp/mockcompute/regionalforwardingrulev1.go b/mockgcp/mockcompute/regionalforwardingrulev1.go index 75b5f9c758..8869ee984e 100644 --- a/mockgcp/mockcompute/regionalforwardingrulev1.go +++ b/mockgcp/mockcompute/regionalforwardingrulev1.go @@ -107,7 +107,15 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) } - // output only field. + if obj.Subnetwork != nil { + subnetworkName, err := s.parseSubnetName(obj.GetSubnetwork()) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "subnetwork %q is not valid", obj.GetSubnetwork()) + } + obj.Subnetwork = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", subnetworkName.Project.ID, subnetworkName.Region, subnetworkName.Name)) + } + + // output only fields obj.Region = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s", name.Project.ID, name.Region)) // output only field, this field is only used for internal load balancing. if obj.LoadBalancingScheme != nil && *obj.LoadBalancingScheme == "INTERNAL" { @@ -131,6 +139,45 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo }) } +func (s *RegionalForwardingRulesV1) Patch(ctx context.Context, req *pb.PatchForwardingRuleRequest) (*pb.Operation, error) { + reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/forwardingRules/" + req.GetForwardingRule() + name, err := s.parseRegionalForwardingRuleName(reqName) + if err != nil { + return nil, err + } + + fqn := name.String() + + obj := &pb.ForwardingRule{} + + if err := s.storage.Get(ctx, fqn, obj); err != nil { + if status.Code(err) == codes.NotFound { + return nil, status.Errorf(codes.NotFound, "The resource '%s' was not found", fqn) + } + return nil, err + } + + proto.Merge(obj, req.GetForwardingRuleResource()) + // checked GCP log, when AllowGlobalAccess is false, the field will be ignored + if obj.AllowGlobalAccess != nil && *obj.AllowGlobalAccess == false { + obj.AllowGlobalAccess = nil + } + + if err := s.storage.Update(ctx, fqn, obj); err != nil { + return nil, err + } + + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("patch"), + User: PtrTo("user@example.com"), + } + return s.startRegionalLRO(ctx, name.Project.ID, name.Region, op, func() (proto.Message, error) { + return obj, nil + }) +} + func (s *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteForwardingRuleRequest) (*pb.Operation, error) { reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/forwardingRules/" + req.GetForwardingRule() name, err := s.parseRegionalForwardingRuleName(reqName) diff --git a/pkg/controller/direct/compute/forwardingrule_controller.go b/pkg/controller/direct/compute/forwardingrule_controller.go index a91caba4cd..04a6c0d97e 100644 --- a/pkg/controller/direct/compute/forwardingrule_controller.go +++ b/pkg/controller/direct/compute/forwardingrule_controller.go @@ -323,10 +323,37 @@ func (a *forwardingRuleAdapter) Update(ctx context.Context, updateOp *directbase forwardingRule.Name = direct.LazyPtr(a.id.forwardingRule) forwardingRule.Labels = desired.Labels - // Patch only support update on networkTier field, which KCC does not support yet. - // Use setTarget and setLabels to update target and labels fields. op := &gcp.Operation{} updated := &computepb.ForwardingRule{} + if !reflect.DeepEqual(forwardingRule.AllowGlobalAccess, a.actual.AllowGlobalAccess) { + // To match the request body in TF-controller log + // https://github.com/hashicorp/terraform-provider-google/blob/main/google/services/compute/resource_compute_forwarding_rule.go#L1151 + reqBody := &computepb.ForwardingRule{AllowGlobalAccess: forwardingRule.AllowGlobalAccess} + if a.id.location == "global" { + // TF does not support allowGlobalAccess field for global forwarding rule + // Underlying API as well, error message: `Field allow-global-access is only supported for regional INTERNAL + // forwarding rules with backend service/target instance or regional INTERNAL_MANAGED forwarding rules.` + forwardingRule.AllowGlobalAccess = nil + } else { + patchReq := &computepb.PatchForwardingRuleRequest{ + ForwardingRule: a.id.forwardingRule, + ForwardingRuleResource: reqBody, + Project: a.id.project, + Region: a.id.location, + } + op, err = a.forwardingRulesClient.Patch(ctx, patchReq) + } + if err != nil { + return fmt.Errorf("updating ComputeForwardingRule %s: %w", a.fullyQualifiedName(), err) + } + err = op.Wait(ctx) + if err != nil { + return fmt.Errorf("waiting ComputeForwardingRule %s update failed: %w", a.fullyQualifiedName(), err) + } + log.V(2).Info("successfully updated ComputeForwardingRule", "name", a.fullyQualifiedName()) + } + + // Use setTarget and setLabels to update target and labels fields. if !reflect.DeepEqual(forwardingRule.Labels, a.actual.Labels) { op, err := a.setLabels(ctx, a.actual.LabelFingerprint, forwardingRule.Labels) if err != nil { diff --git a/pkg/controller/direct/compute/refs.go b/pkg/controller/direct/compute/refs.go index 77e3a07ef5..8ec36dfe40 100644 --- a/pkg/controller/direct/compute/refs.go +++ b/pkg/controller/direct/compute/refs.go @@ -73,8 +73,7 @@ func ResolveComputeNetwork(ctx context.Context, reader client.Reader, src client return nil, err } - // targetField: self_link - // See compute servicemappings for details + // convert to format `projects//global/networks/` return &refs.ComputeNetworkRef{ External: fmt.Sprintf("projects/%s/global/networks/%s", projectID, resourceID)}, nil } @@ -111,14 +110,26 @@ func ResolveComputeSubnetwork(ctx context.Context, reader client.Reader, src cli if err != nil { return nil, err } - // targetField: self_link - // See compute servicemappings for details - selfLink, _, err := unstructured.NestedString(computeSubnetwork.Object, "status", "selfLink") - if err != nil || selfLink == "" { - return nil, fmt.Errorf("cannot get selfLink for referenced %s %v (status.selfLink is empty)", computeSubnetwork.GetKind(), computeSubnetwork.GetNamespace()) + + resourceID, err := refs.GetResourceID(computeSubnetwork) + if err != nil { + return nil, err } + + projectID, err := refs.ResolveProjectID(ctx, reader, computeSubnetwork) + if err != nil { + return nil, err + } + + region, _, _ := unstructured.NestedString(computeSubnetwork.Object, "spec", "region") + if region == "" { + return nil, fmt.Errorf("cannot get region from references ComputeSubnetwork %v: %w", key, err) + } + + // convert to format `projects//regions//subnetworks/` return &refs.ComputeSubnetworkRef{ - External: selfLink}, nil + External: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", projectID, region, resourceID), + }, nil } func ResolveComputeAddress(ctx context.Context, reader client.Reader, src client.Object, ref *refs.ComputeAddressRef) (*refs.ComputeAddressRef, error) { diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_generated_object_regionalcomputeforwardingrulefull.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_generated_object_regionalcomputeforwardingrulefull.golden.yaml index 944c69c590..ae16f67c04 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_generated_object_regionalcomputeforwardingrulefull.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_generated_object_regionalcomputeforwardingrulefull.golden.yaml @@ -7,15 +7,15 @@ metadata: finalizers: - cnrm.cloud.google.com/finalizer - cnrm.cloud.google.com/deletion-defender - generation: 1 + generation: 2 labels: cnrm-test: "true" - label-one: value-one + label-one: value-two name: computeregionalforwardingrule-${uniqueId} namespace: ${uniqueId} spec: allPorts: true - allowGlobalAccess: true + allowGlobalAccess: false backendServiceRef: name: computebackendservice-${uniqueId} description: A regional forwarding rule @@ -29,9 +29,6 @@ spec: networkRef: name: customnetwork networkTier: PREMIUM - serviceDirectoryRegistrations: - - namespace: sd-namespace - service: sd-service serviceLabel: label subnetworkRef: name: customsubnetwork @@ -45,5 +42,5 @@ status: creationTimestamp: "1970-01-01T00:00:00Z" externalRef: //compute.googleapis.com/projects/${projectId}/regions/us-central1/forwardingrules/computeregionalforwardingrule-${uniqueId} labelFingerprint: abcdef0123A= - observedGeneration: 1 + observedGeneration: 2 selfLink: https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId} diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_http.log index 63367e72c8..014339eaa7 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/_http.log @@ -504,170 +504,6 @@ X-Xss-Protection: 0 --- -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace?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 - -404 Not Found -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 - -{ - "error": { - "code": 404, - "message": "Resource 'projects/${projectId}/locations/us-central1/namespaces/sd-namespace' was not found", - "status": "NOT_FOUND" - } -} - ---- - -POST https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces?alt=json&namespaceId=sd-namespace -Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager - -{ - "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 - -{ - "labels": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace" -} - ---- - -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace?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 - -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 - -{ - "labels": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace" -} - ---- - -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service?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 - -404 Not Found -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 - -{ - "error": { - "code": 404, - "message": "Resource 'projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service' was not found", - "status": "NOT_FOUND" - } -} - ---- - -POST https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services?alt=json&serviceId=sd-service -Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager - -{ - "metadata": { - "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 - -{ - "metadata": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service" -} - ---- - -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service?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 - -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 - -{ - "metadata": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service" -} - ---- - GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} Content-Type: application/json User-Agent: kcc/controller-manager @@ -723,14 +559,8 @@ x-goog-request-params: project=${projectId}®ion=us-central1 "name": "computeregionalforwardingrule-${uniqueId}", "network": "projects/${projectId}/global/networks/${networkID}", "networkTier": "PREMIUM", - "serviceDirectoryRegistrations": [ - { - "namespace": "sd-namespace", - "service": "sd-service" - } - ], "serviceLabel": "label", - "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/${subnetworkID}" + "subnetwork": "projects/${projectId}/regions/us-central1/subnetworks/${subnetworkID}" } 200 OK @@ -833,12 +663,6 @@ X-Xss-Protection: 0 "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/computeregionalforwardingrule-${uniqueId}", - "serviceDirectoryRegistrations": [ - { - "namespace": "sd-namespace", - "service": "sd-service" - } - ], "serviceLabel": "label", "serviceName": "label.computeregionalforwardingrule-${uniqueId}.il4.us-central1.lb.${projectId}.internal", "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/${subnetworkID}" @@ -931,12 +755,6 @@ X-Xss-Protection: 0 "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/computeregionalforwardingrule-${uniqueId}", - "serviceDirectoryRegistrations": [ - { - "namespace": "sd-namespace", - "service": "sd-service" - } - ], "serviceLabel": "label", "serviceName": "label.computeregionalforwardingrule-${uniqueId}.il4.us-central1.lb.${projectId}.internal", "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/${subnetworkID}" @@ -944,11 +762,15 @@ X-Xss-Protection: 0 --- -DELETE https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} +PATCH 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=computeregionalforwardingrule-${uniqueId} +{ + "allowGlobalAccess": false +} + 200 OK Cache-Control: private Content-Type: application/json; charset=UTF-8 @@ -965,7 +787,7 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", - "operationType": "delete", + "operationType": "patch", "progress": 0, "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}", @@ -1000,7 +822,7 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", - "operationType": "delete", + "operationType": "patch", "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}", @@ -1013,9 +835,19 @@ X-Xss-Protection: 0 --- -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service?alt=json +POST https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID}/setLabels Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&resource=computeregionalforwardingrule-${uniqueId} + +{ + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "label-one": "value-two", + "managed-by-cnrm": "true" + } +} 200 OK Cache-Control: private @@ -1029,18 +861,28 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { - "metadata": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service" + "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/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- -DELETE https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace/services/sd-service?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&forwarding_rule=computeregionalforwardingrule-${uniqueId} 200 OK Cache-Control: private @@ -1053,13 +895,41 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 -{} +{ + "IPAddress": "8.8.8.8", + "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 regional forwarding rule", + "fingerprint": "abcdef0123A=", + "id": "000000000000000000000", + "ipVersion": "IPV4", + "isMirroringCollector": true, + "kind": "compute#forwardingRule", + "labelFingerprint": "abcdef0123A=", + "labels": { + "cnrm-test": "true", + "label-one": "value-two", + "managed-by-cnrm": "true" + }, + "loadBalancingScheme": "INTERNAL", + "name": "computeregionalforwardingrule-${uniqueId}", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/${networkID}", + "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/computeregionalforwardingrule-${uniqueId}", + "serviceLabel": "label", + "serviceName": "label.computeregionalforwardingrule-${uniqueId}.il4.us-central1.lb.${projectId}.internal", + "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/${subnetworkID}" +} --- -GET https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace?alt=json +DELETE https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/${forwardingRuleID} Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&forwarding_rule=computeregionalforwardingrule-${uniqueId} 200 OK Cache-Control: private @@ -1073,18 +943,27 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { - "labels": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "name": "projects/${projectId}/locations/us-central1/namespaces/sd-namespace" + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "delete", + "progress": 0, + "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", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- -DELETE https://servicedirectory.googleapis.com/v1beta1/projects/${projectId}/locations/us-central1/namespaces/sd-namespace?alt=json +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/operations/${operationID} Content-Type: application/json -User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager +User-Agent: kcc/controller-manager +x-goog-request-params: project=${projectId}®ion=us-central1&operation=${operationID} 200 OK Cache-Control: private @@ -1097,7 +976,22 @@ 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": "delete", + "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/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" +} --- diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/create.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/create.yaml index e9d05324e0..16c5adffbc 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/create.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/create.yaml @@ -36,7 +36,8 @@ spec: name: computebackendservice-${uniqueId} ipAddress: ip: "10.128.8.8" - serviceDirectoryRegistrations: - - namespace: "sd-namespace" - service: "sd-service" +# Patch operation is not allowed on Forwarding Rule that integrates with Service Directory Registrations +# serviceDirectoryRegistrations: +# - namespace: "sd-namespace" +# service: "sd-service" serviceLabel: "label" diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/dependencies.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/dependencies.yaml index 032a65f1d2..f471ef8672 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/dependencies.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/dependencies.yaml @@ -49,18 +49,18 @@ metadata: name: computebackendservice-2-${uniqueId} spec: location: "us-central1" ---- -apiVersion: servicedirectory.cnrm.cloud.google.com/v1beta1 -kind: ServiceDirectoryNamespace -metadata: - name: sd-namespace -spec: - location: us-central1 ---- -apiVersion: servicedirectory.cnrm.cloud.google.com/v1beta1 -kind: ServiceDirectoryService -metadata: - name: sd-service -spec: - namespaceRef: - name: sd-namespace +#--- +#apiVersion: servicedirectory.cnrm.cloud.google.com/v1beta1 +#kind: ServiceDirectoryNamespace +#metadata: +# name: sd-namespace +#spec: +# location: us-central1 +#--- +#apiVersion: servicedirectory.cnrm.cloud.google.com/v1beta1 +#kind: ServiceDirectoryService +#metadata: +# name: sd-service +#spec: +# namespaceRef: +# name: sd-namespace diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/update.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/update.yaml index e9d05324e0..4a97b9e1f1 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/update.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrulefull/update.yaml @@ -16,11 +16,11 @@ apiVersion: compute.cnrm.cloud.google.com/v1beta1 kind: ComputeForwardingRule metadata: labels: - label-one: "value-one" + label-one: "value-two" name: computeregionalforwardingrule-${uniqueId} spec: description: "A regional forwarding rule" - allowGlobalAccess: true + allowGlobalAccess: false loadBalancingScheme: INTERNAL isMirroringCollector: true allPorts: true @@ -36,7 +36,8 @@ spec: name: computebackendservice-${uniqueId} ipAddress: ip: "10.128.8.8" - serviceDirectoryRegistrations: - - namespace: "sd-namespace" - service: "sd-service" +# Patch operation is not allowed on Forwarding Rule that integrates with Service Directory Registrations +# serviceDirectoryRegistrations: +# - namespace: "sd-namespace" +# service: "sd-service" serviceLabel: "label" 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 d429432947..003290b713 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 @@ -1301,7 +1301,7 @@ x-goog-request-params: project=${projectId}®ion=us-central1 "loadBalancingScheme": "INTERNAL", "name": "computeforwardingrule-1-${uniqueId}", "network": "projects/${projectId}/global/networks/computenetwork-2-${uniqueId}", - "subnetwork": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-2-${uniqueId}" + "subnetwork": "projects/${projectId}/regions/us-central1/subnetworks/computesubnetwork-2-${uniqueId}" } 200 OK 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 557d759910..bcadc87fba 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeserviceattachment/_http.log @@ -1104,7 +1104,7 @@ x-goog-request-params: project=example-project-01®ion=us-west1 "name": "computeforwardingrule-${uniqueId}", "network": "projects/example-project-01/global/networks/${networkID}", "networkTier": "PREMIUM", - "subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project-01/regions/us-west1/subnetworks/computesubnetwork-3-${uniqueId}" + "subnetwork": "projects/example-project-01/regions/us-west1/subnetworks/computesubnetwork-3-${uniqueId}" } 200 OK