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

chore: refactor actions code #2276

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d4feaf2
feat: introduce actions conditionals
Racer159 Jan 31, 2024
858702a
add GitLab rules as an option
Racer159 Jan 31, 2024
68cc598
big bang refactor of actions and variables
Racer159 Feb 1, 2024
85371c3
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Feb 1, 2024
a79e0b4
Update schema and linting issues
Racer159 Feb 1, 2024
f5210f4
Fix tests
Racer159 Feb 1, 2024
4557cfc
Actually save actions.go
Racer159 Feb 1, 2024
1058121
Fix a few bugs
Racer159 Feb 1, 2024
88d4efb
A bit more cleanup to ActionConfig
Racer159 Feb 1, 2024
8677c1e
address some feedback and reorganize more code
Racer159 Feb 1, 2024
2c29846
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Feb 1, 2024
561c330
add more messaging around gitea updates and fix agent updates
Racer159 Feb 1, 2024
4bae16b
remove component knowledge from Helm
Racer159 Feb 1, 2024
37c66b9
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Feb 12, 2024
2c91d96
Remove if for now since this should focus on the refactor
Racer159 Feb 12, 2024
58074bb
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Feb 20, 2024
ea70d21
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Mar 7, 2024
8eb97f6
remove ADR for conditional actions
Racer159 Mar 7, 2024
bc4b66f
move Zarf component actions back
Racer159 Mar 8, 2024
1281433
Move actions validate to actions pkg
Racer159 Mar 8, 2024
2854b50
move variable to anonymous inline struct
Racer159 Mar 8, 2024
f27f37b
Remove unused func
Racer159 Mar 8, 2024
d26e5a2
Merge branch 'main' into 2273-storage-class-check-edge-cases
Racer159 Mar 8, 2024
cfb6efd
Fix linting
Racer159 Mar 8, 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
125 changes: 26 additions & 99 deletions docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionSet |
| **Defined in** | #/definitions/ActionSet |

<details open>
<summary>
Expand All @@ -1724,7 +1724,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionDefaults |
| **Defined in** | #/definitions/ActionDefaults |

<details>
<summary>
Expand Down Expand Up @@ -1832,7 +1832,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionShell |
| **Defined in** | #/definitions/ExecShell |

<details>
<summary>
Expand Down Expand Up @@ -1923,13 +1923,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_21"></a>ZarfComponentAction
### <a name="autogenerated_heading_21"></a>Action

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

<details>
<summary>
Expand Down Expand Up @@ -2078,13 +2078,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 Down Expand Up @@ -2115,7 +2115,7 @@ Must be one of:
&nbsp;
<blockquote>

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

| | |
| -------- | --------- |
Expand Down Expand Up @@ -2212,7 +2212,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionWait |
| **Defined in** | #/definitions/ActionWait |

<details open>
<summary>
Expand All @@ -2229,7 +2229,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionWaitCluster |
| **Defined in** | #/definitions/ActionWaitCluster |

<details>
<summary>
Expand Down Expand Up @@ -2332,7 +2332,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionWaitNetwork |
| **Defined in** | #/definitions/ActionWaitNetwork |

<details>
<summary>
Expand Down Expand Up @@ -2432,7 +2432,7 @@ 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_24"></a>ZarfComponentAction
### <a name="autogenerated_heading_24"></a>Action

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2463,7 +2463,7 @@ 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_25"></a>ZarfComponentAction
### <a name="autogenerated_heading_25"></a>Action

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2494,7 +2494,7 @@ 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_26"></a>ZarfComponentAction
### <a name="autogenerated_heading_26"></a>Action

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2574,13 +2574,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 @@ -2693,32 +2693,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 @@ -2771,76 +2768,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: 1 addition & 2 deletions src/cmd/common/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
)

// LogLevelCLI holds the log level as input from a command
var LogLevelCLI string

