forked from GoogleCloudPlatform/k8s-config-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,634 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,15 @@ func (s *GlobalAddressesV1) Insert(ctx context.Context, req *pb.InsertGlobalAddr | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("insert"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *GlobalAddressesV1) Delete(ctx context.Context, req *pb.DeleteGlobalAddressRequest) (*pb.Operation, error) { | ||
|
@@ -93,7 +101,15 @@ func (s *GlobalAddressesV1) Delete(ctx context.Context, req *pb.DeleteGlobalAddr | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: deleted.Id, | ||
TargetLink: deleted.SelfLink, | ||
OperationType: PtrTo("delete"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return deleted, nil | ||
}) | ||
} | ||
|
||
func (s *GlobalAddressesV1) SetLabels(ctx context.Context, req *pb.SetLabelsGlobalAddressRequest) (*pb.Operation, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mockcompute | ||
|
||
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" | ||
) | ||
|
||
type TargetSslProxyV1 struct { | ||
*MockService | ||
pb.UnimplementedTargetSslProxiesServer | ||
} | ||
|
||
func (s *TargetSslProxyV1) Get(ctx context.Context, req *pb.GetTargetSslProxyRequest) (*pb.TargetSslProxy, error) { | ||
reqName := "projects/" + req.GetProject() + "/global/targetSslProxies/" + req.GetTargetSslProxy() | ||
name, err := s.parseTargetSslProxyName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
obj := &pb.TargetSslProxy{} | ||
if err := s.storage.Get(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
func (s *TargetSslProxyV1) Insert(ctx context.Context, req *pb.InsertTargetSslProxyRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/global/targetSslProxies/" + req.GetTargetSslProxyResource().GetName() | ||
name, err := s.parseTargetSslProxyName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
id := s.generateID() | ||
|
||
obj := proto.Clone(req.GetTargetSslProxyResource()).(*pb.TargetSslProxy) | ||
obj.SelfLink = PtrTo("https://www.googleapis.com/compute/v1/" + name.String()) | ||
obj.CreationTimestamp = PtrTo(s.nowString()) | ||
obj.Id = &id | ||
obj.Kind = PtrTo("compute#targetSslProxy") | ||
|
||
if err := s.storage.Create(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("insert"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *TargetSslProxyV1) Delete(ctx context.Context, req *pb.DeleteTargetSslProxyRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/global/targetSslProxies/" + req.GetTargetSslProxy() | ||
name, err := s.parseTargetSslProxyName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
deleted := &pb.TargetSslProxy{} | ||
if err := s.storage.Delete(ctx, fqn, deleted); err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: deleted.Id, | ||
TargetLink: deleted.SelfLink, | ||
OperationType: PtrTo("delete"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return deleted, nil | ||
}) | ||
} | ||
|
||
type targetSslProxyName struct { | ||
Project *projects.ProjectData | ||
Name string | ||
} | ||
|
||
func (n *targetSslProxyName) String() string { | ||
return "projects/" + n.Project.ID + "/global/targetSslProxies/" + n.Name | ||
} | ||
|
||
// parseTargetSslProxyName parses a string into a targetSslProxyName. | ||
// The expected form is `projects/*/global/targetSslProxies/*`. | ||
func (s *MockService) parseTargetSslProxyName(name string) (*targetSslProxyName, error) { | ||
tokens := strings.Split(name, "/") | ||
|
||
if len(tokens) == 5 && tokens[0] == "projects" && tokens[3] == "targetSslProxies" { | ||
project, err := s.Projects.GetProjectByID(tokens[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
name := &targetSslProxyName{ | ||
Project: project, | ||
Name: tokens[4], | ||
} | ||
|
||
return name, nil | ||
} else { | ||
return nil, status.Errorf(codes.InvalidArgument, "name %q is not valid", name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...obalcomputeforwardingrulessl/_generated_object_globalcomputeforwardingrulessl.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: compute.cnrm.cloud.google.com/v1beta1 | ||
kind: ComputeForwardingRule | ||
metadata: | ||
annotations: | ||
cnrm.cloud.google.com/management-conflict-prevention-policy: none | ||
cnrm.cloud.google.com/project-id: ${projectId} | ||
finalizers: | ||
- cnrm.cloud.google.com/finalizer | ||
- cnrm.cloud.google.com/deletion-defender | ||
generation: 1 | ||
labels: | ||
cnrm-test: "true" | ||
label-one: value-two | ||
name: computeglobalforwardingrule-${uniqueId} | ||
namespace: ${uniqueId} | ||
spec: | ||
description: A global forwarding rule | ||
ipAddress: | ||
addressRef: | ||
name: computeaddress-${uniqueId} | ||
loadBalancingScheme: EXTERNAL | ||
location: global | ||
portRange: "443" | ||
target: | ||
targetSSLProxyRef: | ||
name: computetargetsslproxy-${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" | ||
labelFingerprint: abcdef0123A= | ||
observedGeneration: 1 | ||
selfLink: https://www.googleapis.com/compute/v1/projects/${projectId}/global/forwardingRules/computeglobalforwardingrule-${uniqueId} |
Oops, something went wrong.