Use events and metrics from fluxcd/pkg/runtime
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
deb902a13f
commit
d4cef2f046
|
@ -4,7 +4,7 @@ go 1.14
|
|||
|
||||
require (
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2
|
||||
github.com/fluxcd/pkg/runtime v0.0.6
|
||||
github.com/fluxcd/pkg/runtime v0.1.0
|
||||
k8s.io/api v0.18.9
|
||||
k8s.io/apimachinery v0.18.9
|
||||
sigs.k8s.io/controller-runtime v0.6.3
|
||||
|
|
|
@ -63,8 +63,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
|
||||
github.com/fluxcd/pkg/runtime v0.0.6 h1:m7qwr2wRePs1vzVlM0Y88vitXSsv1lb3QCJflRpa3qQ=
|
||||
github.com/fluxcd/pkg/runtime v0.0.6/go.mod h1:iLjncjktQVpqpb1NsY2fW+UYDFOtVyt+yJrxqrrK8A0=
|
||||
github.com/fluxcd/pkg/runtime v0.1.0 h1:mCLj5GlQZqWtK3tvtZTmfgFOLsTUY1iqg3CmEyS1nRs=
|
||||
github.com/fluxcd/pkg/runtime v0.1.0/go.mod h1:OXkrYtDLw3GhclbzvnzfSktUyxRmC3FFhXj0tVVaIX8=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
|
@ -165,6 +165,9 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb
|
|||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
|
|
|
@ -43,9 +43,9 @@ import (
|
|||
"sigs.k8s.io/kustomize/api/krusty"
|
||||
kustypes "sigs.k8s.io/kustomize/api/types"
|
||||
|
||||
"github.com/fluxcd/kustomize-controller/internal/metrics"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
"github.com/fluxcd/pkg/recorder"
|
||||
"github.com/fluxcd/pkg/runtime/events"
|
||||
"github.com/fluxcd/pkg/runtime/metrics"
|
||||
"github.com/fluxcd/pkg/runtime/predicates"
|
||||
"github.com/fluxcd/pkg/untar"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
|
@ -60,7 +60,7 @@ type KustomizationReconciler struct {
|
|||
Log logr.Logger
|
||||
Scheme *runtime.Scheme
|
||||
EventRecorder kuberecorder.EventRecorder
|
||||
ExternalEventRecorder *recorder.EventRecorder
|
||||
ExternalEventRecorder *events.Recorder
|
||||
MetricsRecorder *metrics.Recorder
|
||||
StatusPoller *polling.StatusPoller
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
// Our finalizer is still present, so lets handle garbage collection
|
||||
if kustomization.Spec.Prune && !kustomization.Spec.Suspend {
|
||||
if err := r.prune(kustomization, kustomization.Status.Snapshot, true); err != nil {
|
||||
r.event(kustomization, kustomization.Status.LastAppliedRevision, recorder.EventSeverityError, "pruning for deleted resource failed", nil)
|
||||
r.event(kustomization, kustomization.Status.LastAppliedRevision, events.EventSeverityError, "pruning for deleted resource failed", nil)
|
||||
// Return the error so we retry the failed garbage collection
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
// instead we requeue on a fix interval.
|
||||
msg := fmt.Sprintf("Dependencies do not meet ready condition, retrying in %s", r.requeueDependency.String())
|
||||
log.Error(err, msg)
|
||||
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityInfo, msg, nil)
|
||||
r.event(kustomization, source.GetArtifact().Revision, events.EventSeverityInfo, msg, nil)
|
||||
r.recordReadiness(kustomization, false)
|
||||
return ctrl.Result{RequeueAfter: r.requeueDependency}, nil
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
reconciledKustomization, reconcileErr := r.reconcile(*kustomization.DeepCopy(), source)
|
||||
if reconcileErr != nil {
|
||||
// broadcast the error
|
||||
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityError, reconcileErr.Error(), nil)
|
||||
r.event(kustomization, source.GetArtifact().Revision, events.EventSeverityError, reconcileErr.Error(), nil)
|
||||
}
|
||||
|
||||
// update status
|
||||
|
@ -212,7 +212,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
}
|
||||
|
||||
// record the reconciliation result
|
||||
r.event(reconciledKustomization, source.GetArtifact().Revision, recorder.EventSeverityInfo,
|
||||
r.event(reconciledKustomization, source.GetArtifact().Revision, events.EventSeverityInfo,
|
||||
"Update completed", map[string]string{"commit_status": "update"})
|
||||
r.recordReadiness(reconciledKustomization, false)
|
||||
return ctrl.Result{RequeueAfter: kustomization.Spec.Interval.Duration}, nil
|
||||
|
@ -643,7 +643,7 @@ func (r *KustomizationReconciler) applyWithRetry(kustomization kustomizev1.Kusto
|
|||
return err
|
||||
} else {
|
||||
if changeSet != "" {
|
||||
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet, nil)
|
||||
r.event(kustomization, revision, events.EventSeverityInfo, changeSet, nil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -651,7 +651,7 @@ func (r *KustomizationReconciler) applyWithRetry(kustomization kustomizev1.Kusto
|
|||
}
|
||||
} else {
|
||||
if changeSet != "" && kustomization.Status.LastAppliedRevision != revision {
|
||||
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet, nil)
|
||||
r.event(kustomization, revision, events.EventSeverityInfo, changeSet, nil)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -688,7 +688,7 @@ func (r *KustomizationReconciler) prune(kustomization kustomizev1.Kustomization,
|
|||
strings.ToLower(kustomization.Kind),
|
||||
fmt.Sprintf("%s/%s", kustomization.GetNamespace(), kustomization.GetName()),
|
||||
).Info(fmt.Sprintf("garbage collection completed: %s", output))
|
||||
r.event(kustomization, snapshot.Checksum, recorder.EventSeverityInfo, output, nil)
|
||||
r.event(kustomization, snapshot.Checksum, events.EventSeverityInfo, output, nil)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -706,7 +706,7 @@ func (r *KustomizationReconciler) checkHealth(kustomization kustomizev1.Kustomiz
|
|||
}
|
||||
|
||||
if kustomization.Status.LastAppliedRevision != revision {
|
||||
r.event(kustomization, revision, recorder.EventSeverityInfo, "Health check passed", nil)
|
||||
r.event(kustomization, revision, events.EventSeverityInfo, "Health check passed", nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
5
go.mod
5
go.mod
|
@ -5,11 +5,9 @@ go 1.14
|
|||
replace github.com/fluxcd/kustomize-controller/api => ./api
|
||||
|
||||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/fluxcd/kustomize-controller/api v0.1.0
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2
|
||||
github.com/fluxcd/pkg/recorder v0.0.6
|
||||
github.com/fluxcd/pkg/runtime v0.0.6
|
||||
github.com/fluxcd/pkg/runtime v0.1.0
|
||||
github.com/fluxcd/pkg/testserver v0.0.2
|
||||
github.com/fluxcd/pkg/untar v0.0.5
|
||||
github.com/fluxcd/source-controller/api v0.1.0
|
||||
|
@ -17,7 +15,6 @@ require (
|
|||
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c
|
||||
github.com/onsi/ginkgo v1.12.1
|
||||
github.com/onsi/gomega v1.10.1
|
||||
github.com/prometheus/client_golang v1.0.0
|
||||
go.mozilla.org/gopgagent v0.0.0-20170926210634-4d7ea76ff71a
|
||||
go.mozilla.org/sops/v3 v3.6.1
|
||||
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
|
||||
|
|
17
go.sum
17
go.sum
|
@ -68,9 +68,8 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
|
|||
github.com/aws/aws-sdk-go v1.33.18 h1:Ccy1SV2SsgJU3rfrD+SOhQ0jvuzfrFuja/oKI86ruPw=
|
||||
github.com/aws/aws-sdk-go v1.33.18/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
|
||||
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
|
@ -139,7 +138,6 @@ github.com/emicklei/go-restful v2.9.5+incompatible h1:spTtZBk5DYEvbxMVutUuTyh1Ao
|
|||
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQobrkAqrL+WFZwQses=
|
||||
|
@ -151,10 +149,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
|
|||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
|
||||
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
|
||||
github.com/fluxcd/pkg/recorder v0.0.6 h1:me/n8syeeGXz50OXoPX3jgIj9AtinvhHdKT9Dy+MbHs=
|
||||
github.com/fluxcd/pkg/recorder v0.0.6/go.mod h1:IfQxfVRSNsWs3B0Yp5B6ObEWwKHILlAx8N7XkoDdhFg=
|
||||
github.com/fluxcd/pkg/runtime v0.0.6 h1:m7qwr2wRePs1vzVlM0Y88vitXSsv1lb3QCJflRpa3qQ=
|
||||
github.com/fluxcd/pkg/runtime v0.0.6/go.mod h1:iLjncjktQVpqpb1NsY2fW+UYDFOtVyt+yJrxqrrK8A0=
|
||||
github.com/fluxcd/pkg/runtime v0.1.0 h1:mCLj5GlQZqWtK3tvtZTmfgFOLsTUY1iqg3CmEyS1nRs=
|
||||
github.com/fluxcd/pkg/runtime v0.1.0/go.mod h1:OXkrYtDLw3GhclbzvnzfSktUyxRmC3FFhXj0tVVaIX8=
|
||||
github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk=
|
||||
github.com/fluxcd/pkg/testserver v0.0.2/go.mod h1:pgUZTh9aQ44FSTQo+5NFlh7YMbUfdz1B80DalW7k96Y=
|
||||
github.com/fluxcd/pkg/untar v0.0.5 h1:UGI3Ch1UIEIaqQvMicmImL1s9npQa64DJ/ozqHKB7gk=
|
||||
|
@ -361,8 +357,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP
|
|||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
|
||||
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
|
||||
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
|
||||
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.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8=
|
||||
github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
|
||||
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
|
||||
|
@ -394,7 +390,6 @@ github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
|||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
|
||||
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
|
@ -913,7 +908,6 @@ k8s.io/api v0.0.0-20191214185829-ca1d04f8b0d3/go.mod h1:itOjKREfmUTvcjantxOsyYU5
|
|||
k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI=
|
||||
k8s.io/api v0.17.2/go.mod h1:BS9fjjLc4CMuqfSO8vgbHPKMt5+SF0ET6u/RVDihTo4=
|
||||
k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI=
|
||||
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
|
||||
k8s.io/api v0.18.9 h1:7VDtivqwbvLOf8hmXSd/PDSSbpCBq49MELg84EYBYiQ=
|
||||
k8s.io/api v0.18.9/go.mod h1:9u/h6sUh6FxfErv7QqetX1EB3yBMIYOBXzdcf0Gf0rc=
|
||||
k8s.io/apiextensions-apiserver v0.0.0-20190918161926-8f644eb6e783/go.mod h1:xvae1SZB3E17UpV59AWc271W/Ph25N+bjPyR63X6tPY=
|
||||
|
@ -926,7 +920,6 @@ k8s.io/apimachinery v0.0.0-20191216025728-0ee8b4573e3a/go.mod h1:Ng1IY8TS7sC44KJ
|
|||
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
|
||||
k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
|
||||
k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
|
||||
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
|
||||
k8s.io/apimachinery v0.18.9 h1:3ZABKQx3F3xPWlsGhCfUl8W+JXRRblV6Wo2A3zn0pvY=
|
||||
k8s.io/apimachinery v0.18.9/go.mod h1:PF5taHbXgTEJLU+xMypMmYTXTWPJ5LaW8bfsisxnEXk=
|
||||
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad/go.mod h1:XPCXEwhjaFN29a8NldXA901ElnKeKLrLtREO9ZhFyhg=
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
const (
|
||||
ConditionDeleted = "Deleted"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
conditionGauge *prometheus.GaugeVec
|
||||
durationHistogram *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
func NewRecorder() *Recorder {
|
||||
return &Recorder{
|
||||
conditionGauge: prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "gotk_reconcile_condition",
|
||||
Help: "The current condition status of a GitOps Toolkit resource reconciliation.",
|
||||
},
|
||||
[]string{"kind", "name", "namespace", "type", "status"},
|
||||
),
|
||||
durationHistogram: prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "gotk_reconcile_duration",
|
||||
Help: "The duration in seconds of a GitOps Toolkit resource reconciliation.",
|
||||
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10),
|
||||
},
|
||||
[]string{"kind", "name", "namespace"},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Recorder) Collectors() []prometheus.Collector {
|
||||
return []prometheus.Collector{r.conditionGauge, r.durationHistogram}
|
||||
}
|
||||
|
||||
func (r *Recorder) RecordCondition(ref corev1.ObjectReference, condition meta.Condition, deleted bool) {
|
||||
for _, status := range []string{string(corev1.ConditionTrue), string(corev1.ConditionFalse), string(corev1.ConditionUnknown), ConditionDeleted} {
|
||||
var value float64
|
||||
if deleted {
|
||||
if status == ConditionDeleted {
|
||||
value = 1
|
||||
}
|
||||
} else {
|
||||
if status == string(condition.Status) {
|
||||
value = 1
|
||||
}
|
||||
}
|
||||
|
||||
r.conditionGauge.WithLabelValues(ref.Kind, ref.Name, ref.Namespace, condition.Type, status).Set(value)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Recorder) RecordDuration(ref corev1.ObjectReference, start time.Time) {
|
||||
r.durationHistogram.WithLabelValues(ref.Kind, ref.Name, ref.Namespace).Observe(time.Since(start).Seconds())
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
func TestRecorder_RecordCondition(t *testing.T) {
|
||||
rec := NewRecorder()
|
||||
reg := prometheus.NewRegistry()
|
||||
reg.MustRegister(rec.conditionGauge)
|
||||
|
||||
ref := corev1.ObjectReference{
|
||||
Kind: "Kustomization",
|
||||
Namespace: "default",
|
||||
Name: "test",
|
||||
}
|
||||
|
||||
cond := meta.Condition{
|
||||
Type: meta.ReadyCondition,
|
||||
Status: corev1.ConditionTrue,
|
||||
}
|
||||
|
||||
rec.RecordCondition(ref, cond, false)
|
||||
|
||||
metricFamilies, err := reg.Gather()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(metricFamilies) != 1 {
|
||||
t.Fatalf("expected one metric family, got %v", metricFamilies)
|
||||
}
|
||||
|
||||
if len(metricFamilies[0].Metric) != 4 {
|
||||
t.Fatalf("expected four metrics, got %v", metricFamilies[0].Metric)
|
||||
}
|
||||
|
||||
var conditionTrueValue float64
|
||||
for _, m := range metricFamilies[0].Metric {
|
||||
for _, pair := range m.GetLabel() {
|
||||
if *pair.Name == "type" && *pair.Value != meta.ReadyCondition {
|
||||
t.Errorf("expected condition type to be %s, got %s", meta.ReadyCondition, *pair.Value)
|
||||
}
|
||||
if *pair.Name == "status" && *pair.Value == string(corev1.ConditionTrue) {
|
||||
conditionTrueValue = *m.GetGauge().Value
|
||||
} else if *pair.Name == "status" && *m.GetGauge().Value != 0 {
|
||||
t.Errorf("expected guage value to be 0, got %v", *m.GetGauge().Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if conditionTrueValue != 1 {
|
||||
t.Errorf("expected guage value to be 1, got %v", conditionTrueValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecorder_RecordDuration(t *testing.T) {
|
||||
rec := NewRecorder()
|
||||
reg := prometheus.NewRegistry()
|
||||
reg.MustRegister(rec.durationHistogram)
|
||||
|
||||
ref := corev1.ObjectReference{
|
||||
Kind: "GitRepository",
|
||||
Namespace: "default",
|
||||
Name: "test",
|
||||
}
|
||||
|
||||
reconcileStart := time.Now().Add(-time.Second)
|
||||
rec.RecordDuration(ref, reconcileStart)
|
||||
|
||||
metricFamilies, err := reg.Gather()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(metricFamilies) != 1 {
|
||||
t.Fatalf("expected one metric family, got %v", metricFamilies)
|
||||
}
|
||||
|
||||
if len(metricFamilies[0].Metric) != 1 {
|
||||
t.Fatalf("expected one metric, got %v", metricFamilies[0].Metric)
|
||||
}
|
||||
|
||||
sampleCount := metricFamilies[0].Metric[0].Histogram.GetSampleCount()
|
||||
if sampleCount != 1 {
|
||||
t.Errorf("expected histogram sample count to be 1, got %v", sampleCount)
|
||||
}
|
||||
|
||||
labels := metricFamilies[0].Metric[0].GetLabel()
|
||||
|
||||
if len(labels) != 3 {
|
||||
t.Fatalf("expected three labels, got %v", metricFamilies[0].Metric[0].GetLabel())
|
||||
}
|
||||
|
||||
for _, pair := range labels {
|
||||
if *pair.Name == "kind" && *pair.Value != ref.Kind {
|
||||
t.Errorf("expected kind label to be %s, got %s", ref.Kind, *pair.Value)
|
||||
}
|
||||
if *pair.Name == "name" && *pair.Value != ref.Name {
|
||||
t.Errorf("expected name label to be %s, got %s", ref.Name, *pair.Value)
|
||||
}
|
||||
if *pair.Name == "namespace" && *pair.Value != ref.Namespace {
|
||||
t.Errorf("expected namespace label to be %s, got %s", ref.Namespace, *pair.Value)
|
||||
}
|
||||
}
|
||||
}
|
8
main.go
8
main.go
|
@ -30,9 +30,9 @@ import (
|
|||
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
|
||||
"github.com/fluxcd/kustomize-controller/controllers"
|
||||
"github.com/fluxcd/kustomize-controller/internal/metrics"
|
||||
"github.com/fluxcd/pkg/recorder"
|
||||
"github.com/fluxcd/pkg/runtime/events"
|
||||
"github.com/fluxcd/pkg/runtime/logger"
|
||||
"github.com/fluxcd/pkg/runtime/metrics"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
// +kubebuilder:scaffold:imports
|
||||
)
|
||||
|
@ -77,9 +77,9 @@ func main() {
|
|||
|
||||
ctrl.SetLogger(logger.NewLogger(logLevel, logJSON))
|
||||
|
||||
var eventRecorder *recorder.EventRecorder
|
||||
var eventRecorder *events.Recorder
|
||||
if eventsAddr != "" {
|
||||
if er, err := recorder.NewEventRecorder(eventsAddr, "kustomize-controller"); err != nil {
|
||||
if er, err := events.NewRecorder(eventsAddr, "kustomize-controller"); err != nil {
|
||||
setupLog.Error(err, "unable to create event recorder")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue