Skip to content

Commit 67e085b

Browse files
committed
fixup! Update CRD generator to support experimental CRDs
1 parent 167481c commit 67e085b

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

hack/tools/crd-generator/main.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ func runGenerator(args ...string) {
7070
crdRoot = args[2]
7171
}
7272

73-
log.Printf("crdRoot: %s", crdRoot)
74-
7573
roots, err := loader.LoadRoots(
7674
"k8s.io/apimachinery/pkg/runtime/schema", // Needed to parse generated register functions.
7775
crdRoot,
@@ -96,7 +94,6 @@ func runGenerator(args ...string) {
9694

9795
crd.AddKnownTypes(parser)
9896
for _, r := range roots {
99-
log.Printf("Looking at package %v", r)
10097
parser.NeedPackage(r)
10198
}
10299

@@ -144,7 +141,6 @@ func runGenerator(args ...string) {
144141

145142
conv, err := crd.AsVersion(*channelCrd, apiextensionsv1.SchemeGroupVersion)
146143
if err != nil {
147-
log.Printf("CRD: %v", *channelCrd)
148144
log.Fatalf("failed to convert CRD: %s", err)
149145
}
150146

@@ -174,8 +170,6 @@ func runGenerator(args ...string) {
174170
out = append(breakLine, out...)
175171
}
176172

177-
log.Printf("writing %v bytes", len(out))
178-
179173
fileName := fmt.Sprintf("%s/%s/%s_%s.yaml", outputDir, channel, crdRaw.Spec.Group, crdRaw.Spec.Names.Plural)
180174
err = os.WriteFile(fileName, out, 0o600)
181175
if err != nil {
@@ -216,8 +210,6 @@ func opconTweaks(channel string, name string, jsonProps apiextensionsv1.JSONSche
216210
numExpressions := strings.Count(jsonProps.Description, validationPrefix)
217211
numValid := 0
218212
if numExpressions > 0 {
219-
log.Printf("found validations")
220-
221213
enumRe := regexp.MustCompile(validationPrefix + "Enum=([A-Za-z;]*)>")
222214
enumMatches := enumRe.FindAllStringSubmatch(jsonProps.Description, 64)
223215
for _, enumMatch := range enumMatches {
@@ -248,7 +240,6 @@ func opconTweaks(channel string, name string, jsonProps apiextensionsv1.JSONSche
248240
}
249241

250242
if numValid < numExpressions {
251-
fmt.Printf("Description: %s\n", jsonProps.Description)
252243
log.Fatalf("Found %d Opcon validation expressions, but only %d were valid", numExpressions, numValid)
253244
}
254245

@@ -274,7 +265,6 @@ func formatDescription(description string, channel string, name string) string {
274265
log.Fatalf("Invalid <opcon:experimental:description> tag for %s", name)
275266
}
276267
description = re.ReplaceAllString(description, "\n\n")
277-
log.Printf("found experimental:description")
278268
} else {
279269
description = strings.ReplaceAll(description, startTag, "")
280270
description = strings.ReplaceAll(description, endTag, "")
@@ -292,7 +282,6 @@ func formatDescription(description string, channel string, name string) string {
292282
log.Fatalf("Invalid <opcon:util:excludeFromCRD> tag for %s", name)
293283
}
294284
description = re.ReplaceAllString(description, "\n\n\n")
295-
log.Printf("found excludeFromCRD")
296285
}
297286

298287
opconRe := regexp.MustCompile(`<opcon:.*>`)

hack/tools/crd-generator/main_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ func TestRunGenerator(t *testing.T) {
1616
// Get to repo root
1717
err = os.Chdir("../../..")
1818
require.NoError(t, err)
19-
defer os.Chdir(here)
19+
defer func() {
20+
_ = os.Chdir(here)
21+
}()
2022
dir, err := os.MkdirTemp("", "crd-generate-*")
2123
require.NoError(t, err)
2224
defer os.RemoveAll(dir)
@@ -49,7 +51,9 @@ func TestTags(t *testing.T) {
4951
here, err := os.Getwd()
5052
require.NoError(t, err)
5153
err = os.Chdir("testdata")
52-
defer os.Chdir(here)
54+
defer func() {
55+
_ = os.Chdir(here)
56+
}()
5357
require.NoError(t, err)
5458
dir, err := os.MkdirTemp("", "crd-generate-*")
5559
require.NoError(t, err)
@@ -72,11 +76,15 @@ func TestTags(t *testing.T) {
7276
func compareFiles(t *testing.T, file1, file2 string) {
7377
f1, err := os.Open(file1)
7478
require.NoError(t, err)
75-
defer f1.Close()
79+
defer func() {
80+
_ = f1.Close()
81+
}()
7682

7783
f2, err := os.Open(file2)
7884
require.NoError(t, err)
79-
defer f2.Close()
85+
defer func() {
86+
_ = f2.Close()
87+
}()
8088

8189
for {
8290
b1 := make([]byte, 64000)

0 commit comments

Comments
 (0)