diff --git a/integrationtests/cli/apply/apply_test.go b/integrationtests/cli/apply/apply_test.go index 27a9d6c9b5..08febbcd48 100644 --- a/integrationtests/cli/apply/apply_test.go +++ b/integrationtests/cli/apply/apply_test.go @@ -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)) } @@ -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)) } @@ -457,7 +483,7 @@ 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 @@ -465,7 +491,7 @@ var _ = Describe("Fleet apply driven", Ordered, func() { 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")) diff --git a/integrationtests/cli/assets/driven/kustomize/.fleetignore b/integrationtests/cli/assets/driven/kustomize/.fleetignore new file mode 100644 index 0000000000..4cbca083a8 --- /dev/null +++ b/integrationtests/cli/assets/driven/kustomize/.fleetignore @@ -0,0 +1 @@ +dev.yaml diff --git a/integrationtests/cli/assets/driven2/kustomize/.fleetignore b/integrationtests/cli/assets/driven2/kustomize/.fleetignore new file mode 100644 index 0000000000..dacb2652fe --- /dev/null +++ b/integrationtests/cli/assets/driven2/kustomize/.fleetignore @@ -0,0 +1 @@ +fleetProd.yaml diff --git a/internal/bundlereader/read.go b/internal/bundlereader/read.go index 9bfcf682d5..96f6122634 100644 --- a/internal/bundlereader/read.go +++ b/internal/bundlereader/read.go @@ -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 @@ -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) } diff --git a/internal/bundlereader/resources.go b/internal/bundlereader/resources.go index 1fdafc9a3b..ec5af3b9d5 100644 --- a/internal/bundlereader/resources.go +++ b/internal/bundlereader/resources.go @@ -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 @@ -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 { @@ -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. diff --git a/internal/cmd/cli/apply/apply.go b/internal/cmd/cli/apply/apply.go index cac28199a1..8bc0b9f141 100644 --- a/internal/cmd/cli/apply/apply.go +++ b/internal/cmd/cli/apply/apply.go @@ -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,