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

feat: default-required feature flag #2211

Closed
wants to merge 147 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
b27ed3b
required --> optional transition
Noxsios Jan 2, 2024
c93fabd
docs and scheme
Noxsios Jan 2, 2024
7fe7919
migrate
Noxsios Jan 2, 2024
d3d2d9b
docs and scheme
Noxsios Jan 2, 2024
0e17d52
unit tests
Noxsios Jan 2, 2024
3eb3a0c
cleaner override logic
Noxsios Jan 2, 2024
5e6056f
fix zarf-seed-registry optional status
Noxsios Jan 2, 2024
2a98254
fix example
Noxsios Jan 2, 2024
7b13799
fix tests + examples
Noxsios Jan 2, 2024
2ffd606
initial migration code
Noxsios Jan 2, 2024
d1d7258
add warning to migrate
Noxsios Jan 2, 2024
d05c515
cleanup
Noxsios Jan 2, 2024
36bfdf4
cleanup
Noxsios Jan 2, 2024
59e769f
fix example
Noxsios Jan 2, 2024
e88fa82
fix migrations overwriting mutations
Noxsios Jan 2, 2024
0246af6
upgrade flake
Noxsios Jan 3, 2024
acac49d
revert upgrade package required
Noxsios Jan 3, 2024
ac50291
init adr 23
Noxsios Jan 3, 2024
b3988ee
Merge branch 'main' into required-components
Noxsios Jan 3, 2024
adeebc3
seasonal migrations
Noxsios Jan 3, 2024
4d7de02
upgrade workflow and override and validate fixes
Noxsios Jan 3, 2024
37c9f28
tweaks
Noxsios Jan 3, 2024
5121822
tweaks
Noxsios Jan 3, 2024
829eecc
dev migrate
Noxsios Jan 4, 2024
0179509
docs and schema
Noxsios Jan 4, 2024
7ab1b8b
lets get silly with it
Noxsios Jan 4, 2024
f7b77b4
docs and schema
Noxsios Jan 4, 2024
755f7ce
logic
Noxsios Jan 4, 2024
a52c056
move some stuff out of packger and into interactive
Noxsios Jan 4, 2024
2e4ac72
fix clear logic
Noxsios Jan 5, 2024
e3a74f2
re-org
Noxsios Jan 5, 2024
f05fd16
lets go the distance
Noxsios Jan 5, 2024
18f9a29
docs and schema
Noxsios Jan 5, 2024
c948451
a little cleaner error
Noxsios Jan 5, 2024
9f787c7
resolve convos
Noxsios Jan 6, 2024
e257ce8
Merge branch 'main' into required-components
Noxsios Jan 8, 2024
b45eaed
cleanup
Noxsios Jan 9, 2024
ab03c58
cli stuffs
Noxsios Jan 9, 2024
c4ffd81
docs and schema
Noxsios Jan 9, 2024
b91fcf4
handle differences in filtering OCI based upon operation
Noxsios Jan 9, 2024
2c70de7
rename symbol
Noxsios Jan 9, 2024
7900e4f
Merge branch 'main' into required-components
Noxsios Jan 9, 2024
519d220
Merge branch 'main' into required-components
Noxsios Jan 11, 2024
0e698fc
my new insanity
Noxsios Jan 11, 2024
a758a27
spdx
Noxsios Jan 11, 2024
c254463
lint
Noxsios Jan 11, 2024
5bcf902
filter manager
Noxsios Jan 12, 2024
1dd33c8
move unit tests
Noxsios Jan 12, 2024
e612765
fix deploy
Noxsios Jan 14, 2024
4037da6
smarter
Noxsios Jan 14, 2024
f82b0f3
tweaks
Noxsios Jan 16, 2024
28dbfc9
dev migrate cli autocomplete
Noxsios Jan 16, 2024
0db5904
handle unset cli version
Noxsios Jan 16, 2024
826bb09
docs and schema
Noxsios Jan 16, 2024
3a2dc36
fix dev migrate --run --run
Noxsios Jan 16, 2024
44fe5ec
fix dev deploy version
Noxsios Jan 20, 2024
1129035
Merge branch 'main' into required-components
Noxsios Jan 20, 2024
78bdb71
fix upgrade test, little ugly
Noxsios Jan 21, 2024
e5965c4
rename string
Noxsios Jan 22, 2024
96664d4
Merge branch 'main' into required-components
Noxsios Jan 22, 2024
6fa3e2c
Merge branch 'main' into required-components
Noxsios Jan 28, 2024
1ad2e58
slighly different filter based on isInteractive
Noxsios Jan 28, 2024
c9ba849
fix component choice
Noxsios Jan 28, 2024
b4adcbe
remove usage of required
Noxsios Jan 28, 2024
985114d
Merge branch 'main' into required-components
Noxsios Jan 29, 2024
44367a6
optional agrees w/ required if required is set and optional dne
Noxsios Jan 30, 2024
a92602a
changes from review
Noxsios Feb 2, 2024
db974ce
cleanup
Noxsios Feb 5, 2024
e14b48e
utils fn
Noxsios Feb 5, 2024
cd3a266
feedback
Noxsios Feb 5, 2024
8f0fb19
update adr
Noxsios Feb 5, 2024
e19e3c5
changes from review
Noxsios Feb 5, 2024
1bc07c8
Merge branch 'main' into required-components
Noxsios Feb 6, 2024
6e6472c
revert
Noxsios Feb 6, 2024
cc99d8d
simpler filter logic
Noxsios Feb 6, 2024
b8e4996
migrate manifest-with-symlink
Noxsios Feb 6, 2024
4df3415
Merge branch 'main' into required-components
Noxsios Feb 7, 2024
e766cba
Merge branch 'main' into required-components
Noxsios Feb 8, 2024
a059543
feedback
Noxsios Feb 9, 2024
7cf2339
feedback
Noxsios Feb 9, 2024
7cca728
Merge branch 'main' into required-components
Noxsios Feb 9, 2024
41b9d29
comments
Noxsios Feb 9, 2024
a2cf0e5
Merge branch 'main' into required-components
Noxsios Feb 17, 2024
a7d9ccb
unit testing filters
Noxsios Feb 18, 2024
d3e342c
comments
Noxsios Feb 18, 2024
693b794
move stuff to a better spot
Noxsios Feb 18, 2024
3bc3f97
remove multi from eks distro
Noxsios Feb 18, 2024
fe8c233
md
Noxsios Feb 18, 2024
2e823b7
more unit tests
Noxsios Feb 19, 2024
57b0bd8
rename
Noxsios Feb 19, 2024
f61a836
fix unit tests
Noxsios Feb 19, 2024
6a16db9
Merge branch 'main' into required-components
Noxsios Feb 21, 2024
8a0a33f
Merge branch 'main' into required-components
Noxsios Mar 25, 2024
8873032
fix compile errors
Noxsios Mar 25, 2024
78cd6d7
Merge branch 'main' into required-components
Noxsios Mar 26, 2024
0cbd06f
fix unit tests
Noxsios Mar 27, 2024
e166cba
Merge branch 'main' into required-components
Noxsios Mar 28, 2024
2a66b29
feature flag
Noxsios Apr 2, 2024
2433771
feature flag
Noxsios Apr 2, 2024
bfc150a
docs and schema
Noxsios Apr 2, 2024
0f8fa6d
restore examples and packages
Noxsios Apr 2, 2024
e521098
restore upgrade test
Noxsios Apr 2, 2024
8d2b5ba
restore test packages
Noxsios Apr 2, 2024
9b25338
restore test packages
Noxsios Apr 2, 2024
cc2d72a
ok, i might be a little crazy
Noxsios Apr 3, 2024
7f17d63
docs and schema
Noxsios Apr 3, 2024
6bd2941
don't format and don't mutate, use stdout
Noxsios Apr 3, 2024
2701990
cleanup
Noxsios Apr 3, 2024
16d6bcf
ux
Noxsios Apr 4, 2024
cdd4f9e
update ADR
Noxsios Apr 4, 2024
116f33b
Merge branch 'main' into required-components
Noxsios Apr 4, 2024
1f5a719
cleanup
Noxsios Apr 4, 2024
c310870
cleanup
Noxsios Apr 4, 2024
d91590b
cleanup
Noxsios Apr 5, 2024
1e2404d
rename from beta features to just features
Noxsios Apr 9, 2024
d4841d1
docs and schema
Noxsios Apr 9, 2024
14786e2
docs and schema
Noxsios Apr 9, 2024
b882fe7
validate changes broken into separate PR
Noxsios Apr 9, 2024
baf3368
use Run instead of RunE for consistency
Noxsios Apr 9, 2024
d492e17
re-update validate
Noxsios Apr 9, 2024
7d7b3f8
revert
Noxsios Apr 9, 2024
298d250
Merge branch 'main' into required-components
Noxsios Apr 10, 2024
9af072b
docs and schema
Noxsios Apr 10, 2024
ff3110b
Merge branch 'main' into required-components
Noxsios Apr 25, 2024
2916c45
docs and schema
Noxsios Apr 25, 2024
2e3e175
Merge branch 'main' into required-components
Noxsios Apr 25, 2024
bdf02e7
Merge branch 'main' into required-components
Noxsios Apr 26, 2024
b6789e8
move group deprecation from migration to read
Noxsios Apr 29, 2024
be2f2d8
update ADR
Noxsios Apr 29, 2024
7e4531c
Merge branch 'main' into required-components
Noxsios Apr 29, 2024
3d33cd4
better use of generics and composition
Noxsios May 1, 2024
31d213d
Merge branch 'main' into required-components
Noxsios May 3, 2024
ade37ca
Merge branch 'main' into required-components
Noxsios May 6, 2024
aefb2c2
Merge branch 'main' into required-components
Noxsios May 7, 2024
8a342dc
Merge branch 'main' into required-components
Noxsios May 7, 2024
0c15945
Merge branch 'main' into required-components
Noxsios May 9, 2024
9519392
restore docs due to non-breaking
Noxsios May 10, 2024
2375770
breaking change, will need to discuss
Noxsios May 10, 2024
e23d898
Merge branch 'main' into required-components
Noxsios May 14, 2024
be6d51d
cleanup
Noxsios May 14, 2024
bab6b53
Merge branch 'main' into required-components
Noxsios May 15, 2024
0e1ef9b
rm validate
Noxsios May 15, 2024
f12b143
Merge branch 'main' into required-components
Noxsios May 16, 2024
e395d04
Merge branch 'main' into required-components
Noxsios May 21, 2024
ece00d1
revert behavior
Noxsios May 21, 2024
7cc9973
Merge branch 'main' into required-components
Noxsios May 22, 2024
0368956
rebase
May 28, 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
8 changes: 3 additions & 5 deletions .github/workflows/test-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:

