Skip to content

Commit

Permalink
mappers for computeforwardingrule
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Jul 19, 2024
1 parent 6df3bad commit 13023b5
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis/compute/v1beta1/computeforwardingrule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
}
)

// +kcc:proto=google.cloud.compute.v1.MetadataFilterLabelMatch
type ForwardingruleFilterLabels struct {
/* Immutable. Name of the metadata label. The length must be between
1 and 1024 characters, inclusive. */
Expand All @@ -55,6 +56,7 @@ type ForwardingruleIpAddress struct {
Ip *string `json:"ip,omitempty"`
}

// +kcc:proto=google.cloud.compute.v1.MetadataFilter
type ForwardingruleMetadataFilters struct {
/* Immutable. The list of label value pairs that must match labels in the
provided metadata based on filterMatchCriteria
Expand All @@ -72,6 +74,7 @@ type ForwardingruleMetadataFilters struct {
FilterMatchCriteria string `json:"filterMatchCriteria"`
}

// +kcc:proto=google.cloud.compute.v1.ForwardingRuleServiceDirectoryRegistration
type ForwardingruleServiceDirectoryRegistrations struct {
/* Immutable. Service Directory namespace to register the forwarding rule under. */
// +optional
Expand Down Expand Up @@ -105,6 +108,7 @@ type ForwardingruleTarget struct {
TargetVPNGatewayRef *v1alpha1.ResourceRef `json:"targetVPNGatewayRef,omitempty"`
}

// +kcc:proto=google.cloud.compute.v1.ForwardingRule
type ComputeForwardingRuleSpec struct {
/* Immutable. This field can only be used:
* If 'IPProtocol' is one of TCP, UDP, or SCTP.
Expand Down Expand Up @@ -358,6 +362,7 @@ type ComputeForwardingRuleSpec struct {
Target *ForwardingruleTarget `json:"target,omitempty"`
}

// +kcc:proto=google.cloud.compute.v1.ForwardingRule
type ComputeForwardingRuleStatus struct {
/* Conditions represent the latest available observations of the
ComputeForwardingRule's current state. */
Expand Down
191 changes: 191 additions & 0 deletions pkg/controller/direct/compute/mapper.generated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// 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 compute

import (
pb "cloud.google.com/go/compute/apiv1/computepb"

krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/compute/v1beta1"
)

func ComputeForwardingRuleSpec_FromProto(mapCtx *MapContext, in *pb.ForwardingRule) *krm.ComputeForwardingRuleSpec {
if in == nil {
return nil
}
out := &krm.ComputeForwardingRuleSpec{}
out.IpAddress = ComputeForwardingRuleSpec_IpAddress_FromProto(mapCtx, in.GetIPAddress())
out.IpProtocol = LazyPtr(in.GetIPProtocol())
out.AllPorts = LazyPtr(in.GetAllPorts())
out.AllowGlobalAccess = LazyPtr(in.GetAllowGlobalAccess())
out.AllowPscGlobalAccess = LazyPtr(in.GetAllowPscGlobalAccess())
out.BackendServiceRef = ResourceRef_FromProto(mapCtx, in.GetBackendService())
// MISSING: BaseForwardingRule
// MISSING: CreationTimestamp
out.Description = LazyPtr(in.GetDescription())
// MISSING: Fingerprint
// MISSING: Id
// MISSING: IpCollection
out.IpVersion = LazyPtr(in.GetIpVersion())
out.IsMirroringCollector = LazyPtr(in.GetIsMirroringCollector())
// MISSING: Kind
// MISSING: LabelFingerprint
// MISSING: Labels
out.LoadBalancingScheme = LazyPtr(in.GetLoadBalancingScheme())
out.MetadataFilters = Slice_FromProto(mapCtx, in.MetadataFilters, ForwardingruleMetadataFilters_FromProto)
// MISSING: Name
out.NetworkRef = ResourceRef_FromProto(mapCtx, in.GetNetwork())
out.NetworkTier = LazyPtr(in.GetNetworkTier())
out.NoAutomateDnsZone = LazyPtr(in.GetNoAutomateDnsZone())
out.PortRange = LazyPtr(in.GetPortRange())
out.Ports = in.Ports
// MISSING: PscConnectionId
// MISSING: PscConnectionStatus
// MISSING: Region
// MISSING: SelfLink
out.ServiceDirectoryRegistrations = Slice_FromProto(mapCtx, in.ServiceDirectoryRegistrations, ForwardingruleServiceDirectoryRegistrations_FromProto)
out.ServiceLabel = LazyPtr(in.GetServiceLabel())
// MISSING: ServiceName
out.SourceIpRanges = in.SourceIpRanges
out.SubnetworkRef = ResourceRef_FromProto(mapCtx, in.GetSubnetwork())
out.Target = ComputeForwardingRuleSpec_Target_FromProto(mapCtx, in.GetTarget())
return out
}
func ComputeForwardingRuleSpec_ToProto(mapCtx *MapContext, in *krm.ComputeForwardingRuleSpec) *pb.ForwardingRule {
if in == nil {
return nil
}
out := &pb.ForwardingRule{}
out.IPAddress = ComputeForwardingRuleSpec_IpAddress_ToProto(mapCtx, in.IpAddress)
out.IPProtocol = in.IpProtocol
out.AllPorts = in.AllPorts
out.AllowGlobalAccess = in.AllowGlobalAccess
out.AllowPscGlobalAccess = in.AllowPscGlobalAccess
out.BackendService = ResourceRef_ToProto(mapCtx, in.BackendServiceRef)
// MISSING: BaseForwardingRule
// MISSING: CreationTimestamp
out.Description = in.Description
// MISSING: Fingerprint
// MISSING: Id
// MISSING: IpCollection
out.IpVersion = in.IpVersion
out.IsMirroringCollector = in.IsMirroringCollector
// MISSING: Kind
// MISSING: LabelFingerprint
// MISSING: Labels
out.LoadBalancingScheme = in.LoadBalancingScheme
out.MetadataFilters = Slice_ToProto(mapCtx, in.MetadataFilters, ForwardingruleMetadataFilters_ToProto)
// MISSING: Name
out.Network = ResourceRef_ToProto(mapCtx, in.NetworkRef)
out.NetworkTier = in.NetworkTier
out.NoAutomateDnsZone = in.NoAutomateDnsZone
out.PortRange = in.PortRange
out.Ports = in.Ports
// MISSING: PscConnectionId
// MISSING: PscConnectionStatus
// MISSING: Region
// MISSING: SelfLink
out.ServiceDirectoryRegistrations = Slice_ToProto(mapCtx, in.ServiceDirectoryRegistrations, ForwardingruleServiceDirectoryRegistrations_ToProto)
out.ServiceLabel = in.ServiceLabel
// MISSING: ServiceName
out.SourceIpRanges = in.SourceIpRanges
out.Subnetwork = ResourceRef_ToProto(mapCtx, in.SubnetworkRef)
out.Target = ComputeForwardingRuleSpec_Target_ToProto(mapCtx, in.Target)
return out
}
func ComputeForwardingRuleStatus_FromProto(mapCtx *MapContext, in *pb.ForwardingRule) *krm.ComputeForwardingRuleStatus {
if in == nil {
return nil
}
out := &krm.ComputeForwardingRuleStatus{}

out.BaseForwardingRule = LazyPtr(in.GetBaseForwardingRule())
out.CreationTimestamp = LazyPtr(in.GetCreationTimestamp())
out.LabelFingerprint = LazyPtr(in.GetLabelFingerprint())
out.PscConnectionId = ComputeForwardingRuleStatus_PscConnectionId_FromProto(mapCtx, in.GetPscConnectionId())
out.PscConnectionStatus = LazyPtr(in.GetPscConnectionStatus())
out.SelfLink = LazyPtr(in.GetSelfLink())
out.ServiceName = LazyPtr(in.GetServiceName())
return out
}
func ComputeForwardingRuleStatus_ToProto(mapCtx *MapContext, in *krm.ComputeForwardingRuleStatus) *pb.ForwardingRule {
if in == nil {
return nil
}
out := &pb.ForwardingRule{}
out.BaseForwardingRule = in.BaseForwardingRule
out.CreationTimestamp = in.CreationTimestamp
out.LabelFingerprint = in.LabelFingerprint
out.PscConnectionId = ComputeForwardingRuleStatus_PscConnectionId_ToProto(mapCtx, in.PscConnectionId)
out.PscConnectionStatus = in.PscConnectionStatus
out.SelfLink = in.SelfLink
out.ServiceName = in.ServiceName
return out
}
func ForwardingruleFilterLabels_FromProto(mapCtx *MapContext, in *pb.MetadataFilterLabelMatch) *krm.ForwardingruleFilterLabels {
if in == nil {
return nil
}
out := &krm.ForwardingruleFilterLabels{}
out.Name = in.GetName()
out.Value = in.GetValue()
return out
}
func ForwardingruleFilterLabels_ToProto(mapCtx *MapContext, in *krm.ForwardingruleFilterLabels) *pb.MetadataFilterLabelMatch {
if in == nil {
return nil
}
out := &pb.MetadataFilterLabelMatch{}
out.Name = LazyPtr(in.Name)
out.Value = LazyPtr(in.Value)
return out
}
func ForwardingruleMetadataFilters_FromProto(mapCtx *MapContext, in *pb.MetadataFilter) *krm.ForwardingruleMetadataFilters {
if in == nil {
return nil
}
out := &krm.ForwardingruleMetadataFilters{}
out.FilterLabels = Slice_FromProto(mapCtx, in.FilterLabels, ForwardingruleFilterLabels_FromProto)
out.FilterMatchCriteria = in.GetFilterMatchCriteria()
return out
}
func ForwardingruleMetadataFilters_ToProto(mapCtx *MapContext, in *krm.ForwardingruleMetadataFilters) *pb.MetadataFilter {
if in == nil {
return nil
}
out := &pb.MetadataFilter{}
out.FilterLabels = Slice_ToProto(mapCtx, in.FilterLabels, ForwardingruleFilterLabels_ToProto)
out.FilterMatchCriteria = LazyPtr(in.FilterMatchCriteria)
return out
}
func ForwardingruleServiceDirectoryRegistrations_FromProto(mapCtx *MapContext, in *pb.ForwardingRuleServiceDirectoryRegistration) *krm.ForwardingruleServiceDirectoryRegistrations {
if in == nil {
return nil
}
out := &krm.ForwardingruleServiceDirectoryRegistrations{}
out.Namespace = LazyPtr(in.GetNamespace())
out.Service = LazyPtr(in.GetService())
// MISSING: ServiceDirectoryRegion
return out
}
func ForwardingruleServiceDirectoryRegistrations_ToProto(mapCtx *MapContext, in *krm.ForwardingruleServiceDirectoryRegistrations) *pb.ForwardingRuleServiceDirectoryRegistration {
if in == nil {
return nil
}
out := &pb.ForwardingRuleServiceDirectoryRegistration{}
out.Namespace = in.Namespace
out.Service = in.Service
// MISSING: ServiceDirectoryRegion
return out
}
114 changes: 114 additions & 0 deletions pkg/controller/direct/compute/mapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// 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 compute

import (
"strconv"

krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/compute/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
)

func ComputeForwardingRuleSpec_IpAddress_ToProto(mapCtx *MapContext, in *krm.ForwardingruleIpAddress) *string {
if in == nil {
return nil
}

var out *string
if oneof := ResourceRef_ToProto(mapCtx, in.AddressRef); oneof != nil {
out = oneof
}
if in.Ip != nil {
out = in.Ip
}
return out
}

func ComputeForwardingRuleSpec_IpAddress_FromProto(mapCtx *MapContext, in string) *krm.ForwardingruleIpAddress {
if in == "" {
return nil
}
out := &krm.ForwardingruleIpAddress{}
out.AddressRef = &v1alpha1.ResourceRef{
External: in,
}
return out
}

func ComputeForwardingRuleSpec_Target_ToProto(mapCtx *MapContext, in *krm.ForwardingruleTarget) *string {
if in == nil {
return nil
}

var out *string
if oneof := ResourceRef_ToProto(mapCtx, in.ServiceAttachmentRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetGRPCProxyRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetHTTPProxyRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetHTTPSProxyRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetSSLProxyRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetTCPProxyRef); oneof != nil {
out = oneof
}
if oneof := ResourceRef_ToProto(mapCtx, in.TargetVPNGatewayRef); oneof != nil {
out = oneof
}
return out
}

func ComputeForwardingRuleSpec_Target_FromProto(mapCtx *MapContext, in string) *krm.ForwardingruleTarget {
if in == "" {
return nil
}
out := &krm.ForwardingruleTarget{}
// TODO(yuhou): ForwardingRuleTarget can be one of multiple target objects. We need to determine which one to assign the value to.
// Assign to TargetHTTPProxy temporarily
out.TargetHTTPProxyRef = &v1alpha1.ResourceRef{
External: in,
}
return out
}

func ComputeForwardingRuleStatus_PscConnectionId_FromProto(mapCtx *MapContext, in uint64) *string {
if in == 0 {
return nil
}
strValue := strconv.FormatUint(in, 10)
return &strValue

}

func ComputeForwardingRuleStatus_PscConnectionId_ToProto(mapCtx *MapContext, in *string) *uint64 {
if in == nil {
return nil
}

num, err := strconv.ParseUint(*in, 10, 64)
if err != nil {
mapCtx.Errorf("Error converting string to uint64")
return nil
}

return &num
}
Loading

0 comments on commit 13023b5

Please sign in to comment.