Skip to content

Commit

Permalink
Merge pull request #3136 from jasonvigil/workstationconfig-mappers
Browse files Browse the repository at this point in the history
feat: Generate and fixup WorkstationConfig mapping functions
  • Loading branch information
google-oss-prow[bot] authored Nov 20, 2024
2 parents de797cd + 3f85d2c commit 8de3627
Show file tree
Hide file tree
Showing 5 changed files with 811 additions and 84 deletions.
7 changes: 7 additions & 0 deletions dev/tools/controllerbuilder/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ go run . generate-types \
--output-api ${APIS_DIR} \
--resource WorkstationCluster:WorkstationCluster

go run . generate-types \
--proto-source-path ../proto-to-mapper/build/googleapis.pb \
--service google.cloud.workstations.v1 \
--api-version workstations.cnrm.cloud.google.com/v1alpha1 \
--output-api ${APIS_DIR} \
--resource WorkstationConfig:WorkstationConfig

go run . generate-mapper \
--proto-source-path ../proto-to-mapper/build/googleapis.pb \
--service google.cloud.workstations.v1 \
Expand Down
90 changes: 6 additions & 84 deletions pkg/controller/direct/workstations/cluster_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package workstations

import (
pb "cloud.google.com/go/workstations/apiv1/workstationspb"
status "google.golang.org/genproto/googleapis/rpc/status"

refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/workstations/v1beta1"
Expand All @@ -29,37 +28,15 @@ func WorkstationClusterSpec_ToProto(mapCtx *direct.MapContext, in *krm.Workstati
}
out := &pb.WorkstationCluster{
DisplayName: direct.ValueOf(in.DisplayName),
Annotations: WorkstationClusterAnnotations_ToProto(mapCtx, in.Annotations),
Labels: WorkstationClusterLabels_ToProto(mapCtx, in.Labels),
Annotations: WorkstationAnnotations_ToProto(mapCtx, in.Annotations),
Labels: WorkstationLabels_ToProto(mapCtx, in.Labels),
Network: in.NetworkRef.External,
Subnetwork: in.SubnetworkRef.External,
PrivateClusterConfig: WorkstationCluster_PrivateClusterConfig_ToProto(mapCtx, in.PrivateClusterConfig),
}
return out
}

func WorkstationClusterAnnotations_ToProto(mapCtx *direct.MapContext, in []krm.WorkstationAnnotation) map[string]string {
if in == nil {
return nil
}
out := make(map[string]string)
for _, a := range in {
out[a.Key] = a.Value
}
return out
}

func WorkstationClusterLabels_ToProto(mapCtx *direct.MapContext, in []krm.WorkstationLabel) map[string]string {
if in == nil {
return nil
}
out := make(map[string]string)
for _, l := range in {
out[l.Key] = l.Value
}
return out
}

func WorkstationCluster_PrivateClusterConfig_ToProto(mapCtx *direct.MapContext, in *krm.WorkstationCluster_PrivateClusterConfig) *pb.WorkstationCluster_PrivateClusterConfig {
if in == nil {
return nil
Expand Down Expand Up @@ -88,8 +65,8 @@ func WorkstationClusterSpec_FromProto(mapCtx *direct.MapContext, in *pb.Workstat
}
out := &krm.WorkstationClusterSpec{
DisplayName: direct.LazyPtr(in.GetDisplayName()),
Annotations: WorkstationClusterAnnotations_FromProto(mapCtx, in.GetAnnotations()),
Labels: WorkstationClusterLabels_FromProto(mapCtx, in.GetLabels()),
Annotations: WorkstationAnnotations_FromProto(mapCtx, in.GetAnnotations()),
Labels: WorkstationLabels_FromProto(mapCtx, in.GetLabels()),
NetworkRef: refs.ComputeNetworkRef{
External: in.GetNetwork(),
},
Expand All @@ -101,34 +78,6 @@ func WorkstationClusterSpec_FromProto(mapCtx *direct.MapContext, in *pb.Workstat
return out
}

func WorkstationClusterAnnotations_FromProto(mapCtx *direct.MapContext, in map[string]string) []krm.WorkstationAnnotation {
if in == nil {
return nil
}
var out []krm.WorkstationAnnotation
for k, v := range in {
out = append(out, krm.WorkstationAnnotation{
Key: k,
Value: v,
})
}
return out
}

func WorkstationClusterLabels_FromProto(mapCtx *direct.MapContext, in map[string]string) []krm.WorkstationLabel {
if in == nil {
return nil
}
var out []krm.WorkstationLabel
for k, v := range in {
out = append(out, krm.WorkstationLabel{
Key: k,
Value: v,
})
}
return out
}

func WorkstationCluster_PrivateClusterConfig_FromProto(mapCtx *direct.MapContext, in *pb.WorkstationCluster_PrivateClusterConfig) *krm.WorkstationCluster_PrivateClusterConfig {
if in == nil {
return nil
Expand Down Expand Up @@ -168,7 +117,7 @@ func WorkstationClusterObservedState_FromProto(mapCtx *direct.MapContext, in *pb
ClusterHostname: WorkstationClusterClusterHostname_FromProto(mapCtx, in.PrivateClusterConfig),
ServiceAttachmentURI: WorkstationClusterServiceAttachmentUri_FromProto(mapCtx, in.PrivateClusterConfig),
Degraded: direct.LazyPtr(in.GetDegraded()),
GCPConditions: WorkstationClusterGCPConditions_FromProto(mapCtx, in.GetConditions()),
GCPConditions: WorkstationGCPConditions_FromProto(mapCtx, in.GetConditions()),
}
return out
}
Expand All @@ -187,7 +136,7 @@ func WorkstationClusterObservedState_ToProto(mapCtx *direct.MapContext, in *krm.
out.Etag = direct.ValueOf(in.Etag)
out.ControlPlaneIp = direct.ValueOf(in.ControlPlaneIP)
out.Degraded = direct.ValueOf(in.Degraded)
out.Conditions = WorkstationClusterGCPConditions_ToProto(mapCtx, in.GCPConditions)
out.Conditions = WorkstationGCPConditions_ToProto(mapCtx, in.GCPConditions)
return out
}

Expand All @@ -204,30 +153,3 @@ func WorkstationClusterServiceAttachmentUri_FromProto(mapCtx *direct.MapContext,
}
return direct.LazyPtr(in.GetServiceAttachmentUri())
}

func WorkstationClusterGCPConditions_FromProto(mapCtx *direct.MapContext, in []*status.Status) []krm.WorkstationServiceGCPCondition {
if in == nil {
return nil
}
var out []krm.WorkstationServiceGCPCondition
for _, c := range in {
out = append(out, krm.WorkstationServiceGCPCondition{
Code: direct.LazyPtr(c.Code),
Message: direct.LazyPtr(c.Message),
})
}
return out
}
func WorkstationClusterGCPConditions_ToProto(mapCtx *direct.MapContext, in []krm.WorkstationServiceGCPCondition) []*status.Status {
if in == nil {
return nil
}
var out []*status.Status
for _, c := range in {
out = append(out, &status.Status{
Code: direct.ValueOf(c.Code),
Message: direct.ValueOf(c.Message),
})
}
return out
}
Loading

0 comments on commit 8de3627

Please sign in to comment.