diff --git a/pkg/manifests/configaware.go b/pkg/manifests/configaware.go index 161899bad..a6242932f 100644 --- a/pkg/manifests/configaware.go +++ b/pkg/manifests/configaware.go @@ -81,6 +81,10 @@ func splitConfigFilesAndRawManifestPaths(baseDir string, paths []string) ([]*Con if err != nil { return nil, nil, fmt.Errorf("cannot parse config file: %s", err) } + if cf.IsJustFiles() { + rawManifestPaths = append(rawManifestPaths, path) + continue + } configFiles = append(configFiles, cf) } diff --git a/pkg/manifests/configaware_test.go b/pkg/manifests/configaware_test.go index c33c53d9c..892b1a9df 100644 --- a/pkg/manifests/configaware_test.go +++ b/pkg/manifests/configaware_test.go @@ -384,3 +384,30 @@ func TestDuplicateInGenerators(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "duplicate") } + +func TestJustFiles(t *testing.T) { + // +-- config + // +-- .flux.yaml (patchUpdated) + // +-- rawfiles + // +-- .flux.yaml (files) + // +-- manifest.yaml + + manifestyaml := ` +apiVersion: v1 +kind: Namespace +metadata: + name: foo-ns +` + + config, baseDir, cleanup := setup(t, []string{filepath.Join("config", "rawfiles")}, + config{path: "config", fluxyaml: patchUpdatedEchoConfigFile}, + config{path: filepath.Join("config", "rawfiles"), fluxyaml: "version: 1\nfiles: {}\n"}, + ) + defer cleanup() + + assert.NoError(t, ioutil.WriteFile(filepath.Join(baseDir, "config", "rawfiles", "manifest.yaml"), []byte(manifestyaml), 0600)) + + res, err := config.GetAllResourcesByID(context.Background()) + assert.NoError(t, err) + assert.Contains(t, res, "default:namespace/foo-ns") +} diff --git a/pkg/manifests/configfile.go b/pkg/manifests/configfile.go index dea0a3496..3193ef1ae 100644 --- a/pkg/manifests/configfile.go +++ b/pkg/manifests/configfile.go @@ -155,6 +155,15 @@ type PatchUpdated struct { type Files struct { } +// IsJustFiles returns true if the config file indicates that the +// directory should be treated as containing YAML files (i.e., should +// act as though there was no config file in operation). This can be +// used to reset the directive given by a .flux.yaml higher in the +// directory structure. +func (cf *ConfigFile) IsJustFiles() bool { + return cf.Files != nil +} + func ParseConfigFile(fileBytes []byte, result *ConfigFile) error { // The file contents are unmarshaled into a map so that we will // see any extraneous fields. This is important, for example, for diff --git a/pkg/manifests/configfile_test.go b/pkg/manifests/configfile_test.go index 933bef960..d0607370c 100644 --- a/pkg/manifests/configfile_test.go +++ b/pkg/manifests/configfile_test.go @@ -82,6 +82,19 @@ files: {} } } +const justFilesConfigFile = ` +version: 1 +files: {} +` + +func TestJustFileDirective(t *testing.T) { + var cf ConfigFile + err := ParseConfigFile([]byte(justFilesConfigFile), &cf) + assert.NoError(t, err) + + assert.True(t, cf.IsJustFiles()) +} + const patchUpdatedConfigFile = `--- version: 1 patchUpdated: @@ -96,6 +109,7 @@ func TestParsePatchUpdatedConfigFile(t *testing.T) { if err := ParseConfigFile([]byte(patchUpdatedConfigFile), &cf); err != nil { t.Fatal(err) } + assert.False(t, cf.IsJustFiles()) assert.NotNil(t, cf.PatchUpdated) assert.Nil(t, cf.CommandUpdated) assert.Equal(t, 1, cf.Version) @@ -126,6 +140,7 @@ func TestParseCmdUpdatedConfigFile(t *testing.T) { if err := ParseConfigFile([]byte(echoCmdUpdatedConfigFile), &cf); err != nil { t.Fatal(err) } + assert.False(t, cf.IsJustFiles()) assert.NotNil(t, cf.CommandUpdated) assert.Nil(t, cf.PatchUpdated) assert.Equal(t, 1, cf.Version) diff --git a/pkg/manifests/rawfiles.go b/pkg/manifests/rawfiles.go index 9945ba736..efd2b022b 100644 --- a/pkg/manifests/rawfiles.go +++ b/pkg/manifests/rawfiles.go @@ -17,6 +17,8 @@ type rawFiles struct { manifests Manifests } +// NewRawFiles constructs a `Store` that assumes the provided +// directories contain plain YAML files func NewRawFiles(baseDir string, paths []string, manifests Manifests) *rawFiles { return &rawFiles{ baseDir: baseDir,