Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 38 additions & 12 deletions integrationtests/cli/apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,26 @@ var _ = Describe("Fleet apply driven", Ordered, func() {
cli.AssetsPath + "driven/kustomize/overlays/dev/secret.yaml",
cli.AssetsPath + "driven/kustomize/overlays/prod/kustomization.yaml",
cli.AssetsPath + "driven/kustomize/overlays/prod/secret.yaml",
cli.AssetsPath + "driven/kustomize/dev.yaml",
cli.AssetsPath + "driven/kustomize/prod.yaml",
}
Expect(kDevBundle.Spec.Resources).To(HaveLen(8))
Expect(kProdBundle.Spec.Resources).To(HaveLen(8))
for _, r := range kResources {

// Note: the presence of a .fleetignore file, at the same level as both `dev.yaml` and
// `prod.yaml`, excluding only `dev.yaml`, enables us to ensure that that file does not end up in
// any bundle, being excluded from the dev bundle, but _also_ from the prod bundle.
// We deliberately don't exclude both `dev.yaml` and `prod.yaml` from `.fleetignore`, simply to
// validate that `prod.yaml` is excluded from the prod bundle without needing to be excluded from
// `.fleetignore`.

kDevResources := append(slices.Clone(kResources), cli.AssetsPath+"driven/kustomize/prod.yaml")
kProdResources := slices.Clone(kResources)

Expect(kDevBundle.Spec.Resources).To(HaveLen(7))
Expect(kProdBundle.Spec.Resources).To(HaveLen(6))

for _, r := range kDevResources {
Expect(r).To(bePresentInBundleResources(kDevBundle.Spec.Resources))
}

for _, r := range kProdResources {
Expect(r).To(bePresentInBundleResources(kProdBundle.Spec.Resources))
}

Expand Down Expand Up @@ -386,13 +399,26 @@ var _ = Describe("Fleet apply driven", Ordered, func() {
cli.AssetsPath + "driven2/kustomize/overlays/dev/secret.yaml",
cli.AssetsPath + "driven2/kustomize/overlays/prod/kustomization.yaml",
cli.AssetsPath + "driven2/kustomize/overlays/prod/secret.yaml",
cli.AssetsPath + "driven2/kustomize/fleetDev.yaml",
cli.AssetsPath + "driven2/kustomize/fleetProd.yaml",
}
Expect(kDevBundle.Spec.Resources).To(HaveLen(8))
Expect(kProdBundle.Spec.Resources).To(HaveLen(8))
for _, r := range kResources {

// Note: the presence of a .fleetignore file, at the same level as both `fleetDev.yaml` and
// `fleetProd.yaml`, excluding only `fleetProd.yaml`, enables us to ensure that that file does
// not end up in any bundle, being excluded from the prod bundle, but _also_ from the dev bundle.
// We deliberately don't exclude both `fleetDev.yaml` and `fleetProd.yaml` from `.fleetignore`,
// simply to validate that `fleetDev.yaml` is excluded from the dev bundle without needing to be
// excluded from `.fleetignore`.

kDevResources := slices.Clone(kResources)
kProdResources := append(slices.Clone(kResources), cli.AssetsPath+"driven2/kustomize/fleetDev.yaml")

Expect(kDevBundle.Spec.Resources).To(HaveLen(6))
Expect(kProdBundle.Spec.Resources).To(HaveLen(7))

for _, r := range kDevResources {
Expect(r).To(bePresentInBundleResources(kDevBundle.Spec.Resources))
}

for _, r := range kProdResources {
Expect(r).To(bePresentInBundleResources(kProdBundle.Spec.Resources))
}

Expand Down Expand Up @@ -457,15 +483,15 @@ var _ = Describe("Fleet apply driven", Ordered, func() {
// helm bundle
helmBundle := bundles[0]
Expect(helmBundle.Name).To(Equal("assets-driven-fleet-yaml-subfolder-helm-test-fl-b676f"))
Expect(helmBundle.Spec.Resources).To(HaveLen(4))
Expect(helmBundle.Spec.Resources).To(HaveLen(3))
// as files were unpacked from the downloaded chart we can't just
// list the files in the original folder and compare.
// Files are only located in the bundle resources
Expect("Chart.yaml").To(bePresentOnlyInBundleResources(helmBundle.Spec.Resources))
Expect("values.yaml").To(bePresentOnlyInBundleResources(helmBundle.Spec.Resources))
Expect("templates/configmap.yaml").To(bePresentOnlyInBundleResources(helmBundle.Spec.Resources))
resPath := cli.AssetsPath + "driven_fleet_yaml_subfolder/helm/test/fleet.yaml"
Expect(resPath).To(bePresentInBundleResources(helmBundle.Spec.Resources))
Expect(resPath).NotTo(bePresentInBundleResources(helmBundle.Spec.Resources))
// check for helm options defined in the fleet.yaml file
Expect(helmBundle.Spec.Helm).ToNot(BeNil())
Expect(helmBundle.Spec.Helm.ReleaseName).To(Equal("config-chart"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fleetProd.yaml
3 changes: 2 additions & 1 deletion internal/bundlereader/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// Options include the GitRepo overrides, which are passed via command line args
type Options struct {
BundleFile string
Compress bool
Labels map[string]string
ServiceAccount string
Expand Down Expand Up @@ -189,7 +190,7 @@ func bundleFromDir(ctx context.Context, name, baseDir string, bundleData []byte,

propagateHelmChartProperties(&fy.BundleSpec)

resources, err := readResources(ctx, &fy.BundleSpec, opts.Compress, baseDir, opts.Auth, opts.HelmRepoURLRegex)
resources, err := readResources(ctx, &fy.BundleSpec, opts.Compress, baseDir, opts.Auth, opts.HelmRepoURLRegex, opts.BundleFile)
if err != nil {
return nil, nil, fmt.Errorf("failed reading resources for %q: %w", baseDir, err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/bundlereader/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var hasOCIURL = regexp.MustCompile(`^oci:\/\/`)

// readResources reads and downloads all resources from the bundle. Resources
// can be downloaded and are spread across multiple directories.
func readResources(ctx context.Context, spec *fleet.BundleSpec, compress bool, base string, auth Auth, helmRepoURLRegex string) ([]fleet.BundleResource, error) {
func readResources(ctx context.Context, spec *fleet.BundleSpec, compress bool, base string, auth Auth, helmRepoURLRegex, bundleFile string) ([]fleet.BundleResource, error) {
directories, err := addDirectory(base, ".", ".")
if err != nil {
return nil, err
Expand Down Expand Up @@ -64,7 +64,7 @@ func readResources(ctx context.Context, spec *fleet.BundleSpec, compress bool, b
loadOpts := loadOpts{
compress: compress,
disableDepsUpdate: disableDepsUpdate,
ignoreApplyConfigs: ignoreApplyConfigs(spec.Helm, spec.Targets...),
ignoreApplyConfigs: ignoreApplyConfigs(bundleFile, spec.Helm, spec.Targets...),
}
resources, err := loadDirectories(ctx, loadOpts, directories...)
if err != nil {
Expand Down Expand Up @@ -93,11 +93,11 @@ type loadOpts struct {
// ignoreApplyConfigs returns a list of config files that should not be added to the
// bundle's resources. Their contents are converted into deployment options.
// This includes:
// * fleet.yaml
// * bundle file (typically named fleet.yaml, but may be arbitrarily named when user-driven bundle scan is used)
// * spec.Helm.ValuesFiles
// * spec.Targets[].Helm.ValuesFiles
func ignoreApplyConfigs(spec *fleet.HelmOptions, targets ...fleet.BundleTarget) []string {
ignore := []string{"fleet.yaml"}
func ignoreApplyConfigs(bundleFile string, spec *fleet.HelmOptions, targets ...fleet.BundleTarget) []string {
ignore := []string{"fleet.yaml", bundleFile}

// Values files may be referenced from `fleet.yaml` files either with their file name
// alone, or with a directory prefix, for instance for a chart directory.
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/cli/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func newBundle(ctx context.Context, name, baseDir string, opts Options) (*fleet.
} else {
var err error
bundle, scans, err = bundlereader.NewBundle(ctx, name, baseDir, opts.BundleFile, &bundlereader.Options{
BundleFile: opts.BundleFile,
Compress: opts.Compress,
Labels: opts.Labels,
ServiceAccount: opts.ServiceAccount,
Expand Down