From 233b3613aee3b98d1692c4271f367f50faaa09f0 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Fri, 28 Jun 2019 14:38:07 -0700 Subject: [PATCH] Add ObjectMeta type. --- pkg/types/kustomization.go | 32 +++++++------------ .../v1/stringprefixer/StringPrefixer.go | 11 +++---- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index 08487230d..6e61606ab 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -1,18 +1,5 @@ -/* -Copyright 2017 The Kubernetes Authors. - -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. -*/ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 // Package types holds struct definitions that should find a better home. package types @@ -29,13 +16,18 @@ const ( KustomizationKind = "Kustomization" ) -// TypeMeta copies apimachinery/pkg/apis/meta/v1.TypeMeta +// TypeMeta partially copies apimachinery/pkg/apis/meta/v1.TypeMeta +// No need for a direct dependence; the fields are stable. type TypeMeta struct { - // Kind copies apimachinery/pkg/apis/meta/v1.Typemeta.Kind - Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` + Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` + APIVersion string `json:"apiVersion,omitempty" yaml:"apiversion,omitempty"` +} - // APIVersion copies apimachinery/pkg/apis/meta/v1.Typemeta.APIVersion - APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"` +// ObjectMeta partially copies apimachinery/pkg/apis/meta/v1.ObjectMeta +// No need for a direct dependence; the fields are stable. +type ObjectMeta struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` } // Kustomization holds the information needed to generate customized k8s api resources. diff --git a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go index e33712bac..e34d620b1 100644 --- a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go +++ b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go @@ -9,6 +9,7 @@ import ( "sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/v3/pkg/transformers/config" + "sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/v3/plugin/builtin" "sigs.k8s.io/yaml" ) @@ -16,12 +17,8 @@ import ( // Add a string prefix to the name. // A plugin that adapts another plugin. type plugin struct { - Metadata metaData `json:"metadata,omitempty" yaml:"metadata,omitempty"` - t transformers.Transformer -} - -type metaData struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` + types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + t transformers.Transformer } //nolint: golint @@ -47,7 +44,7 @@ func (p *plugin) Config( if err != nil { return err } - c, err = p.makePrefixSuffixPluginConfig(p.Metadata.Name) + c, err = p.makePrefixSuffixPluginConfig(p.Name) if err != nil { return err }