From 62925369a7b22c3dd53f62d1dc7d5e0826ecda9c Mon Sep 17 00:00:00 2001 From: Alex Pana <8968914+acpana@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:27:29 +0000 Subject: [PATCH] refactor: maputils Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> --- .../direct/alloydb/cluster_controller.go | 18 +- pkg/controller/direct/alloydb/mapping.go | 32 +- pkg/controller/direct/alloydb/utils.go | 66 --- .../direct/apikeys/apikeyskey_controller.go | 7 +- pkg/controller/direct/apikeys/utils.go | 51 -- pkg/controller/direct/gkehub/acmconversion.go | 10 + .../gkehub/featuremembership_controller.go | 3 +- .../direct/gkehub/pococonversion.go | 5 +- pkg/controller/direct/gkehub/references.go | 3 +- pkg/controller/direct/gkehub/util.go | 60 --- pkg/controller/direct/maputils.go | 74 +++ .../direct/monitoring/changedetection.go | 9 +- .../dashboard_generated.mappings.go | 445 +++++++++--------- .../direct/monitoring/dashboard_mappings.go | 101 ++-- pkg/controller/direct/monitoring/maputils.go | 190 -------- .../monitoringdashboard_controller.go | 15 +- .../direct/monitoring/roundtrip_test.go | 3 +- pkg/controller/direct/monitoring/utils.go | 34 -- .../privateca/privatecapool_controller.go | 5 +- pkg/controller/direct/privateca/utils.go | 64 --- .../resourcemanager/tagkey_controller.go | 27 +- .../direct/resourcemanager/utils.go | 80 ---- .../securesourcemanager/mapper.generated.go | 121 ++--- .../direct/securesourcemanager/mapper.go | 17 +- .../direct/securesourcemanager/maputils.go | 119 ----- .../securesourcemanager/roundtrip_test.go | 5 +- .../direct/securesourcemanager/utils.go | 27 -- 27 files changed, 511 insertions(+), 1080 deletions(-) delete mode 100644 pkg/controller/direct/alloydb/utils.go delete mode 100644 pkg/controller/direct/apikeys/utils.go delete mode 100644 pkg/controller/direct/gkehub/util.go delete mode 100644 pkg/controller/direct/monitoring/maputils.go delete mode 100644 pkg/controller/direct/privateca/utils.go delete mode 100644 pkg/controller/direct/resourcemanager/utils.go delete mode 100644 pkg/controller/direct/securesourcemanager/maputils.go delete mode 100644 pkg/controller/direct/securesourcemanager/utils.go diff --git a/pkg/controller/direct/alloydb/cluster_controller.go b/pkg/controller/direct/alloydb/cluster_controller.go index ea1106206d..7a222e66a2 100644 --- a/pkg/controller/direct/alloydb/cluster_controller.go +++ b/pkg/controller/direct/alloydb/cluster_controller.go @@ -77,7 +77,7 @@ func (m *clusterModel) AdapterForObject(ctx context.Context, reader client.Reade if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &obj); err != nil { return nil, fmt.Errorf("error converting to %T: %w", obj, err) } - resourceID := ValueOf(obj.Spec.ResourceID) + resourceID := direct.ValueOf(obj.Spec.ResourceID) if resourceID == "" { resourceID = obj.GetName() } @@ -125,7 +125,7 @@ func (a *clusterAdapter) Find(ctx context.Context) (bool, error) { } cluster, err := a.client.Projects.Locations.Clusters.Get(a.fullyQualifiedName()).Context(ctx).Do() if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, err @@ -145,7 +145,7 @@ func (a *clusterAdapter) Delete(ctx context.Context) (bool, error) { op, err := a.client.Projects.Locations.Clusters.Delete(a.fullyQualifiedName()).Context(ctx).Do() if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("deleting cluster %s: %w", a.fullyQualifiedName(), err) @@ -303,3 +303,15 @@ func (a *clusterAdapter) Export(ctx context.Context) (*unstructured.Unstructured func (a *clusterAdapter) fullyQualifiedName() string { return fmt.Sprintf("projects/%s/locations/%s/clusters/%s", a.projectID, a.location, a.resourceID) } + +func setStatus(u *unstructured.Unstructured, typedStatus any) error { + // TODO: Just fetch this object? + status, err := runtime.DefaultUnstructuredConverter.ToUnstructured(typedStatus) + if err != nil { + return fmt.Errorf("error converting status to unstructured: %w", err) + } + // TODO: Merge to avoid overwriting conditions? + u.Object["status"] = status + + return nil +} diff --git a/pkg/controller/direct/alloydb/mapping.go b/pkg/controller/direct/alloydb/mapping.go index cd110fe1fc..59df40c5e3 100644 --- a/pkg/controller/direct/alloydb/mapping.go +++ b/pkg/controller/direct/alloydb/mapping.go @@ -26,9 +26,9 @@ func ClusterSpecToApi(ctx *direct.MapContext, in *krm.AlloyDBClusterSpec) *api.C } out := &api.Cluster{ AutomatedBackupPolicy: AutomatedBackupPolicy_KRMToApi(ctx, in.AutomatedBackupPolicy), - ClusterType: ValueOf(in.ClusterType), + ClusterType: direct.ValueOf(in.ClusterType), ContinuousBackupConfig: ContinuousBackupConfig_KRMToApi(ctx, in.ContinuousBackupConfig), - DisplayName: ValueOf(in.DisplayName), + DisplayName: direct.ValueOf(in.DisplayName), EncryptionConfig: EncryptionConfig_KRMToApi(ctx, in.EncryptionConfig), InitialUser: InitialUser_KRMToApi(ctx, in.InitialUser), NetworkConfig: NetworkConfig_KRMToApi(ctx, in.NetworkConfig), @@ -45,7 +45,7 @@ func NetworkConfig_KRMToApi(ctx *direct.MapContext, in *krm.ClusterNetworkConfig return nil } out := &api.NetworkConfig{ - AllocatedIpRange: ValueOf(in.AllocatedIpRange), + AllocatedIpRange: direct.ValueOf(in.AllocatedIpRange), Network: in.NetworkRef.External, } return out @@ -57,11 +57,11 @@ func AutomatedBackupPolicy_KRMToApi(ctx *direct.MapContext, in *krm.ClusterAutom return nil } out := &api.AutomatedBackupPolicy{ - BackupWindow: ValueOf(in.BackupWindow), - Enabled: ValueOf(in.Enabled), + BackupWindow: direct.ValueOf(in.BackupWindow), + Enabled: direct.ValueOf(in.Enabled), EncryptionConfig: EncryptionConfig_KRMToApi(ctx, in.EncryptionConfig), Labels: in.Labels, - Location: ValueOf(in.Location), + Location: direct.ValueOf(in.Location), QuantityBasedRetention: QuantityBasedRetention_KRMToApi(ctx, in.QuantityBasedRetention), TimeBasedRetention: TimeBasedRetention_KRMToApi(ctx, in.TimeBasedRetention), WeeklySchedule: WeeklySchedule_KRMToApi(ctx, in.WeeklySchedule), @@ -94,10 +94,10 @@ func Time_KRMToApi(ctx *direct.MapContext, in *krm.ClusterStartTimes) *api.Googl return nil } out := &api.GoogleTypeTimeOfDay{ - Hours: int64(ValueOf(in.Hours)), - Minutes: int64(ValueOf(in.Minutes)), - Nanos: int64(ValueOf(in.Nanos)), - Seconds: int64(ValueOf(in.Seconds)), + Hours: int64(direct.ValueOf(in.Hours)), + Minutes: int64(direct.ValueOf(in.Minutes)), + Nanos: int64(direct.ValueOf(in.Nanos)), + Seconds: int64(direct.ValueOf(in.Seconds)), } return out } @@ -117,7 +117,7 @@ func TimeBasedRetention_KRMToApi(ctx *direct.MapContext, in *krm.ClusterTimeBase return nil } out := &api.TimeBasedRetention{ - RetentionPeriod: ValueOf(in.RetentionPeriod), + RetentionPeriod: direct.ValueOf(in.RetentionPeriod), } return out @@ -128,7 +128,7 @@ func QuantityBasedRetention_KRMToApi(ctx *direct.MapContext, in *krm.ClusterQuan return nil } out := &api.QuantityBasedRetention{ - Count: int64(ValueOf(in.Count)), + Count: int64(direct.ValueOf(in.Count)), } return out @@ -139,9 +139,9 @@ func ContinuousBackupConfig_KRMToApi(ctx *direct.MapContext, in *krm.ClusterCont return nil } out := &api.ContinuousBackupConfig{ - Enabled: ValueOf(in.Enabled), + Enabled: direct.ValueOf(in.Enabled), EncryptionConfig: EncryptionConfig_KRMToApi(ctx, in.EncryptionConfig), - RecoveryWindowDays: int64(ValueOf(in.RecoveryWindowDays)), + RecoveryWindowDays: int64(direct.ValueOf(in.RecoveryWindowDays)), } return out @@ -152,10 +152,10 @@ func InitialUser_KRMToApi(ctx *direct.MapContext, in *krm.ClusterInitialUser) *a return nil } out := &api.UserPassword{ - User: ValueOf(in.User), + User: direct.ValueOf(in.User), } if in.Password.Value != nil { - out.Password = ValueOf(in.Password.Value) + out.Password = direct.ValueOf(in.Password.Value) } else { out.Password = in.Password.ValueFrom.SecretKeyRef.Key } diff --git a/pkg/controller/direct/alloydb/utils.go b/pkg/controller/direct/alloydb/utils.go deleted file mode 100644 index 8049280541..0000000000 --- a/pkg/controller/direct/alloydb/utils.go +++ /dev/null @@ -1,66 +0,0 @@ -// 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 alloydb - -import ( - "errors" - "fmt" - - "github.com/googleapis/gax-go/v2/apierror" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/klog/v2" -) - -func setStatus(u *unstructured.Unstructured, typedStatus any) error { - // TODO: Just fetch this object? - status, err := runtime.DefaultUnstructuredConverter.ToUnstructured(typedStatus) - if err != nil { - return fmt.Errorf("error converting status to unstructured: %w", err) - } - // TODO: Merge to avoid overwriting conditions? - u.Object["status"] = status - - return nil -} - -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} diff --git a/pkg/controller/direct/apikeys/apikeyskey_controller.go b/pkg/controller/direct/apikeys/apikeyskey_controller.go index c2993ee16f..ece07be629 100644 --- a/pkg/controller/direct/apikeys/apikeyskey_controller.go +++ b/pkg/controller/direct/apikeys/apikeyskey_controller.go @@ -30,6 +30,7 @@ import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/apikeys/v1alpha1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry" @@ -129,7 +130,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u } // TODO: Use name or request resourceID to be set on create? - keyID := ValueOf(obj.Spec.ResourceID) + keyID := direct.ValueOf(obj.Spec.ResourceID) if keyID == "" { return nil, fmt.Errorf("unable to determine resourceID") } @@ -162,7 +163,7 @@ func (a *adapter) Find(ctx context.Context) (bool, error) { } key, err := a.gcp.GetKey(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { klog.Warningf("key was not found: %v", err) return false, nil } @@ -186,7 +187,7 @@ func (a *adapter) Delete(ctx context.Context) (bool, error) { } op, err := a.gcp.DeleteKey(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("deleting key: %w", err) diff --git a/pkg/controller/direct/apikeys/utils.go b/pkg/controller/direct/apikeys/utils.go deleted file mode 100644 index 03ff82487e..0000000000 --- a/pkg/controller/direct/apikeys/utils.go +++ /dev/null @@ -1,51 +0,0 @@ -// 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 apikeys - -import ( - "errors" - - "github.com/googleapis/gax-go/v2/apierror" - "k8s.io/klog/v2" -) - -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} diff --git a/pkg/controller/direct/gkehub/acmconversion.go b/pkg/controller/direct/gkehub/acmconversion.go index a870a637d5..c238e01500 100644 --- a/pkg/controller/direct/gkehub/acmconversion.go +++ b/pkg/controller/direct/gkehub/acmconversion.go @@ -15,6 +15,8 @@ package gkehub import ( + "strconv" + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/gkehub/v1beta1" featureapi "google.golang.org/api/gkehub/v1beta" ) @@ -187,3 +189,11 @@ func convertKRMtoAPI_Oci(r *krm.FeaturemembershipOci) (*featureapi.ConfigManagem } return &apiObj, nil } + +func convertStringToInt64(s string) (int64, error) { + val, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return 0, err + } + return val, nil +} diff --git a/pkg/controller/direct/gkehub/featuremembership_controller.go b/pkg/controller/direct/gkehub/featuremembership_controller.go index 26776188b4..2801e003ea 100644 --- a/pkg/controller/direct/gkehub/featuremembership_controller.go +++ b/pkg/controller/direct/gkehub/featuremembership_controller.go @@ -28,6 +28,7 @@ import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/gkehub/v1beta1" refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry" ) @@ -146,7 +147,7 @@ func (a *gkeHubAdapter) Find(ctx context.Context) (bool, error) { } feature, err := a.featureClient.Get(a.featureID).Context(ctx).Do() if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("getting feature %q: %w", a.featureID, err) diff --git a/pkg/controller/direct/gkehub/pococonversion.go b/pkg/controller/direct/gkehub/pococonversion.go index 090d600f30..e4e0b5db16 100644 --- a/pkg/controller/direct/gkehub/pococonversion.go +++ b/pkg/controller/direct/gkehub/pococonversion.go @@ -16,6 +16,7 @@ package gkehub import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/gkehub/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" featureapi "google.golang.org/api/gkehub/v1beta" ) @@ -32,10 +33,10 @@ func convertKRMtoAPI_Policycontroller(r *krm.FeaturemembershipPolicycontroller) func convertKRMtoAPI_PolicycontrollerHubConfig(r krm.FeaturemembershipPolicyControllerHubConfig) *featureapi.PolicyControllerHubConfig { apiObj := &featureapi.PolicyControllerHubConfig{} if r.AuditIntervalSeconds != nil { - apiObj.AuditIntervalSeconds = int64(ValueOf(r.AuditIntervalSeconds)) + apiObj.AuditIntervalSeconds = int64(direct.ValueOf(r.AuditIntervalSeconds)) } if r.ConstraintViolationLimit != nil { - apiObj.ConstraintViolationLimit = int64(ValueOf(r.ConstraintViolationLimit)) + apiObj.ConstraintViolationLimit = int64(direct.ValueOf(r.ConstraintViolationLimit)) } if r.ExemptableNamespaces != nil { apiObj.ExemptableNamespaces = r.ExemptableNamespaces diff --git a/pkg/controller/direct/gkehub/references.go b/pkg/controller/direct/gkehub/references.go index 4222b0c8fd..f0ec4277a4 100644 --- a/pkg/controller/direct/gkehub/references.go +++ b/pkg/controller/direct/gkehub/references.go @@ -20,6 +20,7 @@ import ( "strings" krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/gkehub/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" @@ -85,7 +86,7 @@ func resolveMembershipRef(ctx context.Context, reader client.Reader, obj *krm.GK if membershipName == "" { membershipName = membership.GetName() } - membershipLocation := ValueOf(obj.Spec.MembershipLocation) + membershipLocation := direct.ValueOf(obj.Spec.MembershipLocation) if membershipLocation == "" { // membership location should default to global if not set. membershipLocation = "global" diff --git a/pkg/controller/direct/gkehub/util.go b/pkg/controller/direct/gkehub/util.go deleted file mode 100644 index 65c652262f..0000000000 --- a/pkg/controller/direct/gkehub/util.go +++ /dev/null @@ -1,60 +0,0 @@ -// 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 gkehub - -import ( - "errors" - "strconv" - - "github.com/googleapis/gax-go/v2/apierror" - "k8s.io/klog/v2" -) - -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} - -func convertStringToInt64(s string) (int64, error) { - val, err := strconv.ParseInt(s, 10, 64) - if err != nil { - return 0, err - } - return val, nil -} diff --git a/pkg/controller/direct/maputils.go b/pkg/controller/direct/maputils.go index 36c3a8eb4f..026007a44d 100644 --- a/pkg/controller/direct/maputils.go +++ b/pkg/controller/direct/maputils.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" "runtime" + "strconv" "strings" "time" @@ -25,6 +26,7 @@ import ( "github.com/googleapis/gax-go/v2/apierror" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" "k8s.io/klog/v2" ) @@ -161,6 +163,10 @@ func ToOpenAPIDateTime(ts *timestamppb.Timestamp) *string { return &formatted } +func PtrTo[T any](t T) *T { + return &t +} + func ValueOf[T any](p *T) T { var v T if p != nil { @@ -189,3 +195,71 @@ func HasHTTPCode(err error, code int) bool { } return false } + +func Duration_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { + if in == nil { + return nil + } + + s := *in + if s == "" { + return nil + } + + if strings.HasSuffix(s, "s") { + d, err := time.ParseDuration(s) + if err != nil { + mapCtx.Errorf("parsing duration %q: %w", s, err) + return nil + } + out := durationpb.New(d) + return out + } + + mapCtx.Errorf("parsing duration %q, must end in s", s) + return nil +} + +func Duration_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { + if in == nil { + return nil + } + + // We want to report the duration without truncation (do don't want to map via float64) + s := strconv.FormatInt(in.Seconds, 10) + if in.Nanos != 0 { + nanos := strconv.FormatInt(int64(in.Nanos), 10) + pad := 9 - len(nanos) + nanos = strings.Repeat("0", pad) + nanos + nanos = strings.TrimRight(nanos, "0") + s += "." + nanos + } + s += "s" + return &s +} + +func SecondsString_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { + if in == nil { + return nil + } + seconds := in.GetSeconds() + out := strconv.FormatInt(seconds, 10) + return &out +} + +func SecondsString_ToProto(mapCtx *MapContext, in *string, fieldName string) *durationpb.Duration { + if in == nil { + return nil + } + v := *in + if strings.HasSuffix(v, "s") { + v = strings.TrimSuffix(v, "s") + } + seconds, err := strconv.ParseInt(v, 10, 64) + if err != nil { + mapCtx.Errorf("%s value %q is not valid", fieldName, *in) + return nil + } + out := &durationpb.Duration{Seconds: seconds} + return out +} diff --git a/pkg/controller/direct/monitoring/changedetection.go b/pkg/controller/direct/monitoring/changedetection.go index bc6fb4b258..9cc330e3b1 100644 --- a/pkg/controller/direct/monitoring/changedetection.go +++ b/pkg/controller/direct/monitoring/changedetection.go @@ -18,6 +18,7 @@ import ( "context" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -64,8 +65,8 @@ func ShouldReconcileBasedOnEtag(ctx context.Context, u *unstructured.Unstructure return true } - if u.GetGeneration() != ValueOf(obj.Status.ObservedGeneration) { - log.V(2).Info("generation does not match", "generation", u.GetGeneration(), "observedGeneration", ValueOf(obj.Status.ObservedGeneration)) + if u.GetGeneration() != direct.ValueOf(obj.Status.ObservedGeneration) { + log.V(2).Info("generation does not match", "generation", u.GetGeneration(), "observedGeneration", direct.ValueOf(obj.Status.ObservedGeneration)) return true } @@ -74,9 +75,9 @@ func ShouldReconcileBasedOnEtag(ctx context.Context, u *unstructured.Unstructure return true } - objectEtag := ValueOf(obj.Status.ObservedState.Etag) + objectEtag := direct.ValueOf(obj.Status.ObservedState.Etag) if objectEtag == "" { - objectEtag = ValueOf(obj.Status.Etag) + objectEtag = direct.ValueOf(obj.Status.Etag) } if objectEtag == "" { diff --git a/pkg/controller/direct/monitoring/dashboard_generated.mappings.go b/pkg/controller/direct/monitoring/dashboard_generated.mappings.go index d5a73cc9a3..12c26a7282 100644 --- a/pkg/controller/direct/monitoring/dashboard_generated.mappings.go +++ b/pkg/controller/direct/monitoring/dashboard_generated.mappings.go @@ -18,183 +18,184 @@ import ( pb "cloud.google.com/go/monitoring/dashboard/apiv1/dashboardpb" krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/monitoring/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" ) -func Aggregation_FromProto(mapCtx *MapContext, in *pb.Aggregation) *krm.Aggregation { +func Aggregation_FromProto(mapCtx *direct.MapContext, in *pb.Aggregation) *krm.Aggregation { if in == nil { return nil } out := &krm.Aggregation{} out.AlignmentPeriod = Aggregation_AlignmentPeriod_FromProto(mapCtx, in.GetAlignmentPeriod()) - out.PerSeriesAligner = Enum_FromProto(mapCtx, in.PerSeriesAligner) - out.CrossSeriesReducer = Enum_FromProto(mapCtx, in.CrossSeriesReducer) + out.PerSeriesAligner = direct.Enum_FromProto(mapCtx, in.PerSeriesAligner) + out.CrossSeriesReducer = direct.Enum_FromProto(mapCtx, in.CrossSeriesReducer) out.GroupByFields = in.GroupByFields return out } -func Aggregation_ToProto(mapCtx *MapContext, in *krm.Aggregation) *pb.Aggregation { +func Aggregation_ToProto(mapCtx *direct.MapContext, in *krm.Aggregation) *pb.Aggregation { if in == nil { return nil } out := &pb.Aggregation{} out.AlignmentPeriod = Aggregation_AlignmentPeriod_ToProto(mapCtx, in.AlignmentPeriod) - out.PerSeriesAligner = Enum_ToProto[pb.Aggregation_Aligner](mapCtx, in.PerSeriesAligner) - out.CrossSeriesReducer = Enum_ToProto[pb.Aggregation_Reducer](mapCtx, in.CrossSeriesReducer) + out.PerSeriesAligner = direct.Enum_ToProto[pb.Aggregation_Aligner](mapCtx, in.PerSeriesAligner) + out.CrossSeriesReducer = direct.Enum_ToProto[pb.Aggregation_Reducer](mapCtx, in.CrossSeriesReducer) out.GroupByFields = in.GroupByFields return out } -func ChartOptions_FromProto(mapCtx *MapContext, in *pb.ChartOptions) *krm.ChartOptions { +func ChartOptions_FromProto(mapCtx *direct.MapContext, in *pb.ChartOptions) *krm.ChartOptions { if in == nil { return nil } out := &krm.ChartOptions{} - out.Mode = Enum_FromProto(mapCtx, in.Mode) + out.Mode = direct.Enum_FromProto(mapCtx, in.Mode) return out } -func ChartOptions_ToProto(mapCtx *MapContext, in *krm.ChartOptions) *pb.ChartOptions { +func ChartOptions_ToProto(mapCtx *direct.MapContext, in *krm.ChartOptions) *pb.ChartOptions { if in == nil { return nil } out := &pb.ChartOptions{} - out.Mode = Enum_ToProto[pb.ChartOptions_Mode](mapCtx, in.Mode) + out.Mode = direct.Enum_ToProto[pb.ChartOptions_Mode](mapCtx, in.Mode) return out } -func CollapsibleGroup_FromProto(mapCtx *MapContext, in *pb.CollapsibleGroup) *krm.CollapsibleGroup { +func CollapsibleGroup_FromProto(mapCtx *direct.MapContext, in *pb.CollapsibleGroup) *krm.CollapsibleGroup { if in == nil { return nil } out := &krm.CollapsibleGroup{} - out.Collapsed = LazyPtr(in.GetCollapsed()) + out.Collapsed = direct.LazyPtr(in.GetCollapsed()) return out } -func CollapsibleGroup_ToProto(mapCtx *MapContext, in *krm.CollapsibleGroup) *pb.CollapsibleGroup { +func CollapsibleGroup_ToProto(mapCtx *direct.MapContext, in *krm.CollapsibleGroup) *pb.CollapsibleGroup { if in == nil { return nil } out := &pb.CollapsibleGroup{} - out.Collapsed = ValueOf(in.Collapsed) + out.Collapsed = direct.ValueOf(in.Collapsed) return out } -func ColumnLayout_FromProto(mapCtx *MapContext, in *pb.ColumnLayout) *krm.ColumnLayout { +func ColumnLayout_FromProto(mapCtx *direct.MapContext, in *pb.ColumnLayout) *krm.ColumnLayout { if in == nil { return nil } out := &krm.ColumnLayout{} - out.Columns = Slice_FromProto(mapCtx, in.Columns, ColumnLayout_Column_FromProto) + out.Columns = direct.Slice_FromProto(mapCtx, in.Columns, ColumnLayout_Column_FromProto) return out } -func ColumnLayout_ToProto(mapCtx *MapContext, in *krm.ColumnLayout) *pb.ColumnLayout { +func ColumnLayout_ToProto(mapCtx *direct.MapContext, in *krm.ColumnLayout) *pb.ColumnLayout { if in == nil { return nil } out := &pb.ColumnLayout{} - out.Columns = Slice_ToProto(mapCtx, in.Columns, ColumnLayout_Column_ToProto) + out.Columns = direct.Slice_ToProto(mapCtx, in.Columns, ColumnLayout_Column_ToProto) return out } -func ColumnLayout_Column_FromProto(mapCtx *MapContext, in *pb.ColumnLayout_Column) *krm.ColumnLayout_Column { +func ColumnLayout_Column_FromProto(mapCtx *direct.MapContext, in *pb.ColumnLayout_Column) *krm.ColumnLayout_Column { if in == nil { return nil } out := &krm.ColumnLayout_Column{} - out.Weight = LazyPtr(in.GetWeight()) - out.Widgets = Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) + out.Weight = direct.LazyPtr(in.GetWeight()) + out.Widgets = direct.Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) return out } -func ColumnLayout_Column_ToProto(mapCtx *MapContext, in *krm.ColumnLayout_Column) *pb.ColumnLayout_Column { +func ColumnLayout_Column_ToProto(mapCtx *direct.MapContext, in *krm.ColumnLayout_Column) *pb.ColumnLayout_Column { if in == nil { return nil } out := &pb.ColumnLayout_Column{} - out.Weight = ValueOf(in.Weight) - out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) + out.Weight = direct.ValueOf(in.Weight) + out.Widgets = direct.Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) return out } -func DashboardFilter_FromProto(mapCtx *MapContext, in *pb.DashboardFilter) *krm.DashboardFilter { +func DashboardFilter_FromProto(mapCtx *direct.MapContext, in *pb.DashboardFilter) *krm.DashboardFilter { if in == nil { return nil } out := &krm.DashboardFilter{} - out.LabelKey = LazyPtr(in.GetLabelKey()) - out.TemplateVariable = LazyPtr(in.GetTemplateVariable()) - out.StringValue = LazyPtr(in.GetStringValue()) - out.FilterType = Enum_FromProto(mapCtx, in.FilterType) + out.LabelKey = direct.LazyPtr(in.GetLabelKey()) + out.TemplateVariable = direct.LazyPtr(in.GetTemplateVariable()) + out.StringValue = direct.LazyPtr(in.GetStringValue()) + out.FilterType = direct.Enum_FromProto(mapCtx, in.FilterType) return out } -func DashboardFilter_ToProto(mapCtx *MapContext, in *krm.DashboardFilter) *pb.DashboardFilter { +func DashboardFilter_ToProto(mapCtx *direct.MapContext, in *krm.DashboardFilter) *pb.DashboardFilter { if in == nil { return nil } out := &pb.DashboardFilter{} - out.LabelKey = ValueOf(in.LabelKey) - out.TemplateVariable = ValueOf(in.TemplateVariable) + out.LabelKey = direct.ValueOf(in.LabelKey) + out.TemplateVariable = direct.ValueOf(in.TemplateVariable) if oneof := DashboardFilter_StringValue_ToProto(mapCtx, in.StringValue); oneof != nil { out.DefaultValue = oneof } - out.FilterType = Enum_ToProto[pb.DashboardFilter_FilterType](mapCtx, in.FilterType) + out.FilterType = direct.Enum_ToProto[pb.DashboardFilter_FilterType](mapCtx, in.FilterType) return out } -func GridLayout_FromProto(mapCtx *MapContext, in *pb.GridLayout) *krm.GridLayout { +func GridLayout_FromProto(mapCtx *direct.MapContext, in *pb.GridLayout) *krm.GridLayout { if in == nil { return nil } out := &krm.GridLayout{} - out.Columns = LazyPtr(in.GetColumns()) - out.Widgets = Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) + out.Columns = direct.LazyPtr(in.GetColumns()) + out.Widgets = direct.Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) return out } -func GridLayout_ToProto(mapCtx *MapContext, in *krm.GridLayout) *pb.GridLayout { +func GridLayout_ToProto(mapCtx *direct.MapContext, in *krm.GridLayout) *pb.GridLayout { if in == nil { return nil } out := &pb.GridLayout{} - out.Columns = ValueOf(in.Columns) - out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) + out.Columns = direct.ValueOf(in.Columns) + out.Widgets = direct.Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) return out } -func LogsPanel_FromProto(mapCtx *MapContext, in *pb.LogsPanel) *krm.LogsPanel { +func LogsPanel_FromProto(mapCtx *direct.MapContext, in *pb.LogsPanel) *krm.LogsPanel { if in == nil { return nil } out := &krm.LogsPanel{} - out.Filter = LazyPtr(in.GetFilter()) + out.Filter = direct.LazyPtr(in.GetFilter()) out.ResourceNames = LogsPanel_ResourceNames_FromProto(mapCtx, in.ResourceNames) return out } -func LogsPanel_ToProto(mapCtx *MapContext, in *krm.LogsPanel) *pb.LogsPanel { +func LogsPanel_ToProto(mapCtx *direct.MapContext, in *krm.LogsPanel) *pb.LogsPanel { if in == nil { return nil } out := &pb.LogsPanel{} - out.Filter = ValueOf(in.Filter) + out.Filter = direct.ValueOf(in.Filter) out.ResourceNames = LogsPanel_ResourceNames_ToProto(mapCtx, in.ResourceNames) return out } -func MonitoringDashboardSpec_FromProto(mapCtx *MapContext, in *pb.Dashboard) *krm.MonitoringDashboardSpec { +func MonitoringDashboardSpec_FromProto(mapCtx *direct.MapContext, in *pb.Dashboard) *krm.MonitoringDashboardSpec { if in == nil { return nil } out := &krm.MonitoringDashboardSpec{} // MISSING: Name - out.DisplayName = LazyPtr(in.GetDisplayName()) + out.DisplayName = direct.LazyPtr(in.GetDisplayName()) // MISSING: Etag out.GridLayout = GridLayout_FromProto(mapCtx, in.GetGridLayout()) out.MosaicLayout = MosaicLayout_FromProto(mapCtx, in.GetMosaicLayout()) out.RowLayout = RowLayout_FromProto(mapCtx, in.GetRowLayout()) out.ColumnLayout = ColumnLayout_FromProto(mapCtx, in.GetColumnLayout()) - out.DashboardFilters = Slice_FromProto(mapCtx, in.DashboardFilters, DashboardFilter_FromProto) + out.DashboardFilters = direct.Slice_FromProto(mapCtx, in.DashboardFilters, DashboardFilter_FromProto) // MISSING: Labels return out } -func MonitoringDashboardSpec_ToProto(mapCtx *MapContext, in *krm.MonitoringDashboardSpec) *pb.Dashboard { +func MonitoringDashboardSpec_ToProto(mapCtx *direct.MapContext, in *krm.MonitoringDashboardSpec) *pb.Dashboard { if in == nil { return nil } out := &pb.Dashboard{} // MISSING: Name - out.DisplayName = ValueOf(in.DisplayName) + out.DisplayName = direct.ValueOf(in.DisplayName) // MISSING: Etag if oneof := GridLayout_ToProto(mapCtx, in.GridLayout); oneof != nil { out.Layout = &pb.Dashboard_GridLayout{GridLayout: oneof} @@ -208,18 +209,18 @@ func MonitoringDashboardSpec_ToProto(mapCtx *MapContext, in *krm.MonitoringDashb if oneof := ColumnLayout_ToProto(mapCtx, in.ColumnLayout); oneof != nil { out.Layout = &pb.Dashboard_ColumnLayout{ColumnLayout: oneof} } - out.DashboardFilters = Slice_ToProto(mapCtx, in.DashboardFilters, DashboardFilter_ToProto) + out.DashboardFilters = direct.Slice_ToProto(mapCtx, in.DashboardFilters, DashboardFilter_ToProto) // MISSING: Labels return out } -func MonitoringDashboardStatus_FromProto(mapCtx *MapContext, in *pb.Dashboard) *krm.MonitoringDashboardStatus { +func MonitoringDashboardStatus_FromProto(mapCtx *direct.MapContext, in *pb.Dashboard) *krm.MonitoringDashboardStatus { if in == nil { return nil } out := &krm.MonitoringDashboardStatus{} // MISSING: Name // MISSING: DisplayName - out.Etag = LazyPtr(in.GetEtag()) + out.Etag = direct.LazyPtr(in.GetEtag()) // MISSING: GridLayout // MISSING: MosaicLayout // MISSING: RowLayout @@ -228,14 +229,14 @@ func MonitoringDashboardStatus_FromProto(mapCtx *MapContext, in *pb.Dashboard) * // MISSING: Labels return out } -func MonitoringDashboardStatus_ToProto(mapCtx *MapContext, in *krm.MonitoringDashboardStatus) *pb.Dashboard { +func MonitoringDashboardStatus_ToProto(mapCtx *direct.MapContext, in *krm.MonitoringDashboardStatus) *pb.Dashboard { if in == nil { return nil } out := &pb.Dashboard{} // MISSING: Name // MISSING: DisplayName - out.Etag = ValueOf(in.Etag) + out.Etag = direct.ValueOf(in.Etag) // MISSING: GridLayout // MISSING: MosaicLayout // MISSING: RowLayout @@ -244,147 +245,147 @@ func MonitoringDashboardStatus_ToProto(mapCtx *MapContext, in *krm.MonitoringDas // MISSING: Labels return out } -func MosaicLayout_FromProto(mapCtx *MapContext, in *pb.MosaicLayout) *krm.MosaicLayout { +func MosaicLayout_FromProto(mapCtx *direct.MapContext, in *pb.MosaicLayout) *krm.MosaicLayout { if in == nil { return nil } out := &krm.MosaicLayout{} - out.Columns = LazyPtr(in.GetColumns()) - out.Tiles = Slice_FromProto(mapCtx, in.Tiles, MosaicLayout_Tile_FromProto) + out.Columns = direct.LazyPtr(in.GetColumns()) + out.Tiles = direct.Slice_FromProto(mapCtx, in.Tiles, MosaicLayout_Tile_FromProto) return out } -func MosaicLayout_ToProto(mapCtx *MapContext, in *krm.MosaicLayout) *pb.MosaicLayout { +func MosaicLayout_ToProto(mapCtx *direct.MapContext, in *krm.MosaicLayout) *pb.MosaicLayout { if in == nil { return nil } out := &pb.MosaicLayout{} - out.Columns = ValueOf(in.Columns) - out.Tiles = Slice_ToProto(mapCtx, in.Tiles, MosaicLayout_Tile_ToProto) + out.Columns = direct.ValueOf(in.Columns) + out.Tiles = direct.Slice_ToProto(mapCtx, in.Tiles, MosaicLayout_Tile_ToProto) return out } -func MosaicLayout_Tile_FromProto(mapCtx *MapContext, in *pb.MosaicLayout_Tile) *krm.MosaicLayout_Tile { +func MosaicLayout_Tile_FromProto(mapCtx *direct.MapContext, in *pb.MosaicLayout_Tile) *krm.MosaicLayout_Tile { if in == nil { return nil } out := &krm.MosaicLayout_Tile{} - out.XPos = LazyPtr(in.GetXPos()) - out.YPos = LazyPtr(in.GetYPos()) - out.Width = LazyPtr(in.GetWidth()) - out.Height = LazyPtr(in.GetHeight()) + out.XPos = direct.LazyPtr(in.GetXPos()) + out.YPos = direct.LazyPtr(in.GetYPos()) + out.Width = direct.LazyPtr(in.GetWidth()) + out.Height = direct.LazyPtr(in.GetHeight()) out.Widget = Widget_FromProto(mapCtx, in.GetWidget()) return out } -func MosaicLayout_Tile_ToProto(mapCtx *MapContext, in *krm.MosaicLayout_Tile) *pb.MosaicLayout_Tile { +func MosaicLayout_Tile_ToProto(mapCtx *direct.MapContext, in *krm.MosaicLayout_Tile) *pb.MosaicLayout_Tile { if in == nil { return nil } out := &pb.MosaicLayout_Tile{} - out.XPos = ValueOf(in.XPos) - out.YPos = ValueOf(in.YPos) - out.Width = ValueOf(in.Width) - out.Height = ValueOf(in.Height) + out.XPos = direct.ValueOf(in.XPos) + out.YPos = direct.ValueOf(in.YPos) + out.Width = direct.ValueOf(in.Width) + out.Height = direct.ValueOf(in.Height) out.Widget = Widget_ToProto(mapCtx, in.Widget) return out } -func PickTimeSeriesFilter_FromProto(mapCtx *MapContext, in *pb.PickTimeSeriesFilter) *krm.PickTimeSeriesFilter { +func PickTimeSeriesFilter_FromProto(mapCtx *direct.MapContext, in *pb.PickTimeSeriesFilter) *krm.PickTimeSeriesFilter { if in == nil { return nil } out := &krm.PickTimeSeriesFilter{} - out.RankingMethod = Enum_FromProto(mapCtx, in.RankingMethod) - out.NumTimeSeries = LazyPtr(in.GetNumTimeSeries()) - out.Direction = Enum_FromProto(mapCtx, in.Direction) + out.RankingMethod = direct.Enum_FromProto(mapCtx, in.RankingMethod) + out.NumTimeSeries = direct.LazyPtr(in.GetNumTimeSeries()) + out.Direction = direct.Enum_FromProto(mapCtx, in.Direction) // MISSING: Interval return out } -func PickTimeSeriesFilter_ToProto(mapCtx *MapContext, in *krm.PickTimeSeriesFilter) *pb.PickTimeSeriesFilter { +func PickTimeSeriesFilter_ToProto(mapCtx *direct.MapContext, in *krm.PickTimeSeriesFilter) *pb.PickTimeSeriesFilter { if in == nil { return nil } out := &pb.PickTimeSeriesFilter{} - out.RankingMethod = Enum_ToProto[pb.PickTimeSeriesFilter_Method](mapCtx, in.RankingMethod) - out.NumTimeSeries = ValueOf(in.NumTimeSeries) - out.Direction = Enum_ToProto[pb.PickTimeSeriesFilter_Direction](mapCtx, in.Direction) + out.RankingMethod = direct.Enum_ToProto[pb.PickTimeSeriesFilter_Method](mapCtx, in.RankingMethod) + out.NumTimeSeries = direct.ValueOf(in.NumTimeSeries) + out.Direction = direct.Enum_ToProto[pb.PickTimeSeriesFilter_Direction](mapCtx, in.Direction) // MISSING: Interval return out } -func PieChart_FromProto(mapCtx *MapContext, in *pb.PieChart) *krm.PieChart { +func PieChart_FromProto(mapCtx *direct.MapContext, in *pb.PieChart) *krm.PieChart { if in == nil { return nil } out := &krm.PieChart{} - out.DataSets = Slice_FromProto(mapCtx, in.DataSets, PieChart_PieChartDataSet_FromProto) - out.ChartType = Enum_FromProto(mapCtx, in.ChartType) - out.ShowLabels = LazyPtr(in.GetShowLabels()) + out.DataSets = direct.Slice_FromProto(mapCtx, in.DataSets, PieChart_PieChartDataSet_FromProto) + out.ChartType = direct.Enum_FromProto(mapCtx, in.ChartType) + out.ShowLabels = direct.LazyPtr(in.GetShowLabels()) return out } -func PieChart_ToProto(mapCtx *MapContext, in *krm.PieChart) *pb.PieChart { +func PieChart_ToProto(mapCtx *direct.MapContext, in *krm.PieChart) *pb.PieChart { if in == nil { return nil } out := &pb.PieChart{} - out.DataSets = Slice_ToProto(mapCtx, in.DataSets, PieChart_PieChartDataSet_ToProto) - out.ChartType = Enum_ToProto[pb.PieChart_PieChartType](mapCtx, in.ChartType) - out.ShowLabels = ValueOf(in.ShowLabels) + out.DataSets = direct.Slice_ToProto(mapCtx, in.DataSets, PieChart_PieChartDataSet_ToProto) + out.ChartType = direct.Enum_ToProto[pb.PieChart_PieChartType](mapCtx, in.ChartType) + out.ShowLabels = direct.ValueOf(in.ShowLabels) return out } -func PieChart_PieChartDataSet_FromProto(mapCtx *MapContext, in *pb.PieChart_PieChartDataSet) *krm.PieChart_PieChartDataSet { +func PieChart_PieChartDataSet_FromProto(mapCtx *direct.MapContext, in *pb.PieChart_PieChartDataSet) *krm.PieChart_PieChartDataSet { if in == nil { return nil } out := &krm.PieChart_PieChartDataSet{} out.TimeSeriesQuery = TimeSeriesQuery_FromProto(mapCtx, in.GetTimeSeriesQuery()) - out.SliceNameTemplate = LazyPtr(in.GetSliceNameTemplate()) + out.SliceNameTemplate = direct.LazyPtr(in.GetSliceNameTemplate()) out.MinAlignmentPeriod = PieChartDataSet_MinAlignmentPeriod_FromProto(mapCtx, in.GetMinAlignmentPeriod()) return out } -func PieChart_PieChartDataSet_ToProto(mapCtx *MapContext, in *krm.PieChart_PieChartDataSet) *pb.PieChart_PieChartDataSet { +func PieChart_PieChartDataSet_ToProto(mapCtx *direct.MapContext, in *krm.PieChart_PieChartDataSet) *pb.PieChart_PieChartDataSet { if in == nil { return nil } out := &pb.PieChart_PieChartDataSet{} out.TimeSeriesQuery = TimeSeriesQuery_ToProto(mapCtx, in.TimeSeriesQuery) - out.SliceNameTemplate = ValueOf(in.SliceNameTemplate) + out.SliceNameTemplate = direct.ValueOf(in.SliceNameTemplate) out.MinAlignmentPeriod = PieChartDataSet_MinAlignmentPeriod_ToProto(mapCtx, in.MinAlignmentPeriod) return out } -func RowLayout_FromProto(mapCtx *MapContext, in *pb.RowLayout) *krm.RowLayout { +func RowLayout_FromProto(mapCtx *direct.MapContext, in *pb.RowLayout) *krm.RowLayout { if in == nil { return nil } out := &krm.RowLayout{} - out.Rows = Slice_FromProto(mapCtx, in.Rows, RowLayout_Row_FromProto) + out.Rows = direct.Slice_FromProto(mapCtx, in.Rows, RowLayout_Row_FromProto) return out } -func RowLayout_ToProto(mapCtx *MapContext, in *krm.RowLayout) *pb.RowLayout { +func RowLayout_ToProto(mapCtx *direct.MapContext, in *krm.RowLayout) *pb.RowLayout { if in == nil { return nil } out := &pb.RowLayout{} - out.Rows = Slice_ToProto(mapCtx, in.Rows, RowLayout_Row_ToProto) + out.Rows = direct.Slice_ToProto(mapCtx, in.Rows, RowLayout_Row_ToProto) return out } -func RowLayout_Row_FromProto(mapCtx *MapContext, in *pb.RowLayout_Row) *krm.RowLayout_Row { +func RowLayout_Row_FromProto(mapCtx *direct.MapContext, in *pb.RowLayout_Row) *krm.RowLayout_Row { if in == nil { return nil } out := &krm.RowLayout_Row{} - out.Weight = LazyPtr(in.GetWeight()) - out.Widgets = Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) + out.Weight = direct.LazyPtr(in.GetWeight()) + out.Widgets = direct.Slice_FromProto(mapCtx, in.Widgets, Widget_FromProto) return out } -func RowLayout_Row_ToProto(mapCtx *MapContext, in *krm.RowLayout_Row) *pb.RowLayout_Row { +func RowLayout_Row_ToProto(mapCtx *direct.MapContext, in *krm.RowLayout_Row) *pb.RowLayout_Row { if in == nil { return nil } out := &pb.RowLayout_Row{} - out.Weight = ValueOf(in.Weight) - out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) + out.Weight = direct.ValueOf(in.Weight) + out.Widgets = direct.Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) return out } -func Scorecard_FromProto(mapCtx *MapContext, in *pb.Scorecard) *krm.Scorecard { +func Scorecard_FromProto(mapCtx *direct.MapContext, in *pb.Scorecard) *krm.Scorecard { if in == nil { return nil } @@ -393,10 +394,10 @@ func Scorecard_FromProto(mapCtx *MapContext, in *pb.Scorecard) *krm.Scorecard { out.GaugeView = Scorecard_GaugeView_FromProto(mapCtx, in.GetGaugeView()) out.SparkChartView = Scorecard_SparkChartView_FromProto(mapCtx, in.GetSparkChartView()) out.BlankView = BlankView_FromProto(mapCtx, in.GetBlankView()) - out.Thresholds = Slice_FromProto(mapCtx, in.Thresholds, Threshold_FromProto) + out.Thresholds = direct.Slice_FromProto(mapCtx, in.Thresholds, Threshold_FromProto) return out } -func Scorecard_ToProto(mapCtx *MapContext, in *krm.Scorecard) *pb.Scorecard { +func Scorecard_ToProto(mapCtx *direct.MapContext, in *krm.Scorecard) *pb.Scorecard { if in == nil { return nil } @@ -411,96 +412,96 @@ func Scorecard_ToProto(mapCtx *MapContext, in *krm.Scorecard) *pb.Scorecard { if oneof := BlankView_ToProto(mapCtx, in.BlankView); oneof != nil { out.DataView = &pb.Scorecard_BlankView{BlankView: oneof} } - out.Thresholds = Slice_ToProto(mapCtx, in.Thresholds, Threshold_ToProto) + out.Thresholds = direct.Slice_ToProto(mapCtx, in.Thresholds, Threshold_ToProto) return out } -func Scorecard_GaugeView_FromProto(mapCtx *MapContext, in *pb.Scorecard_GaugeView) *krm.Scorecard_GaugeView { +func Scorecard_GaugeView_FromProto(mapCtx *direct.MapContext, in *pb.Scorecard_GaugeView) *krm.Scorecard_GaugeView { if in == nil { return nil } out := &krm.Scorecard_GaugeView{} - out.LowerBound = LazyPtr(in.GetLowerBound()) - out.UpperBound = LazyPtr(in.GetUpperBound()) + out.LowerBound = direct.LazyPtr(in.GetLowerBound()) + out.UpperBound = direct.LazyPtr(in.GetUpperBound()) return out } -func Scorecard_GaugeView_ToProto(mapCtx *MapContext, in *krm.Scorecard_GaugeView) *pb.Scorecard_GaugeView { +func Scorecard_GaugeView_ToProto(mapCtx *direct.MapContext, in *krm.Scorecard_GaugeView) *pb.Scorecard_GaugeView { if in == nil { return nil } out := &pb.Scorecard_GaugeView{} - out.LowerBound = ValueOf(in.LowerBound) - out.UpperBound = ValueOf(in.UpperBound) + out.LowerBound = direct.ValueOf(in.LowerBound) + out.UpperBound = direct.ValueOf(in.UpperBound) return out } -func Scorecard_SparkChartView_FromProto(mapCtx *MapContext, in *pb.Scorecard_SparkChartView) *krm.Scorecard_SparkChartView { +func Scorecard_SparkChartView_FromProto(mapCtx *direct.MapContext, in *pb.Scorecard_SparkChartView) *krm.Scorecard_SparkChartView { if in == nil { return nil } out := &krm.Scorecard_SparkChartView{} - out.SparkChartType = Enum_FromProto(mapCtx, in.SparkChartType) + out.SparkChartType = direct.Enum_FromProto(mapCtx, in.SparkChartType) out.MinAlignmentPeriod = SparkChartView_MinAlignmentPeriod_FromProto(mapCtx, in.GetMinAlignmentPeriod()) return out } -func Scorecard_SparkChartView_ToProto(mapCtx *MapContext, in *krm.Scorecard_SparkChartView) *pb.Scorecard_SparkChartView { +func Scorecard_SparkChartView_ToProto(mapCtx *direct.MapContext, in *krm.Scorecard_SparkChartView) *pb.Scorecard_SparkChartView { if in == nil { return nil } out := &pb.Scorecard_SparkChartView{} - out.SparkChartType = Enum_ToProto[pb.SparkChartType](mapCtx, in.SparkChartType) + out.SparkChartType = direct.Enum_ToProto[pb.SparkChartType](mapCtx, in.SparkChartType) out.MinAlignmentPeriod = SparkChartView_MinAlignmentPeriod_ToProto(mapCtx, in.MinAlignmentPeriod) return out } -func SectionHeader_FromProto(mapCtx *MapContext, in *pb.SectionHeader) *krm.SectionHeader { +func SectionHeader_FromProto(mapCtx *direct.MapContext, in *pb.SectionHeader) *krm.SectionHeader { if in == nil { return nil } out := &krm.SectionHeader{} - out.Subtitle = LazyPtr(in.GetSubtitle()) - out.DividerBelow = LazyPtr(in.GetDividerBelow()) + out.Subtitle = direct.LazyPtr(in.GetSubtitle()) + out.DividerBelow = direct.LazyPtr(in.GetDividerBelow()) return out } -func SectionHeader_ToProto(mapCtx *MapContext, in *krm.SectionHeader) *pb.SectionHeader { +func SectionHeader_ToProto(mapCtx *direct.MapContext, in *krm.SectionHeader) *pb.SectionHeader { if in == nil { return nil } out := &pb.SectionHeader{} - out.Subtitle = ValueOf(in.Subtitle) - out.DividerBelow = ValueOf(in.DividerBelow) + out.Subtitle = direct.ValueOf(in.Subtitle) + out.DividerBelow = direct.ValueOf(in.DividerBelow) return out } -func SingleViewGroup_FromProto(mapCtx *MapContext, in *pb.SingleViewGroup) *krm.SingleViewGroup { +func SingleViewGroup_FromProto(mapCtx *direct.MapContext, in *pb.SingleViewGroup) *krm.SingleViewGroup { if in == nil { return nil } out := &krm.SingleViewGroup{} return out } -func SingleViewGroup_ToProto(mapCtx *MapContext, in *krm.SingleViewGroup) *pb.SingleViewGroup { +func SingleViewGroup_ToProto(mapCtx *direct.MapContext, in *krm.SingleViewGroup) *pb.SingleViewGroup { if in == nil { return nil } out := &pb.SingleViewGroup{} return out } -func StatisticalTimeSeriesFilter_FromProto(mapCtx *MapContext, in *pb.StatisticalTimeSeriesFilter) *krm.StatisticalTimeSeriesFilter { +func StatisticalTimeSeriesFilter_FromProto(mapCtx *direct.MapContext, in *pb.StatisticalTimeSeriesFilter) *krm.StatisticalTimeSeriesFilter { if in == nil { return nil } out := &krm.StatisticalTimeSeriesFilter{} - out.RankingMethod = Enum_FromProto(mapCtx, in.RankingMethod) - out.NumTimeSeries = LazyPtr(in.GetNumTimeSeries()) + out.RankingMethod = direct.Enum_FromProto(mapCtx, in.RankingMethod) + out.NumTimeSeries = direct.LazyPtr(in.GetNumTimeSeries()) return out } -func StatisticalTimeSeriesFilter_ToProto(mapCtx *MapContext, in *krm.StatisticalTimeSeriesFilter) *pb.StatisticalTimeSeriesFilter { +func StatisticalTimeSeriesFilter_ToProto(mapCtx *direct.MapContext, in *krm.StatisticalTimeSeriesFilter) *pb.StatisticalTimeSeriesFilter { if in == nil { return nil } out := &pb.StatisticalTimeSeriesFilter{} - out.RankingMethod = Enum_ToProto[pb.StatisticalTimeSeriesFilter_Method](mapCtx, in.RankingMethod) - out.NumTimeSeries = ValueOf(in.NumTimeSeries) + out.RankingMethod = direct.Enum_ToProto[pb.StatisticalTimeSeriesFilter_Method](mapCtx, in.RankingMethod) + out.NumTimeSeries = direct.ValueOf(in.NumTimeSeries) return out } -func TableDisplayOptions_FromProto(mapCtx *MapContext, in *pb.TableDisplayOptions) *krm.TableDisplayOptions { +func TableDisplayOptions_FromProto(mapCtx *direct.MapContext, in *pb.TableDisplayOptions) *krm.TableDisplayOptions { if in == nil { return nil } @@ -508,7 +509,7 @@ func TableDisplayOptions_FromProto(mapCtx *MapContext, in *pb.TableDisplayOption out.ShownColumns = in.ShownColumns return out } -func TableDisplayOptions_ToProto(mapCtx *MapContext, in *krm.TableDisplayOptions) *pb.TableDisplayOptions { +func TableDisplayOptions_ToProto(mapCtx *direct.MapContext, in *krm.TableDisplayOptions) *pb.TableDisplayOptions { if in == nil { return nil } @@ -516,96 +517,96 @@ func TableDisplayOptions_ToProto(mapCtx *MapContext, in *krm.TableDisplayOptions out.ShownColumns = in.ShownColumns return out } -func Text_FromProto(mapCtx *MapContext, in *pb.Text) *krm.Text { +func Text_FromProto(mapCtx *direct.MapContext, in *pb.Text) *krm.Text { if in == nil { return nil } out := &krm.Text{} - out.Content = LazyPtr(in.GetContent()) - out.Format = Enum_FromProto(mapCtx, in.Format) + out.Content = direct.LazyPtr(in.GetContent()) + out.Format = direct.Enum_FromProto(mapCtx, in.Format) out.Style = Text_TextStyle_FromProto(mapCtx, in.GetStyle()) return out } -func Text_ToProto(mapCtx *MapContext, in *krm.Text) *pb.Text { +func Text_ToProto(mapCtx *direct.MapContext, in *krm.Text) *pb.Text { if in == nil { return nil } out := &pb.Text{} - out.Content = ValueOf(in.Content) - out.Format = Enum_ToProto[pb.Text_Format](mapCtx, in.Format) + out.Content = direct.ValueOf(in.Content) + out.Format = direct.Enum_ToProto[pb.Text_Format](mapCtx, in.Format) out.Style = Text_TextStyle_ToProto(mapCtx, in.Style) return out } -func Text_TextStyle_FromProto(mapCtx *MapContext, in *pb.Text_TextStyle) *krm.Text_TextStyle { +func Text_TextStyle_FromProto(mapCtx *direct.MapContext, in *pb.Text_TextStyle) *krm.Text_TextStyle { if in == nil { return nil } out := &krm.Text_TextStyle{} - out.BackgroundColor = LazyPtr(in.GetBackgroundColor()) - out.TextColor = LazyPtr(in.GetTextColor()) - out.HorizontalAlignment = Enum_FromProto(mapCtx, in.HorizontalAlignment) - out.VerticalAlignment = Enum_FromProto(mapCtx, in.VerticalAlignment) - out.Padding = Enum_FromProto(mapCtx, in.Padding) - out.FontSize = Enum_FromProto(mapCtx, in.FontSize) - out.PointerLocation = Enum_FromProto(mapCtx, in.PointerLocation) + out.BackgroundColor = direct.LazyPtr(in.GetBackgroundColor()) + out.TextColor = direct.LazyPtr(in.GetTextColor()) + out.HorizontalAlignment = direct.Enum_FromProto(mapCtx, in.HorizontalAlignment) + out.VerticalAlignment = direct.Enum_FromProto(mapCtx, in.VerticalAlignment) + out.Padding = direct.Enum_FromProto(mapCtx, in.Padding) + out.FontSize = direct.Enum_FromProto(mapCtx, in.FontSize) + out.PointerLocation = direct.Enum_FromProto(mapCtx, in.PointerLocation) return out } -func Text_TextStyle_ToProto(mapCtx *MapContext, in *krm.Text_TextStyle) *pb.Text_TextStyle { +func Text_TextStyle_ToProto(mapCtx *direct.MapContext, in *krm.Text_TextStyle) *pb.Text_TextStyle { if in == nil { return nil } out := &pb.Text_TextStyle{} - out.BackgroundColor = ValueOf(in.BackgroundColor) - out.TextColor = ValueOf(in.TextColor) - out.HorizontalAlignment = Enum_ToProto[pb.Text_TextStyle_HorizontalAlignment](mapCtx, in.HorizontalAlignment) - out.VerticalAlignment = Enum_ToProto[pb.Text_TextStyle_VerticalAlignment](mapCtx, in.VerticalAlignment) - out.Padding = Enum_ToProto[pb.Text_TextStyle_PaddingSize](mapCtx, in.Padding) - out.FontSize = Enum_ToProto[pb.Text_TextStyle_FontSize](mapCtx, in.FontSize) - out.PointerLocation = Enum_ToProto[pb.Text_TextStyle_PointerLocation](mapCtx, in.PointerLocation) + out.BackgroundColor = direct.ValueOf(in.BackgroundColor) + out.TextColor = direct.ValueOf(in.TextColor) + out.HorizontalAlignment = direct.Enum_ToProto[pb.Text_TextStyle_HorizontalAlignment](mapCtx, in.HorizontalAlignment) + out.VerticalAlignment = direct.Enum_ToProto[pb.Text_TextStyle_VerticalAlignment](mapCtx, in.VerticalAlignment) + out.Padding = direct.Enum_ToProto[pb.Text_TextStyle_PaddingSize](mapCtx, in.Padding) + out.FontSize = direct.Enum_ToProto[pb.Text_TextStyle_FontSize](mapCtx, in.FontSize) + out.PointerLocation = direct.Enum_ToProto[pb.Text_TextStyle_PointerLocation](mapCtx, in.PointerLocation) return out } -func Threshold_FromProto(mapCtx *MapContext, in *pb.Threshold) *krm.Threshold { +func Threshold_FromProto(mapCtx *direct.MapContext, in *pb.Threshold) *krm.Threshold { if in == nil { return nil } out := &krm.Threshold{} - out.Label = LazyPtr(in.GetLabel()) - out.Value = LazyPtr(in.GetValue()) - out.Color = Enum_FromProto(mapCtx, in.Color) - out.Direction = Enum_FromProto(mapCtx, in.Direction) - out.TargetAxis = Enum_FromProto(mapCtx, in.TargetAxis) + out.Label = direct.LazyPtr(in.GetLabel()) + out.Value = direct.LazyPtr(in.GetValue()) + out.Color = direct.Enum_FromProto(mapCtx, in.Color) + out.Direction = direct.Enum_FromProto(mapCtx, in.Direction) + out.TargetAxis = direct.Enum_FromProto(mapCtx, in.TargetAxis) return out } -func Threshold_ToProto(mapCtx *MapContext, in *krm.Threshold) *pb.Threshold { +func Threshold_ToProto(mapCtx *direct.MapContext, in *krm.Threshold) *pb.Threshold { if in == nil { return nil } out := &pb.Threshold{} - out.Label = ValueOf(in.Label) - out.Value = ValueOf(in.Value) - out.Color = Enum_ToProto[pb.Threshold_Color](mapCtx, in.Color) - out.Direction = Enum_ToProto[pb.Threshold_Direction](mapCtx, in.Direction) - out.TargetAxis = Enum_ToProto[pb.Threshold_TargetAxis](mapCtx, in.TargetAxis) + out.Label = direct.ValueOf(in.Label) + out.Value = direct.ValueOf(in.Value) + out.Color = direct.Enum_ToProto[pb.Threshold_Color](mapCtx, in.Color) + out.Direction = direct.Enum_ToProto[pb.Threshold_Direction](mapCtx, in.Direction) + out.TargetAxis = direct.Enum_ToProto[pb.Threshold_TargetAxis](mapCtx, in.TargetAxis) return out } -func TimeSeriesFilter_FromProto(mapCtx *MapContext, in *pb.TimeSeriesFilter) *krm.TimeSeriesFilter { +func TimeSeriesFilter_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesFilter) *krm.TimeSeriesFilter { if in == nil { return nil } out := &krm.TimeSeriesFilter{} - out.Filter = LazyPtr(in.GetFilter()) + out.Filter = direct.LazyPtr(in.GetFilter()) out.Aggregation = Aggregation_FromProto(mapCtx, in.GetAggregation()) out.SecondaryAggregation = Aggregation_FromProto(mapCtx, in.GetSecondaryAggregation()) out.PickTimeSeriesFilter = PickTimeSeriesFilter_FromProto(mapCtx, in.GetPickTimeSeriesFilter()) // MISSING: StatisticalTimeSeriesFilter return out } -func TimeSeriesFilter_ToProto(mapCtx *MapContext, in *krm.TimeSeriesFilter) *pb.TimeSeriesFilter { +func TimeSeriesFilter_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesFilter) *pb.TimeSeriesFilter { if in == nil { return nil } out := &pb.TimeSeriesFilter{} - out.Filter = ValueOf(in.Filter) + out.Filter = direct.ValueOf(in.Filter) out.Aggregation = Aggregation_ToProto(mapCtx, in.Aggregation) out.SecondaryAggregation = Aggregation_ToProto(mapCtx, in.SecondaryAggregation) if oneof := PickTimeSeriesFilter_ToProto(mapCtx, in.PickTimeSeriesFilter); oneof != nil { @@ -614,7 +615,7 @@ func TimeSeriesFilter_ToProto(mapCtx *MapContext, in *krm.TimeSeriesFilter) *pb. // MISSING: StatisticalTimeSeriesFilter return out } -func TimeSeriesFilterRatio_FromProto(mapCtx *MapContext, in *pb.TimeSeriesFilterRatio) *krm.TimeSeriesFilterRatio { +func TimeSeriesFilterRatio_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesFilterRatio) *krm.TimeSeriesFilterRatio { if in == nil { return nil } @@ -626,7 +627,7 @@ func TimeSeriesFilterRatio_FromProto(mapCtx *MapContext, in *pb.TimeSeriesFilter // MISSING: StatisticalTimeSeriesFilter return out } -func TimeSeriesFilterRatio_ToProto(mapCtx *MapContext, in *krm.TimeSeriesFilterRatio) *pb.TimeSeriesFilterRatio { +func TimeSeriesFilterRatio_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesFilterRatio) *pb.TimeSeriesFilterRatio { if in == nil { return nil } @@ -640,38 +641,38 @@ func TimeSeriesFilterRatio_ToProto(mapCtx *MapContext, in *krm.TimeSeriesFilterR // MISSING: StatisticalTimeSeriesFilter return out } -func TimeSeriesFilterRatio_RatioPart_FromProto(mapCtx *MapContext, in *pb.TimeSeriesFilterRatio_RatioPart) *krm.TimeSeriesFilterRatio_RatioPart { +func TimeSeriesFilterRatio_RatioPart_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesFilterRatio_RatioPart) *krm.TimeSeriesFilterRatio_RatioPart { if in == nil { return nil } out := &krm.TimeSeriesFilterRatio_RatioPart{} - out.Filter = LazyPtr(in.GetFilter()) + out.Filter = direct.LazyPtr(in.GetFilter()) out.Aggregation = Aggregation_FromProto(mapCtx, in.GetAggregation()) return out } -func TimeSeriesFilterRatio_RatioPart_ToProto(mapCtx *MapContext, in *krm.TimeSeriesFilterRatio_RatioPart) *pb.TimeSeriesFilterRatio_RatioPart { +func TimeSeriesFilterRatio_RatioPart_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesFilterRatio_RatioPart) *pb.TimeSeriesFilterRatio_RatioPart { if in == nil { return nil } out := &pb.TimeSeriesFilterRatio_RatioPart{} - out.Filter = ValueOf(in.Filter) + out.Filter = direct.ValueOf(in.Filter) out.Aggregation = Aggregation_ToProto(mapCtx, in.Aggregation) return out } -func TimeSeriesQuery_FromProto(mapCtx *MapContext, in *pb.TimeSeriesQuery) *krm.TimeSeriesQuery { +func TimeSeriesQuery_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesQuery) *krm.TimeSeriesQuery { if in == nil { return nil } out := &krm.TimeSeriesQuery{} out.TimeSeriesFilter = TimeSeriesFilter_FromProto(mapCtx, in.GetTimeSeriesFilter()) out.TimeSeriesFilterRatio = TimeSeriesFilterRatio_FromProto(mapCtx, in.GetTimeSeriesFilterRatio()) - out.TimeSeriesQueryLanguage = LazyPtr(in.GetTimeSeriesQueryLanguage()) - out.PrometheusQuery = LazyPtr(in.GetPrometheusQuery()) - out.UnitOverride = LazyPtr(in.GetUnitOverride()) - out.OutputFullDuration = LazyPtr(in.GetOutputFullDuration()) + out.TimeSeriesQueryLanguage = direct.LazyPtr(in.GetTimeSeriesQueryLanguage()) + out.PrometheusQuery = direct.LazyPtr(in.GetPrometheusQuery()) + out.UnitOverride = direct.LazyPtr(in.GetUnitOverride()) + out.OutputFullDuration = direct.LazyPtr(in.GetOutputFullDuration()) return out } -func TimeSeriesQuery_ToProto(mapCtx *MapContext, in *krm.TimeSeriesQuery) *pb.TimeSeriesQuery { +func TimeSeriesQuery_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesQuery) *pb.TimeSeriesQuery { if in == nil { return nil } @@ -688,68 +689,68 @@ func TimeSeriesQuery_ToProto(mapCtx *MapContext, in *krm.TimeSeriesQuery) *pb.Ti if oneof := TimeSeriesQuery_PrometheusQuery_ToProto(mapCtx, in.PrometheusQuery); oneof != nil { out.Source = oneof } - out.UnitOverride = ValueOf(in.UnitOverride) - out.OutputFullDuration = ValueOf(in.OutputFullDuration) + out.UnitOverride = direct.ValueOf(in.UnitOverride) + out.OutputFullDuration = direct.ValueOf(in.OutputFullDuration) return out } -func TimeSeriesTable_FromProto(mapCtx *MapContext, in *pb.TimeSeriesTable) *krm.TimeSeriesTable { +func TimeSeriesTable_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesTable) *krm.TimeSeriesTable { if in == nil { return nil } out := &krm.TimeSeriesTable{} - out.DataSets = Slice_FromProto(mapCtx, in.DataSets, TimeSeriesTable_TableDataSet_FromProto) - out.MetricVisualization = Enum_FromProto(mapCtx, in.MetricVisualization) - out.ColumnSettings = Slice_FromProto(mapCtx, in.ColumnSettings, TimeSeriesTable_ColumnSettings_FromProto) + out.DataSets = direct.Slice_FromProto(mapCtx, in.DataSets, TimeSeriesTable_TableDataSet_FromProto) + out.MetricVisualization = direct.Enum_FromProto(mapCtx, in.MetricVisualization) + out.ColumnSettings = direct.Slice_FromProto(mapCtx, in.ColumnSettings, TimeSeriesTable_ColumnSettings_FromProto) return out } -func TimeSeriesTable_ToProto(mapCtx *MapContext, in *krm.TimeSeriesTable) *pb.TimeSeriesTable { +func TimeSeriesTable_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesTable) *pb.TimeSeriesTable { if in == nil { return nil } out := &pb.TimeSeriesTable{} - out.DataSets = Slice_ToProto(mapCtx, in.DataSets, TimeSeriesTable_TableDataSet_ToProto) - out.MetricVisualization = Enum_ToProto[pb.TimeSeriesTable_MetricVisualization](mapCtx, in.MetricVisualization) - out.ColumnSettings = Slice_ToProto(mapCtx, in.ColumnSettings, TimeSeriesTable_ColumnSettings_ToProto) + out.DataSets = direct.Slice_ToProto(mapCtx, in.DataSets, TimeSeriesTable_TableDataSet_ToProto) + out.MetricVisualization = direct.Enum_ToProto[pb.TimeSeriesTable_MetricVisualization](mapCtx, in.MetricVisualization) + out.ColumnSettings = direct.Slice_ToProto(mapCtx, in.ColumnSettings, TimeSeriesTable_ColumnSettings_ToProto) return out } -func TimeSeriesTable_ColumnSettings_ToProto(mapCtx *MapContext, in *krm.TimeSeriesTable_ColumnSettings) *pb.TimeSeriesTable_ColumnSettings { +func TimeSeriesTable_ColumnSettings_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesTable_ColumnSettings) *pb.TimeSeriesTable_ColumnSettings { if in == nil { return nil } out := &pb.TimeSeriesTable_ColumnSettings{} - out.Column = ValueOf(in.Column) - out.Visible = ValueOf(in.Visible) + out.Column = direct.ValueOf(in.Column) + out.Visible = direct.ValueOf(in.Visible) return out } -func TimeSeriesTable_TableDataSet_FromProto(mapCtx *MapContext, in *pb.TimeSeriesTable_TableDataSet) *krm.TimeSeriesTable_TableDataSet { +func TimeSeriesTable_TableDataSet_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesTable_TableDataSet) *krm.TimeSeriesTable_TableDataSet { if in == nil { return nil } out := &krm.TimeSeriesTable_TableDataSet{} out.TimeSeriesQuery = TimeSeriesQuery_FromProto(mapCtx, in.GetTimeSeriesQuery()) - out.TableTemplate = LazyPtr(in.GetTableTemplate()) + out.TableTemplate = direct.LazyPtr(in.GetTableTemplate()) out.MinAlignmentPeriod = TableDataSet_MinAlignmentPeriod_FromProto(mapCtx, in.GetMinAlignmentPeriod()) out.TableDisplayOptions = TableDisplayOptions_FromProto(mapCtx, in.GetTableDisplayOptions()) return out } -func TimeSeriesTable_TableDataSet_ToProto(mapCtx *MapContext, in *krm.TimeSeriesTable_TableDataSet) *pb.TimeSeriesTable_TableDataSet { +func TimeSeriesTable_TableDataSet_ToProto(mapCtx *direct.MapContext, in *krm.TimeSeriesTable_TableDataSet) *pb.TimeSeriesTable_TableDataSet { if in == nil { return nil } out := &pb.TimeSeriesTable_TableDataSet{} out.TimeSeriesQuery = TimeSeriesQuery_ToProto(mapCtx, in.TimeSeriesQuery) - out.TableTemplate = ValueOf(in.TableTemplate) + out.TableTemplate = direct.ValueOf(in.TableTemplate) out.MinAlignmentPeriod = TableDataSet_MinAlignmentPeriod_ToProto(mapCtx, in.MinAlignmentPeriod) out.TableDisplayOptions = TableDisplayOptions_ToProto(mapCtx, in.TableDisplayOptions) return out } -func Widget_FromProto(mapCtx *MapContext, in *pb.Widget) *krm.Widget { +func Widget_FromProto(mapCtx *direct.MapContext, in *pb.Widget) *krm.Widget { if in == nil { return nil } out := &krm.Widget{} - out.Title = LazyPtr(in.GetTitle()) + out.Title = direct.LazyPtr(in.GetTitle()) out.XyChart = XyChart_FromProto(mapCtx, in.GetXyChart()) out.Scorecard = Scorecard_FromProto(mapCtx, in.GetScorecard()) out.Text = Text_FromProto(mapCtx, in.GetText()) @@ -763,15 +764,15 @@ func Widget_FromProto(mapCtx *MapContext, in *pb.Widget) *krm.Widget { out.ErrorReportingPanel = ErrorReportingPanel_FromProto(mapCtx, in.GetErrorReportingPanel()) out.SectionHeader = SectionHeader_FromProto(mapCtx, in.GetSectionHeader()) out.SingleViewGroup = SingleViewGroup_FromProto(mapCtx, in.GetSingleViewGroup()) - out.Id = LazyPtr(in.GetId()) + out.Id = direct.LazyPtr(in.GetId()) return out } -func Widget_ToProto(mapCtx *MapContext, in *krm.Widget) *pb.Widget { +func Widget_ToProto(mapCtx *direct.MapContext, in *krm.Widget) *pb.Widget { if in == nil { return nil } out := &pb.Widget{} - out.Title = ValueOf(in.Title) + out.Title = direct.ValueOf(in.Title) if oneof := XyChart_ToProto(mapCtx, in.XyChart); oneof != nil { out.Content = &pb.Widget_XyChart{XyChart: oneof} } @@ -811,77 +812,77 @@ func Widget_ToProto(mapCtx *MapContext, in *krm.Widget) *pb.Widget { if oneof := SingleViewGroup_ToProto(mapCtx, in.SingleViewGroup); oneof != nil { out.Content = &pb.Widget_SingleViewGroup{SingleViewGroup: oneof} } - out.Id = ValueOf(in.Id) + out.Id = direct.ValueOf(in.Id) return out } -func XyChart_FromProto(mapCtx *MapContext, in *pb.XyChart) *krm.XyChart { +func XyChart_FromProto(mapCtx *direct.MapContext, in *pb.XyChart) *krm.XyChart { if in == nil { return nil } out := &krm.XyChart{} - out.DataSets = Slice_FromProto(mapCtx, in.DataSets, XyChart_DataSet_FromProto) + out.DataSets = direct.Slice_FromProto(mapCtx, in.DataSets, XyChart_DataSet_FromProto) out.TimeshiftDuration = XyChart_TimeshiftDuration_FromProto(mapCtx, in.GetTimeshiftDuration()) - out.Thresholds = Slice_FromProto(mapCtx, in.Thresholds, Threshold_FromProto) + out.Thresholds = direct.Slice_FromProto(mapCtx, in.Thresholds, Threshold_FromProto) out.XAxis = XyChart_Axis_FromProto(mapCtx, in.GetXAxis()) out.YAxis = XyChart_Axis_FromProto(mapCtx, in.GetYAxis()) out.Y2Axis = XyChart_Axis_FromProto(mapCtx, in.GetY2Axis()) out.ChartOptions = ChartOptions_FromProto(mapCtx, in.GetChartOptions()) return out } -func XyChart_ToProto(mapCtx *MapContext, in *krm.XyChart) *pb.XyChart { +func XyChart_ToProto(mapCtx *direct.MapContext, in *krm.XyChart) *pb.XyChart { if in == nil { return nil } out := &pb.XyChart{} - out.DataSets = Slice_ToProto(mapCtx, in.DataSets, XyChart_DataSet_ToProto) + out.DataSets = direct.Slice_ToProto(mapCtx, in.DataSets, XyChart_DataSet_ToProto) out.TimeshiftDuration = XyChart_TimeshiftDuration_ToProto(mapCtx, in.TimeshiftDuration) - out.Thresholds = Slice_ToProto(mapCtx, in.Thresholds, Threshold_ToProto) + out.Thresholds = direct.Slice_ToProto(mapCtx, in.Thresholds, Threshold_ToProto) out.XAxis = XyChart_Axis_ToProto(mapCtx, in.XAxis) out.YAxis = XyChart_Axis_ToProto(mapCtx, in.YAxis) out.Y2Axis = XyChart_Axis_ToProto(mapCtx, in.Y2Axis) out.ChartOptions = ChartOptions_ToProto(mapCtx, in.ChartOptions) return out } -func XyChart_Axis_FromProto(mapCtx *MapContext, in *pb.XyChart_Axis) *krm.XyChart_Axis { +func XyChart_Axis_FromProto(mapCtx *direct.MapContext, in *pb.XyChart_Axis) *krm.XyChart_Axis { if in == nil { return nil } out := &krm.XyChart_Axis{} - out.Label = LazyPtr(in.GetLabel()) - out.Scale = Enum_FromProto(mapCtx, in.Scale) + out.Label = direct.LazyPtr(in.GetLabel()) + out.Scale = direct.Enum_FromProto(mapCtx, in.Scale) return out } -func XyChart_Axis_ToProto(mapCtx *MapContext, in *krm.XyChart_Axis) *pb.XyChart_Axis { +func XyChart_Axis_ToProto(mapCtx *direct.MapContext, in *krm.XyChart_Axis) *pb.XyChart_Axis { if in == nil { return nil } out := &pb.XyChart_Axis{} - out.Label = ValueOf(in.Label) - out.Scale = Enum_ToProto[pb.XyChart_Axis_Scale](mapCtx, in.Scale) + out.Label = direct.ValueOf(in.Label) + out.Scale = direct.Enum_ToProto[pb.XyChart_Axis_Scale](mapCtx, in.Scale) return out } -func XyChart_DataSet_FromProto(mapCtx *MapContext, in *pb.XyChart_DataSet) *krm.XyChart_DataSet { +func XyChart_DataSet_FromProto(mapCtx *direct.MapContext, in *pb.XyChart_DataSet) *krm.XyChart_DataSet { if in == nil { return nil } out := &krm.XyChart_DataSet{} out.TimeSeriesQuery = TimeSeriesQuery_FromProto(mapCtx, in.GetTimeSeriesQuery()) - out.PlotType = Enum_FromProto(mapCtx, in.PlotType) - out.LegendTemplate = LazyPtr(in.GetLegendTemplate()) + out.PlotType = direct.Enum_FromProto(mapCtx, in.PlotType) + out.LegendTemplate = direct.LazyPtr(in.GetLegendTemplate()) out.MinAlignmentPeriod = DataSet_MinAlignmentPeriod_FromProto(mapCtx, in.GetMinAlignmentPeriod()) - out.TargetAxis = Enum_FromProto(mapCtx, in.TargetAxis) + out.TargetAxis = direct.Enum_FromProto(mapCtx, in.TargetAxis) return out } -func XyChart_DataSet_ToProto(mapCtx *MapContext, in *krm.XyChart_DataSet) *pb.XyChart_DataSet { +func XyChart_DataSet_ToProto(mapCtx *direct.MapContext, in *krm.XyChart_DataSet) *pb.XyChart_DataSet { if in == nil { return nil } out := &pb.XyChart_DataSet{} out.TimeSeriesQuery = TimeSeriesQuery_ToProto(mapCtx, in.TimeSeriesQuery) - out.PlotType = Enum_ToProto[pb.XyChart_DataSet_PlotType](mapCtx, in.PlotType) - out.LegendTemplate = ValueOf(in.LegendTemplate) + out.PlotType = direct.Enum_ToProto[pb.XyChart_DataSet_PlotType](mapCtx, in.PlotType) + out.LegendTemplate = direct.ValueOf(in.LegendTemplate) out.MinAlignmentPeriod = DataSet_MinAlignmentPeriod_ToProto(mapCtx, in.MinAlignmentPeriod) - out.TargetAxis = Enum_ToProto[pb.XyChart_DataSet_TargetAxis](mapCtx, in.TargetAxis) + out.TargetAxis = direct.Enum_ToProto[pb.XyChart_DataSet_TargetAxis](mapCtx, in.TargetAxis) return out } diff --git a/pkg/controller/direct/monitoring/dashboard_mappings.go b/pkg/controller/direct/monitoring/dashboard_mappings.go index 95cf5ca5a6..a4c325daac 100644 --- a/pkg/controller/direct/monitoring/dashboard_mappings.go +++ b/pkg/controller/direct/monitoring/dashboard_mappings.go @@ -26,16 +26,17 @@ import ( monitoredres "google.golang.org/genproto/googleapis/api/monitoredres" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" ) -func Empty_FromProto(mapCtx *MapContext, in *emptypb.Empty) *krm.Empty { +func Empty_FromProto(mapCtx *direct.MapContext, in *emptypb.Empty) *krm.Empty { if in == nil { return nil } out := &krm.Empty{} return out } -func Empty_ToProto(mapCtx *MapContext, in *krm.Empty) *emptypb.Empty { +func Empty_ToProto(mapCtx *direct.MapContext, in *krm.Empty) *emptypb.Empty { if in == nil { return nil } @@ -43,7 +44,7 @@ func Empty_ToProto(mapCtx *MapContext, in *krm.Empty) *emptypb.Empty { return out } -func AlertChart_FromProto(mapCtx *MapContext, in *pb.AlertChart) *krm.AlertChart { +func AlertChart_FromProto(mapCtx *direct.MapContext, in *pb.AlertChart) *krm.AlertChart { if in == nil { return nil } @@ -55,7 +56,7 @@ func AlertChart_FromProto(mapCtx *MapContext, in *pb.AlertChart) *krm.AlertChart } return out } -func AlertChart_ToProto(mapCtx *MapContext, in *krm.AlertChart) *pb.AlertChart { +func AlertChart_ToProto(mapCtx *direct.MapContext, in *krm.AlertChart) *pb.AlertChart { if in == nil { return nil } @@ -66,71 +67,71 @@ func AlertChart_ToProto(mapCtx *MapContext, in *krm.AlertChart) *pb.AlertChart { return out } -func Aggregation_AlignmentPeriod_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return SecondsString_FromProto(mapCtx, in) +func Aggregation_AlignmentPeriod_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.SecondsString_FromProto(mapCtx, in) } -func Aggregation_AlignmentPeriod_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return SecondsString_ToProto(mapCtx, in, "alignmentPeriod") +func Aggregation_AlignmentPeriod_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.SecondsString_ToProto(mapCtx, in, "alignmentPeriod") } // TODO: The format is not documented, we need to validate -func DataSet_MinAlignmentPeriod_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return SecondsString_FromProto(mapCtx, in) +func DataSet_MinAlignmentPeriod_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.SecondsString_FromProto(mapCtx, in) } // TODO: The format is not documented, we need to validate -func DataSet_MinAlignmentPeriod_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return SecondsString_ToProto(mapCtx, in, "minAlignmentPeriod") +func DataSet_MinAlignmentPeriod_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.SecondsString_ToProto(mapCtx, in, "minAlignmentPeriod") } // TODO: The format is not documented, we need to validate -func SparkChartView_MinAlignmentPeriod_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return SecondsString_FromProto(mapCtx, in) +func SparkChartView_MinAlignmentPeriod_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.SecondsString_FromProto(mapCtx, in) } // TODO: The format is not documented, we need to validate -func SparkChartView_MinAlignmentPeriod_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return SecondsString_ToProto(mapCtx, in, "minAlignmentPeriod") +func SparkChartView_MinAlignmentPeriod_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.SecondsString_ToProto(mapCtx, in, "minAlignmentPeriod") } // TODO: The format is not documented, we need to validate -func XyChart_TimeshiftDuration_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return Duration_FromProto(mapCtx, in) +func XyChart_TimeshiftDuration_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.Duration_FromProto(mapCtx, in) } // TODO: The format is not documented, we need to validate -func XyChart_TimeshiftDuration_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return Duration_ToProto(mapCtx, in) +func XyChart_TimeshiftDuration_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.Duration_ToProto(mapCtx, in) } -func PieChartDataSet_MinAlignmentPeriod_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return Duration_FromProto(mapCtx, in) +func PieChartDataSet_MinAlignmentPeriod_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.Duration_FromProto(mapCtx, in) } -func PieChartDataSet_MinAlignmentPeriod_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return Duration_ToProto(mapCtx, in) +func PieChartDataSet_MinAlignmentPeriod_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.Duration_ToProto(mapCtx, in) } -func TableDataSet_MinAlignmentPeriod_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - return Duration_FromProto(mapCtx, in) +func TableDataSet_MinAlignmentPeriod_FromProto(mapCtx *direct.MapContext, in *durationpb.Duration) *string { + return direct.Duration_FromProto(mapCtx, in) } -func TableDataSet_MinAlignmentPeriod_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - return Duration_ToProto(mapCtx, in) +func TableDataSet_MinAlignmentPeriod_ToProto(mapCtx *direct.MapContext, in *string) *durationpb.Duration { + return direct.Duration_ToProto(mapCtx, in) } -func TimeSeriesQuery_TimeSeriesQueryLanguage_ToProto(mapCtx *MapContext, in *string) *pb.TimeSeriesQuery_TimeSeriesQueryLanguage { +func TimeSeriesQuery_TimeSeriesQueryLanguage_ToProto(mapCtx *direct.MapContext, in *string) *pb.TimeSeriesQuery_TimeSeriesQueryLanguage { if in == nil { return nil } return &pb.TimeSeriesQuery_TimeSeriesQueryLanguage{ - TimeSeriesQueryLanguage: ValueOf(in), + TimeSeriesQueryLanguage: direct.ValueOf(in), } } -func LogsPanel_ResourceNames_FromProto(mapCtx *MapContext, in []string) []v1alpha1.ResourceRef { +func LogsPanel_ResourceNames_FromProto(mapCtx *direct.MapContext, in []string) []v1alpha1.ResourceRef { if in == nil { return nil } @@ -149,7 +150,7 @@ func LogsPanel_ResourceNames_FromProto(mapCtx *MapContext, in []string) []v1alph return out } -func LogsPanel_ResourceNames_ToProto(mapCtx *MapContext, in []v1alpha1.ResourceRef) []string { +func LogsPanel_ResourceNames_ToProto(mapCtx *direct.MapContext, in []v1alpha1.ResourceRef) []string { if in == nil { return nil } @@ -163,7 +164,7 @@ func LogsPanel_ResourceNames_ToProto(mapCtx *MapContext, in []v1alpha1.ResourceR return out } -func DashboardTimeSeriesQuery_TimeSeriesQueryLanguage_ToProto(mapCtx *MapContext, in *string) *pb.TimeSeriesQuery_TimeSeriesQueryLanguage { +func DashboardTimeSeriesQuery_TimeSeriesQueryLanguage_ToProto(mapCtx *direct.MapContext, in *string) *pb.TimeSeriesQuery_TimeSeriesQueryLanguage { if in == nil { return nil } @@ -172,7 +173,7 @@ func DashboardTimeSeriesQuery_TimeSeriesQueryLanguage_ToProto(mapCtx *MapContext } } -func ErrorReportingPanel_FromProto(mapCtx *MapContext, in *pb.ErrorReportingPanel) *krm.ErrorReportingPanel { +func ErrorReportingPanel_FromProto(mapCtx *direct.MapContext, in *pb.ErrorReportingPanel) *krm.ErrorReportingPanel { if in == nil { return nil } @@ -187,7 +188,7 @@ func ErrorReportingPanel_FromProto(mapCtx *MapContext, in *pb.ErrorReportingPane return out } -func ErrorReportingPanel_ToProto(mapCtx *MapContext, in *krm.ErrorReportingPanel) *pb.ErrorReportingPanel { +func ErrorReportingPanel_ToProto(mapCtx *direct.MapContext, in *krm.ErrorReportingPanel) *pb.ErrorReportingPanel { if in == nil { return nil } @@ -200,7 +201,7 @@ func ErrorReportingPanel_ToProto(mapCtx *MapContext, in *krm.ErrorReportingPanel return out } -func TimeSeriesQuery_PrometheusQuery_ToProto(mapCtx *MapContext, in *string) *pb.TimeSeriesQuery_PrometheusQuery { +func TimeSeriesQuery_PrometheusQuery_ToProto(mapCtx *direct.MapContext, in *string) *pb.TimeSeriesQuery_PrometheusQuery { if in == nil { return nil } @@ -209,39 +210,39 @@ func TimeSeriesQuery_PrometheusQuery_ToProto(mapCtx *MapContext, in *string) *pb return out } -func TimeSeriesTable_ColumnSettings_FromProto(mapCtx *MapContext, in *pb.TimeSeriesTable_ColumnSettings) *krm.TimeSeriesTable_ColumnSettings { +func TimeSeriesTable_ColumnSettings_FromProto(mapCtx *direct.MapContext, in *pb.TimeSeriesTable_ColumnSettings) *krm.TimeSeriesTable_ColumnSettings { if in == nil { return nil } out := &krm.TimeSeriesTable_ColumnSettings{} - out.Column = LazyPtr(in.GetColumn()) + out.Column = direct.LazyPtr(in.GetColumn()) // We want to always output the visible field, i.e. `visible: false` // We probably can automate this, because the visible field is required. - out.Visible = PtrTo(in.GetVisible()) + out.Visible = direct.PtrTo(in.GetVisible()) return out } -func MonitoredResource_FromProto(mapCtx *MapContext, in *monitoredres.MonitoredResource) *krm.MonitoredResource { +func MonitoredResource_FromProto(mapCtx *direct.MapContext, in *monitoredres.MonitoredResource) *krm.MonitoredResource { if in == nil { return nil } out := &krm.MonitoredResource{} - out.Type = LazyPtr(in.GetType()) + out.Type = direct.LazyPtr(in.GetType()) out.Labels = in.Labels return out } -func MonitoredResource_ToProto(mapCtx *MapContext, in *krm.MonitoredResource) *monitoredres.MonitoredResource { +func MonitoredResource_ToProto(mapCtx *direct.MapContext, in *krm.MonitoredResource) *monitoredres.MonitoredResource { if in == nil { return nil } out := &monitoredres.MonitoredResource{} - out.Type = ValueOf(in.Type) + out.Type = direct.ValueOf(in.Type) out.Labels = in.Labels return out } -func DashboardFilter_StringValue_ToProto(mapCtx *MapContext, in *string) *pb.DashboardFilter_StringValue { +func DashboardFilter_StringValue_ToProto(mapCtx *direct.MapContext, in *string) *pb.DashboardFilter_StringValue { if in == nil { return nil } @@ -250,37 +251,37 @@ func DashboardFilter_StringValue_ToProto(mapCtx *MapContext, in *string) *pb.Das return out } -func IncidentList_FromProto(mapCtx *MapContext, in *pb.IncidentList) *krm.IncidentList { +func IncidentList_FromProto(mapCtx *direct.MapContext, in *pb.IncidentList) *krm.IncidentList { if in == nil { return nil } out := &krm.IncidentList{} - out.MonitoredResources = Slice_FromProto(mapCtx, in.MonitoredResources, MonitoredResource_FromProto) + out.MonitoredResources = direct.Slice_FromProto(mapCtx, in.MonitoredResources, MonitoredResource_FromProto) for _, policyName := range in.PolicyNames { out.PolicyRefs = append(out.PolicyRefs, refs.MonitoringAlertPolicyRef{External: policyName}) } return out } -func IncidentList_ToProto(mapCtx *MapContext, in *krm.IncidentList) *pb.IncidentList { +func IncidentList_ToProto(mapCtx *direct.MapContext, in *krm.IncidentList) *pb.IncidentList { if in == nil { return nil } out := &pb.IncidentList{} - out.MonitoredResources = Slice_ToProto(mapCtx, in.MonitoredResources, MonitoredResource_ToProto) + out.MonitoredResources = direct.Slice_ToProto(mapCtx, in.MonitoredResources, MonitoredResource_ToProto) for _, policyRef := range in.PolicyRefs { out.PolicyNames = append(out.PolicyNames, policyRef.External) } return out } -func BlankView_FromProto(mapCtx *MapContext, in *emptypb.Empty) *krm.BlankView { +func BlankView_FromProto(mapCtx *direct.MapContext, in *emptypb.Empty) *krm.BlankView { if in == nil { return nil } out := &krm.BlankView{} return out } -func BlankView_ToProto(mapCtx *MapContext, in *krm.BlankView) *emptypb.Empty { +func BlankView_ToProto(mapCtx *direct.MapContext, in *krm.BlankView) *emptypb.Empty { if in == nil { return nil } diff --git a/pkg/controller/direct/monitoring/maputils.go b/pkg/controller/direct/monitoring/maputils.go deleted file mode 100644 index 3007cedd3e..0000000000 --- a/pkg/controller/direct/monitoring/maputils.go +++ /dev/null @@ -1,190 +0,0 @@ -// 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 monitoring - -import ( - "errors" - "fmt" - "strconv" - "strings" - "time" - - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/known/durationpb" -) - -type MapContext struct { - errs []error -} - -func (c *MapContext) Errorf(msg string, args ...interface{}) { - c.errs = append(c.errs, fmt.Errorf(msg, args...)) -} - -func (c *MapContext) Err() error { - return errors.Join(c.errs...) -} - -func Slice_ToProto[T, U any](mapCtx *MapContext, in []T, mapper func(mapCtx *MapContext, in *T) *U) []*U { - if in == nil { - return nil - } - - outSlice := make([]*U, 0, len(in)) - for _, inItem := range in { - outItem := mapper(mapCtx, &inItem) - outSlice = append(outSlice, outItem) - } - return outSlice -} - -func Slice_FromProto[T, U any](mapCtx *MapContext, in []*T, mapper func(mapCtx *MapContext, in *T) *U) []U { - if in == nil { - return nil - } - - outSlice := make([]U, 0, len(in)) - for _, inItem := range in { - outItem := mapper(mapCtx, inItem) - outSlice = append(outSlice, *outItem) - } - return outSlice -} - -type ProtoEnum interface { - ~int32 - Descriptor() protoreflect.EnumDescriptor -} - -func Enum_ToProto[U ProtoEnum](mapCtx *MapContext, in *string) U { - var defaultU U - descriptor := defaultU.Descriptor() - - inValue := ValueOf(in) - if inValue == "" { - unspecifiedValue := U(0) - return unspecifiedValue - } - - n := descriptor.Values().Len() - for i := 0; i < n; i++ { - value := descriptor.Values().Get(i) - if string(value.Name()) == inValue { - v := U(value.Number()) - return v - } - } - - var validValues []string - for i := 0; i < n; i++ { - value := descriptor.Values().Get(i) - validValues = append(validValues, string(value.Name())) - } - - mapCtx.Errorf("unknown enum value %q for %v (valid values are %v)", inValue, descriptor.FullName(), strings.Join(validValues, ", ")) - return 0 -} - -func Enum_FromProto[U ProtoEnum](mapCtx *MapContext, v U) *string { - descriptor := v.Descriptor() - - if v == 0 { - return nil - } - - val := descriptor.Values().ByNumber(protoreflect.EnumNumber(v)) - if val == nil { - mapCtx.Errorf("unknown enum value %d", v) - return nil - } - s := string(val.Name()) - return &s -} - -func Duration_ToProto(mapCtx *MapContext, in *string) *durationpb.Duration { - if in == nil { - return nil - } - - s := *in - if s == "" { - return nil - } - - if strings.HasSuffix(s, "s") { - d, err := time.ParseDuration(s) - if err != nil { - mapCtx.Errorf("parsing duration %q: %w", s, err) - return nil - } - out := durationpb.New(d) - return out - } - - mapCtx.Errorf("parsing duration %q, must end in s", s) - return nil -} - -func Duration_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - if in == nil { - return nil - } - - // We want to report the duration without truncation (do don't want to map via float64) - s := strconv.FormatInt(in.Seconds, 10) - if in.Nanos != 0 { - nanos := strconv.FormatInt(int64(in.Nanos), 10) - pad := 9 - len(nanos) - nanos = strings.Repeat("0", pad) + nanos - nanos = strings.TrimRight(nanos, "0") - s += "." + nanos - } - s += "s" - return &s -} - -func LazyPtr[V comparable](v V) *V { - var defaultV V - if v == defaultV { - return nil - } - return &v -} - -func SecondsString_FromProto(mapCtx *MapContext, in *durationpb.Duration) *string { - if in == nil { - return nil - } - seconds := in.GetSeconds() - out := strconv.FormatInt(seconds, 10) - return &out -} - -func SecondsString_ToProto(mapCtx *MapContext, in *string, fieldName string) *durationpb.Duration { - if in == nil { - return nil - } - v := *in - if strings.HasSuffix(v, "s") { - v = strings.TrimSuffix(v, "s") - } - seconds, err := strconv.ParseInt(v, 10, 64) - if err != nil { - mapCtx.Errorf("%s value %q is not valid", fieldName, *in) - return nil - } - out := &durationpb.Duration{Seconds: seconds} - return out -} diff --git a/pkg/controller/direct/monitoring/monitoringdashboard_controller.go b/pkg/controller/direct/monitoring/monitoringdashboard_controller.go index 80e639b606..3773b4db56 100644 --- a/pkg/controller/direct/monitoring/monitoringdashboard_controller.go +++ b/pkg/controller/direct/monitoring/monitoringdashboard_controller.go @@ -29,6 +29,7 @@ import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/monitoring/v1beta1" refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry" ) @@ -78,7 +79,7 @@ func (m *dashboardModel) AdapterForObject(ctx context.Context, kube client.Reade return nil, fmt.Errorf("error converting to %T: %w", obj, err) } - resourceID := ValueOf(obj.Spec.ResourceID) + resourceID := direct.ValueOf(obj.Spec.ResourceID) if resourceID == "" { resourceID = obj.GetName() } @@ -99,7 +100,7 @@ func (m *dashboardModel) AdapterForObject(ctx context.Context, kube client.Reade return nil, err } - mapCtx := &MapContext{} + mapCtx := &direct.MapContext{} desiredProto := MonitoringDashboardSpec_ToProto(mapCtx, &obj.Spec) if mapCtx.Err() != nil { return nil, mapCtx.Err() @@ -153,7 +154,7 @@ func (a *dashboardAdapter) Find(ctx context.Context) (bool, error) { } dashboard, err := a.dashboardsClient.GetDashboard(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, err @@ -182,7 +183,7 @@ func (a *dashboardAdapter) Delete(ctx context.Context) (bool, error) { } if err := a.dashboardsClient.DeleteDashboard(ctx, req); err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("deleting dashboard %s: %w", a.fullyQualifiedName(), err) @@ -216,7 +217,7 @@ func (a *dashboardAdapter) Create(ctx context.Context, u *unstructured.Unstructu return fmt.Errorf("setting spec.resourceID: %w", err) } - mapCtx := &MapContext{} + mapCtx := &direct.MapContext{} status := MonitoringDashboardStatus_FromProto(mapCtx, created) if mapCtx.Err() != nil { return mapCtx.Err() @@ -247,7 +248,7 @@ func (a *dashboardAdapter) Update(ctx context.Context, u *unstructured.Unstructu a.actual = updated } - mapCtx := &MapContext{} + mapCtx := &direct.MapContext{} status := MonitoringDashboardStatus_FromProto(mapCtx, a.actual) if mapCtx.Err() != nil { return mapCtx.Err() @@ -260,7 +261,7 @@ func (a *dashboardAdapter) Export(ctx context.Context) (*unstructured.Unstructur return nil, fmt.Errorf("dashboard %q not found", a.fullyQualifiedName()) } - mc := &MapContext{} + mc := &direct.MapContext{} spec := MonitoringDashboardSpec_FromProto(mc, a.actual) if err := mc.Err(); err != nil { return nil, fmt.Errorf("error converting dashboard from API %w", err) diff --git a/pkg/controller/direct/monitoring/roundtrip_test.go b/pkg/controller/direct/monitoring/roundtrip_test.go index eefdf6e986..f5a8256dea 100644 --- a/pkg/controller/direct/monitoring/roundtrip_test.go +++ b/pkg/controller/direct/monitoring/roundtrip_test.go @@ -21,6 +21,7 @@ import ( pb "cloud.google.com/go/monitoring/dashboard/apiv1/dashboardpb" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/fuzz" "github.com/google/go-cmp/cmp" "google.golang.org/protobuf/encoding/prototext" @@ -89,7 +90,7 @@ func FuzzMonitoringDashboardSpec(f *testing.F) { } fuzz.Visit("", p1.ProtoReflect(), nil, r) - ctx := &MapContext{} + ctx := &direct.MapContext{} k := MonitoringDashboardSpec_FromProto(ctx, p1) if ctx.Err() != nil { t.Fatalf("error mapping from proto to krm: %v", ctx.Err()) diff --git a/pkg/controller/direct/monitoring/utils.go b/pkg/controller/direct/monitoring/utils.go index c01ea172de..70e73a6c50 100644 --- a/pkg/controller/direct/monitoring/utils.go +++ b/pkg/controller/direct/monitoring/utils.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/google/go-cmp/cmp" - "github.com/googleapis/gax-go/v2/apierror" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/testing/protocmp" @@ -31,39 +30,6 @@ import ( "k8s.io/klog/v2" ) -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -func PtrTo[T any](t T) *T { - return &t -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} - func lastComponent(s string) string { i := strings.LastIndex(s, "/") return s[i+1:] diff --git a/pkg/controller/direct/privateca/privatecapool_controller.go b/pkg/controller/direct/privateca/privatecapool_controller.go index a6eec84241..2d8e0e7695 100644 --- a/pkg/controller/direct/privateca/privatecapool_controller.go +++ b/pkg/controller/direct/privateca/privatecapool_controller.go @@ -29,6 +29,7 @@ import ( refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" krm "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/privateca/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry" ) @@ -76,7 +77,7 @@ func (m *caPoolModel) AdapterForObject(ctx context.Context, reader client.Reader return nil, fmt.Errorf("error converting to %T: %w", obj, err) } - resourceID := ValueOf(obj.Spec.ResourceID) + resourceID := direct.ValueOf(obj.Spec.ResourceID) if resourceID == "" { resourceID = obj.GetName() } @@ -163,7 +164,7 @@ func (a *caPoolAdapter) Find(ctx context.Context) (bool, error) { } logMetric, err := a.caClient.GetCaPool(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("getting logMetric %q: %w", a.fullyQualifiedName(), err) diff --git a/pkg/controller/direct/privateca/utils.go b/pkg/controller/direct/privateca/utils.go deleted file mode 100644 index e01a625ce2..0000000000 --- a/pkg/controller/direct/privateca/utils.go +++ /dev/null @@ -1,64 +0,0 @@ -// 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 privateca - -import ( - "errors" - - "github.com/googleapis/gax-go/v2/apierror" - "k8s.io/klog/v2" -) - -// todo acpana: add to factor out to top level package -// todo acpana: begin -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -// LazyPtr returns a pointer to v, unless it is the empty value, in which case it returns nil. -// It is essentially the inverse of ValueOf, though it is lossy -// because we can't tell nil and empty apart without a pointer. -func LazyPtr[T comparable](v T) *T { - var defaultValue T - if v == defaultValue { - return nil - } - return &v -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} diff --git a/pkg/controller/direct/resourcemanager/tagkey_controller.go b/pkg/controller/direct/resourcemanager/tagkey_controller.go index cbe3484552..301d080d82 100644 --- a/pkg/controller/direct/resourcemanager/tagkey_controller.go +++ b/pkg/controller/direct/resourcemanager/tagkey_controller.go @@ -31,6 +31,7 @@ import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/tags/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry" ) @@ -81,7 +82,7 @@ func (m *tagKeyModel) AdapterForObject(ctx context.Context, reader client.Reader return nil, fmt.Errorf("error converting to %T: %w", obj, err) } - resourceID := ValueOf(obj.Spec.ResourceID) + resourceID := direct.ValueOf(obj.Spec.ResourceID) // resourceID is server-generated, no fallback // TODO: How do we do resource acquisition - maybe by shortname? resourceID = strings.TrimPrefix(resourceID, "tagKeys/") @@ -109,7 +110,7 @@ func (a *tagKeyAdapter) Find(ctx context.Context) (bool, error) { } tagKey, err := a.tagKeysClient.GetTagKey(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, err @@ -134,7 +135,7 @@ func (a *tagKeyAdapter) Delete(ctx context.Context) (bool, error) { op, err := a.tagKeysClient.DeleteTagKey(ctx, req) if err != nil { - if IsNotFound(err) { + if direct.IsNotFound(err) { return false, nil } return false, fmt.Errorf("deleting tagKey %s: %w", a.fullyQualifiedName(), err) @@ -158,11 +159,11 @@ func (a *tagKeyAdapter) Create(ctx context.Context, u *unstructured.Unstructured tagKey := &pb.TagKey{ Parent: parent, ShortName: a.desired.Spec.ShortName, - Description: ValueOf(a.desired.Spec.Description), + Description: direct.ValueOf(a.desired.Spec.Description), PurposeData: a.desired.Spec.PurposeData, } - if s := ValueOf(a.desired.Spec.Purpose); s != "" { + if s := direct.ValueOf(a.desired.Spec.Purpose); s != "" { purpose, ok := pb.Purpose_value[s] if !ok { return fmt.Errorf("unknown purpose %q", s) @@ -222,9 +223,9 @@ func (a *tagKeyAdapter) Update(ctx context.Context, u *unstructured.Unstructured update.Name = a.fullyQualifiedName() // description is the only field that can be updated - if ValueOf(a.desired.Spec.Description) != a.actual.GetDescription() { + if direct.ValueOf(a.desired.Spec.Description) != a.actual.GetDescription() { updateMask.Paths = append(updateMask.Paths, "description") - update.Description = ValueOf(a.desired.Spec.Description) + update.Description = direct.ValueOf(a.desired.Spec.Description) } // TODO: Where/how do we want to enforce immutability? @@ -257,3 +258,15 @@ func (a *tagKeyAdapter) Export(ctx context.Context) (*unstructured.Unstructured, func (a *tagKeyAdapter) fullyQualifiedName() string { return fmt.Sprintf("tagKeys/%s", a.resourceID) } + +func setStatus(u *unstructured.Unstructured, typedStatus any) error { + // TODO: Just fetch this object? + status, err := runtime.DefaultUnstructuredConverter.ToUnstructured(typedStatus) + if err != nil { + return fmt.Errorf("error converting status to unstructured: %w", err) + } + // TODO: Merge to avoid overwriting conditions? + u.Object["status"] = status + + return nil +} diff --git a/pkg/controller/direct/resourcemanager/utils.go b/pkg/controller/direct/resourcemanager/utils.go deleted file mode 100644 index 81013af78b..0000000000 --- a/pkg/controller/direct/resourcemanager/utils.go +++ /dev/null @@ -1,80 +0,0 @@ -// 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 resourcemanager - -import ( - "errors" - "fmt" - - "github.com/googleapis/gax-go/v2/apierror" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/klog/v2" -) - -func setStatus(u *unstructured.Unstructured, typedStatus any) error { - // TODO: Just fetch this object? - status, err := runtime.DefaultUnstructuredConverter.ToUnstructured(typedStatus) - if err != nil { - return fmt.Errorf("error converting status to unstructured: %w", err) - } - // TODO: Merge to avoid overwriting conditions? - u.Object["status"] = status - - return nil -} - -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -func PtrTo[T any](t T) *T { - return &t -} - -func areSame[T comparable](l, r *T) bool { - if l == nil { - return r == nil - } - if r == nil { - return l == nil - } - return *l == *r -} - -// HasHTTPCode returns true if the given error is an HTTP response with the given code. -func HasHTTPCode(err error, code int) bool { - if err == nil { - return false - } - apiError := &apierror.APIError{} - if errors.As(err, &apiError) { - if apiError.HTTPCode() == code { - return true - } - } else { - klog.Warningf("unexpected error type %T", err) - } - return false -} - -// IsNotFound returns true if the given error is an HTTP 404. -func IsNotFound(err error) bool { - return HasHTTPCode(err, 404) -} diff --git a/pkg/controller/direct/securesourcemanager/mapper.generated.go b/pkg/controller/direct/securesourcemanager/mapper.generated.go index d02496aa84..5df21c301c 100644 --- a/pkg/controller/direct/securesourcemanager/mapper.generated.go +++ b/pkg/controller/direct/securesourcemanager/mapper.generated.go @@ -18,133 +18,134 @@ import ( pb "cloud.google.com/go/securesourcemanager/apiv1/securesourcemanagerpb" krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/securesourcemanager/v1alpha1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" ) -func Instance_HostConfig_FromProto(mapCtx *MapContext, in *pb.Instance_HostConfig) *krm.Instance_HostConfig { +func Instance_HostConfig_FromProto(mapCtx *direct.MapContext, in *pb.Instance_HostConfig) *krm.Instance_HostConfig { if in == nil { return nil } out := &krm.Instance_HostConfig{} - out.Html = LazyPtr(in.GetHtml()) - out.Api = LazyPtr(in.GetApi()) - out.GitHttp = LazyPtr(in.GetGitHttp()) - out.GitSsh = LazyPtr(in.GetGitSsh()) + out.Html = direct.LazyPtr(in.GetHtml()) + out.Api = direct.LazyPtr(in.GetApi()) + out.GitHttp = direct.LazyPtr(in.GetGitHttp()) + out.GitSsh = direct.LazyPtr(in.GetGitSsh()) return out } -func Instance_HostConfig_ToProto(mapCtx *MapContext, in *krm.Instance_HostConfig) *pb.Instance_HostConfig { +func Instance_HostConfig_ToProto(mapCtx *direct.MapContext, in *krm.Instance_HostConfig) *pb.Instance_HostConfig { if in == nil { return nil } out := &pb.Instance_HostConfig{} - out.Html = ValueOf(in.Html) - out.Api = ValueOf(in.Api) - out.GitHttp = ValueOf(in.GitHttp) - out.GitSsh = ValueOf(in.GitSsh) + out.Html = direct.ValueOf(in.Html) + out.Api = direct.ValueOf(in.Api) + out.GitHttp = direct.ValueOf(in.GitHttp) + out.GitSsh = direct.ValueOf(in.GitSsh) return out } -func OperationMetadata_FromProto(mapCtx *MapContext, in *pb.OperationMetadata) *krm.OperationMetadata { +func OperationMetadata_FromProto(mapCtx *direct.MapContext, in *pb.OperationMetadata) *krm.OperationMetadata { if in == nil { return nil } out := &krm.OperationMetadata{} out.CreateTime = OperationMetadata_CreateTime_FromProto(mapCtx, in.GetCreateTime()) out.EndTime = OperationMetadata_EndTime_FromProto(mapCtx, in.GetEndTime()) - out.Target = LazyPtr(in.GetTarget()) - out.Verb = LazyPtr(in.GetVerb()) - out.StatusMessage = LazyPtr(in.GetStatusMessage()) - out.RequestedCancellation = LazyPtr(in.GetRequestedCancellation()) - out.ApiVersion = LazyPtr(in.GetApiVersion()) + out.Target = direct.LazyPtr(in.GetTarget()) + out.Verb = direct.LazyPtr(in.GetVerb()) + out.StatusMessage = direct.LazyPtr(in.GetStatusMessage()) + out.RequestedCancellation = direct.LazyPtr(in.GetRequestedCancellation()) + out.ApiVersion = direct.LazyPtr(in.GetApiVersion()) return out } -func OperationMetadata_ToProto(mapCtx *MapContext, in *krm.OperationMetadata) *pb.OperationMetadata { +func OperationMetadata_ToProto(mapCtx *direct.MapContext, in *krm.OperationMetadata) *pb.OperationMetadata { if in == nil { return nil } out := &pb.OperationMetadata{} out.CreateTime = OperationMetadata_CreateTime_ToProto(mapCtx, in.CreateTime) out.EndTime = OperationMetadata_EndTime_ToProto(mapCtx, in.EndTime) - out.Target = ValueOf(in.Target) - out.Verb = ValueOf(in.Verb) - out.StatusMessage = ValueOf(in.StatusMessage) - out.RequestedCancellation = ValueOf(in.RequestedCancellation) - out.ApiVersion = ValueOf(in.ApiVersion) + out.Target = direct.ValueOf(in.Target) + out.Verb = direct.ValueOf(in.Verb) + out.StatusMessage = direct.ValueOf(in.StatusMessage) + out.RequestedCancellation = direct.ValueOf(in.RequestedCancellation) + out.ApiVersion = direct.ValueOf(in.ApiVersion) return out } -func Repository_FromProto(mapCtx *MapContext, in *pb.Repository) *krm.Repository { +func Repository_FromProto(mapCtx *direct.MapContext, in *pb.Repository) *krm.Repository { if in == nil { return nil } out := &krm.Repository{} - out.Name = LazyPtr(in.GetName()) - out.Description = LazyPtr(in.GetDescription()) - out.Instance = LazyPtr(in.GetInstance()) - out.Uid = LazyPtr(in.GetUid()) + out.Name = direct.LazyPtr(in.GetName()) + out.Description = direct.LazyPtr(in.GetDescription()) + out.Instance = direct.LazyPtr(in.GetInstance()) + out.Uid = direct.LazyPtr(in.GetUid()) out.CreateTime = Repository_CreateTime_FromProto(mapCtx, in.GetCreateTime()) out.UpdateTime = Repository_UpdateTime_FromProto(mapCtx, in.GetUpdateTime()) - out.Etag = LazyPtr(in.GetEtag()) + out.Etag = direct.LazyPtr(in.GetEtag()) out.Uris = Repository_URIs_FromProto(mapCtx, in.GetUris()) out.InitialConfig = Repository_InitialConfig_FromProto(mapCtx, in.GetInitialConfig()) return out } -func Repository_ToProto(mapCtx *MapContext, in *krm.Repository) *pb.Repository { +func Repository_ToProto(mapCtx *direct.MapContext, in *krm.Repository) *pb.Repository { if in == nil { return nil } out := &pb.Repository{} - out.Name = ValueOf(in.Name) - out.Description = ValueOf(in.Description) - out.Instance = ValueOf(in.Instance) - out.Uid = ValueOf(in.Uid) + out.Name = direct.ValueOf(in.Name) + out.Description = direct.ValueOf(in.Description) + out.Instance = direct.ValueOf(in.Instance) + out.Uid = direct.ValueOf(in.Uid) out.CreateTime = Repository_CreateTime_ToProto(mapCtx, in.CreateTime) out.UpdateTime = Repository_UpdateTime_ToProto(mapCtx, in.UpdateTime) - out.Etag = ValueOf(in.Etag) + out.Etag = direct.ValueOf(in.Etag) out.Uris = Repository_URIs_ToProto(mapCtx, in.Uris) out.InitialConfig = Repository_InitialConfig_ToProto(mapCtx, in.InitialConfig) return out } -func Repository_InitialConfig_FromProto(mapCtx *MapContext, in *pb.Repository_InitialConfig) *krm.Repository_InitialConfig { +func Repository_InitialConfig_FromProto(mapCtx *direct.MapContext, in *pb.Repository_InitialConfig) *krm.Repository_InitialConfig { if in == nil { return nil } out := &krm.Repository_InitialConfig{} - out.DefaultBranch = LazyPtr(in.GetDefaultBranch()) + out.DefaultBranch = direct.LazyPtr(in.GetDefaultBranch()) out.Gitignores = in.Gitignores - out.License = LazyPtr(in.GetLicense()) - out.Readme = LazyPtr(in.GetReadme()) + out.License = direct.LazyPtr(in.GetLicense()) + out.Readme = direct.LazyPtr(in.GetReadme()) return out } -func Repository_InitialConfig_ToProto(mapCtx *MapContext, in *krm.Repository_InitialConfig) *pb.Repository_InitialConfig { +func Repository_InitialConfig_ToProto(mapCtx *direct.MapContext, in *krm.Repository_InitialConfig) *pb.Repository_InitialConfig { if in == nil { return nil } out := &pb.Repository_InitialConfig{} - out.DefaultBranch = ValueOf(in.DefaultBranch) + out.DefaultBranch = direct.ValueOf(in.DefaultBranch) out.Gitignores = in.Gitignores - out.License = ValueOf(in.License) - out.Readme = ValueOf(in.Readme) + out.License = direct.ValueOf(in.License) + out.Readme = direct.ValueOf(in.Readme) return out } -func Repository_URIs_FromProto(mapCtx *MapContext, in *pb.Repository_URIs) *krm.Repository_URIs { +func Repository_URIs_FromProto(mapCtx *direct.MapContext, in *pb.Repository_URIs) *krm.Repository_URIs { if in == nil { return nil } out := &krm.Repository_URIs{} - out.Html = LazyPtr(in.GetHtml()) - out.GitHttps = LazyPtr(in.GetGitHttps()) - out.Api = LazyPtr(in.GetApi()) + out.Html = direct.LazyPtr(in.GetHtml()) + out.GitHttps = direct.LazyPtr(in.GetGitHttps()) + out.Api = direct.LazyPtr(in.GetApi()) return out } -func Repository_URIs_ToProto(mapCtx *MapContext, in *krm.Repository_URIs) *pb.Repository_URIs { +func Repository_URIs_ToProto(mapCtx *direct.MapContext, in *krm.Repository_URIs) *pb.Repository_URIs { if in == nil { return nil } out := &pb.Repository_URIs{} - out.Html = ValueOf(in.Html) - out.GitHttps = ValueOf(in.GitHttps) - out.Api = ValueOf(in.Api) + out.Html = direct.ValueOf(in.Html) + out.GitHttps = direct.ValueOf(in.GitHttps) + out.Api = direct.ValueOf(in.Api) return out } -func SecureSourceManagerInstanceObservedState_FromProto(mapCtx *MapContext, in *pb.Instance) *krm.SecureSourceManagerInstanceObservedState { +func SecureSourceManagerInstanceObservedState_FromProto(mapCtx *direct.MapContext, in *pb.Instance) *krm.SecureSourceManagerInstanceObservedState { if in == nil { return nil } @@ -153,13 +154,13 @@ func SecureSourceManagerInstanceObservedState_FromProto(mapCtx *MapContext, in * // MISSING: CreateTime // MISSING: UpdateTime // MISSING: Labels - out.State = Enum_FromProto(mapCtx, in.State) - out.StateNote = Enum_FromProto(mapCtx, in.StateNote) + out.State = direct.Enum_FromProto(mapCtx, in.State) + out.StateNote = direct.Enum_FromProto(mapCtx, in.StateNote) // MISSING: KmsKey out.HostConfig = Instance_HostConfig_FromProto(mapCtx, in.GetHostConfig()) return out } -func SecureSourceManagerInstanceObservedState_ToProto(mapCtx *MapContext, in *krm.SecureSourceManagerInstanceObservedState) *pb.Instance { +func SecureSourceManagerInstanceObservedState_ToProto(mapCtx *direct.MapContext, in *krm.SecureSourceManagerInstanceObservedState) *pb.Instance { if in == nil { return nil } @@ -168,13 +169,13 @@ func SecureSourceManagerInstanceObservedState_ToProto(mapCtx *MapContext, in *kr // MISSING: CreateTime // MISSING: UpdateTime // MISSING: Labels - out.State = Enum_ToProto[pb.Instance_State](mapCtx, in.State) - out.StateNote = Enum_ToProto[pb.Instance_StateNote](mapCtx, in.StateNote) + out.State = direct.Enum_ToProto[pb.Instance_State](mapCtx, in.State) + out.StateNote = direct.Enum_ToProto[pb.Instance_StateNote](mapCtx, in.StateNote) // MISSING: KmsKey out.HostConfig = Instance_HostConfig_ToProto(mapCtx, in.HostConfig) return out } -func SecureSourceManagerInstanceSpec_FromProto(mapCtx *MapContext, in *pb.Instance) *krm.SecureSourceManagerInstanceSpec { +func SecureSourceManagerInstanceSpec_FromProto(mapCtx *direct.MapContext, in *pb.Instance) *krm.SecureSourceManagerInstanceSpec { if in == nil { return nil } @@ -185,11 +186,11 @@ func SecureSourceManagerInstanceSpec_FromProto(mapCtx *MapContext, in *pb.Instan out.Labels = in.Labels // MISSING: State // MISSING: StateNote - out.KmsKey = LazyPtr(in.GetKmsKey()) + out.KmsKey = direct.LazyPtr(in.GetKmsKey()) // MISSING: HostConfig return out } -func SecureSourceManagerInstanceSpec_ToProto(mapCtx *MapContext, in *krm.SecureSourceManagerInstanceSpec) *pb.Instance { +func SecureSourceManagerInstanceSpec_ToProto(mapCtx *direct.MapContext, in *krm.SecureSourceManagerInstanceSpec) *pb.Instance { if in == nil { return nil } @@ -200,7 +201,7 @@ func SecureSourceManagerInstanceSpec_ToProto(mapCtx *MapContext, in *krm.SecureS out.Labels = in.Labels // MISSING: State // MISSING: StateNote - out.KmsKey = ValueOf(in.KmsKey) + out.KmsKey = direct.ValueOf(in.KmsKey) // MISSING: HostConfig return out } diff --git a/pkg/controller/direct/securesourcemanager/mapper.go b/pkg/controller/direct/securesourcemanager/mapper.go index 05d2c485a9..4c8eef427e 100644 --- a/pkg/controller/direct/securesourcemanager/mapper.go +++ b/pkg/controller/direct/securesourcemanager/mapper.go @@ -15,45 +15,46 @@ package securesourcemanager import ( + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "google.golang.org/protobuf/types/known/timestamppb" ) -func Repository_CreateTime_FromProto(mapCtx *MapContext, in *timestamppb.Timestamp) *string { +func Repository_CreateTime_FromProto(mapCtx *direct.MapContext, in *timestamppb.Timestamp) *string { mapCtx.Errorf("Repository_CreateTime_FromProto not implemented") return nil } -func Repository_CreateTime_ToProto(mapCtx *MapContext, in *string) *timestamppb.Timestamp { +func Repository_CreateTime_ToProto(mapCtx *direct.MapContext, in *string) *timestamppb.Timestamp { mapCtx.Errorf("Repository_CreateTime_ToProto not implemented") return nil } -func Repository_UpdateTime_FromProto(mapCtx *MapContext, in *timestamppb.Timestamp) *string { +func Repository_UpdateTime_FromProto(mapCtx *direct.MapContext, in *timestamppb.Timestamp) *string { mapCtx.Errorf("Repository_UpdateTime_FromProto not implemented") return nil } -func Repository_UpdateTime_ToProto(mapCtx *MapContext, in *string) *timestamppb.Timestamp { +func Repository_UpdateTime_ToProto(mapCtx *direct.MapContext, in *string) *timestamppb.Timestamp { mapCtx.Errorf("Repository_UpdateTime_ToProto not implemented") return nil } -func OperationMetadata_CreateTime_FromProto(mapCtx *MapContext, in *timestamppb.Timestamp) *string { +func OperationMetadata_CreateTime_FromProto(mapCtx *direct.MapContext, in *timestamppb.Timestamp) *string { mapCtx.Errorf("OperationMetadata_CreateTime_FromProto not implemented") return nil } -func OperationMetadata_CreateTime_ToProto(mapCtx *MapContext, in *string) *timestamppb.Timestamp { +func OperationMetadata_CreateTime_ToProto(mapCtx *direct.MapContext, in *string) *timestamppb.Timestamp { mapCtx.Errorf("OperationMetadata_CreateTime_ToProto not implemented") return nil } -func OperationMetadata_EndTime_FromProto(mapCtx *MapContext, in *timestamppb.Timestamp) *string { +func OperationMetadata_EndTime_FromProto(mapCtx *direct.MapContext, in *timestamppb.Timestamp) *string { mapCtx.Errorf("OperationMetadata_EndTime_FromProto not implemented") return nil } -func OperationMetadata_EndTime_ToProto(mapCtx *MapContext, in *string) *timestamppb.Timestamp { +func OperationMetadata_EndTime_ToProto(mapCtx *direct.MapContext, in *string) *timestamppb.Timestamp { mapCtx.Errorf("OperationMetadata_EndTime_ToProto not implemented") return nil } diff --git a/pkg/controller/direct/securesourcemanager/maputils.go b/pkg/controller/direct/securesourcemanager/maputils.go deleted file mode 100644 index e40b7d404b..0000000000 --- a/pkg/controller/direct/securesourcemanager/maputils.go +++ /dev/null @@ -1,119 +0,0 @@ -// 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 securesourcemanager - -import ( - "errors" - "fmt" - "strings" - - "google.golang.org/protobuf/reflect/protoreflect" -) - -type MapContext struct { - errs []error -} - -func (c *MapContext) Errorf(msg string, args ...interface{}) { - c.errs = append(c.errs, fmt.Errorf(msg, args...)) -} - -func (c *MapContext) Err() error { - return errors.Join(c.errs...) -} - -func Slice_ToProto[T, U any](mapCtx *MapContext, in []T, mapper func(mapCtx *MapContext, in *T) *U) []*U { - if in == nil { - return nil - } - - outSlice := make([]*U, 0, len(in)) - for _, inItem := range in { - outItem := mapper(mapCtx, &inItem) - outSlice = append(outSlice, outItem) - } - return outSlice -} - -func Slice_FromProto[T, U any](mapCtx *MapContext, in []*T, mapper func(mapCtx *MapContext, in *T) *U) []U { - if in == nil { - return nil - } - - outSlice := make([]U, 0, len(in)) - for _, inItem := range in { - outItem := mapper(mapCtx, inItem) - outSlice = append(outSlice, *outItem) - } - return outSlice -} - -type ProtoEnum interface { - ~int32 - Descriptor() protoreflect.EnumDescriptor -} - -func Enum_ToProto[U ProtoEnum](mapCtx *MapContext, in *string) U { - var defaultU U - descriptor := defaultU.Descriptor() - - inValue := ValueOf(in) - if inValue == "" { - unspecifiedValue := U(0) - return unspecifiedValue - } - - n := descriptor.Values().Len() - for i := 0; i < n; i++ { - value := descriptor.Values().Get(i) - if string(value.Name()) == inValue { - v := U(value.Number()) - return v - } - } - - var validValues []string - for i := 0; i < n; i++ { - value := descriptor.Values().Get(i) - validValues = append(validValues, string(value.Name())) - } - - mapCtx.Errorf("unknown enum value %q for %v (valid values are %v)", inValue, descriptor.FullName(), strings.Join(validValues, ", ")) - return 0 -} - -func Enum_FromProto[U ProtoEnum](mapCtx *MapContext, v U) *string { - descriptor := v.Descriptor() - - if v == 0 { - return nil - } - - val := descriptor.Values().ByNumber(protoreflect.EnumNumber(v)) - if val == nil { - mapCtx.Errorf("unknown enum value %d", v) - return nil - } - s := string(val.Name()) - return &s -} - -func LazyPtr[V comparable](v V) *V { - var defaultV V - if v == defaultV { - return nil - } - return &v -} diff --git a/pkg/controller/direct/securesourcemanager/roundtrip_test.go b/pkg/controller/direct/securesourcemanager/roundtrip_test.go index bc1d13775d..16b00b83e1 100644 --- a/pkg/controller/direct/securesourcemanager/roundtrip_test.go +++ b/pkg/controller/direct/securesourcemanager/roundtrip_test.go @@ -20,6 +20,7 @@ import ( pb "cloud.google.com/go/securesourcemanager/apiv1/securesourcemanagerpb" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/fuzz" "github.com/google/go-cmp/cmp" "google.golang.org/protobuf/encoding/prototext" @@ -56,7 +57,7 @@ func FuzzSecureSourceManagerInstanceSpec(f *testing.F) { } fuzz.Visit("", p1.ProtoReflect(), nil, clearFields) - ctx := &MapContext{} + ctx := &direct.MapContext{} k := SecureSourceManagerInstanceSpec_FromProto(ctx, p1) if ctx.Err() != nil { t.Fatalf("error mapping from proto to krm: %v", ctx.Err()) @@ -101,7 +102,7 @@ func FuzzSecureSourceManagerInstanceObservedState(f *testing.F) { } fuzz.Visit("", p1.ProtoReflect(), nil, clearFields) - ctx := &MapContext{} + ctx := &direct.MapContext{} k := SecureSourceManagerInstanceObservedState_FromProto(ctx, p1) if ctx.Err() != nil { t.Fatalf("error mapping from proto to krm: %v", ctx.Err()) diff --git a/pkg/controller/direct/securesourcemanager/utils.go b/pkg/controller/direct/securesourcemanager/utils.go deleted file mode 100644 index 7988fd8ddd..0000000000 --- a/pkg/controller/direct/securesourcemanager/utils.go +++ /dev/null @@ -1,27 +0,0 @@ -// 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 securesourcemanager - -func ValueOf[T any](p *T) T { - var v T - if p != nil { - v = *p - } - return v -} - -func PtrTo[T any](t T) *T { - return &t -}