diff --git a/config/tests/samples/create/harness.go b/config/tests/samples/create/harness.go index dfb441f5cf..e8683dd90d 100644 --- a/config/tests/samples/create/harness.go +++ b/config/tests/samples/create/harness.go @@ -674,7 +674,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/mockgcp/mockcompute/globalforwardingrulesv1.go b/mockgcp/mockcompute/globalforwardingrulesv1.go index a3111ddcda..355bd06ac0 100644 --- a/mockgcp/mockcompute/globalforwardingrulesv1.go +++ b/mockgcp/mockcompute/globalforwardingrulesv1.go @@ -120,7 +120,9 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob // output only field. This field is only used for internal load balancing. if obj.LoadBalancingScheme != nil && *obj.LoadBalancingScheme == "INTERNAL" { - obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.global.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Project.ID)) + if obj.ServiceLabel != nil { + obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.global.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Project.ID)) + } } if err := s.storage.Create(ctx, fqn, obj); err != nil { diff --git a/mockgcp/mockcompute/regionalforwardingrulev1.go b/mockgcp/mockcompute/regionalforwardingrulev1.go index 93dcef08a8..75b5f9c758 100644 --- a/mockgcp/mockcompute/regionalforwardingrulev1.go +++ b/mockgcp/mockcompute/regionalforwardingrulev1.go @@ -111,7 +111,9 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo 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" { - obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.%s.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Region, name.Project.ID)) + if obj.ServiceLabel != nil { + obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.%s.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Region, name.Project.ID)) + } } if err := s.storage.Create(ctx, fqn, obj); err != nil { diff --git a/pkg/controller/direct/compute/forwardingrule_controller.go b/pkg/controller/direct/compute/forwardingrule_controller.go index eed468167c..43cddc5168 100644 --- a/pkg/controller/direct/compute/forwardingrule_controller.go +++ b/pkg/controller/direct/compute/forwardingrule_controller.go @@ -79,6 +79,7 @@ type forwardingRuleAdapter struct { globalForwardingRulesClient *gcp.GlobalForwardingRulesClient desired *krm.ComputeForwardingRule actual *computepb.ForwardingRule + reader client.Reader } var _ directbase.Adapter = &forwardingRuleAdapter{} @@ -101,109 +102,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 compute address, 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 @@ -244,6 +142,7 @@ func (m *forwardingRuleModel) AdapterForObject(ctx context.Context, reader clien forwardingRuleAdapter := &forwardingRuleAdapter{ id: id, desired: obj, + reader: reader, } // Get GCP client @@ -295,6 +194,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") @@ -303,6 +203,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{} @@ -326,7 +231,6 @@ func (a *forwardingRuleAdapter) Create(ctx context.Context, createOp *directbase } // Create forwarding rule(labels are not set during Insert) - var err error op := &gcp.Operation{} if a.id.location == "global" { req := &computepb.InsertGlobalForwardingRuleRequest{ @@ -396,11 +300,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{} @@ -415,7 +325,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..d429432947 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,14 +1668,9 @@ 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": { - "cnrm-test": "true", - "label-one": "value-one", - "managed-by-cnrm": "true" - }, "loadBalancingScheme": "", "name": "computeforwardingrule-${uniqueId}", "network": "projects/${projectId}/global/networks/computenetwork-1-${uniqueId}", @@ -1682,7 +1758,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 +1767,10 @@ 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 +1786,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 +1808,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 +1821,60 @@ 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" + }, + "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 +1893,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 +1923,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", @@ -1816,10 +1937,10 @@ X-Xss-Protection: 0 "label-one": "value-two", "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}" } @@ -2059,6 +2180,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 +2623,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 +2650,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 +2682,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 +2715,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}" }