Skip to content

Commit

Permalink
mockGCP for ComputeVpnGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Jul 9, 2024
1 parent b06fc1b commit e7224aa
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 22 deletions.
30 changes: 8 additions & 22 deletions mockgcp/mockcompute/vpngatewayv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 VPNGatewaysV1 struct {
Expand All @@ -43,11 +41,7 @@ func (s *VPNGatewaysV1) Get(ctx context.Context, req *pb.GetVpnGatewayRequest) (

obj := &pb.VpnGateway{}
if err := s.storage.Get(ctx, fqn, obj); err != nil {
if apierrors.IsNotFound(err) {
return nil, status.Errorf(codes.NotFound, "vpnGateway %q not found", name)
} else {
return nil, status.Errorf(codes.Internal, "error reading vpnGateway: %v", err)
}
return nil, err
}

return obj, nil
Expand All @@ -71,7 +65,7 @@ func (s *VPNGatewaysV1) Insert(ctx context.Context, req *pb.InsertVpnGatewayRequ
obj.Kind = PtrTo("compute#vpnGateway")

if err := s.storage.Create(ctx, fqn, obj); err != nil {
return nil, status.Errorf(codes.Internal, "error creating vpnGateway: %v", err)
return nil, err
}

return s.newLRO(ctx, name.Project.ID)
Expand All @@ -88,11 +82,7 @@ func (s *VPNGatewaysV1) Delete(ctx context.Context, req *pb.DeleteVpnGatewayRequ

deleted := &pb.VpnGateway{}
if err := s.storage.Delete(ctx, fqn, deleted); err != nil {
if apierrors.IsNotFound(err) {
return nil, status.Errorf(codes.NotFound, "vpnGateway %q not found", name)
} else {
return nil, status.Errorf(codes.Internal, "error deleting vpnGateway: %v", err)
}
return nil, err
}

return s.newLRO(ctx, name.Project.ID)
Expand All @@ -109,16 +99,12 @@ func (s *VPNGatewaysV1) SetLabels(ctx context.Context, req *pb.SetLabelsVpnGatew

obj := &pb.VpnGateway{}
if err := s.storage.Get(ctx, fqn, obj); err != nil {
if apierrors.IsNotFound(err) {
return nil, status.Errorf(codes.NotFound, "vpnGateway %q not found", name)
} else {
return nil, status.Errorf(codes.Internal, "error reading vpnGateway: %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 vpnGateway: %v", err)
return nil, err
}

return s.newLRO(ctx, name.Project.ID)
Expand All @@ -140,7 +126,7 @@ func (s *MockService) parseRegionalVpnGatewayName(name string) (*regionalVpnGate
tokens := strings.Split(name, "/")

if len(tokens) == 6 && tokens[0] == "projects" && tokens[2] == "regions" && tokens[4] == "vpnGateways" {
project, err := s.projects.GetProjectByID(tokens[1])
project, err := s.Projects.GetProjectByID(tokens[1])
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeVPNGateway
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"
label-one: value-one
name: computevpngateway-${uniqueId}
namespace: ${uniqueId}
spec:
networkRef:
name: default
region: us-central1
resourceID: computevpngateway-${uniqueId}
stackType: IPV4_ONLY
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
observedGeneration: 2
selfLink: https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/vpnGateways/computevpngateway-${uniqueId}
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
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": "[email protected]"
}

---

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": "[email protected]"
}

---

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/vpnGateways/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": "vpnGateway \"projects/${projectId}/regions/us-central1/vpnGateways/computevpngateway-${uniqueId}\" not found",
"reason": "notFound"
}
],
"message": "vpnGateway \"projects/${projectId}/regions/us-central1/vpnGateways/computevpngateway-${uniqueId}\" not found"
}
}

---

POST https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/vpnGateways?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",
"stackType": "IPV4_ONLY"
}

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/vpnGateways/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#vpnGateway",
"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/vpnGateways/computevpngateway-${uniqueId}",
"stackType": "IPV4_ONLY"
}

---

DELETE https://compute.googleapis.com/compute/beta/projects/${projectId}/regions/us-central1/vpnGateways/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"
}
Loading

0 comments on commit e7224aa

Please sign in to comment.