Skip to content

Commit 423dc68

Browse files
authored
Merge pull request #152 from fluxcd/use-annotation-helpers
Use annotation helpers
2 parents 81a990f + 3ca1bf2 commit 423dc68

13 files changed

+55
-58
lines changed

api/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/fluxcd/kustomize-controller/api
33
go 1.15
44

55
require (
6-
github.com/fluxcd/pkg/apis/meta v0.0.2
6+
github.com/fluxcd/pkg/apis/meta v0.1.0
77
github.com/fluxcd/pkg/runtime v0.1.0
88
k8s.io/api v0.18.9
99
k8s.io/apimachinery v0.18.9

api/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
6363
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
6464
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
6565
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
66+
github.com/fluxcd/pkg/apis/meta v0.1.0 h1:CfOYHYaHslhcb3QlzgKCOXl4ziCbA5zG/fUa1qFlHis=
67+
github.com/fluxcd/pkg/apis/meta v0.1.0/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
6668
github.com/fluxcd/pkg/runtime v0.1.0 h1:mCLj5GlQZqWtK3tvtZTmfgFOLsTUY1iqg3CmEyS1nRs=
6769
github.com/fluxcd/pkg/runtime v0.1.0/go.mod h1:OXkrYtDLw3GhclbzvnzfSktUyxRmC3FFhXj0tVVaIX8=
6870
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

api/v1beta1/kustomization_types.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ type KustomizationStatus struct {
154154
// +optional
155155
LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"`
156156

157-
// LastHandledReconcileAt is the last manual reconciliation request (by
158-
// annotating the Kustomization) handled by the reconciler.
159-
// +optional
160-
LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"`
157+
meta.ReconcileRequestStatus `json:",inline"`
161158

162159
// The last successfully applied revision metadata.
163160
// +optional

api/v1beta1/zz_generated.deepcopy.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ spec:
250250
attempt.
251251
type: string
252252
lastHandledReconcileAt:
253-
description: LastHandledReconcileAt is the last manual reconciliation
254-
request (by annotating the Kustomization) handled by the reconciler.
253+
description: LastHandledReconcileAt holds the value of the most recent
254+
reconcile request value, so a change can be detected.
255255
type: string
256256
observedGeneration:
257257
description: ObservedGeneration is the last reconciled generation.

controllers/bucket_watcher.go

+1-20
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ import (
2323
"time"
2424

2525
"github.com/go-logr/logr"
26-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/runtime"
2827
"k8s.io/apimachinery/pkg/types"
29-
"k8s.io/client-go/util/retry"
3028
ctrl "sigs.k8s.io/controller-runtime"
3129
"sigs.k8s.io/controller-runtime/pkg/client"
3230

3331
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
34-
"github.com/fluxcd/pkg/apis/meta"
3532
"github.com/fluxcd/pkg/runtime/dependency"
3633
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
3734
)
@@ -80,7 +77,7 @@ func (r *BucketWatcher) Reconcile(req ctrl.Request) (ctrl.Result, error) {
8077
// trigger apply for each kustomization using this Bucket taking into account the dependency order
8178
for _, k := range sorted {
8279
name := types.NamespacedName(k)
83-
if err := r.requestReconciliation(name); err != nil {
80+
if err := requestReconciliation(r, name); err != nil {
8481
log.Error(err, "unable to annotate Kustomization", "kustomization", name)
8582
continue
8683
}
@@ -114,19 +111,3 @@ func (r *BucketWatcher) SetupWithManager(mgr ctrl.Manager) error {
114111
WithEventFilter(BucketRevisionChangePredicate{}).
115112
Complete(r)
116113
}
117-
118-
func (r *BucketWatcher) requestReconciliation(name types.NamespacedName) error {
119-
var kustomization kustomizev1.Kustomization
120-
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
121-
if err := r.Get(context.TODO(), name, &kustomization); err != nil {
122-
return err
123-
}
124-
125-
if kustomization.Annotations == nil {
126-
kustomization.Annotations = make(map[string]string)
127-
}
128-
kustomization.Annotations[meta.ReconcileAtAnnotation] = metav1.Now().String()
129-
err = r.Update(context.TODO(), &kustomization)
130-
return
131-
})
132-
}

controllers/gitrepository_watcher.go

+1-20
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ import (
2323
"time"
2424

2525
"github.com/go-logr/logr"
26-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/runtime"
2827
"k8s.io/apimachinery/pkg/types"
29-
"k8s.io/client-go/util/retry"
3028
ctrl "sigs.k8s.io/controller-runtime"
3129
"sigs.k8s.io/controller-runtime/pkg/client"
3230

3331
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
34-
"github.com/fluxcd/pkg/apis/meta"
3532
"github.com/fluxcd/pkg/runtime/dependency"
3633
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
3734
)
@@ -80,7 +77,7 @@ func (r *GitRepositoryWatcher) Reconcile(req ctrl.Request) (ctrl.Result, error)
8077
// trigger apply for each kustomization using this Git repository
8178
for _, k := range sorted {
8279
name := types.NamespacedName(k)
83-
if err := r.requestReconciliation(name); err != nil {
80+
if err := requestReconciliation(r, name); err != nil {
8481
log.Error(err, "unable to annotate Kustomization", "kustomization", name)
8582
continue
8683
}
@@ -114,19 +111,3 @@ func (r *GitRepositoryWatcher) SetupWithManager(mgr ctrl.Manager) error {
114111
WithEventFilter(GitRepositoryRevisionChangePredicate{}).
115112
Complete(r)
116113
}
117-
118-
func (r *GitRepositoryWatcher) requestReconciliation(name types.NamespacedName) error {
119-
var kustomization kustomizev1.Kustomization
120-
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
121-
if err := r.Get(context.TODO(), name, &kustomization); err != nil {
122-
return err
123-
}
124-
125-
if kustomization.Annotations == nil {
126-
kustomization.Annotations = make(map[string]string)
127-
}
128-
kustomization.Annotations[meta.ReconcileAtAnnotation] = metav1.Now().String()
129-
err = r.Update(context.TODO(), &kustomization)
130-
return
131-
})
132-
}

controllers/kustomization_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ func (r *KustomizationReconciler) reconcile(
232232
kustomization kustomizev1.Kustomization,
233233
source sourcev1.Source) (kustomizev1.Kustomization, error) {
234234
// record the value of the reconciliation request, if any
235-
if v, ok := kustomization.GetAnnotations()[meta.ReconcileAtAnnotation]; ok {
236-
kustomization.Status.LastHandledReconcileAt = v
235+
if v, ok := meta.ReconcileAnnotationValue(kustomization.GetAnnotations()); ok {
236+
kustomization.Status.SetLastHandledReconcileRequest(v)
237237
}
238238

239239
// create tmp dir

controllers/kustomization_request.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"k8s.io/apimachinery/pkg/types"
8+
"k8s.io/client-go/util/retry"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
11+
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
12+
"github.com/fluxcd/pkg/apis/meta"
13+
)
14+
15+
func requestReconciliation(r client.Client, name types.NamespacedName) error {
16+
var kustomization kustomizev1.Kustomization
17+
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
18+
if err := r.Get(context.TODO(), name, &kustomization); err != nil {
19+
return err
20+
}
21+
22+
if kustomization.Annotations == nil {
23+
kustomization.Annotations = make(map[string]string)
24+
}
25+
kustomization.Annotations[meta.ReconcileRequestAnnotation] = metav1.Now().String()
26+
err = r.Update(context.TODO(), &kustomization)
27+
return
28+
})
29+
}

docs/api/kustomize.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -748,15 +748,17 @@ string
748748
</tr>
749749
<tr>
750750
<td>
751-
<code>lastHandledReconcileAt</code><br>
751+
<code>ReconcileRequestStatus</code><br>
752752
<em>
753-
string
753+
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#ReconcileRequestStatus">
754+
github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus
755+
</a>
754756
</em>
755757
</td>
756758
<td>
757-
<em>(Optional)</em>
758-
<p>LastHandledReconcileAt is the last manual reconciliation request (by
759-
annotating the Kustomization) handled by the reconciler.</p>
759+
<p>
760+
(Members of <code>ReconcileRequestStatus</code> are embedded into this type.)
761+
</p>
760762
</td>
761763
</tr>
762764
<tr>

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ replace github.com/fluxcd/kustomize-controller/api => ./api
66

77
require (
88
github.com/fluxcd/kustomize-controller/api v0.1.2
9-
github.com/fluxcd/pkg/apis/meta v0.0.2
10-
github.com/fluxcd/pkg/runtime v0.1.0
9+
github.com/fluxcd/pkg/apis/meta v0.1.0
10+
github.com/fluxcd/pkg/runtime v0.1.2
1111
github.com/fluxcd/pkg/testserver v0.0.2
1212
github.com/fluxcd/pkg/untar v0.0.5
1313
github.com/fluxcd/source-controller/api v0.1.1

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
149149
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
150150
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
151151
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
152+
github.com/fluxcd/pkg/apis/meta v0.1.0 h1:CfOYHYaHslhcb3QlzgKCOXl4ziCbA5zG/fUa1qFlHis=
153+
github.com/fluxcd/pkg/apis/meta v0.1.0/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
152154
github.com/fluxcd/pkg/runtime v0.1.0 h1:mCLj5GlQZqWtK3tvtZTmfgFOLsTUY1iqg3CmEyS1nRs=
153155
github.com/fluxcd/pkg/runtime v0.1.0/go.mod h1:OXkrYtDLw3GhclbzvnzfSktUyxRmC3FFhXj0tVVaIX8=
156+
github.com/fluxcd/pkg/runtime v0.1.2 h1:bKhjJGVOJgTQTWjqhwasyt69lBItq1ZWjX04rUkiypo=
157+
github.com/fluxcd/pkg/runtime v0.1.2/go.mod h1:HXYTNdkK8ulcT1mhuGhio9tsX65ACKaealtd/MsnkhM=
154158
github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk=
155159
github.com/fluxcd/pkg/testserver v0.0.2/go.mod h1:pgUZTh9aQ44FSTQo+5NFlh7YMbUfdz1B80DalW7k96Y=
156160
github.com/fluxcd/pkg/untar v0.0.5 h1:UGI3Ch1UIEIaqQvMicmImL1s9npQa64DJ/ozqHKB7gk=

hack/api-docs/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/runtime/dependency#CrossNamespaceDependencyReference"
2121
},
2222
{
23-
"typeMatchPrefix": "^github.com/fluxcd/pkg/apis/meta\\.Condition$",
24-
"docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/apis/meta#Condition"
23+
"typeMatchPrefix": "^github.com/fluxcd/pkg/apis/meta",
24+
"docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/apis/meta#{{ .TypeIdentifier }}"
2525
}
2626
],
2727
"typeDisplayNamePrefixOverrides": {

0 commit comments

Comments
 (0)