diff --git a/mockgcp/mockcompute/globaladdress.go b/mockgcp/mockcompute/globaladdress.go index ecceffa507..4ba0fb9012 100644 --- a/mockgcp/mockcompute/globaladdress.go +++ b/mockgcp/mockcompute/globaladdress.go @@ -65,7 +65,9 @@ func (s *GlobalAddressesV1) Insert(ctx context.Context, req *pb.InsertGlobalAddr obj.Id = &id obj.Kind = PtrTo("compute#address") obj.Address = PtrTo("8.8.8.8") - obj.LabelFingerprint = PtrTo("abcdef0123A=") + if obj.LabelFingerprint == nil { + obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) + } if err := s.storage.Create(ctx, fqn, obj); err != nil { return nil, err diff --git a/mockgcp/mockcompute/globalforwardingrulesv1.go b/mockgcp/mockcompute/globalforwardingrulesv1.go index a1f1e9c52e..5338e34d26 100644 --- a/mockgcp/mockcompute/globalforwardingrulesv1.go +++ b/mockgcp/mockcompute/globalforwardingrulesv1.go @@ -16,6 +16,7 @@ package mockcompute import ( "context" + "fmt" "strings" "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" @@ -63,13 +64,53 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob obj.CreationTimestamp = PtrTo(s.nowString()) obj.Id = &id obj.Kind = PtrTo("compute#forwardingRule") - obj.LabelFingerprint = PtrTo("abcdef0123A=") + // If below values are not provided by user, it appears to default by GCP + if obj.LabelFingerprint == nil { + obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) + } + if obj.Fingerprint == nil { + obj.Fingerprint = PtrTo(computeFingerprint(obj)) + } + if obj.IPProtocol == nil { + obj.IPProtocol = PtrTo("TCP") + } + if obj.NetworkTier == nil { + obj.NetworkTier = PtrTo("PREMIUM") + } + + // pattern: \d+(?:-\d+)? + if obj.PortRange != nil { + r := obj.GetPortRange() + token := strings.Split(r, "-") + if len(token) == 1 { + obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[0])) + } else if len(token) == 2 { + obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[1])) + } else { + return nil, status.Errorf(codes.InvalidArgument, "portRange %s is not valid", obj.GetPortRange()) + } + } + if obj.Network != nil { + networkName, err := s.parseNetworkName(obj.GetNetwork()) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "network %q is not valid", obj.GetNetwork()) + } + obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) + } if err := s.storage.Create(ctx, fqn, obj); err != nil { return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("insert"), + 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) { @@ -86,7 +127,15 @@ func (s *GlobalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteGlob return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: deleted.Id, + TargetLink: deleted.SelfLink, + OperationType: PtrTo("delete"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return deleted, nil + }) } func (s *GlobalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabelsGlobalForwardingRuleRequest) (*pb.Operation, error) { @@ -108,7 +157,17 @@ func (s *GlobalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabe return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("SetLabels"), + User: PtrTo("user@example.com"), + // SetLabels operation has EndTime in response + EndTime: PtrTo("2024-04-01T12:34:56.123456Z"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) } func (s *GlobalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTargetGlobalForwardingRuleRequest) (*pb.Operation, error) { @@ -130,7 +189,15 @@ func (s *GlobalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTarg return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("SetTarget"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) } type globalForwardingRuleName struct { diff --git a/mockgcp/mockcompute/instancesv1.go b/mockgcp/mockcompute/instancesv1.go index fdf3608429..e5309e04ef 100644 --- a/mockgcp/mockcompute/instancesv1.go +++ b/mockgcp/mockcompute/instancesv1.go @@ -66,6 +66,9 @@ func (s *InstancesV1) Insert(ctx context.Context, req *pb.InsertInstanceRequest) obj.Kind = PtrTo("compute#instance") obj.Zone = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s", name.Project.ID, name.Zone)) obj.Status = PtrTo("RUNNING") + if obj.LabelFingerprint == nil { + obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) + } // if obj.MachineType == nil { // machineType := "pd-standard" // obj.MachineType = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/machineTypes/%s", name.Project.ID, name.Zone, machineType)) diff --git a/mockgcp/mockcompute/regionalforwardingrulev1.go b/mockgcp/mockcompute/regionalforwardingrulev1.go index 62bd91ebd8..14d7ef5a8a 100644 --- a/mockgcp/mockcompute/regionalforwardingrulev1.go +++ b/mockgcp/mockcompute/regionalforwardingrulev1.go @@ -16,6 +16,7 @@ package mockcompute import ( "context" + "fmt" "strings" "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" @@ -63,13 +64,54 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo obj.CreationTimestamp = PtrTo(s.nowString()) obj.Id = &id obj.Kind = PtrTo("compute#forwardingRule") - obj.LabelFingerprint = PtrTo("abcdef0123A=") + // If below values are not provided by user, it appears to default by GCP + if obj.LabelFingerprint == nil { + obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) + } + if obj.Fingerprint == nil { + obj.Fingerprint = PtrTo(computeFingerprint(obj)) + } + if obj.IPProtocol == nil { + obj.IPProtocol = PtrTo("TCP") + } + if obj.NetworkTier == nil { + obj.NetworkTier = PtrTo("PREMIUM") + } + + // pattern: \d+(?:-\d+)? + if obj.PortRange != nil { + r := obj.GetPortRange() + token := strings.Split(r, "-") + if len(token) == 1 { + obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[0])) + } else if len(token) == 2 { + obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[1])) + } else { + return nil, status.Errorf(codes.InvalidArgument, "portRange %s is not valid", obj.GetPortRange()) + } + } + + if obj.Network != nil { + networkName, err := s.parseNetworkName(obj.GetNetwork()) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "network %q is not valid", obj.GetNetwork()) + } + obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) + } if err := s.storage.Create(ctx, fqn, obj); err != nil { return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("insert"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) } func (s *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteForwardingRuleRequest) (*pb.Operation, error) { @@ -86,7 +128,15 @@ func (s *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteFo return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: deleted.Id, + TargetLink: deleted.SelfLink, + OperationType: PtrTo("delete"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return deleted, nil + }) } func (s *RegionalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabelsForwardingRuleRequest) (*pb.Operation, error) { @@ -108,7 +158,17 @@ func (s *RegionalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLa return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("SetLabels"), + User: PtrTo("user@example.com"), + // SetLabels operation has EndTime in response + EndTime: PtrTo("2024-04-01T12:34:56.123456Z"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) } func (s *RegionalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTargetForwardingRuleRequest) (*pb.Operation, error) { @@ -130,7 +190,15 @@ func (s *RegionalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTa return nil, err } - return s.newLRO(ctx, name.Project.ID) + op := &pb.Operation{ + TargetId: obj.Id, + TargetLink: obj.SelfLink, + OperationType: PtrTo("SetTarget"), + User: PtrTo("user@example.com"), + } + return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { + return obj, nil + }) } type regionalForwardingRuleName struct { diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeaddress/regionalcomputeaddress/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeaddress/regionalcomputeaddress/_http.log index 1e8c2e16bc..74f37a8338 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeaddress/regionalcomputeaddress/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeaddress/regionalcomputeaddress/_http.log @@ -470,7 +470,7 @@ Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { - "labelFingerprint": "", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "managed-by-cnrm": "true" diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_generated_object_globalcomputeforwardingrule.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_generated_object_globalcomputeforwardingrule.golden.yaml index 7dbc69d9e4..ef5044232e 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_generated_object_globalcomputeforwardingrule.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_generated_object_globalcomputeforwardingrule.golden.yaml @@ -32,6 +32,7 @@ spec: description: A global forwarding rule ipAddress: ip: 0.0.0.0 + ipProtocol: TCP loadBalancingScheme: INTERNAL_SELF_MANAGED location: global networkRef: diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_http.log index abb169c3a0..0f920030c8 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/globalcomputeforwardingrule/_http.log @@ -775,10 +775,46 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", + "operationType": "insert", "progress": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "endTime": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "insert", + "progress": 100, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- @@ -800,8 +836,10 @@ X-Xss-Protection: 0 { "IPAddress": "0.0.0.0", + "IPProtocol": "TCP", "creationTimestamp": "2024-04-01T12:34:56.123456Z", "description": "A global forwarding rule", + "fingerprint": "abcdef0123A=", "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", @@ -812,8 +850,9 @@ X-Xss-Protection: 0 }, "loadBalancingScheme": "INTERNAL_SELF_MANAGED", "name": "computeglobalforwardingrule-${uniqueId}", - "network": "projects/${projectId}/global/networks/${networkID}", - "portRange": "80", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/${networkID}", + "networkTier": "PREMIUM", + "portRange": "80-80", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/targetHttpProxies/computetargethttpproxy-${uniqueId}" } @@ -845,14 +884,51 @@ 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": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "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, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- @@ -874,8 +950,10 @@ X-Xss-Protection: 0 { "IPAddress": "0.0.0.0", + "IPProtocol": "TCP", "creationTimestamp": "2024-04-01T12:34:56.123456Z", "description": "A global forwarding rule", + "fingerprint": "abcdef0123A=", "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", @@ -886,8 +964,9 @@ X-Xss-Protection: 0 }, "loadBalancingScheme": "INTERNAL_SELF_MANAGED", "name": "computeglobalforwardingrule-${uniqueId}", - "network": "projects/${projectId}/global/networks/${networkID}", - "portRange": "80", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/${networkID}", + "networkTier": "PREMIUM", + "portRange": "80-80", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/targetHttpProxies/computetargethttpproxy-${uniqueId}" } @@ -918,10 +997,46 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", + "operationType": "SetTarget", "progress": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "endTime": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "SetTarget", + "progress": 100, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- @@ -943,8 +1058,10 @@ X-Xss-Protection: 0 { "IPAddress": "0.0.0.0", + "IPProtocol": "TCP", "creationTimestamp": "2024-04-01T12:34:56.123456Z", "description": "A global forwarding rule", + "fingerprint": "abcdef0123A=", "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", @@ -955,8 +1072,9 @@ X-Xss-Protection: 0 }, "loadBalancingScheme": "INTERNAL_SELF_MANAGED", "name": "computeglobalforwardingrule-${uniqueId}", - "network": "projects/${projectId}/global/networks/${networkID}", - "portRange": "80", + "network": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/networks/${networkID}", + "networkTier": "PREMIUM", + "portRange": "80-80", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/targetHttpProxies/computetargethttpproxy-2-${uniqueId}" } @@ -983,10 +1101,46 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", + "operationType": "delete", "progress": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "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, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId}", + "user": "user@example.com" } --- diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_generated_object_regionalcomputeforwardingrule.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_generated_object_regionalcomputeforwardingrule.golden.yaml index 6fcd63673a..496880bf44 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_generated_object_regionalcomputeforwardingrule.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_generated_object_regionalcomputeforwardingrule.golden.yaml @@ -36,6 +36,7 @@ spec: ipProtocol: ESP loadBalancingScheme: EXTERNAL location: us-central1 + networkTier: PREMIUM resourceID: computeregionalforwardingrule-${uniqueId} target: targetVPNGatewayRef: diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_http.log index 6560b8084f..62799c2fde 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeforwardingrule/regionalcomputeforwardingrule/_http.log @@ -106,7 +106,7 @@ Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { - "labelFingerprint": "", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-one", @@ -548,10 +548,46 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", + "operationType": "insert", "progress": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "endTime": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "insert", + "progress": 100, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/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" } --- @@ -576,6 +612,7 @@ X-Xss-Protection: 0 "IPProtocol": "ESP", "creationTimestamp": "2024-04-01T12:34:56.123456Z", "description": "A regional forwarding rule", + "fingerprint": "abcdef0123A=", "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", @@ -586,6 +623,7 @@ X-Xss-Protection: 0 }, "loadBalancingScheme": "EXTERNAL", "name": "computeregionalforwardingrule-${uniqueId}", + "networkTier": "PREMIUM", "region": "projects/${projectId}/global/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/targetVpnGateways/computetargetvpngateway-${uniqueId}" @@ -618,14 +656,51 @@ 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": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "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, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/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" } --- @@ -650,6 +725,7 @@ X-Xss-Protection: 0 "IPProtocol": "ESP", "creationTimestamp": "2024-04-01T12:34:56.123456Z", "description": "A regional forwarding rule", + "fingerprint": "abcdef0123A=", "id": "000000000000000000000", "kind": "compute#forwardingRule", "labelFingerprint": "abcdef0123A=", @@ -660,6 +736,7 @@ X-Xss-Protection: 0 }, "loadBalancingScheme": "EXTERNAL", "name": "computeregionalforwardingrule-${uniqueId}", + "networkTier": "PREMIUM", "region": "projects/${projectId}/global/regions/us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", "target": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/targetVpnGateways/computetargetvpngateway-${uniqueId}" @@ -687,10 +764,46 @@ X-Xss-Protection: 0 "insertTime": "2024-04-01T12:34:56.123456Z", "kind": "compute#operation", "name": "${operationID}", + "operationType": "delete", "progress": 0, "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", "startTime": "2024-04-01T12:34:56.123456Z", - "status": "DONE" + "status": "RUNNING", + "targetId": "${forwardingRulesId}", + "targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/forwardingRules/computeregionalforwardingrule-${uniqueId}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 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 + +{ + "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, + "selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/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/computeinstance/computeinstancebasicexample/_generated_object_computeinstancebasicexample.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_generated_object_computeinstancebasicexample.golden.yaml index feb32cbeeb..a07410e9e0 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_generated_object_computeinstancebasicexample.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_generated_object_computeinstancebasicexample.golden.yaml @@ -84,5 +84,6 @@ status: type: Ready currentStatus: RUNNING instanceId: "1111111111111111" + labelFingerprint: abcdef0123A= observedGeneration: 4 selfLink: https://www.googleapis.com/compute/v1/projects/${projectId}/zones/us-west1-a/instances/computeinstance-${uniqueId} diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_http.log index 378e107019..e8a82dde91 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancebasicexample/_http.log @@ -674,7 +674,7 @@ Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { - "labelFingerprint": "", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "managed-by-cnrm": "true" @@ -844,7 +844,7 @@ Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { - "labelFingerprint": "", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "managed-by-cnrm": "true" @@ -1093,6 +1093,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-one", @@ -1218,6 +1219,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-one", @@ -1343,6 +1345,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-one", @@ -1468,6 +1471,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-one", @@ -1532,6 +1536,7 @@ Content-Type: application/json User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-two", @@ -1689,6 +1694,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-two", @@ -1807,6 +1813,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-two", @@ -1932,6 +1939,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-two", @@ -2057,6 +2065,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "label-one": "value-two", diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_generated_object_computeinstancewithencrypteddisk.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_generated_object_computeinstancewithencrypteddisk.golden.yaml index e5f6a9c9b3..4481e3f32a 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_generated_object_computeinstancewithencrypteddisk.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_generated_object_computeinstancewithencrypteddisk.golden.yaml @@ -64,5 +64,6 @@ status: type: Ready currentStatus: RUNNING instanceId: "1111111111111111" + labelFingerprint: abcdef0123A= observedGeneration: 2 selfLink: https://www.googleapis.com/compute/v1/projects/${projectId}/zones/us-west1-a/instances/computeinstance-${uniqueId} diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_http.log index 0206871167..2cf03e5524 100644 --- a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computeinstance/computeinstancewithencrypteddisk/_http.log @@ -535,6 +535,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "env": "test", @@ -632,6 +633,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "env": "test", @@ -729,6 +731,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "env": "test", @@ -826,6 +829,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "env": "test", diff --git a/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_generated_object_networkipcomputeinstance.golden.yaml b/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_generated_object_networkipcomputeinstance.golden.yaml index c8ba7e6af7..b980db6484 100644 --- a/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_generated_object_networkipcomputeinstance.golden.yaml +++ b/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_generated_object_networkipcomputeinstance.golden.yaml @@ -60,5 +60,6 @@ status: type: Ready currentStatus: RUNNING instanceId: "1111111111111111" + labelFingerprint: abcdef0123A= observedGeneration: 4 selfLink: https://www.googleapis.com/compute/v1/projects/${projectId}/zones/us-central1-a/instances/computeinstance-${uniqueId} diff --git a/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_http.log b/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_http.log index bd3cf48c4f..ab7b4ad260 100644 --- a/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_http.log +++ b/pkg/test/resourcefixture/testdata/resourceoverrides/computeinstance/networkipcomputeinstance/_http.log @@ -568,6 +568,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "created-from": "image", @@ -606,6 +607,7 @@ Content-Type: application/json User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "created-from": "image-2", @@ -668,6 +670,7 @@ X-Xss-Protection: 0 ], "id": "000000000000000000000", "kind": "compute#instance", + "labelFingerprint": "abcdef0123A=", "labels": { "cnrm-test": "true", "created-from": "image-2", diff --git a/tests/e2e/normalize.go b/tests/e2e/normalize.go index bbed4cc68c..daf0e0898f 100644 --- a/tests/e2e/normalize.go +++ b/tests/e2e/normalize.go @@ -118,6 +118,7 @@ func normalizeKRMObject(u *unstructured.Unstructured, project testgcp.GCPProject visitor.replacePaths[".status.gatewayId"] = 1111111111111111 visitor.replacePaths[".status.proxyId"] = 1111111111111111 visitor.replacePaths[".status.mapId"] = 1111111111111111 + visitor.replacePaths[".status.labelFingerprint"] = "abcdef0123A=" // Specific to MonitoringDashboard visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { diff --git a/tests/e2e/unified_test.go b/tests/e2e/unified_test.go index febac6e36c..71edacaa4e 100644 --- a/tests/e2e/unified_test.go +++ b/tests/e2e/unified_test.go @@ -397,28 +397,6 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso } } - // Extract resource numbers from compute operations - for _, event := range events { - body := event.Response.ParseBody() - - targetLink, _, _ := unstructured.NestedString(body, "targetLink") - targetId, _, _ := unstructured.NestedString(body, "targetId") - - if targetLink != "" && targetId != "" { - tokens := strings.Split(targetLink, "/") - n := len(tokens) - if n >= 2 { - kind := tokens[n-2] - switch kind { - case "subnetworks": - r.PathIDs[targetId] = "${subnetworkNumber}" - case "sslCertificates": - r.PathIDs[targetId] = "${sslCertificatesId}" - } - } - } - } - // Replace any operation IDs that appear in URLs for _, event := range events { u := event.Request.URL @@ -533,10 +511,43 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso addReplacement("reservedIpRange", "10.1.2.0/24") addReplacement("metadata.endTime", "2024-04-01T12:34:56.123456Z") - // For compute operations + // Specific to Compute addReplacement("insertTime", "2024-04-01T12:34:56.123456Z") addReplacement("user", "user@example.com") addReplacement("natIP", "192.0.0.10") + addReplacement("labelFingerprint", "abcdef0123A=") + // Extract resource targetID numbers from compute operations + for _, event := range events { + body := event.Response.ParseBody() + targetLink, _, _ := unstructured.NestedString(body, "targetLink") + targetId, _, _ := unstructured.NestedString(body, "targetId") + if targetLink != "" && targetId != "" { + tokens := strings.Split(targetLink, "/") + n := len(tokens) + if n >= 2 { + kind := tokens[n-2] + switch kind { + case "subnetworks": + r.PathIDs[targetId] = "${subnetworkNumber}" + case "sslCertificates": + r.PathIDs[targetId] = "${sslCertificatesId}" + case "forwardingRules": + r.PathIDs[targetId] = "${forwardingRulesId}" + } + } + } + + u := event.Request.URL + // Terraform uses the /beta/ endpoints, but mocks and direct controller should use /v1/ + // This special handling to avoid diffs in http logs. + // This can be removed once all Compute resources are migrated to direct controller. + basePath := "https://compute.googleapis.com/compute" + if strings.HasPrefix(u, basePath+"/beta/") { + u = basePath + "/v1/" + strings.TrimPrefix(u, basePath+"/beta/") + } + event.Request.URL = u + + } // Specific to IAM/policy addReplacement("policy.etag", "abcdef0123A=")