Commit Graph

56 Commits

Author SHA1 Message Date
Corentin Néau 6840a0ea61
Exclude Fleet config files regardless of their naming (#4207)
While Fleet config files are typically named `fleet.yaml`, the recent
introduction of user-driven bundle scanning enables a config file to be
named arbitrarily, in which case it must still be excluded from the
corresponding bundle. Fleet now takes care of this without any action
needed from the user.

Integration tests also demonstrate that `.fleetignore` files can be
leveraged to exclude config files living in the same directory as
the config file referenced explicitly through user-driven bundle
scanning. Fleet would otherwise not exclude those files from the bundle.
2025-10-10 16:28:57 +02:00
Corentin Néau b10cca0425
Support globbing for secrets per path in user-driven mode (#4158)
While we had recently added support for globbing for path-based secrets
to classic bundle scanning, that had been omitted for user-driven bundle
scanning.

This commit remedies this, ensuring that globbing support works
regardless of the chosen bundle scanning mode.
2025-10-01 18:10:17 +02:00
renovate-rancher[bot] eeedd60a6f
chore(deps): update gomod-k8s-dependencies (main) (#4087)
* Update  sigs.k8s.io/controller-runtime to v0.22.0

* Bump to Kubernetes v1.34.0 libraries

* Run go generate

* Adapt mockgen cmds to prevent conflicts

* Remove obsolete mock files

---------

Co-authored-by: renovate-rancher[bot] <119870437+renovate-rancher[bot]@users.noreply.github.com>
Co-authored-by: Tim Hardeck <thardeck@suse.com>
2025-09-08 15:16:53 +02:00
Mario Manno a939ba1706
Fleet apply refuses to update bundle scheduled for deletion (#4075)
Fleet apply refuses to update bundle scheduled for deletion
2025-09-03 13:58:48 +02:00
Mario Manno 3c79abb0d1
Stuck helm release in pending-install are replaced (SURE-10627) (#4051)
The Helm deployer now honours Helm's `atomic` flag for installs, not just
updates.
It also supports overwriting releases in `pending-install` state, which can
unblock deployments.

A new integration test case simulates an existing release with
`pending-install` status, by creating the corresponding Helm secret, as
Fleet uses Helm's secret storage back-end, then validates that Fleet can
install a release with the same name on top of it.

---------

Co-authored-by: Mario Manno <mario.manno@suse.com>
Co-authored-by: Corentin Néau <tan.neau@suse.com>
2025-08-27 17:10:59 +02:00
Corentin Néau 088bcbea7e Harden values files exclusion from bundle resources
Values files may be referenced by file name alone, or with a directory
prefix. Both variants now lead to values files being excluded from
bundles resources, regardless of where a `fleet.yaml` file referencing
them lives (inside or outside of a chart directory).
2025-08-06 17:15:09 +02:00
Xavi Garcia c17777907e
Adds InsecureTLS and BasicHTTP to helm secret (#3872)
* Add new values for basicHTTP and insecureSkipTLS

---------

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-08-04 15:52:37 +02:00
Corentin Néau 6f2a86cb44
Test bundle name override (#3932)
A bundle's name can be computed from a GitRepo's name and the path
leading to the bundle. However, overriding that name is also possible,
by populating the `name` field in a `fleet.yaml` file.

A new integration test case covers and demonstrates this.
2025-07-31 16:26:41 +02:00
Corentin Néau e52f0ff54c
Support globbing in HelmSecretForPaths (#3815)
* Support globbing in helmSecretNameForPaths

Helm access secrets referenced in a GitRepo's `helmSecretNameForPaths`
field now support globbing, such as `my-path/*`, or `foo?bar`.

When more than one path listed in the `helmSecretNameForPaths` secret
matches a given GitRepo path, then the first match listed in the
`helmSecretNameForPaths` secret will be used.

* Ensure deterministic order of iteration over auth map

When more than one patterns match a given bundle path, the first
matching pattern, in lexical order, will be used.
2025-07-31 15:20:09 +02:00
Xavi Garcia 09187480ac
Enables OCI storage by default (#3819)
* Enables OCI storage by default

Changes the env variable from `EXPERIMENTAL_OCI_STORAGE` to `OCI_STORAGE`

The feature is enabled by default and in order to disable it users should pass `OCI_STORAGE=false` in `extraEnv`

Refers to: https://github.com/rancher/fleet/issues/3818

---------

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-06-20 13:59:09 +02:00
Xavi Garcia 2607d94efb
Oci storage secret label and event (#3775)
* Adds a label to internal/cloned secrets.

It also adds an event when the oci artifact is purged and could not be deleted for whatever reason.

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-06-16 12:04:38 +02:00
Alejandro Ruiz 6b06d3dc50
Refactor fleet apply and enable concurrent bundle scanning (#3721)
The goal of this commit is to detach the processing of every individual Bundle from the directory scanning.
2025-06-16 09:22:07 +02:00
Corentin Néau 90e56619ff
Detect bundle naming collision (#3718)
* Detect bundle naming collision in HelmOps reconciler

When building a HelmOps bundle, the reconciler now aborts with an error
if a non-HelmOps bundle with the same name exists in the same namespace.

* Detect bundle naming collision in `fleet apply`

When creating or updating a bundle, `fleet apply` checks the spec of any
existing bundle with the same name in the same namespace. If one bundle
is a HelmOps bundle while the other is not, `fleet apply` will abort the
update and output an error message.

* Simplify collision detection in `fleet apply`

Relying on the fact that `fleet apply` does not support creating HelmOps
bundles at this point, there is no need to generalise collision
detection to any mismatch in HelmOps state between a possibly existing
bundle and the one to be created or updated.

Instead, checking whether a HelmOps bundle already exists is enough to
establish a collision.
2025-05-27 08:41:56 +02:00
Xavi Garcia 57aaf58e01
Use controller-runtime client in fleet cli (#3670)
* Use controller-runtime client in fleet apply

This change is made to eliminate dependencies on Wrangler in the Fleet CLI and also to support future proposed changes related to reading secrets for OCI registries.

It also facilitates the creation of new integration tests, as the client interface is simplified and a single mock is used.

* Delete cluster instantiation and cache start in the cli
* Avoid adding new verbs that are not strictly required
2025-05-14 13:35:34 +02:00
Mario Manno 00d57424e4
Remove progress from apply (#3587)
Progress is not working. This also wraps more errors and skips .git
folders when scanning cloned git repos.

Co-authored-by: Mario Manno <mario.manno@suse.com>
2025-04-30 17:59:53 +02:00
Xavi Garcia b54f338104
Adds driven bundle scan (#3480)
* Adds driven bundle scan
This adds a new feature to let the user define the bundles to be considered by Fleet.

It adds a new field `bundles` that is a list of path and config files.
The path is the base path for the resources contained in the Bundle and the config file is optional
and it's the Bundle's fleet.yaml file (that may have any custom name).

This is an example showing the new fields:
```yaml
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
  name: driven
  namespace: fleet-local
spec:
  repo: https://github.com/0xavi0/fleet-test-data
  branch: driven-scan-example
  bundles:
  - path: driven/helm
  - path: driven/simple
  - path: driven/kustomize
    options: dev.yaml
  - path: driven/kustomize
    options: test.yaml
```

Given the root driven folder with the contents:
```
driven
     |___helm
     |      |__ fleet.yaml
     |
     |___simple
     |      |__ configmap.yaml
     |      |__ service.yaml
     |
     |___kustomize
            |__ base
            |      |__ kustomization.yaml
            |      |__ secret.yaml
            |
            |__ overlays
            |         |__ dev
            |         |     |__ kustomization.yaml
            |         |     |__ secret.yaml
            |         |__ prod
            |         |     |__ kustomization.yaml
            |         |     |__ secret.yaml
            |         |__ test
            |               |__ kustomization.yaml
            |               |__ secret.yaml
            |__ dev.yaml
            |__ prod.yaml
            |__ test.yaml
```

The GitRepo above would describe the following bundles:

**Helm based bundle (path: `driven/helm`, no config file)**
This one has a `fleet.yaml` file in the root folder and we're not specifying any config file.
In this case Fleet will read the `fleet.yaml` file in the root folder and will load the helm chart resources.

**Raw yaml folder based bundle (path: `driven/simple`, no config file)**
In this case the folder contains 2 yamls and no `fleet.yaml` in its root. We are not specifying any config file,
so the folder is considered as a bundle made of raw yaml files.
It will contain:
- configmap.yaml
- service.yaml

**Kustomize bundle (path: `driven/kustomize`, config file: `dev.yaml`)**
In this case we are specifying a config file (with the format of a `fleet.yaml` file).
Fleet will load all the resources found in the `drive/kustomize` folder and will load the config found
in the `dev.yaml` file.
The `dev.yaml` has the following content:
```yaml
namespace: kustomize-dev
kustomize:
  dir: "overlays/dev"
```
Which means it points to the `overlays/dev` kustomization.

This Bundle will load all the resources, but will only apply the `overlays/dev` kustomization

**Kustomize bundle (path: `driven/kustomize`, config file: `test.yaml`)**
This Bundle will be equivalent to the `dev` one described above, but pointint to the `overlays/test` kustomization.

Note that the `prod` kustomization is not used in this case, which shows that not all the options defined in the kustomization must be deployed.

Possible improvements:
As we can be loading the same folder multiple times it would be better to just load the resources once and cache them for the next repeated folder.


Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-04-10 14:02:05 +02:00
Mario Manno 7891ae0439
Add Lifecycle Secrets (#3527)
Each Bundle and BundleDeployment can have a secret to store options in. The secrets have the same name and namespace as the resource. For now they only store the helm values.
2025-04-09 16:02:26 +02:00
Corentin Néau 41016aa980
Fix linting errors
* Remove unused function

This function became obsolete when using a delaying enqueue handler for
drift detection; see fleet#3401 [1].

[1]: https://github.com/rancher/fleet/pull/3401

* Modernise output setting in deployer integration tests

This makes use of `SetOut` and `SetErr` instead of `SetOutput`, which is
deprecated.

* Remove unused parameter from test helper methods

That parameter is no longer necessary now that our test infrastructure
uses `default` as its namespace.
2025-03-13 11:25:35 +01:00
Mario Manno 9954607347
Remove "fleet apply" config files from bundle resources (#3403)
* Remove unecessary files from bundle resources

This will make the bundle and content resources smaller. However, it
should not change the helm chart that is deployed. The files are parsed
into deployment options and have no use after the fleet apply stage.

Minor changes:
* Extract loaddirectory args to struct
* Remove unused key
* Clean up creation of agent manifests
* Separate bundledeployment construction from creation
* Remove slow unit test
  This test relied on a network timeout and took up to 3 minutes.
2025-03-04 13:48:49 +01:00
Xavi Garcia f8e5fe8119
Adds message context to fleet apply errors (#3385)
Adds message context to fleet apply errors

Adds context to message in fleet apply. Specially to those running inside loops.

For example, when loading directories, remote charts, etc...

Contexts are wrapped in top of the previous one.

It also fixes the `gitjob` init container to use `log.sh` and redirect the errors to `/dev/termination-log`
Related to: https://github.com/rancher/fleet/issues/3234

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>

* Changes after review

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>

* More changes after review

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>

---------

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-02-21 15:53:52 +00:00
Xavi Garcia 8684928e0f
Add extra error info when downloading remote charts (#3368)
Refers to: https://github.com/rancher/fleet/issues/3160

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2025-02-20 10:11:56 +01:00
Mario Manno 526dff454f
Bump k3s in workflows for 1.32 (#3369) 2025-02-19 18:47:30 +01:00
Mario Manno 5510d4d744
Hide controller logs in integrationtests (#3326)
This introduces new environment variables for integrationtests:

* CI_SILENCE_CTRL - no logging output, even when test fails
* CI_KUBECONFIG - write kubeconfig for testenv to this path
* CI_USE_EXISTING_CLUSTER - integrationtests don't setup testenv, but
  use existing cluster from current KUBECONFIG
2025-02-11 11:08:32 +01:00
Mario Manno 40a9f8bea9
Add ginkgolinter (#3309)
* ginkgolinter added and applied suggestions
* disable funlen for tests, just like gocylco
2025-02-07 18:05:28 +01:00
Mario Manno bf50628b8d
Fleet deploy prints hook resources too (#2968)
Also reduce ReleaseToObjects usage in CLI commands, it focuses only on
  the "ressources"
2024-10-23 11:15:10 +02:00
Tim Hardeck 947e734438
Fix gomock import
to go.uber.org/mock/gomock
2024-10-23 10:27:04 +02:00
Xavi Garcia 5de7a7829f
Converts the delete gitjobs to one-time job (#2928)
The job also deletes all completed gitjobs, not leaving the last one active, as
https://github.com/rancher/fleet/pull/2903 was merged.

Also fixes the ServiceAccount to be able to list and delete jobs.

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2024-10-07 14:04:23 +02:00
Mario Manno 29471373d7
Cleanup completed gitjobs (#2907)
* Cleanup clusterregistration is a subcommand
* Switch cleanup CLI to new k8s client
* Add cleanup CLI command for gitrepo jobs
2024-09-30 10:27:49 +02:00
Mario Manno 79d35253c5 Fleet CLI deploy output matches dry-run output 2024-09-17 15:31:38 +02:00
Ampie Barnard 96e96deddf Fixes #2633 by a.) increasing the default kubeVersion to 1.25 and b.) allowing users to specify target kubeVersion when running fleet deploy --dry-run 2024-07-26 15:38:51 +02:00
Mario Manno 4e68169acb
Bump helm/wrangler/controller-runtime (#2565)
* Bump helm, wrangler/v2, controller-runtim

* Bump to wrangler/v3
2024-07-01 17:19:18 +02:00
Tommy Girardi f7cedab5d4
Replace ImageScan and Bundle Labels With fleet.yaml Labels (#2360)
This ensures that, when updating bundles and imagescans, `fleet apply` only uses labels and annotations from fleet.yaml. It prevents pre-existing labels and annotations from being kept on those resources even if they are no longer reflected in fleet.yaml.

Co-authored-by: Corentin Néau <tan.neau@suse.com>
2024-05-03 11:37:29 +02:00
Xavi Garcia 3ad25e1375
Merge pull request #2135 from 0xavi0/1672-depedency-update
Implements DependencyUpdate for helm charts
2024-02-16 18:10:10 +01:00
Xavi Garcia 28c9c5b9b1
Delete Eventually and add Gomega custom matchers
Eventually is not needed when testing for resources in bundles as we get
the bundle from `cli.GetBundleListFromOutput` and the buffer read will be
in its final state once `cli.GetBundleListFromOutput` returns.

Also addind custom Gomega matchers to avoid using helper functions and
to get the exact line when any test assertion fails.

Already existing tests have been changed to use the custom matchers and
don't use Eventually, also.

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2024-02-16 16:54:52 +01:00
Xavi Garcia 702ba99dcc
Changes after code-review
Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2024-02-13 13:34:05 +01:00
Xavi Garcia 999dc47010
Implements DependencyUpdate for helm charts
A new flag `disableDependencyUpdate` is added to the `fleet.yaml`
file in order to disable the feature, which is active by default.

A new package `helmupdater` is added to implement the dependencies
update.
The implementation is based on helm's when ussing the
`--dependency-update` flag in the install command.

Dependencies are applied to the bundle (upstream) to they're resolved
already when applying downstream.

Refers to: https://github.com/rancher/fleet/issues/1672

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
2024-02-09 12:35:01 +01:00
Mario Manno ad2d2d829a
Add target/deploy/dry-run CLI commands (#2102)
Add new CLI commands to create and deploy bundledeployments
2024-02-08 12:19:10 +01:00
Mario Manno 45a0891161
Refactor targeting/bundle controller (#2111)
* Rename CLI apply.Apply to apply.CreateBundles
* Refactor target package
* new UpdatePartitions
* new file rollout.go
* Extract BundleDeployment to func
* Remove global fleet args, remove unused args

These arguments were not shared between all commands.
There is one set of commands (apply, cleanup) which use the fleet/client
pkg and another set which uses a controller-runtime client. Same is true
for the debug flag.

* Move fleet apply helm test into apply folder

Both apply/ and helm/ are testing the fleet apply sub command

* Fix typos

---------

Co-authored-by: Corentin Néau <tan.neau@suse.com>
2024-02-01 12:38:17 +01:00
Mario Manno 98529b0e68
Use apimachinery yaml package directly
Wrangler would just call
	`yamlDecoder.NewYAMLToJSONDecoder(bytes.NewBuffer(data)).Decode(v)`
2024-01-24 14:47:35 +01:00
Alejandro Ruiz e81fa50231 Update wrangler import paths 2023-10-23 17:13:51 +02:00
Tim Hardeck 73fb9bc9f5
Add integration test to verify helm options with kustomize 2023-09-12 11:28:24 +02:00
Tim Hardeck 752578e999
Improve Apply test indentation 2023-09-12 10:20:55 +02:00
Tim Hardeck 9b80f18a50
Add integration test to verify fleet.yaml helm options
even when fleet.yaml does not reference a helm chart.

Also make sure that the values are actually evaluated and that no
potential default value is interfering with the test.
2023-09-12 08:26:25 +02:00
Mario Manno 40d6a1de85
Cleanup command takes string durations as arguments (#1697)
* Cleanup command takes string durations as arguments
2023-08-08 07:47:50 -07:00
Mario Manno 43cf8c9604
Implement slow clusterregistration clean up in fleetcli 2023-08-03 18:11:04 +02:00
Mario Manno 1f098a23a9
Restructure package layout to add internal package (#1624)
* Move codegen into cmd folder
* Split pkgs by command/binary into internal folder
* Update go imports after moving
* Remove cmd/agent/agent, cmd/controller/fleetcontroller packages
* Remove package comments, which indicated the binary the package belongs to
* Move fleetcli's main.go into cmd/
2023-07-03 16:24:51 +02:00
raul 0c495154d7
Add DoNotDeploy and OverrideTargets
DoNotDeploy: BundleDeployments will not be created for targets that matches a targetCustomization that has DoNotDeploy set to true, which means no resources will be deployed.

OverrideTargets: Targets defined in a GitRepo will be overridden if a Bundle defines overrideTargets in the fleet.yaml

Signed-off-by: raul <raul.cabello@suse.com>
2023-06-05 17:52:37 +02:00
Raul Cabello Martin 87483fb82c
Allow helm credentials to be defined for each path
Add HelmSecretNameForPaths in GitRepo

This allows to specify different credentials for each Bundle that will be generated for each path.
HelmSecretName will be ignored if HelmSecretNameForPaths is present.

Tests returned an "address already in use" error on very rare occasions. This was due to the previous helm repository was not fully closed before creating the new one, as it might take an extra milliseconds to fully close after calling closed. Retry if "address already in use" error is returned after 100 milliseconds for a maximum of 10 attempts
2023-05-30 16:54:41 +02:00
raul 7f7e611b09 Add keepResources parameter
keepResources can be specified in the GitRepo or in a fleet.yaml. If true it will not delete resources after the GitRepo or Bundle is deleted. It will delete helm release secrets instead.

Signed-off-by: raul <raul.cabello@suse.com>
2023-03-07 11:34:14 +01:00
raul ebb385290e fix helm test by running them in different ports
Run the helm integration tests in different port, so they can be run in parallel.

Use Serial instead of Ordered, as the order doesn't matter.

Signed-off-by: raul <raul.cabello@suse.com>
2023-02-27 12:11:30 +01:00