Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move variables into separate package #2414

Merged
merged 30 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3cab72e
chore: refactor variables into separate package
Racer159 Apr 3, 2024
25729e9
update schema
Racer159 Apr 3, 2024
747e765
fix var config
Racer159 Apr 3, 2024
4490882
Update src/internal/packager/helm/common.go
Racer159 Apr 3, 2024
87b524d
implement slog
Racer159 Apr 3, 2024
ed4666f
remove unneeded code
Racer159 Apr 4, 2024
307c938
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 4, 2024
a67c3fc
just do the one chart yaml
Racer159 Apr 4, 2024
703f59c
Merge branch 'main' into 2253-variables-refactor
AustinAbro321 Apr 5, 2024
4d1e142
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 9, 2024
40edb01
fix merge issues and some feedback
Racer159 Apr 9, 2024
30d8b86
fix the dang test
Racer159 Apr 10, 2024
7fb339f
Update src/pkg/variables/variables.go
Racer159 Apr 10, 2024
28dac9c
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 10, 2024
9048f19
remove docs
Racer159 Apr 10, 2024
ed4f9eb
fix the site
Racer159 Apr 10, 2024
e74db47
fix more docs stuff
Racer159 Apr 10, 2024
6345a39
allow for magic unwrapping
Racer159 Apr 10, 2024
d44a211
lint fixes
Racer159 Apr 10, 2024
3b3414d
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 15, 2024
429fbfc
remove width
Racer159 Apr 15, 2024
7e0ac72
initial rewrite of variables docs
Racer159 Apr 16, 2024
65629b0
refine docs further
Racer159 Apr 16, 2024
dfa52ab
further cleanup
Racer159 Apr 16, 2024
2b1d4b4
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 16, 2024
cb4bfc3
further cleanup
Racer159 Apr 16, 2024
e7facee
update tmp to include the l
Racer159 Apr 16, 2024
7c9f9af
fix little issues
Racer159 Apr 16, 2024
4f6f054
fix nit
Racer159 Apr 22, 2024
04108bd
Merge branch 'main' into 2253-variables-refactor
Racer159 Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 40 additions & 113 deletions docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -2094,13 +2094,13 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_23"></a>ZarfComponentActionSetVariable
### <a name="autogenerated_heading_23"></a>Variable

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionSetVariable |
| **Defined in** | #/definitions/Variable |

<details>
<summary>
Expand All @@ -2126,70 +2126,70 @@ Must be one of:

<details>
<summary>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_type"></a>type</strong>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_sensitive"></a>sensitive</strong>
</summary>
&nbsp;
<blockquote>

**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)

| | |
| -------- | ------------------ |
| **Type** | `enum (of string)` |
**Description:** Whether to mark this variable as sensitive to not print it in the log

:::note
Must be one of:
* "raw"
* "file"
:::
| | |
| -------- | --------- |
| **Type** | `boolean` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_pattern"></a>pattern</strong>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_autoIndent"></a>autoIndent</strong>
</summary>
&nbsp;
<blockquote>

**Description:** An optional regex pattern that a variable value must match before a package deployment can continue.
**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_.

| | |
| -------- | -------- |
| **Type** | `string` |
| | |
| -------- | --------- |
| **Type** | `boolean` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_sensitive"></a>sensitive</strong>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_pattern"></a>pattern</strong>
</summary>
&nbsp;
<blockquote>

**Description:** Whether to mark this variable as sensitive to not print it in the Zarf log
**Description:** An optional regex pattern that a variable value must match before a package deployment can continue.

| | |
| -------- | --------- |
| **Type** | `boolean` |
| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_autoIndent"></a>autoIndent</strong>
<strong> <a name="components_items_actions_onCreate_before_items_setVariables_items_type"></a>type</strong>
</summary>
&nbsp;
<blockquote>

**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_.
**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)

| | |
| -------- | --------- |
| **Type** | `boolean` |
| | |
| -------- | ------------------ |
| **Type** | `enum (of string)` |

:::note
Must be one of:
* "raw"
* "file"
:::

</blockquote>
</details>
Expand Down Expand Up @@ -2590,13 +2590,13 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_27"></a>ZarfPackageConstant
### <a name="autogenerated_heading_27"></a>Constant

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfPackageConstant |
| **Defined in** | #/definitions/Constant |

<details>
<summary>
Expand Down Expand Up @@ -2709,32 +2709,29 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_28"></a>ZarfPackageVariable
### <a name="autogenerated_heading_28"></a>InteractiveVariable

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfPackageVariable |
| **Defined in** | #/definitions/InteractiveVariable |

<details>
<details open>
<summary>
<strong> <a name="variables_items_name"></a>name *</strong>
<strong> <a name="variables_items_Variable"></a>Variable *</strong>
</summary>
&nbsp;
<blockquote>

