Skip to content

Commit 2e53745

Browse files
committed
Allow specifying the path for manifests updates
- Add optional `path` field to `spec.update`, defaults to the git repo root - Restrict updates to the specified `spec.update.path` Signed-off-by: Stefan Prodan <[email protected]>
1 parent 43d9d39 commit 2e53745

File tree

7 files changed

+119
-6
lines changed

7 files changed

+119
-6
lines changed

api/v1alpha1/imageupdateautomation_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ type ImageUpdateAutomationSpec struct {
3030
// ready to make changes.
3131
// +required
3232
Checkout GitCheckoutSpec `json:"checkout"`
33+
3334
// Interval gives an lower bound for how often the automation
3435
// run should be attempted.
3536
// +required
3637
Interval metav1.Duration `json:"interval"`
38+
3739
// Update gives the specification for how to update the files in
3840
// the repository. This can be left empty, to use the default
3941
// value.
4042
// +kubebuilder:default={"strategy":"Setters"}
4143
Update *UpdateStrategy `json:"update,omitempty"`
44+
4245
// Commit specifies how to commit to the git repository.
4346
// +required
4447
Commit CommitSpec `json:"commit"`
@@ -87,6 +90,12 @@ type UpdateStrategy struct {
8790
// +required
8891
// +kubebuilder:default=Setters
8992
Strategy UpdateStrategyName `json:"strategy"`
93+
94+
// Path to the directory containing the manifests to be updated.
95+
// Defaults to 'None', which translates to the root path
96+
// of the GitRepositoryRef.
97+
// +optional
98+
Path string `json:"path,omitempty"`
9099
}
91100

92101
// CommitSpec specifies how to commit changes to the git repository

config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ spec:
111111
files in the repository. This can be left empty, to use the default
112112
value.
113113
properties:
114+
path:
115+
description: Path to the directory containing the manifests to
116+
be updated. Defaults to 'None', which translates to the root
117+
path of the GitRepositoryRef.
118+
type: string
114119
strategy:
115120
default: Setters
116121
description: Strategy names the strategy to be used.

controllers/imageupdateautomation_controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
gogit "github.com/go-git/go-git/v5"
3131
libgit2 "github.com/libgit2/git2go/v31"
3232

33+
securejoin "github.com/cyphar/filepath-securejoin"
3334
"github.com/go-git/go-git/v5/plumbing"
3435
"github.com/go-git/go-git/v5/plumbing/object"
3536
"github.com/go-logr/logr"
@@ -196,7 +197,16 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
196197
return failWithError(err)
197198
}
198199

