Skip to content

Commit 2dc7132

Browse files
author
Philip Laine
authored
Merge pull request #348 from fluxcd/feature/include-source
Add include property to GitRepositories
2 parents 16c9af5 + fcf7048 commit 2dc7132

File tree

13 files changed

+747
-275
lines changed

13 files changed

+747
-275
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ifeq (, $(shell which gen-crd-api-reference-docs))
105105
API_REF_GEN_TMP_DIR=$$(mktemp -d) ;\
106106
cd $$API_REF_GEN_TMP_DIR ;\
107107
go mod init tmp ;\
108-
go get github.com/ahmetb/gen-crd-api-reference-docs@v0.2.0 ;\
108+
go get github.com/ahmetb/gen-crd-api-reference-docs@v0.3.0 ;\
109109
rm -rf $$API_REF_GEN_TMP_DIR ;\
110110
}
111111
API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs

api/v1beta1/gitrepository_types.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,34 @@ type GitRepositorySpec struct {
8787
// This option is available only when using the 'go-git' GitImplementation.
8888
// +optional
8989
RecurseSubmodules bool `json:"recurseSubmodules,omitempty"`
90+
91+
// Extra git repositories to map into the repository
92+
Include []GitRepositoryInclude `json:"include,omitempty"`
93+
}
94+
95+
func (in *GitRepositoryInclude) GetFromPath() string {
96+
return in.FromPath
97+
}
98+
99+
func (in *GitRepositoryInclude) GetToPath() string {
100+
if in.ToPath == "" {
101+
return in.GitRepositoryRef.Name
102+
}
103+
return in.ToPath
104+
}
105+
106+
// GitRepositoryInclude defines a source with a from and to path.
107+
type GitRepositoryInclude struct {
108+
// Reference to a GitRepository to include.
109+
GitRepositoryRef meta.LocalObjectReference `json:"repository"`
110+
111+
// The path to copy contents from, defaults to the root directory.
112+
// +optional
113+
FromPath string `json:"fromPath"`
114+
115+
// The path to copy contents to, defaults to the name of the source ref.
116+
// +optional
117+
ToPath string `json:"toPath"`
90118
}
91119

92120
// GitRepositoryRef defines the Git ref used for pull and checkout operations.
@@ -138,6 +166,10 @@ type GitRepositoryStatus struct {
138166
// +optional
139167
Artifact *Artifact `json:"artifact,omitempty"`
140168

169+
// IncludedArtifacts represents the included artifacts from the last successful repository sync.
170+
// +optional
171+
IncludedArtifacts []*Artifact `json:"includedArtifacts,omitempty"`
172+
141173
meta.ReconcileRequestStatus `json:",inline"`
142174
}
143175

