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
9 changed files
with
270 additions
and
246 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,14 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob | |
obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) | ||
} | ||
|
||
if obj.Subnetwork != nil { | ||
subnetworkName, err := s.parseSubnetName(obj.GetSubnetwork()) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "subnetwork %q is not valid", obj.GetSubnetwork()) | ||
} | ||
obj.Subnetwork = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", subnetworkName.Project.ID, subnetworkName.Region, subnetworkName.Name)) | ||
} | ||
|
||
// output only field | ||
obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.global.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Project.ID)) | ||
|
||
|
@@ -122,6 +130,44 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob | |
}) | ||
} | ||
|
||
func (s *GlobalForwardingRulesV1) Patch(ctx context.Context, req *pb.PatchGlobalForwardingRuleRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/global" + "/forwardingRules/" + req.GetForwardingRule() | ||
name, err := s.parseGlobalForwardingRuleName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
obj := &pb.ForwardingRule{} | ||
if err := s.storage.Get(ctx, fqn, obj); err != nil { | ||
if status.Code(err) == codes.NotFound { | ||
return nil, status.Errorf(codes.NotFound, "The resource '%s' was not found", fqn) | ||
} | ||
return nil, err | ||
} | ||
|
||
proto.Merge(obj, req.GetForwardingRuleResource()) | ||
// checked GCP log, when AllowGlobalAccess is false, the field will be ignored | ||
if *obj.AllowGlobalAccess == false { | ||
obj.AllowGlobalAccess = nil | ||
} | ||
|
||
if err := s.storage.Update(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("patch"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
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) { | ||
reqName := "projects/" + req.GetProject() + "/global" + "/forwardingRules/" + req.GetForwardingRule() | ||
name, err := s.parseGlobalForwardingRuleName(reqName) | ||
|
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 |
---|---|---|
|
@@ -104,6 +104,14 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo | |
obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) | ||
} | ||
|
||
if obj.Subnetwork != nil { | ||
subnetworkName, err := s.parseSubnetName(obj.GetSubnetwork()) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "subnetwork %q is not valid", obj.GetSubnetwork()) | ||
} | ||
obj.Subnetwork = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", subnetworkName.Project.ID, subnetworkName.Region, subnetworkName.Name)) | ||
} | ||
|
||
// output only fields | ||
obj.Region = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s", name.Project.ID, name.Region)) | ||
obj.ServiceName = PtrTo(fmt.Sprintf("%s.%s.il4.%s.lb.%s.internal", obj.GetServiceLabel(), name.Name, name.Region, name.Project.ID)) | ||
|
@@ -123,6 +131,45 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo | |
}) | ||
} | ||
|
||
func (s *RegionalForwardingRulesV1) Patch(ctx context.Context, req *pb.PatchForwardingRuleRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/forwardingRules/" + req.GetForwardingRule() | ||
name, err := s.parseRegionalForwardingRuleName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
obj := &pb.ForwardingRule{} | ||
|
||
if err := s.storage.Get(ctx, fqn, obj); err != nil { | ||
if status.Code(err) == codes.NotFound { | ||
return nil, status.Errorf(codes.NotFound, "The resource '%s' was not found", fqn) | ||
} | ||
return nil, err | ||
} | ||
|
||
proto.Merge(obj, req.GetForwardingRuleResource()) | ||
// checked GCP log, when AllowGlobalAccess is false, the field will be ignored | ||
if *obj.AllowGlobalAccess == false { | ||
obj.AllowGlobalAccess = nil | ||
} | ||
|
||
if err := s.storage.Update(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("patch"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startRegionalLRO(ctx, name.Project.ID, name.Region, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteForwardingRuleRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/forwardingRules/" + req.GetForwardingRule() | ||
name, err := s.parseRegionalForwardingRuleName(reqName) | ||
|
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
Oops, something went wrong.