diff --git a/mockgcp/mockcompute/targetvpngatewayv1.go b/mockgcp/mockcompute/targetvpngatewayv1.go index bab2685450..c6df0d156d 100644 --- a/mockgcp/mockcompute/targetvpngatewayv1.go +++ b/mockgcp/mockcompute/targetvpngatewayv1.go @@ -18,13 +18,11 @@ import ( "context" "strings" + "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" + pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/compute/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" - apierrors "k8s.io/apimachinery/pkg/api/errors" - - "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" - pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/compute/v1" ) type TargetVpnGatewaysV1 struct { @@ -43,11 +41,7 @@ func (s *TargetVpnGatewaysV1) Get(ctx context.Context, req *pb.GetTargetVpnGatew obj := &pb.TargetVpnGateway{} if err := s.storage.Get(ctx, fqn, obj); err != nil { - if apierrors.IsNotFound(err) { - return nil, status.Errorf(codes.NotFound, "targetVpnGateway %q not found", name) - } else { - return nil, status.Errorf(codes.Internal, "error reading targetVpnGateway: %v", err) - } + return nil, err } return obj, nil @@ -71,7 +65,7 @@ func (s *TargetVpnGatewaysV1) Insert(ctx context.Context, req *pb.InsertTargetVp obj.Kind = PtrTo("compute#targetVpnGateway") if err := s.storage.Create(ctx, fqn, obj); err != nil { - return nil, status.Errorf(codes.Internal, "error creating targetVpnGateway: %v", err) + return nil, err } return s.newLRO(ctx, name.Project.ID) @@ -88,11 +82,7 @@ func (s *TargetVpnGatewaysV1) Delete(ctx context.Context, req *pb.DeleteTargetVp deleted := &pb.TargetVpnGateway{} if err := s.storage.Delete(ctx, fqn, deleted); err != nil { - if apierrors.IsNotFound(err) { - return nil, status.Errorf(codes.NotFound, "targetVpnGateway %q not found", name) - } else { - return nil, status.Errorf(codes.Internal, "error deleting targetVpnGateway: %v", err) - } + return nil, err } return s.newLRO(ctx, name.Project.ID) @@ -109,16 +99,12 @@ func (s *TargetVpnGatewaysV1) SetLabels(ctx context.Context, req *pb.SetLabelsTa obj := &pb.TargetVpnGateway{} if err := s.storage.Get(ctx, fqn, obj); err != nil { - if apierrors.IsNotFound(err) { - return nil, status.Errorf(codes.NotFound, "targetVpnGateway %q not found", name) - } else { - return nil, status.Errorf(codes.Internal, "error reading targetVpnGateway: %v", err) - } + return nil, err } obj.Labels = req.GetRegionSetLabelsRequestResource().GetLabels() if err := s.storage.Update(ctx, fqn, obj); err != nil { - return nil, status.Errorf(codes.Internal, "error updating targetVpnGateway: %v", err) + return nil, err } return s.newLRO(ctx, name.Project.ID) @@ -140,7 +126,7 @@ func (s *MockService) parseRegionalTargetVpnGatewayName(name string) (*regionalT tokens := strings.Split(name, "/") if len(tokens) == 6 && tokens[0] == "projects" && tokens[2] == "regions" && tokens[4] == "targetVpnGateways" { - project, err := s.projects.GetProjectByID(tokens[1]) + project, err := s.Projects.GetProjectByID(tokens[1]) if err != nil { return nil, err } diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_generated_object_computetargetvpngateway.golden.yaml b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_generated_object_computetargetvpngateway.golden.yaml new file mode 100644 index 0000000000..9d640fd543 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_generated_object_computetargetvpngateway.golden.yaml @@ -0,0 +1,31 @@ +apiVersion: compute.cnrm.cloud.google.com/v1beta1 +kind: ComputeTargetVPNGateway +metadata: + annotations: + cnrm.cloud.google.com/management-conflict-prevention-policy: none + cnrm.cloud.google.com/project-id: ${projectId} + cnrm.cloud.google.com/state-into-spec: merge + finalizers: + - cnrm.cloud.google.com/finalizer + - cnrm.cloud.google.com/deletion-defender + generation: 2 + labels: + cnrm-test: "true" + name: computevpngateway-${uniqueId} + namespace: ${uniqueId} +spec: + networkRef: + name: default + region: us-central1 + resourceID: computevpngateway-${uniqueId} +status: + conditions: + - lastTransitionTime: "1970-01-01T00:00:00Z" + message: The resource is up to date + reason: UpToDate + status: "True" + type: Ready + creationTimestamp: "1970-01-01T00:00:00Z" + gatewayId: "1.719337333063698e+18" + observedGeneration: 2 + selfLink: https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${uniqueId} diff --git a/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_http.log b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_http.log new file mode 100644 index 0000000000..7a004cdc58 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computetargetvpngateway/_http.log @@ -0,0 +1,270 @@ +GET https://compute.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}?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 + +{ + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "Default network for the project", + "id": "000000000000000000000", + "kind": "compute#network", + "name": "${networkID}", + "selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}", + "selfLinkWithId": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}" +} + +--- + +PATCH https://compute.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}?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 + +{ + "networkFirewallPolicyEnforcementOrder": "AFTER_CLASSIC_FIREWALL" +} + +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 + +{ + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "compute.networks.patch", + "progress": 0, + "selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "RUNNING", + "targetId": "${networkID}", + "targetLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}?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 + +{ + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "Default network for the project", + "id": "000000000000000000000", + "kind": "compute#network", + "name": "${networkID}", + "selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}", + "selfLinkWithId": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}" +} + +--- + +PATCH https://compute.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}?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 + +{ + "networkFirewallPolicyEnforcementOrder": "AFTER_CLASSIC_FIREWALL" +} + +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 + +{ + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "operationType": "compute.networks.patch", + "progress": 0, + "selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "RUNNING", + "targetId": "${networkID}", + "targetLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}", + "user": "user@example.com" +} + +--- + +GET https://compute.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}?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 + +{ + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "description": "Default network for the project", + "id": "000000000000000000000", + "kind": "compute#network", + "name": "${networkID}", + "selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}", + "selfLinkWithId": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/${networkID}" +} + +--- + +GET https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${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 + +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, + "errors": [ + { + "domain": "global", + "message": "targetVpnGateway \"projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${uniqueId}\" not found", + "reason": "notFound" + } + ], + "message": "targetVpnGateway \"projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${uniqueId}\" not found" + } +} + +--- + +POST https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/targetVpnGateways?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 + +{ + "name": "computevpngateway-${uniqueId}", + "network": "projects/${projectId}/global/networks/${networkID}", + "region": "projects/${projectId}/global/regions/us-central1" +} + +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 + +{ + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "progress": 0, + "selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE" +} + +--- + +GET https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${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 + +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 + +{ + "creationTimestamp": "2024-04-01T12:34:56.123456Z", + "id": "000000000000000000000", + "kind": "compute#targetVpnGateway", + "name": "computevpngateway-${uniqueId}", + "network": "projects/${projectId}/global/networks/${networkID}", + "region": "projects/${projectId}/global/regions/us-central1", + "selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${uniqueId}" +} + +--- + +DELETE https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/targetVpnGateways/computevpngateway-${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 + +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 + +{ + "id": "000000000000000000000", + "insertTime": "2024-04-01T12:34:56.123456Z", + "kind": "compute#operation", + "name": "${operationID}", + "progress": 0, + "selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", + "startTime": "2024-04-01T12:34:56.123456Z", + "status": "DONE" +} \ No newline at end of file diff --git a/tests/e2e/normalize.go b/tests/e2e/normalize.go index 0efe0d0429..0455671fb1 100644 --- a/tests/e2e/normalize.go +++ b/tests/e2e/normalize.go @@ -106,6 +106,7 @@ func normalizeKRMObject(u *unstructured.Unstructured, project testgcp.GCPProject // Specific to Compute visitor.replacePaths[".status.observedState.certificateID"] = "1.719337333063698e+18" visitor.replacePaths[".status.instanceId"] = "1111111111111111" + visitor.replacePaths[".status.gatewayId"] = "1.719337333063698e+18" // Specific to MonitoringDashboard visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { @@ -414,7 +415,6 @@ func normalizeHTTPResponses(t *testing.T, events test.LogEntries) { // Compute operations visitor.replacePaths[".fingerprint"] = "abcdef0123A=" - visitor.replacePaths[".startTime"] = "2024-04-01T12:34:56.123456Z" events.PrettifyJSON(func(obj map[string]any) {