## variables > Variable
![Required](https://img.shields.io/badge/Required-red)

**Description:** The name to be used for the variable

| | |
| -------- | -------- |
| **Type** | `string` |

| Restrictions | |
| --------------------------------- | ----------------------------------------------------------------------------- |
| **Must match regular expression** | ```^[A-Z0-9_]+$``` [Test](https://regex101.com/?regex=%5E%5BA-Z0-9_%5D%2B%24) |
| | |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Same definition as** | [components_items_actions_onCreate_before_items_setVariables_items](#components_items_actions_onCreate_before_items_setVariables_items) |

</blockquote>
</details>
Expand Down Expand Up @@ -2787,76 +2784,6 @@ Must be one of:
</blockquote>
</details>

<details>
<summary>
<strong> <a name="variables_items_sensitive"></a>sensitive</strong>
</summary>
&nbsp;
<blockquote>

**Description:** Whether to mark this variable as sensitive to not print it in the Zarf log

| | |
| -------- | --------- |
| **Type** | `boolean` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="variables_items_autoIndent"></a>autoIndent</strong>
</summary>
&nbsp;
<blockquote>

**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_.

| | |
| -------- | --------- |
| **Type** | `boolean` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="variables_items_pattern"></a>pattern</strong>
</summary>
&nbsp;
<blockquote>

**Description:** An optional regex pattern that a variable value must match before a package can be deployed.

| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="variables_items_type"></a>type</strong>
</summary>
&nbsp;
<blockquote>

**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)

| | |
| -------- | ------------------ |
| **Type** | `enum (of string)` |

:::note
Must be one of:
* "raw"
* "file"
:::

</blockquote>
</details>

</blockquote>
</details>

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/internal/packager/git"
"github.com/defenseunicorns/zarf/src/internal/packager/helm"
"github.com/defenseunicorns/zarf/src/internal/packager/template"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
Expand Down Expand Up @@ -138,7 +139,7 @@ var updateCredsCmd = &cobra.Command{
}

// Update Zarf 'init' component Helm releases if present
h := helm.NewClusterOnly(&types.PackagerConfig{State: newState}, c)
h := helm.NewClusterOnly(&types.PackagerConfig{}, template.GetZarfVariableConfig(), newState, c)

if slices.Contains(args, message.RegistryKey) && newState.RegistryInfo.InternalRegistry {
err = h.UpdateZarfRegistryValues()
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/bigbang/bigbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/layout"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/variables"
"github.com/defenseunicorns/zarf/src/types"
"github.com/defenseunicorns/zarf/src/types/extensions"
fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1"
Expand Down Expand Up @@ -94,7 +95,7 @@ func Run(YOLO bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (typ
},
path.Join(tmpPaths.Temp, bb),
path.Join(tmpPaths.Temp, bb, "values"),
helm.WithPackageConfig(&types.PackagerConfig{}),
helm.WithVariableConfig(&variables.VariableConfig{}),
)

// Download the chart from Git and save it to a temporary directory.
Expand Down
6 changes: 0 additions & 6 deletions src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) {
h.chart.ReleaseName = h.chart.Name
}

// Do not wait for the chart to be ready if data injections are present.
if len(h.component.DataInjections) > 0 {
spinner.Updatef("Data injections detected, not waiting for chart to be ready")
h.chart.NoWait = true
}

// Setup K8s connection.
err := h.createActionConfig(h.chart.Namespace, spinner)
if err != nil {
Expand Down
39 changes: 22 additions & 17 deletions src/internal/packager/helm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/variables"
"github.com/defenseunicorns/zarf/src/types"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
Expand All @@ -29,19 +30,20 @@ type Helm struct {
chartPath string
valuesPath string

cfg *types.PackagerConfig
component types.ZarfComponent
cluster *cluster.Cluster
timeout time.Duration
retries int
cfg *types.PackagerConfig
cluster *cluster.Cluster
timeout time.Duration
retries int

kubeVersion string

chartOverride *chart.Chart
valuesOverrides map[string]any

settings *cli.EnvSettings
actionConfig *action.Configuration
settings *cli.EnvSettings
actionConfig *action.Configuration
variableConfig *variables.VariableConfig
state *types.ZarfState
}

// Modifier is a function that modifies the Helm config.
Expand All @@ -64,12 +66,14 @@ func New(chart types.ZarfChart, chartPath string, valuesPath string, mods ...Mod
}

// NewClusterOnly returns a new Helm config struct geared toward interacting with the cluster (not packages)
func NewClusterOnly(cfg *types.PackagerConfig, cluster *cluster.Cluster) *Helm {
func NewClusterOnly(cfg *types.PackagerConfig, variableConfig *variables.VariableConfig, state *types.ZarfState, cluster *cluster.Cluster) *Helm {
return &Helm{
cfg: cfg,
cluster: cluster,
timeout: config.ZarfDefaultTimeout,
retries: config.ZarfDefaultRetries,
cfg: cfg,
variableConfig: variableConfig,
state: state,
cluster: cluster,
timeout: config.ZarfDefaultTimeout,
retries: config.ZarfDefaultRetries,
}
}

Expand Down Expand Up @@ -133,10 +137,11 @@ func NewFromZarfManifest(manifest types.ZarfManifest, manifestPath, packageName,
}

// WithDeployInfo adds the necessary information to deploy a given chart
func WithDeployInfo(component types.ZarfComponent, cfg *types.PackagerConfig, cluster *cluster.Cluster, valuesOverrides map[string]any, timeout time.Duration, retries int) Modifier {
func WithDeployInfo(cfg *types.PackagerConfig, variableConfig *variables.VariableConfig, state *types.ZarfState, cluster *cluster.Cluster, valuesOverrides map[string]any, timeout time.Duration, retries int) Modifier {
return func(h *Helm) {
h.component = component
h.cfg = cfg
h.variableConfig = variableConfig
h.state = state
h.cluster = cluster
h.valuesOverrides = valuesOverrides
h.timeout = timeout
Expand All @@ -151,10 +156,10 @@ func WithKubeVersion(kubeVersion string) Modifier {
}
}

// WithPackageConfig sets the packager config for the chart
func WithPackageConfig(cfg *types.PackagerConfig) Modifier {
// WithVariableConfig sets the variable config for the chart
func WithVariableConfig(variableConfig *variables.VariableConfig) Modifier {
return func(h *Helm) {
h.cfg = cfg
h.variableConfig = variableConfig
}
}

Expand Down
Loading
Loading