From df6bb5dcc2699a00529cc8c126ea932e2680013c Mon Sep 17 00:00:00 2001 From: "Luke Mallon (Nalum)" Date: Fri, 4 Oct 2024 00:23:37 +0100 Subject: [PATCH] Update nodoc behaviour Signed-off-by: Luke Mallon (Nalum) --- cmd/timoni/testdata/module/README.md | 22 +++++++++---------- .../testdata/module/templates/config.cue | 4 ---- internal/engine/get_config.go | 19 ++++++++++++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cmd/timoni/testdata/module/README.md b/cmd/timoni/testdata/module/README.md index 740de62d..d788dfcd 100644 --- a/cmd/timoni/testdata/module/README.md +++ b/cmd/timoni/testdata/module/README.md @@ -41,16 +41,14 @@ timoni -n module delete module ## Configuration -| KEY | TYPE | DESCRIPTION | -|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `metadata: annotations:` | `{}` | Annotations is an unstructured key value map stored with a resource that may be set to store and retrieve arbitrary metadata. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations | -| `metadata: labels:` | `{ "app.kubernetes.io/name": "module-name" "app.kubernetes.io/kube": "1.27.5" "app.kubernetes.io/version": "0.0.0-devel" "app.kubernetes.io/team": "test"}` | Map of string keys and values that can be used to organize and categorize (scope and select) objects. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels Standard Kubernetes labels: app name and version. | -| `client: enabled:` | `*true \| bool` | | -| `client: image: repository:` | `*"cgr.dev/chainguard/timoni" \| string` | Repository is the address of a container registry repository. An image repository is made up of slash-separated name components, optionally prefixed by a registry hostname and port in the format [HOST[:PORT_NUMBER]/]PATH. | -| `client: image: tag:` | `*"latest-dev" \| strings.MaxRunes(128)` | Tag identifies an image in the repository. A tag name may contain lowercase and uppercase characters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters. | -| `client: image: digest:` | `*"sha256:b49fbaac0eedc22c1cfcd26684707179cccbed0df205171bae3e1bae61326a10" \| string` | Digest uniquely and immutably identifies an image in the repository. Spec: https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests. | -| `server: enabled:` | `*true \| bool` | | -| `domain:` | `*"example.internal" \| string` | | -| `ns: enabled:` | `*false \| bool` | | -| `team:` | `"test"` | | +| KEY | TYPE | DESCRIPTION | +|------------------------------|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `client: enabled:` | `*true \| bool` | | +| `client: image: repository:` | `*"cgr.dev/chainguard/timoni" \| string` | Repository is the address of a container registry repository. An image repository is made up of slash-separated name components, optionally prefixed by a registry hostname and port in the format [HOST[:PORT_NUMBER]/]PATH. | +| `client: image: tag:` | `*"latest-dev" \| strings.MaxRunes(128)` | Tag identifies an image in the repository. A tag name may contain lowercase and uppercase characters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters. | +| `client: image: digest:` | `*"sha256:b49fbaac0eedc22c1cfcd26684707179cccbed0df205171bae3e1bae61326a10" \| string` | Digest uniquely and immutably identifies an image in the repository. Spec: https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests. | +| `server: enabled:` | `*true \| bool` | | +| `domain:` | `*"example.internal" \| string` | | +| `ns: enabled:` | `*false \| bool` | | +| `team:` | `"test"` | | diff --git a/cmd/timoni/testdata/module/templates/config.cue b/cmd/timoni/testdata/module/templates/config.cue index dd5722b8..3da673ba 100644 --- a/cmd/timoni/testdata/module/templates/config.cue +++ b/cmd/timoni/testdata/module/templates/config.cue @@ -17,11 +17,9 @@ import ( "app.kubernetes.io/team": team } - // +nodoc client: { enabled: *true | bool - // +nodoc image: timoniv1.#Image & { repository: *"cgr.dev/chainguard/timoni" | string tag: *"latest-dev" | string @@ -29,13 +27,11 @@ import ( } } - // +nodoc server: { enabled: *true | bool } domain: *"example.internal" | string - // +nodoc ns: { enabled: *false | bool } diff --git a/internal/engine/get_config.go b/internal/engine/get_config.go index 614437d3..d1b3e7f3 100644 --- a/internal/engine/get_config.go +++ b/internal/engine/get_config.go @@ -98,6 +98,11 @@ func iterateFields(v cue.Value) ([][]string, error) { for fields.Next() { v := fields.Value() + _, noDoc := hasNoDoc(v) + + if noDoc { + continue + } // We are chekcing if the field is a struct and not optional and is concrete before we iterate through it // this allows for definition of default values as full structs without generating output for each @@ -106,6 +111,7 @@ func iterateFields(v cue.Value) ([][]string, error) { // - annotations?: {[string]: string} // - affinity: corev1.Affinity | *{nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [...]} if v.IncompleteKind() == cue.StructKind && !fields.IsOptional() && v.IsConcrete() { + //if _, ok := v.Default(); v.IncompleteKind() == cue.StructKind && !fields.IsOptional() && ok { // Assume we want to use the field useField := true iRows, err := iterateFields(v) @@ -133,10 +139,7 @@ func iterateFields(v cue.Value) ([][]string, error) { return rows, nil } -func getField(v cue.Value) []string { - var row []string - labelDomain := regexp.MustCompile(`^([a-zA-Z0-9-_.]+)?(".+")?$`) - +func hasNoDoc(v cue.Value) (string, bool) { var noDoc bool var doc string @@ -155,6 +158,14 @@ func getField(v cue.Value) []string { doc = strings.ReplaceAll(doc, "+optional", "") } + return doc, noDoc +} + +func getField(v cue.Value) []string { + var row []string + labelDomain := regexp.MustCompile(`^([a-zA-Z0-9-_.]+)?(".+")?$`) + doc, noDoc := hasNoDoc(v) + if !noDoc { fieldType := strings.ReplaceAll(fmt.Sprintf("%v", v), "\n", "") fieldType = strings.ReplaceAll(fieldType, "|", "\\|")