mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #54441 from apelisse/fix-apply-govet
Automatic merge from submit-queue (batch tested with PRs 53479, 54373, 54441, 54443). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix govet in pkg/kubectl/apply **What this PR does / why we need it**: Fix govet warning by explicitly using field keys. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
78c7e7f79f
@ -86,17 +86,35 @@ func (v *ElementBuildingVisitor) getItem(s proto.Schema, name string, data apply
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("expected openapi Array, was %T for %v", s, kind)
|
return nil, fmt.Errorf("expected openapi Array, was %T for %v", s, kind)
|
||||||
}
|
}
|
||||||
return &listItem{name, a, apply.ListElementData{data}}, nil
|
return &listItem{
|
||||||
|
Name: name,
|
||||||
|
Array: a,
|
||||||
|
ListElementData: apply.ListElementData{
|
||||||
|
RawElementData: data,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
if k, err := getKind(s); err == nil {
|
if k, err := getKind(s); err == nil {
|
||||||
return &typeItem{name, k, apply.MapElementData{data}}, nil
|
return &typeItem{
|
||||||
|
Name: name,
|
||||||
|
Type: k,
|
||||||
|
MapElementData: apply.MapElementData{
|
||||||
|
RawElementData: data,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
// If it looks like a map, and no openapi type is found, default to mapItem
|
// If it looks like a map, and no openapi type is found, default to mapItem
|
||||||
m, err := getMap(s)
|
m, err := getMap(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("expected openapi Kind or Map, was %T for %v", s, kind)
|
return nil, fmt.Errorf("expected openapi Kind or Map, was %T for %v", s, kind)
|
||||||
}
|
}
|
||||||
return &mapItem{name, m, apply.MapElementData{data}}, nil
|
return &mapItem{
|
||||||
|
Name: name,
|
||||||
|
Map: m,
|
||||||
|
MapElementData: apply.MapElementData{
|
||||||
|
RawElementData: data,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("unsupported type type %v", kind)
|
return nil, fmt.Errorf("unsupported type type %v", kind)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,11 @@ func (v ElementBuildingVisitor) doMapList(meta apply.FieldMetaImpl, item *listIt
|
|||||||
// Uses the "replace" strategy and identify "same" elements across lists by their index
|
// Uses the "replace" strategy and identify "same" elements across lists by their index
|
||||||
func (v ElementBuildingVisitor) replaceListElement(meta apply.FieldMetaImpl, item *listItem) (*apply.ListElement, error) {
|
func (v ElementBuildingVisitor) replaceListElement(meta apply.FieldMetaImpl, item *listItem) (*apply.ListElement, error) {
|
||||||
meta.Name = item.Name
|
meta.Name = item.Name
|
||||||
result := &apply.ListElement{meta, item.ListElementData, []apply.Element{}}
|
result := &apply.ListElement{
|
||||||
|
FieldMetaImpl: meta,
|
||||||
|
ListElementData: item.ListElementData,
|
||||||
|
Values: []apply.Element{},
|
||||||
|
}
|
||||||
|
|
||||||
// Use the max length to iterate over the slices
|
// Use the max length to iterate over the slices
|
||||||
for i := 0; i < max(len(item.GetRecordedList()), len(item.GetLocalList()), len(item.GetRemoteList())); i++ {
|
for i := 0; i < max(len(item.GetRecordedList()), len(item.GetLocalList()), len(item.GetRemoteList())); i++ {
|
||||||
|
@ -39,7 +39,11 @@ func (v ElementBuildingVisitor) mapElement(meta apply.FieldMetaImpl, item *mapIt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return &apply.MapElement{meta, item.MapElementData, values}, nil
|
return &apply.MapElement{
|
||||||
|
FieldMetaImpl: meta,
|
||||||
|
MapElementData: item.MapElementData,
|
||||||
|
Values: values,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// schemaFn returns the schema for a field or map value based on its name or key
|
// schemaFn returns the schema for a field or map value based on its name or key
|
||||||
|
@ -21,5 +21,8 @@ import "k8s.io/kubernetes/pkg/kubectl/apply"
|
|||||||
// primitiveElement builds a new primitiveElement from a PrimitiveItem
|
// primitiveElement builds a new primitiveElement from a PrimitiveItem
|
||||||
func (v ElementBuildingVisitor) primitiveElement(item *primitiveItem) (*apply.PrimitiveElement, error) {
|
func (v ElementBuildingVisitor) primitiveElement(item *primitiveItem) (*apply.PrimitiveElement, error) {
|
||||||
meta := apply.FieldMetaImpl{Name: item.Name}
|
meta := apply.FieldMetaImpl{Name: item.Name}
|
||||||
return &apply.PrimitiveElement{meta, item.RawElementData}, nil
|
return &apply.PrimitiveElement{
|
||||||
|
FieldMetaImpl: meta,
|
||||||
|
RawElementData: item.RawElementData,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -38,5 +38,9 @@ func (v ElementBuildingVisitor) typeElement(meta apply.FieldMetaImpl, item *type
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return &apply.TypeElement{meta, item.MapElementData, values}, nil
|
return &apply.TypeElement{
|
||||||
|
FieldMetaImpl: meta,
|
||||||
|
MapElementData: item.MapElementData,
|
||||||
|
Values: values,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func runWith(instance apply.Strategy, recorded, local, remote, expected map[stri
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
resources, err := openapi.NewOpenAPIData(s)
|
resources, err := openapi.NewOpenAPIData(s)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
parseFactory := parse.Factory{resources}
|
parseFactory := parse.Factory{Resources: resources}
|
||||||
|
|
||||||
parsed, err := parseFactory.CreateElement(recorded, local, remote)
|
parsed, err := parseFactory.CreateElement(recorded, local, remote)
|
||||||
Expect(err).Should(Not(HaveOccurred()))
|
Expect(err).Should(Not(HaveOccurred()))
|
||||||
|
Loading…
Reference in New Issue
Block a user