- name: Initialize the cluster with the release version
# NOTE: "PATH=$PATH" preserves the default user $PATH. This is needed to maintain the version of zarf installed
# in a previous step. This test run will the current release to create a K3s cluster.
# in a previous step. This test run will use the current release to create a K3s cluster.
run: |
sudo env "PATH=$PATH" CI=true zarf init --components k3s,git-server,logging --nodeport 31337 --confirm

Expand All @@ -79,7 +79,7 @@ jobs:

- name: Create and deploy the upgrade test packages
# NOTE: "PATH=$PATH" preserves the default user $PATH. This is needed to maintain the version of zarf installed
# in a previous step. This test run will the current release to create a K3s cluster.
# in a previous step. This test run will use the current release to create a K3s cluster.
run: |
zarf package create src/test/upgrade --set PODINFO_VERSION=6.3.3 --confirm
sudo env "PATH=$PATH" CI=true zarf package deploy zarf-package-test-upgrade-package-amd64-6.3.3.tar.zst --confirm
Expand All @@ -105,12 +105,10 @@ jobs:

- name: Run the upgrade tests
# NOTE: "PATH=$PATH" preserves the default user $PATH. This is needed to maintain the version of zarf installed
# in a previous step. This test run will the current release to create a K3s cluster.
# in a previous step. This test run will use the current release to create a K3s cluster.
run: |
sudo env "PATH=$PATH" CI=true zarf tools kubectl describe nodes

