Skip to content

Commit

Permalink
Update schema with +nodoc tags and copy to blueprint starter module
Browse files Browse the repository at this point in the history
Hide certain fields

This change brings the output more inline with the definition

Update output to remove default column

Commit updated test data

Signed-off-by: Luke Mallon (Nalum) <[email protected]>
  • Loading branch information
Nalum committed Oct 3, 2024
1 parent b0e99db commit 96e8f5b
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 52 deletions.
49 changes: 33 additions & 16 deletions blueprints/starter/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

// Reference is the image address computed from repository, tag and digest
// in the format [REPOSITORY]:[TAG]@[DIGEST].
// +nodoc
reference: string

if digest != "" && tag != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ import "strings"

// Standard Kubernetes labels: app name, version and managed-by.
labels: {
(#StdLabelName): name
(#StdLabelVersion): #Version
// +nodoc
(#StdLabelName): name
// +nodoc
(#StdLabelVersion): #Version
// +nodoc
(#StdLabelManagedBy): "timoni"
}

// LabelSelector selects Pods based on the app.kubernetes.io/name label.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelName): name
}

Expand All @@ -74,6 +78,7 @@ import "strings"
namespace: #Meta.namespace

labels: #Meta.labels
// +nodoc
labels: (#StdLabelComponent): #Component

annotations?: #Annotations
Expand All @@ -84,8 +89,10 @@ import "strings"
// LabelSelector selects Pods based on the app.kubernetes.io/name
// and app.kubernetes.io/component labels.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelComponent): #Component
(#StdLabelName): #Meta.name
// +nodoc
(#StdLabelName): #Meta.name
}
}

Expand All @@ -104,6 +111,7 @@ import "strings"
name: #Meta.name + "-" + #Component

labels: #Meta.labels
// +nodoc
labels: (#StdLabelComponent): #Component

annotations?: #Annotations
Expand All @@ -114,7 +122,9 @@ import "strings"
// LabelSelector selects Pods based on the app.kubernetes.io/name
// and app.kubernetes.io/component labels.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelComponent): #Component
(#StdLabelName): #Meta.name
// +nodoc
(#StdLabelName): #Meta.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ package v1alpha1
labels: #Labels

// Standard Kubernetes label: app name.
labels: (#StdLabelName): #Name
labels: {
// +nodoc
(#StdLabelName): #Name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
let minMajor = strconv.Atoi(strings.Split(#Minimum, ".")[0])
let minMinor = strconv.Atoi(strings.Split(#Minimum, ".")[1])

// +nodoc
major: int & >=minMajor
major: strconv.Atoi(strings.Split(#Version, ".")[0])

// +nodoc
minor: int & >=minMinor
minor: strconv.Atoi(strings.Split(#Version, ".")[1])
}
3 changes: 3 additions & 0 deletions blueprints/starter/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
#Config: {
// The kubeVersion is a required field, set at apply-time
// via timoni.cue by querying the user's Kubernetes API.
// +nodoc
kubeVersion!: string
// Using the kubeVersion you can enforce a minimum Kubernetes minor version.
// By default, the minimum Kubernetes version is set to 1.20.
// +nodoc
clusterVersion: timoniv1.#SemVer & {#Version: kubeVersion, #Minimum: "1.20.0"}

// The moduleVersion is set from the user-supplied module version.
// This field is used for the `app.kubernetes.io/version` label.
// +nodoc
moduleVersion!: string

// The Kubernetes metadata common to all resources.
Expand Down
2 changes: 1 addition & 1 deletion cmd/timoni/mod_show_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func runConfigShowModCmd(cmd *cobra.Command, args []string) error {
return describeErr(f.GetModuleRoot(), "failed to get config structure", err)
}

header := []string{"Key", "Type", "Default", "Description"}
header := []string{"Key", "Type", "Description"}

if configShowModArgs.output == "" {
printMarkDownTable(rootCmd.OutOrStdout(), header, rows)
Expand Down
24 changes: 12 additions & 12 deletions cmd/timoni/testdata/module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ timoni -n module delete module

## Configuration

| KEY | TYPE | DEFAULT | DESCRIPTION |
|------------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `metadata: annotations:` | `struct` | `{}` | 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:` | `struct` | `{"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:` | `bool` | `true` | |
| `client: image: repository:` | `string` | `"cgr.dev/chainguard/timoni"` | 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:` | `string` | `"latest-dev"` | 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:` | `string` | `"sha256:b49fbaac0eedc22c1cfcd26684707179cccbed0df205171bae3e1bae61326a10"` | Digest uniquely and immutably identifies an image in the repository. Spec: https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests. |
| `server: enabled:` | `bool` | `true` | |
| `domain:` | `string` | `"example.internal"` | |
| `ns: enabled:` | `bool` | `false` | |
| `team:` | `string` | `"test"` | |
| 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"` | |

22 changes: 9 additions & 13 deletions internal/engine/get_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,21 @@ func getField(v cue.Value) []string {
}

if !noDoc {
defaultVal, _ := v.Default()
valueBytes, _ := defaultVal.MarshalJSON()
valueType := strings.ReplaceAll(v.IncompleteKind().String(), "|", "\\|")

value := strings.ReplaceAll(string(valueBytes), "\":", "\": ")
value = strings.ReplaceAll(value, "\":[", "\": [")
value = strings.ReplaceAll(value, "},", "}, ")
value = strings.ReplaceAll(value, "|", "\\|")

if len(value) == 0 {
value = " "
fieldType := strings.ReplaceAll(fmt.Sprintf("%v", v), "\n", "")
fieldType = strings.ReplaceAll(fieldType, "|", "\\|")
fieldType = strings.ReplaceAll(fieldType, "\":", "\": ")
fieldType = strings.ReplaceAll(fieldType, "\":[", "\": [")
fieldType = strings.ReplaceAll(fieldType, "},", "}, ")

if len(fieldType) == 0 {
fieldType = " "
}

field := strings.Replace(v.Path().String(), "timoni.instance.config.", "", 1)
match := labelDomain.FindStringSubmatch(field)

row = append(row, fmt.Sprintf("`%s:`", strings.ReplaceAll(match[1], ".", ": ")+match[2]))
row = append(row, fmt.Sprintf("`%s`", valueType))
row = append(row, fmt.Sprintf("`%s`", value))
row = append(row, fmt.Sprintf("`%s`", fieldType))
row = append(row, fmt.Sprintf("%s", doc))
}

Expand Down
1 change: 1 addition & 0 deletions schemas/timoni.sh/core/v1alpha1/image.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

// Reference is the image address computed from repository, tag and digest
// in the format [REPOSITORY]:[TAG]@[DIGEST].
// +nodoc
reference: string

if digest != "" && tag != "" {
Expand Down
18 changes: 14 additions & 4 deletions schemas/timoni.sh/core/v1alpha1/metadata.cue
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ import "strings"

// Standard Kubernetes labels: app name, version and managed-by.
labels: {
(#StdLabelName): name
(#StdLabelVersion): #Version
// +nodoc
(#StdLabelName): name
// +nodoc
(#StdLabelVersion): #Version
// +nodoc
(#StdLabelManagedBy): "timoni"
}

// LabelSelector selects Pods based on the app.kubernetes.io/name label.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelName): name
}

Expand All @@ -74,6 +78,7 @@ import "strings"
namespace: #Meta.namespace

labels: #Meta.labels
// +nodoc
labels: (#StdLabelComponent): #Component

annotations?: #Annotations
Expand All @@ -84,8 +89,10 @@ import "strings"
// LabelSelector selects Pods based on the app.kubernetes.io/name
// and app.kubernetes.io/component labels.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelComponent): #Component
(#StdLabelName): #Meta.name
// +nodoc
(#StdLabelName): #Meta.name
}
}

Expand All @@ -104,6 +111,7 @@ import "strings"
name: #Meta.name + "-" + #Component

labels: #Meta.labels
// +nodoc
labels: (#StdLabelComponent): #Component

annotations?: #Annotations
Expand All @@ -114,7 +122,9 @@ import "strings"
// LabelSelector selects Pods based on the app.kubernetes.io/name
// and app.kubernetes.io/component labels.
#LabelSelector: #Labels & {
// +nodoc
(#StdLabelComponent): #Component
(#StdLabelName): #Meta.name
// +nodoc
(#StdLabelName): #Meta.name
}
}
5 changes: 4 additions & 1 deletion schemas/timoni.sh/core/v1alpha1/selector.cue
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ package v1alpha1
labels: #Labels

// Standard Kubernetes label: app name.
labels: (#StdLabelName): #Name
labels: {
// +nodoc
(#StdLabelName): #Name
}
}
2 changes: 2 additions & 0 deletions schemas/timoni.sh/core/v1alpha1/semver.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
let minMajor = strconv.Atoi(strings.Split(#Minimum, ".")[0])
let minMinor = strconv.Atoi(strings.Split(#Minimum, ".")[1])

// +nodoc
major: int & >=minMajor
major: strconv.Atoi(strings.Split(#Version, ".")[0])

// +nodoc
minor: int & >=minMinor
minor: strconv.Atoi(strings.Split(#Version, ".")[1])
}

0 comments on commit 96e8f5b

Please sign in to comment.