Skip to content

Commit 351f5e5

Browse files
authored
Merge pull request #405 from mengqiy/map
🐛 use map in FindKubeKinds
2 parents 9d85d10 + 81d0342 commit 351f5e5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/crd/gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
104104
crdVersions = []string{"v1beta1"}
105105
}
106106

107-
for _, groupKind := range kubeKinds {
107+
for groupKind := range kubeKinds {
108108
parser.NeedCRDFor(groupKind, g.MaxDescLen)
109109
crdRaw := parser.CustomResourceDefinitions[groupKind]
110110
addAttribution(&crdRaw)
@@ -206,9 +206,9 @@ func FindMetav1(roots []*loader.Package) *loader.Package {
206206
// FindKubeKinds locates all types that contain TypeMeta and ObjectMeta
207207
// (and thus may be a Kubernetes object), and returns the corresponding
208208
// group-kinds.
209-
func FindKubeKinds(parser *Parser, metav1Pkg *loader.Package) []schema.GroupKind {
209+
func FindKubeKinds(parser *Parser, metav1Pkg *loader.Package) map[schema.GroupKind]struct{} {
210210
// TODO(directxman12): technically, we should be finding metav1 per-package
211-
var kubeKinds []schema.GroupKind
211+
kubeKinds := map[schema.GroupKind]struct{}{}
212212
for typeIdent, info := range parser.Types {
213213
hasObjectMeta := false
214214
hasTypeMeta := false
@@ -257,7 +257,7 @@ func FindKubeKinds(parser *Parser, metav1Pkg *loader.Package) []schema.GroupKind
257257
Group: parser.GroupVersions[pkg].Group,
258258
Kind: typeIdent.Name,
259259
}
260-
kubeKinds = append(kubeKinds, groupKind)
260+
kubeKinds[groupKind] = struct{}{}
261261
}
262262

263263
return kubeKinds

pkg/schemapatcher/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) (result error) {
115115
}
116116

117117
// generate schemata for the types we care about, and save them to be written later.
118-
for _, groupKind := range crdgen.FindKubeKinds(parser, metav1Pkg) {
118+
for groupKind := range crdgen.FindKubeKinds(parser, metav1Pkg) {
119119
existingSet, wanted := partialCRDSets[groupKind]
120120
if !wanted {
121121
continue

0 commit comments

Comments
 (0)