From 3b2698eab7b30b289657d38446dcfed236a58e50 Mon Sep 17 00:00:00 2001 From: Anh Le Date: Fri, 8 Nov 2024 00:34:02 +0000 Subject: [PATCH] Add mapper for SpannerInstance direct controller --- dev/tools/controllerbuilder/generate.sh | 7 + go.mod | 1 + go.sum | 2 + .../direct/spanner/mapper.generated.go | 228 ++++++++++++++++++ .../direct/spanner/spannerinstace_mapper.go | 66 +++++ 5 files changed, 304 insertions(+) create mode 100644 pkg/controller/direct/spanner/mapper.generated.go create mode 100644 pkg/controller/direct/spanner/spannerinstace_mapper.go diff --git a/dev/tools/controllerbuilder/generate.sh b/dev/tools/controllerbuilder/generate.sh index 9143e2d2f5b..873ef7d4212 100755 --- a/dev/tools/controllerbuilder/generate.sh +++ b/dev/tools/controllerbuilder/generate.sh @@ -227,6 +227,13 @@ go run . generate-mapper \ --output-dir $REPO_ROOT/pkg/controller/direct/ \ --api-dir $REPO_ROOT/apis/ +go run . generate-direct-reconciler \ +--kind SecretManagerSecretVersion \ +--proto-resource SecretVersion \ +--api-version "secretmanager.cnrm.cloud.google.com/v1beta1" \ +--service "google.cloud.secretmanager.v1" \ +--proto-source-path ../proto-to-mapper/build/googleapis.pb + # Spanner go run main.go generate-types \ --service google.spanner.admin.instance.v1 \ diff --git a/go.mod b/go.mod index db15dbd7f78..1a5f6429aa1 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( cloud.google.com/go/secretmanager v1.14.1 cloud.google.com/go/securesourcemanager v1.1.1 cloud.google.com/go/security v1.18.1 + cloud.google.com/go/spanner v1.70.0 cloud.google.com/go/workstations v1.1.1 contrib.go.opencensus.io/exporter/prometheus v0.1.0 github.com/GoogleCloudPlatform/declarative-resource-client-library v1.62.0 diff --git a/go.sum b/go.sum index c7155745418..da9266af393 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ cloud.google.com/go/securesourcemanager v1.1.1 h1:raOxRsR507ALLlc5yG79LK7O2TuDbD cloud.google.com/go/securesourcemanager v1.1.1/go.mod h1:qMVTY4bzBRhcrUe0B8KvDCK5mhGQD6PyrHbzqOn3TLQ= cloud.google.com/go/security v1.18.1 h1:w7XbMR90Ir0y8NUxKJ3uyRHuHYWPUxVI5Z/sGqbrdAQ= cloud.google.com/go/security v1.18.1/go.mod h1:5P1q9rqwt0HuVeL9p61pTqQ6Lgio1c64jL2ZMWZV21Y= +cloud.google.com/go/spanner v1.70.0 h1:nj6p/GJTgMDiSQ1gQ034ItsKuJgHiMOjtOlONOg8PSo= +cloud.google.com/go/spanner v1.70.0/go.mod h1:X5T0XftydYp0K1adeJQDJtdWpbrOeJ7wHecM4tK6FiE= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= diff --git a/pkg/controller/direct/spanner/mapper.generated.go b/pkg/controller/direct/spanner/mapper.generated.go new file mode 100644 index 00000000000..41c2af9b322 --- /dev/null +++ b/pkg/controller/direct/spanner/mapper.generated.go @@ -0,0 +1,228 @@ +// 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 spanner + +import ( + pb "cloud.google.com/go/spanner/admin/instance/apiv1/instancepb" + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/spanner/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" +) + +func AutoscalingConfig_FromProto(mapCtx *direct.MapContext, in *pb.AutoscalingConfig) *krm.AutoscalingConfig { + if in == nil { + return nil + } + out := &krm.AutoscalingConfig{} + out.AutoscalingLimits = AutoscalingConfig_AutoscalingLimits_FromProto(mapCtx, in.GetAutoscalingLimits()) + out.AutoscalingTargets = AutoscalingConfig_AutoscalingTargets_FromProto(mapCtx, in.GetAutoscalingTargets()) + out.AsymmetricAutoscalingOptions = direct.Slice_FromProto(mapCtx, in.AsymmetricAutoscalingOptions, AutoscalingConfig_AsymmetricAutoscalingOption_FromProto) + return out +} +func AutoscalingConfig_ToProto(mapCtx *direct.MapContext, in *krm.AutoscalingConfig) *pb.AutoscalingConfig { + if in == nil { + return nil + } + out := &pb.AutoscalingConfig{} + out.AutoscalingLimits = AutoscalingConfig_AutoscalingLimits_ToProto(mapCtx, in.AutoscalingLimits) + out.AutoscalingTargets = AutoscalingConfig_AutoscalingTargets_ToProto(mapCtx, in.AutoscalingTargets) + out.AsymmetricAutoscalingOptions = direct.Slice_ToProto(mapCtx, in.AsymmetricAutoscalingOptions, AutoscalingConfig_AsymmetricAutoscalingOption_ToProto) + return out +} +func AutoscalingConfig_AsymmetricAutoscalingOption_FromProto(mapCtx *direct.MapContext, in *pb.AutoscalingConfig_AsymmetricAutoscalingOption) *krm.AutoscalingConfig_AsymmetricAutoscalingOption { + if in == nil { + return nil + } + out := &krm.AutoscalingConfig_AsymmetricAutoscalingOption{} + out.ReplicaSelection = ReplicaSelection_FromProto(mapCtx, in.GetReplicaSelection()) + out.Overrides = AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides_FromProto(mapCtx, in.GetOverrides()) + return out +} +func AutoscalingConfig_AsymmetricAutoscalingOption_ToProto(mapCtx *direct.MapContext, in *krm.AutoscalingConfig_AsymmetricAutoscalingOption) *pb.AutoscalingConfig_AsymmetricAutoscalingOption { + if in == nil { + return nil + } + out := &pb.AutoscalingConfig_AsymmetricAutoscalingOption{} + out.ReplicaSelection = ReplicaSelection_ToProto(mapCtx, in.ReplicaSelection) + out.Overrides = AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides_ToProto(mapCtx, in.Overrides) + return out +} +func AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides_FromProto(mapCtx *direct.MapContext, in *pb.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides) *krm.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides { + if in == nil { + return nil + } + out := &krm.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides{} + out.AutoscalingLimits = AutoscalingConfig_AutoscalingLimits_FromProto(mapCtx, in.GetAutoscalingLimits()) + out.AutoscalingTargetHighPriorityCpuUtilizationPercent = direct.LazyPtr(in.GetAutoscalingTargetHighPriorityCpuUtilizationPercent()) + return out +} +func AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides_ToProto(mapCtx *direct.MapContext, in *krm.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides) *pb.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides { + if in == nil { + return nil + } + out := &pb.AutoscalingConfig_AsymmetricAutoscalingOption_AutoscalingConfigOverrides{} + out.AutoscalingLimits = AutoscalingConfig_AutoscalingLimits_ToProto(mapCtx, in.AutoscalingLimits) + out.AutoscalingTargetHighPriorityCpuUtilizationPercent = direct.ValueOf(in.AutoscalingTargetHighPriorityCpuUtilizationPercent) + return out +} +func AutoscalingConfig_AutoscalingLimits_FromProto(mapCtx *direct.MapContext, in *pb.AutoscalingConfig_AutoscalingLimits) *krm.AutoscalingConfig_AutoscalingLimits { + if in == nil { + return nil + } + out := &krm.AutoscalingConfig_AutoscalingLimits{} + out.MinNodes = direct.LazyPtr(in.GetMinNodes()) + out.MinProcessingUnits = direct.LazyPtr(in.GetMinProcessingUnits()) + out.MaxNodes = direct.LazyPtr(in.GetMaxNodes()) + out.MaxProcessingUnits = direct.LazyPtr(in.GetMaxProcessingUnits()) + return out +} +func AutoscalingConfig_AutoscalingLimits_ToProto(mapCtx *direct.MapContext, in *krm.AutoscalingConfig_AutoscalingLimits) *pb.AutoscalingConfig_AutoscalingLimits { + if in == nil { + return nil + } + out := &pb.AutoscalingConfig_AutoscalingLimits{} + if oneof := AutoscalingConfig_AutoscalingLimits_MinNodes_ToProto(mapCtx, in.MinNodes); oneof != nil { + out.MinLimit = oneof + } + if oneof := AutoscalingConfig_AutoscalingLimits_MinProcessingUnits_ToProto(mapCtx, in.MinProcessingUnits); oneof != nil { + out.MinLimit = oneof + } + if oneof := AutoscalingConfig_AutoscalingLimits_MaxNodes_ToProto(mapCtx, in.MaxNodes); oneof != nil { + out.MaxLimit = oneof + } + if oneof := AutoscalingConfig_AutoscalingLimits_MaxProcessingUnits_ToProto(mapCtx, in.MaxProcessingUnits); oneof != nil { + out.MaxLimit = oneof + } + return out +} +func AutoscalingConfig_AutoscalingTargets_FromProto(mapCtx *direct.MapContext, in *pb.AutoscalingConfig_AutoscalingTargets) *krm.AutoscalingConfig_AutoscalingTargets { + if in == nil { + return nil + } + out := &krm.AutoscalingConfig_AutoscalingTargets{} + out.HighPriorityCpuUtilizationPercent = direct.LazyPtr(in.GetHighPriorityCpuUtilizationPercent()) + out.StorageUtilizationPercent = direct.LazyPtr(in.GetStorageUtilizationPercent()) + return out +} +func AutoscalingConfig_AutoscalingTargets_ToProto(mapCtx *direct.MapContext, in *krm.AutoscalingConfig_AutoscalingTargets) *pb.AutoscalingConfig_AutoscalingTargets { + if in == nil { + return nil + } + out := &pb.AutoscalingConfig_AutoscalingTargets{} + out.HighPriorityCpuUtilizationPercent = direct.ValueOf(in.HighPriorityCpuUtilizationPercent) + out.StorageUtilizationPercent = direct.ValueOf(in.StorageUtilizationPercent) + return out +} +func Instance_FromProto(mapCtx *direct.MapContext, in *pb.Instance) *krm.Instance { + if in == nil { + return nil + } + out := &krm.Instance{} + out.Name = direct.LazyPtr(in.GetName()) + out.Config = direct.LazyPtr(in.GetConfig()) + out.DisplayName = direct.LazyPtr(in.GetDisplayName()) + out.NodeCount = direct.LazyPtr(in.GetNodeCount()) + out.ProcessingUnits = direct.LazyPtr(in.GetProcessingUnits()) + out.ReplicaComputeCapacity = direct.Slice_FromProto(mapCtx, in.ReplicaComputeCapacity, ReplicaComputeCapacity_FromProto) + out.AutoscalingConfig = AutoscalingConfig_FromProto(mapCtx, in.GetAutoscalingConfig()) + out.State = direct.Enum_FromProto(mapCtx, in.GetState()) + out.Labels = in.Labels + out.EndpointUris = in.EndpointUris + out.CreateTime = direct.StringTimestamp_FromProto(mapCtx, in.GetCreateTime()) + out.UpdateTime = direct.StringTimestamp_FromProto(mapCtx, in.GetUpdateTime()) + out.Edition = direct.Enum_FromProto(mapCtx, in.GetEdition()) + return out +} +func Instance_ToProto(mapCtx *direct.MapContext, in *krm.Instance) *pb.Instance { + if in == nil { + return nil + } + out := &pb.Instance{} + out.Name = direct.ValueOf(in.Name) + out.Config = direct.ValueOf(in.Config) + out.DisplayName = direct.ValueOf(in.DisplayName) + out.NodeCount = direct.ValueOf(in.NodeCount) + out.ProcessingUnits = direct.ValueOf(in.ProcessingUnits) + out.ReplicaComputeCapacity = direct.Slice_ToProto(mapCtx, in.ReplicaComputeCapacity, ReplicaComputeCapacity_ToProto) + out.AutoscalingConfig = AutoscalingConfig_ToProto(mapCtx, in.AutoscalingConfig) + out.State = direct.Enum_ToProto[pb.Instance_State](mapCtx, in.State) + out.Labels = in.Labels + out.EndpointUris = in.EndpointUris + out.CreateTime = direct.StringTimestamp_ToProto(mapCtx, in.CreateTime) + out.UpdateTime = direct.StringTimestamp_ToProto(mapCtx, in.UpdateTime) + out.Edition = direct.Enum_ToProto[pb.Instance_Edition](mapCtx, in.Edition) + return out +} +func ReplicaComputeCapacity_FromProto(mapCtx *direct.MapContext, in *pb.ReplicaComputeCapacity) *krm.ReplicaComputeCapacity { + if in == nil { + return nil + } + out := &krm.ReplicaComputeCapacity{} + out.ReplicaSelection = ReplicaSelection_FromProto(mapCtx, in.GetReplicaSelection()) + out.NodeCount = direct.LazyPtr(in.GetNodeCount()) + out.ProcessingUnits = direct.LazyPtr(in.GetProcessingUnits()) + return out +} +func ReplicaComputeCapacity_ToProto(mapCtx *direct.MapContext, in *krm.ReplicaComputeCapacity) *pb.ReplicaComputeCapacity { + if in == nil { + return nil + } + out := &pb.ReplicaComputeCapacity{} + out.ReplicaSelection = ReplicaSelection_ToProto(mapCtx, in.ReplicaSelection) + if oneof := ReplicaComputeCapacity_NodeCount_ToProto(mapCtx, in.NodeCount); oneof != nil { + out.ComputeCapacity = oneof + } + if oneof := ReplicaComputeCapacity_ProcessingUnits_ToProto(mapCtx, in.ProcessingUnits); oneof != nil { + out.ComputeCapacity = oneof + } + return out +} +func ReplicaSelection_FromProto(mapCtx *direct.MapContext, in *pb.ReplicaSelection) *krm.ReplicaSelection { + if in == nil { + return nil + } + out := &krm.ReplicaSelection{} + out.Location = direct.LazyPtr(in.GetLocation()) + return out +} +func ReplicaSelection_ToProto(mapCtx *direct.MapContext, in *krm.ReplicaSelection) *pb.ReplicaSelection { + if in == nil { + return nil + } + out := &pb.ReplicaSelection{} + out.Location = direct.ValueOf(in.Location) + return out +} +func SpannerInstanceSpec_FromProto(mapCtx *direct.MapContext, in *pb.Instance) *krm.SpannerInstanceSpec { + if in == nil { + return nil + } + out := &krm.SpannerInstanceSpec{} + out.Config = in.GetConfig() + out.DisplayName = in.GetDisplayName() + out.ProcessingUnits = direct.LazyPtr(int64(in.GetProcessingUnits())) + out.NumNodes = direct.LazyPtr(int64(in.GetNodeCount())) + return out +} +func SpannerInstanceSpec_ToProto(mapCtx *direct.MapContext, in *krm.SpannerInstanceSpec) *pb.Instance { + if in == nil { + return nil + } + out := &pb.Instance{} + out.Config = in.Config + out.DisplayName = in.DisplayName + out.NodeCount = int32(direct.ValueOf(in.NumNodes)) + out.ProcessingUnits = int32(direct.ValueOf(in.ProcessingUnits)) + return out +} diff --git a/pkg/controller/direct/spanner/spannerinstace_mapper.go b/pkg/controller/direct/spanner/spannerinstace_mapper.go new file mode 100644 index 00000000000..8ebf8a841fc --- /dev/null +++ b/pkg/controller/direct/spanner/spannerinstace_mapper.go @@ -0,0 +1,66 @@ +// 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 spanner + +import ( + pb "cloud.google.com/go/spanner/admin/instance/apiv1/instancepb" + // krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/spanner/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" +) + +func AutoscalingConfig_AutoscalingLimits_MinNodes_ToProto(mapCtx *direct.MapContext, m *int32) *pb.AutoscalingConfig_AutoscalingLimits_MinNodes { + if m == nil { + return nil + } + return &pb.AutoscalingConfig_AutoscalingLimits_MinNodes{ + MinNodes: direct.ValueOf(m), + } +} +func AutoscalingConfig_AutoscalingLimits_MinProcessingUnits_ToProto(mapCtx *direct.MapContext, m *int32) *pb.AutoscalingConfig_AutoscalingLimits_MinProcessingUnits { + if m == nil { + return nil + } + return &pb.AutoscalingConfig_AutoscalingLimits_MinProcessingUnits{ + MinProcessingUnits: direct.ValueOf(m), + } +} +func AutoscalingConfig_AutoscalingLimits_MaxNodes_ToProto(mapCtx *direct.MapContext, m *int32) *pb.AutoscalingConfig_AutoscalingLimits_MaxNodes { + if m == nil { + return nil + } + return &pb.AutoscalingConfig_AutoscalingLimits_MaxNodes{ + MaxNodes: direct.ValueOf(m), + } +} +func AutoscalingConfig_AutoscalingLimits_MaxProcessingUnits_ToProto(mapCtx *direct.MapContext, m *int32) *pb.AutoscalingConfig_AutoscalingLimits_MaxProcessingUnits { + if m == nil { + return nil + } + return &pb.AutoscalingConfig_AutoscalingLimits_MaxProcessingUnits{ + MaxProcessingUnits: direct.ValueOf(m), + } +} +func ReplicaComputeCapacity_NodeCount_ToProto(mapCtx *direct.MapContext, m *int32) *pb.ReplicaComputeCapacity_NodeCount { + if m == nil { + return nil + } + return &pb.ReplicaComputeCapacity_NodeCount{NodeCount: direct.ValueOf(m)} +} +func ReplicaComputeCapacity_ProcessingUnits_ToProto(mapCtx *direct.MapContext, m *int32) *pb.ReplicaComputeCapacity_ProcessingUnits { + if m == nil { + return nil + } + return &pb.ReplicaComputeCapacity_ProcessingUnits{ProcessingUnits: direct.ValueOf(m)} +}