-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sam boyer
committed
Nov 11, 2022
1 parent
c2cee21
commit 076bfe1
Showing
6 changed files
with
293 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,97 @@ | ||
package crd | ||
|
||
import ( | ||
"list" | ||
"strings" | ||
"github.com/grafana/thema" | ||
"list" | ||
"strings" | ||
"github.com/grafana/thema" | ||
) | ||
|
||
// CRD transforms a lineage into a Kubernetes custom resource definition, or a series thereof. | ||
#CRD: { | ||
_sv: [<len(lin.seqs), <len(lin.seqs[_sv[0]].schemas)] | ||
served: [..._sv] | ||
storage: _sv | ||
lin: thema.#Lineage | ||
_sv: [<len(lin.seqs), <len(lin.seqs[_sv[0]].schemas)] | ||
served: [..._sv] | ||
storage: _sv | ||
lin: thema.#Lineage | ||
|
||
// Additional metadata necessary to convert a thema lineage into a | ||
// Kubernetes Custom Resource Definition (CRD). | ||
crdspec = spec: { | ||
// Additional metadata necessary to convert a thema lineage into a | ||
// Kubernetes Custom Resource Definition (CRD). | ||
crdspec = spec: { | ||
// scope indicates whether the defined custom resource is cluster- | ||
// or namespace-scoped. | ||
scope: "Namespaced" | "Cluster" | ||
scope: "Namespaced" | "Cluster" | ||
|
||
// group is the API group of the defined custom resource. The | ||
// custom resources are served under `/apis/<group>/...`. | ||
// Ex.: stable.example.com | ||
group: string | ||
// Ex.: stable.example.com | ||
group: string | ||
|
||
names: { | ||
// categories is a list of grouped resources this custom resource | ||
// belongs to (e.g. 'all'). This is published in API discovery | ||
// documents, and used by clients to support invocations like | ||
// `kubectl get all`. | ||
categories?: [...string] | ||
names: { | ||
// categories is a list of grouped resources this custom resource | ||
// belongs to (e.g. 'all'). This is published in API discovery | ||
// documents, and used by clients to support invocations like | ||
// `kubectl get all`. | ||
categories?: [...string] | ||
|
||
// kind is the serialized kind of the resource. It is normally | ||
// CamelCase and singular. Custom resource instances will use | ||
// this value as the `kind` attribute in API calls. | ||
// TODO default this to thema name | ||
kind: string | *lin.name | ||
// kind is the serialized kind of the resource. It is normally | ||
// CamelCase and singular. Custom resource instances will use | ||
// this value as the `kind` attribute in API calls. | ||
// TODO default this to thema name | ||
kind: string | *lin.name | ||
|
||
// listKind is the serialized kind of the list for this resource. | ||
listKind: string | *"\(kind)List" | ||
// listKind is the serialized kind of the list for this resource. | ||
listKind: string | *"\(kind)List" | ||
|
||
// plural is the plural name of the resource to serve. The custom | ||
// resources are served under | ||
// `/apis/<group>/<version>/.../<plural>`. | ||
plural: string | =~ #"[a-z]"# | *"\(lin.name)s" | ||
// plural is the plural name of the resource to serve. The custom | ||
// resources are served under | ||
// `/apis/<group>/<version>/.../<plural>`. | ||
plural: string | =~#"[a-z]"# | *"\(lin.name)s" | ||
|
||
// shortNames allow shorter string to match your resource on the CLI | ||
shortNames?: [...string] | ||
// shortNames allow shorter string to match your resource on the CLI | ||
shortNames?: [...string] | ||
|
||
// singular is the singular name of the resource. It must be all | ||
// lowercase. | ||
singular: string | *strings.ToLower(kind) | ||
// TODO(must) https://github.com/cue-lang/cue/issues/943 | ||
// singular: must(singular == strings.ToLower(singular), "singular form must be all lower case") | ||
} | ||
// Deprecated upstream, so omitted | ||
// preserveUnknownFields: bool | *false | ||
// singular is the singular name of the resource. It must be all | ||
// lowercase. | ||
singular: string | *strings.ToLower(kind) | ||
// TODO(must) https://github.com/cue-lang/cue/issues/943 | ||
// singular: must(singular == strings.ToLower(singular), "singular form must be all lower case") | ||
} | ||
// Deprecated upstream, so omitted | ||
// preserveUnknownFields: bool | *false | ||
|
||
// conversion defines conversion settings for the CRD. | ||
conversion?: { | ||
// TODO for now, only allow this and not webhook, because what we | ||
// really want to do is swap thema translation logic in for | ||
// Scheme | ||
strategy: "None" | ||
} | ||
} | ||
conversion?: { | ||
// TODO for now, only allow this and not webhook, because what we | ||
// really want to do is swap thema translation logic in for | ||
// Scheme | ||
strategy: "None" | ||
} | ||
} | ||
|
||
// The lineage, transformed into a valid CRD. | ||
crd: { | ||
apiVersion: "apiextensions.k8s.io/v1" | ||
kind: "CustomResourceDefinition" | ||
metadata: { | ||
name: "\(crdspec.names.plural).\(crdspec.group)" | ||
} | ||
spec: crdspec | ||
spec: versions: [ | ||
for seqv, seq in lin.seqs { | ||
for schv, sch in seq.schemas { | ||
served: list.Contains(served, [seqv, schv]) | ||
storage: [seqv, schv] == storage | ||
name: "v\(seqv).\(schv)" // Not sure if the dot is allowed | ||
schema: { | ||
openAPIV3Schema: {...} // This is what needs to be filled in by the encoder | ||
cueSchema: sch | ||
} | ||
} | ||
} | ||
] | ||
} | ||
// The lineage, transformed into a valid CRD. | ||
crd: { | ||
apiVersion: "apiextensions.k8s.io/v1" | ||
kind: "CustomResourceDefinition" | ||
metadata: { | ||
name: "\(crdspec.names.plural).\(crdspec.group)" | ||
} | ||
spec: crdspec | ||
spec: versions: [ | ||
for seqv, seq in lin.seqs { | ||
for schv, sch in seq.schemas { | ||
served: list.Contains(served, [seqv, schv]) | ||
storage: [seqv, schv] == storage | ||
name: "v\(seqv).\(schv)" // Not sure if the dot is allowed | ||
schema: { | ||
openAPIV3Schema: {...} // This is what needs to be filled in by the encoder | ||
cueSchema: sch | ||
} | ||
} | ||
}, | ||
] | ||
} | ||
|
||
// The lineage, reformed in the shape of a custom resource validator. | ||
crv: { | ||
// TODO | ||
} | ||
// The lineage, reformed in the shape of a custom resource validator. | ||
crv: { | ||
// TODO | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.