199-
if result, err := updateAccordingToSetters(ctx, tmp, policies.Items); err != nil {
200+
manifestsPath := tmp
201+
if auto.Spec.Update.Path != "" {
202+
if p, err := securejoin.SecureJoin(tmp, auto.Spec.Update.Path); err != nil {
203+
return failWithError(err)
204+
} else {
205+
manifestsPath = p
206+
}
207+
}
208+
209+
if result, err := updateAccordingToSetters(ctx, manifestsPath, policies.Items); err != nil {
200210
return failWithError(err)
201211
} else {
202212
templateValues.Updated = result

docs/api/image-automation.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ into which will be interpolated the details of the change made.</p>
8888
<td>
8989
<code>gitRepositoryRef</code><br>
9090
<em>
91-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#localobjectreference-v1-core">
92-
Kubernetes core/v1.LocalObjectReference
91+
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
92+
github.com/fluxcd/pkg/apis/meta.LocalObjectReference
9393
</a>
9494
</em>
9595
</td>
@@ -106,7 +106,9 @@ string
106106
</em>
107107
</td>
108108
<td>
109-
<p>Branch gives the branch to clone from the git repository.</p>
109+
<p>Branch gives the branch to clone from the git repository. If
110+
<code>.spec.push</code> is not supplied, commits will also be pushed to
111+
this branch.</p>
110112
</td>
111113
</tr>
112114
</tbody>
@@ -206,7 +208,23 @@ CommitSpec
206208
</em>
207209
</td>
208210
<td>
209-
<p>Commit specifies how to commit to the git repo</p>
211+
<p>Commit specifies how to commit to the git repository.</p>
212+
</td>
213+
</tr>
214+
<tr>
215+
<td>
216+
<code>push</code><br>
217+
<em>
218+
<a href="#image.toolkit.fluxcd.io/v1alpha1.PushSpec">
219+
PushSpec
220+
</a>
221+
</em>
222+
</td>
223+
<td>
224+
<em>(Optional)</em>
225+
<p>Push specifies how and where to push commits made by the
226+
automation. If missing, commits are pushed (back) to
227+
<code>.spec.checkout.branch</code>.</p>
210228
</td>
211229
</tr>
212230
<tr>
@@ -311,7 +329,23 @@ CommitSpec
311329
</em>
312330
</td>
313331
<td>
314-
<p>Commit specifies how to commit to the git repo</p>
332+
<p>Commit specifies how to commit to the git repository.</p>
333+
</td>
334+
</tr>
335+
<tr>
336+
<td>
337+
<code>push</code><br>
338+
<em>
339+
<a href="#image.toolkit.fluxcd.io/v1alpha1.PushSpec">
340+
PushSpec
341+
</a>
342+
</em>
343+
</td>
344+
<td>
345+
<em>(Optional)</em>
346+
<p>Push specifies how and where to push commits made by the
347+
automation. If missing, commits are pushed (back) to
348+
<code>.spec.checkout.branch</code>.</p>
315349
</td>
316350
</tr>
317351
<tr>
@@ -434,6 +468,40 @@ github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus
434468
</table>
435469
</div>
436470
</div>
471+
<h3 id="image.toolkit.fluxcd.io/v1alpha1.PushSpec">PushSpec
472+
</h3>
473+
<p>
474+
(<em>Appears on:</em>
475+
<a href="#image.toolkit.fluxcd.io/v1alpha1.ImageUpdateAutomationSpec">ImageUpdateAutomationSpec</a>)
476+
</p>
477+
<p>PushSpec specifies how and where to push commits.</p>
478+
<div class="md-typeset__scrollwrap">
479+
<div class="md-typeset__table">
480+
<table>
481+
<thead>
482+
<tr>
483+
<th>Field</th>
484+
<th>Description</th>
485+
</tr>
486+
</thead>
487+
<tbody>
488+
<tr>
489+
<td>
490+
<code>branch</code><br>
491+
<em>
492+
string
493+
</em>
494+
</td>
495+
<td>
496+
<p>Branch specifies that commits should be pushed to the branch
497+
named. The branch is created using <code>.spec.checkout.branch</code> as the
498+
starting point, if it doesn&rsquo;t already exist.</p>
499+
</td>
500+
</tr>
501+
</tbody>
502+
</table>
503+
</div>
504+
</div>
437505
<h3 id="image.toolkit.fluxcd.io/v1alpha1.UpdateStrategy">UpdateStrategy
438506
</h3>
439507
<p>
@@ -466,6 +534,20 @@ UpdateStrategyName
466534
<p>Strategy names the strategy to be used.</p>
467535
</td>
468536
</tr>
537+
<tr>
538+
<td>
539+
<code>path</code><br>
540+
<em>
541+
string
542+
</em>
543+
</td>
544+
<td>
545+
<em>(Optional)</em>
546+
<p>Path to the directory containing the manifests to be updated.
547+
Defaults to &lsquo;None&rsquo;, which translates to the root path
548+
of the GitRepositoryRef.</p>
549+
</td>
550+
</tr>
469551
</tbody>
470552
</table>
471553
</div>

docs/spec/v1alpha1/imageupdateautomations.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ type UpdateStrategy struct {
108108
// Strategy names the strategy to be used.
109109
// +required
110110
Strategy UpdateStrategyName `json:"strategy"`
111+
// Path to the directory containing the manifests to be updated.
112+
// Defaults to 'None', which translates to the root path
113+
// of the GitRepositoryRef.
114+
// +optional
115+
Path string `json:"path,omitempty"`
111116
}
112117
```
113118

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ replace github.com/fluxcd/image-automation-controller/api => ./api
88
replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
99

1010
require (
11+
github.com/cyphar/filepath-securejoin v0.2.2
1112
github.com/fluxcd/image-automation-controller/api v0.6.1
1213
github.com/fluxcd/image-reflector-controller/api v0.7.0
1314
github.com/fluxcd/pkg/apis/meta v0.8.0

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
252252
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
253253
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
254254
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
255+
github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg=
255256
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
256257
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
257258
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)