// SetupCLI sets up the CLI logging, interrupt functions, and more
func SetupCLI() {
exec.ExitOnInterrupt()
ExitOnInterrupt()

match := map[string]message.LogLevel{
"warn": message.WarnLevel,
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
package common

import (
"os"
"os/signal"
"syscall"

"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
)

// SuppressGlobalInterrupt suppresses the global error on an interrupt
var SuppressGlobalInterrupt = false

// SetBaseDirectory sets base directory on package config when given in args
func SetBaseDirectory(args []string, pkgConfig *types.PackagerConfig) {
if len(args) > 0 {
Expand All @@ -16,3 +25,15 @@ func SetBaseDirectory(args []string, pkgConfig *types.PackagerConfig) {
pkgConfig.CreateOpts.BaseDir = "."
}
}

// ExitOnInterrupt catches an interrupt and exits with fatal error
func ExitOnInterrupt() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
if !SuppressGlobalInterrupt {
message.Fatal(lang.ErrInterrupt, lang.ErrInterrupt.Error())
}
}()
}
3 changes: 2 additions & 1 deletion src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/signal"
"syscall"

"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/k8s"
Expand Down Expand Up @@ -72,7 +73,7 @@ var (
// Keep this open until an interrupt signal is received.
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
exec.SuppressGlobalInterrupt = true
common.SuppressGlobalInterrupt = true

// Wait for the interrupt signal or an error.
select {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/defenseunicorns/zarf/src/internal/packager/helm"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ var destroyCmd = &cobra.Command{

// Run all the scripts!
pattern := regexp.MustCompile(`(?mi)zarf-clean-.+\.sh$`)
scripts, _ := utils.RecursiveFileList(config.ZarfCleanupScriptsPath, pattern, true)
scripts, _ := helpers.RecursiveFileList(config.ZarfCleanupScriptsPath, pattern, true)
// Iterate over all matching zarf-clean scripts and exec them
for _, script := range scripts {
// Run the matched script
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var initCmd = &cobra.Command{

func findInitPackage(initPackageName string) (string, error) {
// First, look for the init package in the current working directory
if !utils.InvalidPath(initPackageName) {
if !helpers.InvalidPath(initPackageName) {
return initPackageName, nil
}

Expand All @@ -87,19 +87,19 @@ func findInitPackage(initPackageName string) (string, error) {
return "", err
}
executableDir := path.Dir(binaryPath)
if !utils.InvalidPath(filepath.Join(executableDir, initPackageName)) {
if !helpers.InvalidPath(filepath.Join(executableDir, initPackageName)) {
return filepath.Join(executableDir, initPackageName), nil
}

// Create the cache directory if it doesn't exist
if utils.InvalidPath(config.GetAbsCachePath()) {
if err := utils.CreateDirectory(config.GetAbsCachePath(), helpers.ReadExecuteAllWriteUser); err != nil {
if helpers.InvalidPath(config.GetAbsCachePath()) {
if err := helpers.CreateDirectory(config.GetAbsCachePath(), helpers.ReadExecuteAllWriteUser); err != nil {
message.Fatalf(err, lang.CmdInitErrUnableCreateCache, config.GetAbsCachePath())
}
}

// Next, look in the cache directory
if !utils.InvalidPath(filepath.Join(config.GetAbsCachePath(), initPackageName)) {
if !helpers.InvalidPath(filepath.Join(config.GetAbsCachePath(), initPackageName)) {
return filepath.Join(config.GetAbsCachePath(), initPackageName), nil
}

Expand Down
3 changes: 1 addition & 2 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"

"oras.land/oras-go/v2/registry"
Expand Down Expand Up @@ -214,7 +213,7 @@ var packagePublishCmd = &cobra.Command{
message.Fatalf(nil, "%s", err.Error())
}

if utils.IsDir(pkgConfig.PkgOpts.PackageSource) {
if helpers.IsDir(pkgConfig.PkgOpts.PackageSource) {
pkgConfig.CreateOpts.BaseDir = pkgConfig.PkgOpts.PackageSource
pkgConfig.CreateOpts.IsSkeleton = true
}
Expand Down
Loading
Loading