zarf package create src/test/upgrade --set PODINFO_VERSION=6.3.4 --confirm
Noxsios marked this conversation as resolved.
Show resolved Hide resolved

sudo env "PATH=$PATH" CI=true make test-upgrade ARCH=amd64

- name: Save logs
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ else
endif
endif

CLI_VERSION ?= $(if $(shell git describe --tags),$(shell git describe --tags),"UnknownVersion")
CLI_VERSION ?= $(if $(shell git describe --tags),$(shell git describe --tags),"unset-development-only")
BUILD_ARGS := -s -w -X github.com/defenseunicorns/zarf/src/config.CLIVersion=$(CLI_VERSION)
K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go)))
K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1)))
Expand Down Expand Up @@ -203,7 +203,7 @@ test-upgrade: ## Run the Zarf CLI E2E tests for an external registry and cluster
@test -s $(ZARF_BIN) || $(MAKE) build-cli
[ -n "$(shell zarf version)" ] || (echo "Zarf must be installed prior to the upgrade test" && exit 1)
[ -n "$(shell zarf package list 2>&1 | grep test-upgrade-package)" ] || (echo "Zarf must be initialized and have the 6.3.3 upgrade-test package installed prior to the upgrade test" && exit 1)
@test -s "zarf-package-test-upgrade-package-amd64-6.3.4.tar.zst" || zarf package create src/test/upgrade/ --set PODINFO_VERSION=6.3.4 --confirm
@test -s ./zarf-package-test-upgrade-package-$(ARCH)-6.3.4.tar.zst || zarf package create src/test/upgrade --set PODINFO_VERSION=6.3.4 --confirm
cd src/test/upgrade && go test -failfast -v -timeout 30m