@@ -166,8 +198,9 @@ func GitRepositoryProgressing(repository GitRepository) GitRepository {
166198
// GitRepositoryReady sets the given Artifact and URL on the GitRepository and
167199
// sets the meta.ReadyCondition to 'True', with the given reason and message. It
168200
// returns the modified GitRepository.
169-
func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository {
201+
func GitRepositoryReady(repository GitRepository, artifact Artifact, includedArtifacts []*Artifact, url, reason, message string) GitRepository {
170202
repository.Status.Artifact = &artifact
203+
repository.Status.IncludedArtifacts = includedArtifacts
171204
repository.Status.URL = url
172205
meta.SetResourceCondition(&repository, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
173206
return repository

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ spec:
6565
a default will be used, consult the documentation for your version
6666
to find out what those are.
6767
type: string
68+
include:
69+
description: Extra git repositories to map into the repository
70+
items:
71+
description: GitRepositoryInclude defines a source with a from and
72+
to path.
73+
properties:
74+
fromPath:
75+
description: The path to copy contents from, defaults to the
76+
root directory.
77+
type: string
78+
repository:
79+
description: Reference to a GitRepository to include.
80+
properties:
81+
name:
82+
description: Name of the referent
83+
type: string
84+
required:
85+
- name
86+
type: object
87+
toPath:
88+
description: The path to copy contents to, defaults to the name
89+
of the source ref.
90+
type: string
91+
required:
92+
- repository
93+
type: object
94+
type: array
6895
interval:
6996
description: The interval at which to check for repository updates.
7097
type: string
@@ -245,6 +272,36 @@ spec:
245272
- type
246273
type: object
247274
type: array
275+
includedArtifacts:
276+
description: IncludedArtifacts represents the included artifacts from
277+
the last successful repository sync.
278+
items:
279+
description: Artifact represents the output of a source synchronisation.
280+
properties:
281+
checksum:
282+
description: Checksum is the SHA1 checksum of the artifact.
283+
type: string
284+
lastUpdateTime:
285+
description: LastUpdateTime is the timestamp corresponding to
286+
the last update of this artifact.
287+
format: date-time
288+
type: string
289+
path:
290+
description: Path is the relative file path of this artifact.
291+
type: string
292+
revision:
293+
description: Revision is a human readable identifier traceable
294+
in the origin source system. It can be a Git commit SHA, Git
295+
tag, a Helm index timestamp, a Helm chart version, etc.
296+
type: string
297+
url:
298+
description: URL is the HTTP address of this artifact.
299+
type: string
300+
required:
301+
- path
302+
- url
303+
type: object
304+
type: array
248305
lastHandledReconcileAt:
249306
description: LastHandledReconcileAt holds the value of the most recent
250307
reconcile request value, so a change can be detected.

controllers/artifact.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package controllers
2+
3+
import sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
4+
5+
// hasArtifactUpdated returns true if any of the revisions in the current artifacts
6+
// does not match any of the artifacts in the updated artifacts
7+
func hasArtifactUpdated(current []*sourcev1.Artifact, updated []*sourcev1.Artifact) bool {
8+
if len(current) != len(updated) {
9+
return true
10+
}
11+
12+
OUTER:
13+
for _, c := range current {
14+
for _, u := range updated {
15+
if u.HasRevision(c.Revision) {
16+
continue OUTER
17+
}
18+
}
19+
return true
20+
}
21+
22+
return false
23+
}

controllers/artifact_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package controllers
2+
3+
import (
4+
"testing"
5+
6+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
7+
)
8+
9+
func TestHasUpdated(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
current []*sourcev1.Artifact
13+
updated []*sourcev1.Artifact
14+
expected bool
15+
}{
16+
{
17+
name: "not updated single",
18+
current: []*sourcev1.Artifact{
19+
{
20+
Revision: "foo",
21+
},
22+
},
23+
updated: []*sourcev1.Artifact{
24+
{
25+
Revision: "foo",
26+
},
27+
},
28+
expected: false,
29+
},
30+
{
31+
name: "updated single",
32+
current: []*sourcev1.Artifact{
33+
{
34+
Revision: "foo",
35+
},
36+
},
37+
updated: []*sourcev1.Artifact{
38+
{
39+
Revision: "bar",
40+
},
41+
},
42+
expected: true,
43+
},
44+
{
45+
name: "not updated multiple",
46+
current: []*sourcev1.Artifact{
47+
{
48+
Revision: "foo",
49+
},
50+
{
51+
Revision: "bar",
52+
},
53+
},
54+
updated: []*sourcev1.Artifact{
55+
{
56+
Revision: "foo",
57+
},
58+
{
59+
Revision: "bar",
60+
},
61+
},
62+
expected: false,
63+
},
64+
{
65+
name: "updated multiple",
66+
current: []*sourcev1.Artifact{
67+
{
68+
Revision: "foo",
69+
},
70+
{
71+
Revision: "bar",
72+
},
73+
},
74+
updated: []*sourcev1.Artifact{
75+
{
76+
Revision: "foo",
77+
},
78+
{
79+
Revision: "baz",
80+
},
81+
},
82+
expected: true,
83+
},
84+
{
85+
name: "updated different artifact count",
86+
current: []*sourcev1.Artifact{
87+
{
88+
Revision: "foo",
89+
},
90+
{
91+
Revision: "bar",
92+
},
93+
},
94+
updated: []*sourcev1.Artifact{
95+
{
96+
Revision: "foo",
97+
},
98+
},
99+
expected: true,
100+
},
101+
}
102+
for _, tt := range tests {
103+
t.Run(tt.name, func(t *testing.T) {
104+
result := hasArtifactUpdated(tt.current, tt.updated)
105+
if result != tt.expected {
106+
t.Errorf("Archive() result = %v, wantResult %v", result, tt.expected)
107+
}
108+
})
109+
}
110+
}

0 commit comments

Comments
 (0)