Skip to content

Commit

Permalink
Add enum definition for apiVersion and kind schema
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 18, 2023
1 parent e99760d commit 76c06a1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func GenDescriptor(dir string) error {
rdir := filepath.Join(dir, g, r)
os.MkdirAll(rdir, 0o755)

Check failure on line 60 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

Error return value of `os.MkdirAll` is not checked (errcheck)

// os.WriteFile(filepath.Join(rdir, "crd.yaml"), []byte("crd.yaml"), 0644)

vdir := filepath.Join(rdir, rd.Spec.Resource.Version)
os.MkdirAll(vdir, 0o755)

Check failure on line 63 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

Error return value of `os.MkdirAll` is not checked (errcheck)

Expand All @@ -71,7 +69,21 @@ func GenDescriptor(dir string) error {
os.WriteFile(filepath.Join(vdir, "resourcedescriptor.yaml"), data, 0o644)

Check failure on line 69 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

Error return value of `os.WriteFile` is not checked (errcheck)

if rd.Spec.Validation != nil && rd.Spec.Validation.OpenAPIV3Schema != nil {
data, err := yaml.Marshal(rd.Spec.Validation.OpenAPIV3Schema)
schema := rd.Spec.Validation.OpenAPIV3Schema
if prop, ok := schema.Properties["apiVersion"]; ok {
prop.Enum = []crdv1.JSON{
{[]byte(fmt.Sprintf("%q", rd.Spec.Resource.GroupVersion()))},

Check failure on line 75 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

composites: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1.JSON struct literal uses unkeyed fields (govet)
}
schema.Properties["apiVersion"] = prop
}
if prop, ok := schema.Properties["kind"]; ok {
prop.Enum = []crdv1.JSON{
{[]byte(fmt.Sprintf("%q", rd.Spec.Resource.Kind))},
}
schema.Properties["kind"] = prop
}

data, err := yaml.Marshal(schema)
if err != nil {
return err
}
Expand Down

0 comments on commit 76c06a1

Please sign in to comment.