.PHONY: test-unit
Expand Down
127 changes: 127 additions & 0 deletions adr/0025-required-optional.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# 25. Components can be required by default + introduction of feature flags

Date: 2024-04-29

## Status

Accepted

## Context

> Feature request: <https://github.com/defenseunicorns/zarf/issues/2059>

Currently, all Zarf components default to being optional due to the `required` key being _optional_ in the YAML. This leads to package authors needing to ensure that they annotate this key for each component, and since nothing in the current validations prompts them about this they may be confused about the "all things are optional" default state.

When Zarf was first created, we didn't really know how it would evolve and this key was introduced in those very early days. At this point it would be better to require all components by default--especially with the introduction of composability and the OCI skeleton work, there is plenty of flexibility in the API to compose bespoke packages assembled from other packages.

A few ways to handle this:

1. Simply force the `required` key to be a non-optional, so that package authors would be forced to specify it for each component, thereby removing any ambiguity--but also force one more key for every single component ever created 🫠

2. Deprecate `required` and introduce an optional `optional` key, which would default to _false_.

3. Do something more significant like combine various condition-based things such as `only`, `optional` (instead of `required`), or `default`.

4. Introduce `feature` flags to allow for certain schema behavior to be configurable to the user.

## Decision

Option 4. Introduce `.metadata.features` flags to `zarf.yaml` to allow for certain schema behavior to be configurable to the user.

The `features` key will be added to the `metadata` section of the package schema. This key will be an array of strings, where each string is the name of a beta feature that can be enabled. To enable a feature, the user will need to add the name of the feature to this array and edit the package schema accordingly.
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the .metadata.features field might not be necessary for this purpose. Have we considered keeping the required key optional in the schema and defaulting to required: true for all components unless explicitly set to required: false? This would achieve the same behavior as the default-required flag but without needing the feature flag.


