Skip to content

Commit

Permalink
Update nodoc behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Mallon (Nalum) <[email protected]>
  • Loading branch information
Nalum committed Oct 3, 2024
1 parent 96e8f5b commit df6bb5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
22 changes: 10 additions & 12 deletions cmd/timoni/testdata/module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"` | |

4 changes: 0 additions & 4 deletions cmd/timoni/testdata/module/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ 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
digest: *"sha256:b49fbaac0eedc22c1cfcd26684707179cccbed0df205171bae3e1bae61326a10" | string
}
}

// +nodoc
server: {
enabled: *true | bool
}
domain: *"example.internal" | string

// +nodoc
ns: {
enabled: *false | bool
}
Expand Down
19 changes: 15 additions & 4 deletions internal/engine/get_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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, "|", "\\|")
Expand Down

0 comments on commit df6bb5d

Please sign in to comment.