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
4 changes: 2 additions & 2 deletions api/v1alpha1/gitrepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ type GitRepositorySpec struct {
// +optional
Verification *GitRepositoryVerification `json:"verify,omitempty"`

// SourceIgnore overrides the set of excluded patterns in the .sourceignore
// Ignore overrides the set of excluded patterns in the .sourceignore
// format (which is the same as .gitignore). If not provided, a default will
// be used, consult the documentation for your version to find out what those
// are.
// +optional
SourceIgnore *string `json:"sourceIgnore,omitempty"`
Ignore *string `json:"ignore,omitempty"`
}

// GitRepositoryRef defines the git ref used for pull and checkout operations.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions config/crd/bases/source.fluxcd.io_gitrepositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ spec:
spec:
description: GitRepositorySpec defines the desired state of a Git repository.
properties:
ignore:
description: Ignore overrides the set of excluded patterns in the .sourceignore
format (which is the same as .gitignore). If not provided, a default
will be used, consult the documentation for your version to find out
what those are.
type: string
interval:
description: The interval at which to check for repository updates.
type: string
Expand Down Expand Up @@ -82,12 +88,6 @@ spec:
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
sourceIgnore:
description: SourceIgnore overrides the set of excluded patterns in
the .sourceignore format (which is the same as .gitignore). If not
provided, a default will be used, consult the documentation for your
version to find out what those are.
type: string
timeout:
description: The timeout for remote git operations like cloning, default
to 20s.
Expand Down
4 changes: 2 additions & 2 deletions controllers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func loadExcludePatterns(dir string, spec sourcev1.GitRepositorySpec) ([]gitigno
ps = append(ps, gitignore.ParsePattern(p, path))
}

if spec.SourceIgnore == nil {
if spec.Ignore == nil {
for _, p := range strings.Split(excludeExt, ",") {
ps = append(ps, gitignore.ParsePattern(p, path))
}
Expand All @@ -280,7 +280,7 @@ func loadExcludePatterns(dir string, spec sourcev1.GitRepositorySpec) ([]gitigno
return nil, err
}
} else {
ps = append(ps, getPatterns(bytes.NewBufferString(*spec.SourceIgnore), path)...)
ps = append(ps, getPatterns(bytes.NewBufferString(*spec.Ignore), path)...)
}

return ps, nil
Expand Down
4 changes: 2 additions & 2 deletions controllers/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ func TestArchiveIgnore(t *testing.T) {
}

t.Run("only vcs ignored files", func(t *testing.T) {
testPatterns(t, createArchive(t, filenames, "", sourcev1.GitRepositorySpec{SourceIgnore: stringPtr("")}), table)
testPatterns(t, createArchive(t, filenames, "", sourcev1.GitRepositorySpec{Ignore: stringPtr("")}), table)
})

filenames = append(filenames, "test.txt")
table["test.txt"] = false
sourceIgnoreFile := "*.txt"

t.Run("sourceignore injected via CRD", func(t *testing.T) {
testPatterns(t, createArchive(t, filenames, "", sourcev1.GitRepositorySpec{SourceIgnore: stringPtr(sourceIgnoreFile)}), table)
testPatterns(t, createArchive(t, filenames, "", sourcev1.GitRepositorySpec{Ignore: stringPtr(sourceIgnoreFile)}), table)
})

table = ignoreMap{}
Expand Down
8 changes: 4 additions & 4 deletions docs/api/source.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ GitRepositoryVerification
</tr>
<tr>
<td>
<code>sourceIgnore</code><br>
<code>ignore</code><br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>SourceIgnore overrides the set of excluded patterns in the .sourceignore
<p>Ignore overrides the set of excluded patterns in the .sourceignore
format (which is the same as .gitignore). If not provided, a default will
be used, consult the documentation for your version to find out what those
are.</p>
Expand Down Expand Up @@ -683,14 +683,14 @@ GitRepositoryVerification
</tr>
<tr>
<td>
<code>sourceIgnore</code><br>
<code>ignore</code><br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>SourceIgnore overrides the set of excluded patterns in the .sourceignore
<p>Ignore overrides the set of excluded patterns in the .sourceignore
format (which is the same as .gitignore). If not provided, a default will
be used, consult the documentation for your version to find out what those
are.</p>
Expand Down
38 changes: 30 additions & 8 deletions docs/spec/v1alpha1/gitrepositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ type GitRepositorySpec struct {
// Verify OpenPGP signature for the commit that HEAD points to.
// +optional
Verification *GitRepositoryVerification `json:"verify,omitempty"`

// Ignore overrides the set of excluded patterns in the .sourceignore
// format (which is the same as .gitignore). If not provided, a default will
// be used, consult the documentation for your version to find out what those
// are.
// +optional
Ignore *string `json:"ignore,omitempty"`

}
```

Expand Down Expand Up @@ -130,6 +138,28 @@ follows [the `.gitignore` pattern
format](https://git-scm.com/docs/gitignore#_pattern_format), pattern
entries may overrule default exclusions.

Another option is to use the `spec.ignore` field, for example:

```yaml
apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
spec:
interval: 5m
url: https://github.com/stefanprodan/podinfo
ignore: |
# exclude all
/*
# include deploy dir
!/deploy
# exclude file extensions from deploy dir
/deploy/**/*.md
/deploy/**/*.txt
```

When specified, `spec.ignore` overrides the default exclusion list.

## Spec examples

Pull the master branch of a public repository every minute:
Expand All @@ -139,7 +169,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand All @@ -152,7 +181,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand All @@ -167,7 +195,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand All @@ -183,7 +210,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand All @@ -198,7 +224,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand All @@ -213,7 +238,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
url: https://github.com/stefanprodan/podinfo
secretRef:
Expand All @@ -237,7 +261,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
url: ssh://git@github.com/stefanprodan/podinfo
secretRef:
Expand Down Expand Up @@ -277,7 +300,6 @@ apiVersion: source.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
namespace: default
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
Expand Down