> Such feature migrations can also be accomplished using `zarf dev migrate`, see the [Consequences](#consequences) section for more information.

e.g.

```diff
kind: ZarfInitConfig
metadata:
name: init
description: Used to establish a new Zarf cluster
+ features:
+ - default-required

components:
- name: k3s
+ required: false
import:
path: packages/distros/k3s

# This package moves the injector & registries binaries
- name: zarf-injector
- required: true
import:
path: packages/zarf-registry
```

## Consequences

The introduction of feature flags will allow Zarf to introduce new features and schema behavior without breaking existing packages and schemas, but also introduces more complexity. This will require more documentation and user education to ensure that users understand how to use these flags.

Beta feature flags will become the default behavior of Zarf upon the next major release, and will _not_ be configurable by the user at that time. This will allow for a more consistent experience across all Zarf packages.

There will be a flag added to the `zarf dev migrate` command `--enable-feature <feature-name>` to allow users to enable features on a per-package basis. This will allow users to test new features in a controlled environment before they are enabled by default.

> Tab autocompletion for the `--enable-feature` flag is enabled for the `zarf dev migrate` command.

e.g. (some output omitted for brevity)

```bash
$ zarf dev migrate --enable-feature default-required > migrated-zarf.yaml

NOTE Using config file ...

NOTE Saving log file to ...


Migration | Type | Affected
default-required | feature | .

```

```diff
$ git diff --no-index zarf.yaml migrated-zarf.yaml

kind: ZarfInitConfig
metadata:
name: init
description: Used to establish a new Zarf cluster
+ features:
+ - default-required
components:
- name: k3s
+ required: false
import:
path: packages/distros/k3s

- name: zarf-injector
- required: true
import:
path: packages/zarf-registry

- name: zarf-seed-registry
- required: true
import:
path: packages/zarf-registry

- name: zarf-registry
- required: true
import:
path: packages/zarf-registry

- name: zarf-agent
- required: true
import:
path: packages/zarf-agent

- name: logging
+ required: false
import:
path: packages/logging-pgl

- name: git-server
+ required: false
import:
path: packages/gitea
```
5 changes: 4 additions & 1 deletion packages/distros/k3s/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
kind: ZarfInitConfig
metadata:
name: distro-k3s
description: Used to establish a new Zarf cluster
description: |
Used to establish a new Zarf cluster

This package is NOT meant to be used as a standalone package. It is meant to be used as a dependency of an 'init' package.

components:
# AMD-64 version of the K3s stack
Expand Down
4 changes: 3 additions & 1 deletion packages/gitea/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
kind: ZarfPackageConfig
metadata:
name: init-package-git-server
name: git-server
description: |
This package is NOT meant to be used as a standalone package. It is meant to be used as a dependency of an 'init' package.

variables:
- name: GIT_SERVER_EXISTING_PVC
Expand Down
6 changes: 5 additions & 1 deletion packages/logging-pgl/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
kind: ZarfPackageConfig
metadata:
name: init-package-logging
name: logging
description: |
Deploys the Promtail Grafana & Loki (PGL) stack.

This package is NOT meant to be used as a standalone package. It is meant to be used as a dependency of an 'init' package.

components:
- name: logging
Expand Down
8 changes: 5 additions & 3 deletions packages/zarf-agent/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
kind: ZarfPackageConfig
metadata:
name: init-package-zarf-agent
description: Install the zarf agent mutating webhook on a new cluster
name: zarf-agent
description: |
Install the zarf agent mutating webhook on a new cluster

This package is NOT meant to be used as a standalone package. It is meant to be used as a dependency of an 'init' package.

constants:
- name: AGENT_IMAGE
Expand All @@ -16,7 +19,6 @@ components:
images and git repository references in Kubernetes manifests. This prevents
the need to manually update URLs from their original sources to the Zarf-managed
docker registry and git server.
required: true
images:
- "###ZARF_PKG_TMPL_AGENT_IMAGE_DOMAIN######ZARF_PKG_TMPL_AGENT_IMAGE###:###ZARF_PKG_TMPL_AGENT_IMAGE_TAG###"
manifests:
Expand Down
9 changes: 6 additions & 3 deletions packages/zarf-registry/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
kind: ZarfPackageConfig
metadata:
name: init-package-zarf-registry
name: zarf-registry
description: |
Initializes the Zarf Registry by bootstrapping a Kubernetes cluster with a running pod and hosting the registry image.
The Zarf Registry is then updated to use the self-hosted registry image.

This package is NOT meant to be used as a standalone package. It is meant to be used as a dependency of an 'init' package.

variables:
- name: REGISTRY_EXISTING_PVC
Expand Down Expand Up @@ -105,7 +110,6 @@ components:
description: |
Bootstraps a Kubernetes cluster by cloning a running pod in the cluster and hosting the registry image.
Removed and destroyed after the Zarf Registry is self-hosting the registry image.
required: true
only:
cluster:
architecture: amd64
Expand All @@ -120,7 +124,6 @@ components:
description: |
Bootstraps a Kubernetes cluster by cloning a running pod in the cluster and hosting the registry image.
Removed and destroyed after the Zarf Registry is self-hosting the registry image.
required: true
only:
cluster:
architecture: arm64
Expand Down
1 change: 1 addition & 0 deletions site/src/content/docs/commands/zarf_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Commands useful for developing packages
* [zarf dev generate](/commands/zarf_dev_generate/) - [alpha] Creates a zarf.yaml automatically from a given remote (git) Helm chart
* [zarf dev generate-config](/commands/zarf_dev_generate-config/) - Generates a config file for Zarf
* [zarf dev lint](/commands/zarf_dev_lint/) - Lints the given package for valid schema and recommended practices
* [zarf dev migrate](/commands/zarf_dev_migrate/) - [alpha] Migrates the zarf.yaml in a given directory to the latest version of the zarf.yaml format
* [zarf dev patch-git](/commands/zarf_dev_patch-git/) - Converts all .git URLs to the specified Zarf HOST and with the Zarf URL pattern in a given FILE. NOTE:
This should only be used for manifests that are not mutated by the Zarf Agent Mutating Webhook.
* [zarf dev sha256sum](/commands/zarf_dev_sha256sum/) - Generates a SHA256SUM for the given file
Expand Down
41 changes: 41 additions & 0 deletions site/src/content/docs/commands/zarf_dev_migrate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: zarf dev migrate
description: Zarf CLI command reference for <code>zarf dev migrate</code>.
tableOfContents: false
---

<!-- Page generated by Zarf; DO NOT EDIT -->

## zarf dev migrate

[alpha] Migrates the zarf.yaml in a given directory to the latest version of the zarf.yaml format

```
zarf dev migrate [flags]
```

### Options

```
--enable-feature stringArray feature migrations to run and enable (available: default-required)
-h, --help help for migrate
--run stringArray migrations of deprecated features to run (default: all, available: scripts-to-actions, pluralize-set-variable)
```

### Options inherited from parent commands

```
-a, --architecture string Architecture for OCI images and Zarf packages
--insecure Allow access to insecure registries and disable other recommended security enforcements such as package checksum and signature validation. This flag should only be used if you have a specific reason and accept the reduced security posture.
-l, --log-level string Log level when running Zarf. Valid options are: warn, info, debug, trace (default "info")
--no-color Disable colors in output
--no-log-file Disable log file creation
--no-progress Disable fancy UI progress bars, spinners, logos, etc
--tmpdir string Specify the temporary directory to use for intermediate files
--zarf-cache string Specify the location of the Zarf cache directory (default "~/.zarf-cache")
```

### SEE ALSO

* [zarf dev](/commands/zarf_dev/) - Commands useful for developing packages

Loading
Loading