mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Merge pull request #4272 from mengqiy/pointer
Make ResourceList follow k8s api conventions
This commit is contained in:
@@ -322,11 +322,11 @@ func ExampleBuild_validate() {
|
||||
validationResults = append(validationResults, &framework.Result{
|
||||
Severity: framework.Error,
|
||||
Message: "field is required",
|
||||
ResourceRef: yaml.ResourceIdentifier{
|
||||
ResourceRef: &yaml.ResourceIdentifier{
|
||||
TypeMeta: meta.TypeMeta,
|
||||
NameMeta: meta.ObjectMeta.NameMeta,
|
||||
},
|
||||
Field: framework.Field{
|
||||
Field: &framework.Field{
|
||||
Path: "spec.replicas",
|
||||
ProposedValue: "1",
|
||||
},
|
||||
|
||||
@@ -47,12 +47,12 @@ type ResourceList struct {
|
||||
// kind: Example
|
||||
// spec:
|
||||
// foo: var
|
||||
FunctionConfig *yaml.RNode `yaml:"functionConfig" json:"functionConfig"`
|
||||
FunctionConfig *yaml.RNode `yaml:"functionConfig,omitempty" json:"functionConfig,omitempty"`
|
||||
|
||||
// Results is ResourceList.results output value.
|
||||
// Validating functions can optionally use this field to communicate structured
|
||||
// validation error data to downstream functions.
|
||||
Results Results `yaml:"results" json:"results"`
|
||||
Results Results `yaml:"results,omitempty" json:"results,omitempty"`
|
||||
}
|
||||
|
||||
// ResourceListProcessor is implemented by configuration functions built with this framework
|
||||
|
||||
@@ -20,16 +20,16 @@ func TestExecute_Result(t *testing.T) {
|
||||
{
|
||||
Message: "bad value for replicas",
|
||||
Severity: framework.Error,
|
||||
ResourceRef: yaml.ResourceIdentifier{
|
||||
ResourceRef: &yaml.ResourceIdentifier{
|
||||
TypeMeta: yaml.TypeMeta{APIVersion: "v1", Kind: "Deployment"},
|
||||
NameMeta: yaml.NameMeta{Name: "tester", Namespace: "default"},
|
||||
},
|
||||
Field: framework.Field{
|
||||
Field: &framework.Field{
|
||||
Path: ".spec.Replicas",
|
||||
CurrentValue: "0",
|
||||
ProposedValue: "3",
|
||||
},
|
||||
File: framework.File{
|
||||
File: &framework.File{
|
||||
Path: "/path/to/deployment.yaml",
|
||||
Index: 0,
|
||||
},
|
||||
@@ -59,7 +59,7 @@ items:
|
||||
err := framework.Execute(p, source)
|
||||
assert.EqualError(t, err, `[error] v1/Deployment/default/tester .spec.Replicas: bad value for replicas
|
||||
|
||||
[error] : some error`)
|
||||
[error]: some error`)
|
||||
assert.Equal(t, 1, err.(*framework.Results).ExitCode())
|
||||
assert.Equal(t, `apiVersion: config.kubernetes.io/v1
|
||||
kind: ResourceList
|
||||
|
||||
@@ -32,13 +32,13 @@ type Result struct {
|
||||
|
||||
// ResourceRef is a reference to a resource.
|
||||
// Required fields: apiVersion, kind, name.
|
||||
ResourceRef yaml.ResourceIdentifier `yaml:"resourceRef,omitempty" json:"resourceRef,omitempty"`
|
||||
ResourceRef *yaml.ResourceIdentifier `yaml:"resourceRef,omitempty" json:"resourceRef,omitempty"`
|
||||
|
||||
// Field is a reference to the field in a resource this result refers to
|
||||
Field Field `yaml:"field,omitempty" json:"field,omitempty"`
|
||||
Field *Field `yaml:"field,omitempty" json:"field,omitempty"`
|
||||
|
||||
// File references a file containing the resource this result refers to
|
||||
File File `yaml:"file,omitempty" json:"file,omitempty"`
|
||||
File *File `yaml:"file,omitempty" json:"file,omitempty"`
|
||||
|
||||
// Tags is an unstructured key value map stored with a result that may be set
|
||||
// by external tools to store and retrieve arbitrary metadata
|
||||
@@ -49,23 +49,33 @@ type Result struct {
|
||||
func (i Result) String() string {
|
||||
identifier := i.ResourceRef
|
||||
var idStringList []string
|
||||
if identifier.APIVersion != "" {
|
||||
idStringList = append(idStringList, identifier.APIVersion)
|
||||
}
|
||||
if identifier.Kind != "" {
|
||||
idStringList = append(idStringList, identifier.Kind)
|
||||
}
|
||||
if identifier.Namespace != "" {
|
||||
idStringList = append(idStringList, identifier.Namespace)
|
||||
}
|
||||
if identifier.Name != "" {
|
||||
idStringList = append(idStringList, identifier.Name)
|
||||
if identifier != nil {
|
||||
if identifier.APIVersion != "" {
|
||||
idStringList = append(idStringList, identifier.APIVersion)
|
||||
}
|
||||
if identifier.Kind != "" {
|
||||
idStringList = append(idStringList, identifier.Kind)
|
||||
}
|
||||
if identifier.Namespace != "" {
|
||||
idStringList = append(idStringList, identifier.Namespace)
|
||||
}
|
||||
if identifier.Name != "" {
|
||||
idStringList = append(idStringList, identifier.Name)
|
||||
}
|
||||
}
|
||||
formatString := "[%s]"
|
||||
list := []interface{}{i.Severity}
|
||||
if len(idStringList) > 0 {
|
||||
idString := strings.Join(idStringList, "/")
|
||||
return fmt.Sprintf("[%s] %s %s: %s", i.Severity, idString, i.Field.Path, i.Message)
|
||||
formatString += " %s"
|
||||
list = append(list, strings.Join(idStringList, "/"))
|
||||
}
|
||||
return fmt.Sprintf("[%s] %s: %s", i.Severity, i.Field.Path, i.Message)
|
||||
if i.Field != nil {
|
||||
formatString += " %s"
|
||||
list = append(list, i.Field.Path)
|
||||
}
|
||||
formatString += ": %s"
|
||||
list = append(list, i.Message)
|
||||
return fmt.Sprintf(formatString, list...)
|
||||
}
|
||||
|
||||
// File references a file containing a resource
|
||||
|
||||
Reference in New Issue
Block a user