Skip to content

Commit

Permalink
switching json description to go comments
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Jul 29, 2024
1 parent a54b4d6 commit d746067
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 311 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stoewer/go-strcase v1.2.0
github.com/stretchr/testify v1.9.0
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/crypto v0.24.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,8 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk=
github.com/spiffe/go-spiffe/v2 v2.1.7/go.mod h1:QJDGdhXllxjxvd5B+2XnhhXB/+rC8gr+lNrtOryiWeE=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/pflag"
strcase "github.com/stoewer/go-strcase"
"github.com/zarf-dev/zarf/src/cmd/common"
"github.com/zarf-dev/zarf/src/config/lang"
"github.com/zarf-dev/zarf/src/internal/agent"
Expand Down Expand Up @@ -166,6 +167,13 @@ var genConfigSchemaCmd = &cobra.Command{
if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil {
return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err)
}
varPackagePath := filepath.Join("src", "pkg", "variables")
if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil {
return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err)
}

reflector.KeyNamer = strcase.LowerCamelCase
reflector.RequiredFromJSONSchemaTags = true
schema := reflector.Reflect(&types.ZarfPackage{})
output, err := json.MarshalIndent(schema, "", " ")
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/bigbang/bigbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type
MaxTotalSeconds: &maxTotalSeconds,
Wait: &types.ZarfComponentActionWait{
Cluster: &types.ZarfComponentActionWaitCluster{
Kind: "HelmRelease",
Identifier: hr.Metadata.Name,
Namespace: hr.Metadata.Namespace,
Condition: "ready",
Kind: "HelmRelease",
Name: hr.Metadata.Name,
Namespace: hr.Metadata.Namespace,
Condition: "ready",
},
},
}
Expand All @@ -171,7 +171,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type
action.Wait.Cluster = &types.ZarfComponentActionWaitCluster{
Kind: "APIService",
// https://github.com/kubernetes-sigs/metrics-server#compatibility-matrix
Identifier: "v1beta1.metrics.k8s.io",
Name: "v1beta1.metrics.k8s.io",
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func convertWaitToCmd(wait types.ZarfComponentActionWait, timeout *int) (string,

// Build a call to the zarf tools wait-for command.
return fmt.Sprintf("./zarf tools wait-for %s %s %s %s %s",
cluster.Kind, cluster.Identifier, cluster.Condition, ns, timeoutString), nil
cluster.Kind, cluster.Name, cluster.Condition, ns, timeoutString), nil
}

network := wait.Network
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/composer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (n *Node) Prev() *Node {
// otherwise the name of the component will be used
func (n *Node) ImportName() string {
name := n.ZarfComponent.Name
if n.Import.ComponentName != "" {
name = n.Import.ComponentName
if n.Import.Name != "" {
name = n.Import.Name
}
return name
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (p *Packager) Publish(ctx context.Context) (err error) {
ex = append(ex, types.ZarfComponent{
Name: fmt.Sprintf("import-%s", c.Name),
Import: types.ZarfComponentImport{
ComponentName: c.Name,
URL: helpers.OCIURLPrefix + remote.Repo().Reference.String(),
Name: c.Name,
URL: helpers.OCIURLPrefix + remote.Repo().Reference.String(),
},
})
}
Expand Down
47 changes: 30 additions & 17 deletions src/pkg/variables/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,48 @@ var (

// Variable represents a variable that has a value set programmatically
type Variable struct {
Name string `json:"name" jsonschema:"description=The name to be used for the variable,pattern=^[A-Z0-9_]+$"`
Sensitive bool `json:"sensitive,omitempty" jsonschema:"description=Whether to mark this variable as sensitive to not print it in the log"`
AutoIndent bool `json:"autoIndent,omitempty" jsonschema:"description=Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_."`
Pattern string `json:"pattern,omitempty" jsonschema:"description=An optional regex pattern that a variable value must match before a package deployment can continue."`
Type VariableType `json:"type,omitempty" jsonschema:"description=Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB),enum=raw,enum=file"`
// The name to be used for the variable
Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"`
// Whether to mark this variable as sensitive to not print it in the log
Sensitive bool
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_.
AutoIndent bool
// An optional regex pattern that a variable value must match before a package deployment can continue.
Pattern string
// Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB)
Type VariableType `jsonschema:"enum=raw,enum=file"`
}

// InteractiveVariable is a variable that can be used to prompt a user for more information
type InteractiveVariable struct {
Variable `json:",inline"`
Description string `json:"description,omitempty" jsonschema:"description=A description of the variable to be used when prompting the user a value"`
Default string `json:"default,omitempty" jsonschema:"description=The default value to use for the variable"`
Prompt bool `json:"prompt,omitempty" jsonschema:"description=Whether to prompt the user for input for this variable"`
Variable
// A description of the variable to be used when prompting the user a value
Description string
// The default value to use for the variable
Default string
// Whether to prompt the user for input for this variable
Prompt bool
}

// Constant are constants that can be used to dynamically template K8s resources or run in actions.
type Constant struct {
Name string `json:"name" jsonschema:"description=The name to be used for the constant,pattern=^[A-Z0-9_]+$"`
Value string `json:"value" jsonschema:"description=The value to set for the constant during deploy"`
// Include a description that will only be displayed during package create/deploy confirm prompts
Description string `json:"description,omitempty" jsonschema:"description=A description of the constant to explain its purpose on package create or deploy confirmation prompts"`
AutoIndent bool `json:"autoIndent,omitempty" jsonschema:"description=Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_."`
Pattern string `json:"pattern,omitempty" jsonschema:"description=An optional regex pattern that a constant value must match before a package can be created."`
// The name to be used for the constant
Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"`
// The value to set for the constant during deploy
Value string `jsonschema:"required"`
// A description of the constant to explain its purpose on package create or deploy confirmation prompts
Description string
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_.
AutoIndent bool
// An optional regex pattern that a constant value must match before a package can be created.
Pattern string
}

// SetVariable tracks internal variables that have been set during this run of Zarf
type SetVariable struct {
Variable `json:",inline"`
Value string `json:"value" jsonschema:"description=The value the variable is currently set with"`
Variable
// The value the variable is currently set with
Value string `jsonschema:"required"`
}

// Validate runs all validation checks on a package constant.
Expand Down
Loading

0 comments on commit d746067

Please sign in to comment.