Send event on success/failure to commit change
The useful events to know about for the update automation are when it either errors out while trying to update the git repo, or succeeds. Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
parent
59975f6ad0
commit
c762ce8d6f
|
@ -44,6 +44,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
|
||||
"github.com/fluxcd/pkg/runtime/events"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/fluxcd/source-controller/pkg/git"
|
||||
|
||||
|
@ -134,6 +135,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
|
|||
}
|
||||
|
||||
if err := updateAccordingToSetters(ctx, tmp, policies.Items); err != nil {
|
||||
r.event(auto, events.EventSeverityError, err.Error())
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
default:
|
||||
|
@ -145,14 +147,17 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
|
|||
log.V(debug).Info("ran updates to working dir", "working", tmp)
|
||||
|
||||
var commitMade bool
|
||||
|
||||
if rev, err := commitAllAndPush(ctx, repo, access, &auto.Spec.Commit); err != nil {
|
||||
if err == errNoChanges {
|
||||
log.Info("no changes made in working directory; no commit")
|
||||
} else {
|
||||
r.event(auto, events.EventSeverityError, err.Error())
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
} else {
|
||||
commitMade = true
|
||||
r.event(auto, events.EventSeverityInfo, "committed and pushed change "+rev)
|
||||
log.V(debug).Info("pushed commit to origin", "revision", rev)
|
||||
}
|
||||
|
||||
|
@ -331,6 +336,14 @@ func commitAllAndPush(ctx context.Context, repo *gogit.Repository, access repoAc
|
|||
})
|
||||
}
|
||||
|
||||
// --- events
|
||||
|
||||
func (r *ImageUpdateAutomationReconciler) event(auto imagev1.ImageUpdateAutomation, severity, msg string) {
|
||||
if r.EventRecorder != nil {
|
||||
r.EventRecorder.Event(&auto, "Normal", severity, msg)
|
||||
}
|
||||
}
|
||||
|
||||
// --- updates
|
||||
|
||||
// updateAccordingToSetters updates files under the root by treating
|
||||
|
|
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
|||
github.com/fluxcd/image-automation-controller/api v0.0.0-00010101000000-000000000000
|
||||
github.com/fluxcd/image-reflector-controller v0.0.0-20200810165546-c2265d9b49b9
|
||||
github.com/fluxcd/pkg/gittestserver v0.0.2
|
||||
github.com/fluxcd/pkg/runtime v0.2.0
|
||||
github.com/fluxcd/source-controller v0.2.2
|
||||
// If you bump this, change TOOLKIT_VERSION in the Makefile to match
|
||||
github.com/fluxcd/source-controller/api v0.2.2
|
||||
|
|
4
go.sum
4
go.sum
|
@ -295,6 +295,7 @@ github.com/fluxcd/pkg/gittestserver v0.0.2 h1:11aKRVuuHiyeaicdN4wPNSMy/dUarQkrPr
|
|||
github.com/fluxcd/pkg/gittestserver v0.0.2/go.mod h1:GW8N9d1o8/+mXWnSzs02qCB5WlArWQHdMpDPf7b/GZg=
|
||||
github.com/fluxcd/pkg/helmtestserver v0.0.1/go.mod h1:GR8LriiU7PqZSTH4Xe6Cimpig2VVPB29PeUXJjNJYfA=
|
||||
github.com/fluxcd/pkg/lockedfile v0.0.5/go.mod h1:uAtPUBId6a2RqO84MTH5HKGX0SbM1kNW3Wr/FhYyDVA=
|
||||
github.com/fluxcd/pkg/runtime v0.2.0 h1:aZmSLuyA9pF/KANf4wi7pZIICE19BKTYFSPRbl6WHtY=
|
||||
github.com/fluxcd/pkg/runtime v0.2.0/go.mod h1:P1/S8TOSuJgVPU0SRahWzbNxLWYoUwvBcPCNGc+dWWg=
|
||||
github.com/fluxcd/pkg/ssh v0.0.5 h1:rnbFZ7voy2JBlUfMbfyqArX2FYaLNpDhccGFC3qW83A=
|
||||
github.com/fluxcd/pkg/ssh v0.0.5/go.mod h1:7jXPdXZpc0ttMNz2kD9QuMi3RNn/e0DOFbj0Tij/+Hs=
|
||||
|
@ -573,7 +574,9 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
|
|||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
|
||||
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
|
@ -581,6 +584,7 @@ github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:
|
|||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
|
|
Loading…
Reference in New Issue