mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Inline TypeMeta.
This commit is contained in:
@@ -275,40 +275,67 @@ func TestCreatePathAnnotationValue(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
`dir`,
|
`dir`,
|
||||||
yaml.ResourceMeta{Kind: "foo",
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
ObjectMeta: yaml.ObjectMeta{Name: "bar", Namespace: "baz"},
|
Kind: "foo",
|
||||||
|
},
|
||||||
|
ObjectMeta: yaml.ObjectMeta{
|
||||||
|
NameMeta: yaml.NameMeta{
|
||||||
|
Name: "bar", Namespace: "baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
`dir/baz/foo_bar.yaml`, `with namespace`,
|
`dir/baz/foo_bar.yaml`, `with namespace`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
``,
|
``,
|
||||||
yaml.ResourceMeta{Kind: "foo",
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
ObjectMeta: yaml.ObjectMeta{Name: "bar", Namespace: "baz"},
|
Kind: "foo",
|
||||||
|
},
|
||||||
|
ObjectMeta: yaml.ObjectMeta{
|
||||||
|
NameMeta: yaml.NameMeta{
|
||||||
|
Name: "bar", Namespace: "baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
`baz/foo_bar.yaml`, `without dir`,
|
`baz/foo_bar.yaml`, `without dir`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`dir`,
|
`dir`,
|
||||||
yaml.ResourceMeta{Kind: "foo",
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
ObjectMeta: yaml.ObjectMeta{Name: "bar"},
|
Kind: "foo",
|
||||||
|
},
|
||||||
|
ObjectMeta: yaml.ObjectMeta{
|
||||||
|
NameMeta: yaml.NameMeta{Name: "bar"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
`dir/foo_bar.yaml`, `without namespace`,
|
`dir/foo_bar.yaml`, `without namespace`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
``,
|
``,
|
||||||
yaml.ResourceMeta{Kind: "foo",
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
ObjectMeta: yaml.ObjectMeta{Name: "bar"},
|
Kind: "foo",
|
||||||
|
},
|
||||||
|
ObjectMeta: yaml.ObjectMeta{
|
||||||
|
NameMeta: yaml.NameMeta{Name: "bar"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
`foo_bar.yaml`, `without namespace or dir`,
|
`foo_bar.yaml`, `without namespace or dir`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
``,
|
``,
|
||||||
yaml.ResourceMeta{Kind: "foo",
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "foo",
|
||||||
|
},
|
||||||
ObjectMeta: yaml.ObjectMeta{},
|
ObjectMeta: yaml.ObjectMeta{},
|
||||||
},
|
},
|
||||||
`foo_.yaml`, `without namespace, dir or name`,
|
`foo_.yaml`, `without namespace, dir or name`,
|
||||||
@@ -316,7 +343,9 @@ func TestCreatePathAnnotationValue(t *testing.T) {
|
|||||||
{
|
{
|
||||||
``,
|
``,
|
||||||
yaml.ResourceMeta{
|
yaml.ResourceMeta{
|
||||||
|
TypeMeta: yaml.TypeMeta{
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
|
},
|
||||||
ObjectMeta: yaml.ObjectMeta{},
|
ObjectMeta: yaml.ObjectMeta{},
|
||||||
},
|
},
|
||||||
`_.yaml`, `without any`,
|
`_.yaml`, `without any`,
|
||||||
|
|||||||
@@ -698,11 +698,15 @@ metadata:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.Equal(t, ResourceMeta{
|
assert.Equal(t, ResourceMeta{
|
||||||
|
TypeMeta: TypeMeta{
|
||||||
Kind: "Deployment",
|
Kind: "Deployment",
|
||||||
APIVersion: "v1/apps",
|
APIVersion: "v1/apps",
|
||||||
|
},
|
||||||
ObjectMeta: ObjectMeta{
|
ObjectMeta: ObjectMeta{
|
||||||
|
NameMeta: NameMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Namespace: "bar",
|
Namespace: "bar",
|
||||||
|
},
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"ka": "va",
|
"ka": "va",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,11 +36,15 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected := ResourceMeta{
|
expected := ResourceMeta{
|
||||||
|
TypeMeta: TypeMeta{
|
||||||
APIVersion: "rbac.istio.io/v1alpha1",
|
APIVersion: "rbac.istio.io/v1alpha1",
|
||||||
Kind: "ServiceRole",
|
Kind: "ServiceRole",
|
||||||
|
},
|
||||||
ObjectMeta: ObjectMeta{
|
ObjectMeta: ObjectMeta{
|
||||||
|
NameMeta: NameMeta{
|
||||||
Name: "wildcard",
|
Name: "wildcard",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
|
},
|
||||||
Annotations: map[string]string{"foo": "bar"},
|
Annotations: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,27 +88,33 @@ func (f FilterFunc) Filter(object *RNode) (*RNode, error) {
|
|||||||
return f(object)
|
return f(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypeMeta partially copies apimachinery/pkg/apis/meta/v1.TypeMeta
|
||||||
|
// No need for a direct dependence; the fields are stable.
|
||||||
type TypeMeta struct {
|
type TypeMeta struct {
|
||||||
Kind string
|
// APIVersion is the apiVersion field of a Resource
|
||||||
APIVersion string
|
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
||||||
|
// Kind is the kind field of a Resource
|
||||||
|
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameMeta contains name information.
|
||||||
|
type NameMeta struct {
|
||||||
|
// Name is the metadata.name field of a Resource
|
||||||
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
|
// Namespace is the metadata.namespace field of a Resource
|
||||||
|
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceMeta contains the metadata for a both Resource Type and Resource.
|
// ResourceMeta contains the metadata for a both Resource Type and Resource.
|
||||||
type ResourceMeta struct {
|
type ResourceMeta struct {
|
||||||
// APIVersion is the apiVersion field of a Resource
|
TypeMeta `json:",inline" yaml:",inline"`
|
||||||
APIVersion string `yaml:"apiVersion,omitempty"`
|
|
||||||
// Kind is the kind field of a Resource
|
|
||||||
Kind string `yaml:"kind,omitempty"`
|
|
||||||
// ObjectMeta is the metadata field of a Resource
|
// ObjectMeta is the metadata field of a Resource
|
||||||
ObjectMeta `yaml:"metadata,omitempty"`
|
ObjectMeta `yaml:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectMeta contains metadata about a Resource
|
// ObjectMeta contains metadata about a Resource
|
||||||
type ObjectMeta struct {
|
type ObjectMeta struct {
|
||||||
// Name is the metadata.name field of a Resource
|
NameMeta `json:",inline" yaml:",inline"`
|
||||||
Name string `yaml:"name,omitempty"`
|
|
||||||
// Namespace is the metadata.namespace field of a Resource
|
|
||||||
Namespace string `yaml:"namespace,omitempty"`
|
|
||||||
// Labels is the metadata.labels field of a Resource
|
// Labels is the metadata.labels field of a Resource
|
||||||
Labels map[string]string `yaml:"labels,omitempty"`
|
Labels map[string]string `yaml:"labels,omitempty"`
|
||||||
// Annotations is the metadata.annotations field of a Resource.
|
// Annotations is the metadata.annotations field of a Resource.
|
||||||
@@ -119,24 +125,16 @@ type ObjectMeta struct {
|
|||||||
// the information needed to uniquely identify a resource in a cluster.
|
// the information needed to uniquely identify a resource in a cluster.
|
||||||
func (m *ResourceMeta) GetIdentifier() ResourceIdentifier {
|
func (m *ResourceMeta) GetIdentifier() ResourceIdentifier {
|
||||||
return ResourceIdentifier{
|
return ResourceIdentifier{
|
||||||
Name: m.Name,
|
TypeMeta: m.TypeMeta,
|
||||||
Namespace: m.Namespace,
|
NameMeta: m.NameMeta,
|
||||||
APIVersion: m.APIVersion,
|
|
||||||
Kind: m.Kind,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceIdentifier contains the information needed to uniquely
|
// ResourceIdentifier contains the information needed to uniquely
|
||||||
// identify a resource in a cluster.
|
// identify a resource in a cluster.
|
||||||
type ResourceIdentifier struct {
|
type ResourceIdentifier struct {
|
||||||
// Name is the name of the resource as set in metadata.name
|
TypeMeta `json:",inline" yaml:",inline"`
|
||||||
Name string `yaml:"name,omitempty"`
|
NameMeta `json:",inline" yaml:",inline"`
|
||||||
// Namespace is the namespace of the resource as set in metadata.namespace
|
|
||||||
Namespace string `yaml:"namespace,omitempty"`
|
|
||||||
// ApiVersion is the apiVersion of the resource
|
|
||||||
APIVersion string `yaml:"apiVersion,omitempty"`
|
|
||||||
// Kind is the kind of the resource
|
|
||||||
Kind string `yaml:"kind,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResourceIdentifier) GetName() string {
|
func (r *ResourceIdentifier) GetName() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user