Skip to content

Commit

Permalink
Merge pull request #253 from MbolotSuse/schema-less
Browse files Browse the repository at this point in the history
Handle Schema-less CRDs
  • Loading branch information
MbolotSuse authored Aug 5, 2024
2 parents 435e220 + dfae21c commit 1d42891
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
49 changes: 49 additions & 0 deletions pkg/schema/definitions/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ spec:
nullable: true
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: schemaless.management.cattle.io
spec:
conversion:
strategy: None
group: management.cattle.io
names:
kind: Schemaless
listKind: SchemalessList
plural: schemalese
singular: schemaless
scope: Cluster
preserveUnkownFields: true
versions:
- name: v2
served: true
storage: true
`
)

Expand Down Expand Up @@ -346,6 +366,35 @@ definitions:
- group: "management.cattle.io"
version: "v2"
kind: "Nullable"
io.cattle.management.v2.Schemaless:
description: "this kind has no schema"
type: "object"
properties:
apiVersion:
description: "The APIVersion of this resource"
type: "string"
kind:
description: "The kind"
type: "string"
metadata:
description: "The metadata"
$ref: "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"
spec:
description: "The spec for the resource"
type: "object"
required:
- "name"
properties:
name:
description: "The name of the resource"
type: "string"
notRequired:
description: "Some field that isn't required"
type: "boolean"
x-kubernetes-group-version-kind:
- group: "management.cattle.io"
version: "v2"
kind: "Schemaless"
io.cattle.management.NotAKind:
type: "string"
description: "Some string which isn't a kind"
Expand Down
4 changes: 3 additions & 1 deletion pkg/schema/definitions/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func listGVKModels(models proto.Models, groups *metav1.APIGroupList, crdCache wa
Version: version.Name,
Kind: crd.Spec.Names.Kind,
}
gvkToCRD[gvk] = version.Schema.OpenAPIV3Schema
if version.Schema != nil {
gvkToCRD[gvk] = version.Schema.OpenAPIV3Schema
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/schema/definitions/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRefresh(t *testing.T) {
require.NotNil(t, userAttributesV2)

nullableV2 := getJSONSchema(crds, "nullable.management.cattle.io", "v2")
require.NotNil(t, userAttributesV2)
require.NotNil(t, nullableV2)

tests := []struct {
name string
Expand Down Expand Up @@ -85,6 +85,11 @@ func TestRefresh(t *testing.T) {
Schema: defaultModels.LookupModel("io.cattle.management.v2.Nullable"),
CRD: nullableV2,
},
"management.cattle.io.schemaless": {
ModelName: "io.cattle.management.v2.Schemaless",
Schema: defaultModels.LookupModel("io.cattle.management.v2.Schemaless"),
CRD: nil,
},
},
},
{
Expand Down Expand Up @@ -147,6 +152,11 @@ func TestRefresh(t *testing.T) {
Schema: defaultModels.LookupModel("io.cattle.management.v2.Nullable"),
CRD: nullableV2,
},
"management.cattle.io.schemaless": {
ModelName: "io.cattle.management.v2.Schemaless",
Schema: defaultModels.LookupModel("io.cattle.management.v2.Schemaless"),
CRD: nil,
},
},
},
}
Expand Down

0 comments on commit 1d42891

Please sign in to comment.