Skip to content

Commit c79d689

Browse files
authored
Merge pull request #325 from fluxcd/runtime-meta-rc
2 parents 7f13552 + 307950d commit c79d689

20 files changed

+290
-1020
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ CACHE := cache
2121

2222
# Version of the source-controller from which to get the GitRepository CRD.
2323
# Change this if you bump the source-controller/api version in go.mod.
24-
SOURCE_VER ?= v0.21.1
24+
SOURCE_VER ?= v0.22.0
2525

2626
# Version of the image-reflector-controller from which to get the ImagePolicy CRD.
2727
# Change this if you bump the image-reflector-controller/api version in go.mod.
28-
REFLECTOR_VER ?= v0.16.0
28+
REFLECTOR_VER ?= v0.17.0
2929

3030
# Repository root based on Git metadata.
3131
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
@@ -136,15 +136,15 @@ ifeq ($(shell uname -s),Darwin)
136136
endif
137137

138138
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
139-
test: $(LIBGIT2) test-api test_deps generate fmt vet manifests api-docs install-envtest ## Run tests
139+
test: $(LIBGIT2) tidy test-api test_deps generate fmt vet manifests api-docs install-envtest ## Run tests
140140
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
141141
go test $(GO_STATIC_FLAGS) ./... -coverprofile cover.out
142142

143143
test-api: ## Run api tests
144144
cd api; go test ./... -coverprofile cover.out
145145

146146
manager: $(LIBGIT2) generate fmt vet ## Build manager binary
147-
go build ./main.go
147+
go build -o $(BUILD_DIR)/bin/manager ./main.go
148148

149149
run: $(LIBGIT2) generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
150150
go run $(GO_STATIC_FLAGS) ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
@@ -172,8 +172,8 @@ api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
172172
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/image-automation.md
173173

174174
tidy: ## Run go mod tidy
175-
cd api; rm -f go.sum; go mod tidy
176-
rm -f go.sum; go mod tidy
175+
cd api; rm -f go.sum; go mod tidy -compat=1.17
176+
rm -f go.sum; go mod tidy -compat=1.17
177177

178178
fmt: ## Run go fmt against code
179179
go fmt ./...

api/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module github.com/fluxcd/image-automation-controller/api
33
go 1.17
44

55
require (
6-
github.com/fluxcd/pkg/apis/meta v0.10.2
7-
github.com/fluxcd/source-controller/api v0.21.0
8-
k8s.io/apimachinery v0.23.1
9-
sigs.k8s.io/controller-runtime v0.11.0
6+
github.com/fluxcd/pkg/apis/meta v0.12.1
7+
github.com/fluxcd/source-controller/api v0.22.0
8+
k8s.io/apimachinery v0.23.4
9+
sigs.k8s.io/controller-runtime v0.11.1
1010
)
1111

1212
require (
@@ -25,5 +25,5 @@ require (
2525
k8s.io/klog/v2 v2.30.0 // indirect
2626
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // indirect
2727
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
28-
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
28+
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
2929
)

api/go.sum

Lines changed: 11 additions & 684 deletions
Large diffs are not rendered by default.

api/v1alpha1/imageupdateautomation_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122

2223
"github.com/fluxcd/pkg/apis/meta"
@@ -169,7 +170,13 @@ const (
169170
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
170171
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
171172
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
172-
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
173+
newCondition := metav1.Condition{
174+
Type: meta.ReadyCondition,
175+
Status: status,
176+
Reason: reason,
177+
Message: message,
178+
}
179+
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
173180
}
174181

175182
// +kubebuilder:object:root=true

api/v1alpha2/imageupdateautomation_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha2
1818

1919
import (
20+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122

2223
"github.com/fluxcd/pkg/apis/meta"
@@ -116,7 +117,13 @@ const (
116117
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
117118
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
118119
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
119-
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
120+
newCondition := metav1.Condition{
121+
Type: meta.ReadyCondition,
122+
Status: status,
123+
Reason: reason,
124+
Message: message,
125+
}
126+
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
120127
}
121128

122129
//+kubebuilder:object:root=true

api/v1beta1/condition_types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
const (
20+
// ReconciliationSucceededReason represents the fact that
21+
// the reconciliation succeeded.
22+
ReconciliationSucceededReason string = "ReconciliationSucceeded"
23+
24+
// ReconciliationFailedReason represents the fact that
25+
// the reconciliation failed.
26+
ReconciliationFailedReason string = "ReconciliationFailed"
27+
)

api/v1beta1/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package v1beta1
1818

1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
21-
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
21+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
2222
)
2323

2424
type GitSpec struct {

api/v1beta1/imageupdateautomation_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122

2223
"github.com/fluxcd/pkg/apis/meta"
@@ -116,7 +117,13 @@ const (
116117
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
117118
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
118119
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
119-
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
120+
newCondition := metav1.Condition{
121+
Type: meta.ReadyCondition,
122+
Status: status,
123+
Reason: reason,
124+
Message: message,
125+
}
126+
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
120127
}
121128

122129
//+kubebuilder:storageversion

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ spec:
5555
details to a git repository to update files in.
5656
properties:
5757
name:
58-
description: Name of the referent
58+
description: Name of the referent.
5959
type: string
6060
required:
6161
- name
@@ -91,7 +91,7 @@ spec:
9191
be in the same namespace as the ImageUpdateAutomation.
9292
properties:
9393
name:
94-
description: Name of the referent
94+
description: Name of the referent.
9595
type: string
9696
required:
9797
- name
@@ -228,7 +228,8 @@ spec:
228228
type: string
229229
lastHandledReconcileAt:
230230
description: LastHandledReconcileAt holds the value of the most recent
231-
reconcile request value, so a change can be detected.
231+
reconcile request value, so a change of the annotation value can
232+
be detected.
232233
type: string
233234
lastPushCommit:
234235
description: LastPushCommit records the SHA1 of the last commit made
@@ -340,7 +341,7 @@ spec:
340341
value. It must be in the same namespace as the ImageUpdateAutomation.
341342
properties:
342343
name:
343-
description: Name of the referent
344+
description: Name of the referent.
344345
type: string
345346
required:
346347
- name
@@ -499,7 +500,8 @@ spec:
499500
type: string
500501
lastHandledReconcileAt:
501502
description: LastHandledReconcileAt holds the value of the most recent
502-
reconcile request value, so a change can be detected.
503+
reconcile request value, so a change of the annotation value can
504+
be detected.
503505
type: string
504506
lastPushCommit:
505507
description: LastPushCommit records the SHA1 of the last commit made
@@ -559,19 +561,24 @@ spec:
559561
from the Git repository.
560562
properties:
561563
branch:
562-
description: The Git branch to checkout, defaults to master.
564+
description: "Branch to check out, defaults to 'master'
565+
if no other field is defined. \n When GitRepositorySpec.GitImplementation
566+
is set to 'go-git', a shallow clone of the specified
567+
branch is performed."
563568
type: string
564569
commit:
565-
description: The Git commit SHA to checkout, if specified
566-
Tag filters will be ignored.
570+
description: "Commit SHA to check out, takes precedence
571+
over all reference fields. \n When GitRepositorySpec.GitImplementation
572+
is set to 'go-git', this can be combined with Branch
573+
to shallow clone the branch, in which the commit is
574+
expected to exist."
567575
type: string
568576
semver:
569-
description: The Git tag semver expression, takes precedence
570-
over Tag.
577+
description: SemVer tag expression to check out, takes
578+
precedence over Tag.
571579
type: string
572580
tag:
573-
description: The Git tag to checkout, takes precedence
574-
over Branch.
581+
description: Tag to check out, takes precedence over Branch.
575582
type: string
576583
type: object
577584
required:
@@ -611,7 +618,7 @@ spec:
611618
value. It must be in the same namespace as the ImageUpdateAutomation.
612619
properties:
613620
name:
614-
description: Name of the referent
621+
description: Name of the referent.
615622
type: string
616623
required:
617624
- name
@@ -776,7 +783,8 @@ spec:
776783
type: string
777784
lastHandledReconcileAt:
778785
description: LastHandledReconcileAt holds the value of the most recent
779-
reconcile request value, so a change can be detected.
786+
reconcile request value, so a change of the annotation value can
787+
be detected.
780788
type: string
781789
lastPushCommit:
782790
description: LastPushCommit records the SHA1 of the last commit made

controllers/imageupdateautomation_controller.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import (
5959
"github.com/fluxcd/pkg/runtime/logger"
6060
"github.com/fluxcd/pkg/runtime/metrics"
6161
"github.com/fluxcd/pkg/runtime/predicates"
62-
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
62+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
6363
"github.com/fluxcd/source-controller/pkg/git"
6464
gitlibgit2 "github.com/fluxcd/source-controller/pkg/git/libgit2"
6565
gitstrat "github.com/fluxcd/source-controller/pkg/git/strategy"
@@ -86,11 +86,10 @@ type TemplateData struct {
8686
// ImageUpdateAutomationReconciler reconciles a ImageUpdateAutomation object
8787
type ImageUpdateAutomationReconciler struct {
8888
client.Client
89-
Scheme *runtime.Scheme
90-
EventRecorder kuberecorder.EventRecorder
91-
ExternalEventRecorder *events.Recorder
92-
MetricsRecorder *metrics.Recorder
93-
NoCrossNamespaceRef bool
89+
Scheme *runtime.Scheme
90+
EventRecorder kuberecorder.EventRecorder
91+
MetricsRecorder *metrics.Recorder
92+
NoCrossNamespaceRef bool
9493
}
9594

9695
type ImageUpdateAutomationReconcilerOptions struct {
@@ -149,7 +148,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
149148
// failWithError is a helper for bailing on the reconciliation.
150149
failWithError := func(err error) (ctrl.Result, error) {
151150
r.event(ctx, auto, events.EventSeverityError, err.Error())
152-
imagev1.SetImageUpdateAutomationReadiness(&auto, metav1.ConditionFalse, meta.ReconciliationFailedReason, err.Error())
151+
imagev1.SetImageUpdateAutomationReadiness(&auto, metav1.ConditionFalse, imagev1.ReconciliationFailedReason, err.Error())
153152
if err := r.patchStatus(ctx, req, auto.Status); err != nil {
154153
log.Error(err, "failed to reconcile")
155154
}
@@ -366,7 +365,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
366365

367366
// Getting to here is a successful run.
368367
auto.Status.LastAutomationRunTime = &metav1.Time{Time: now}
369-
imagev1.SetImageUpdateAutomationReadiness(&auto, metav1.ConditionTrue, meta.ReconciliationSucceededReason, statusMessage)
368+
imagev1.SetImageUpdateAutomationReadiness(&auto, metav1.ConditionTrue, imagev1.ReconciliationSucceededReason, statusMessage)
370369
if err := r.patchStatus(ctx, req, auto.Status); err != nil {
371370
return ctrl.Result{Requeue: true}, err
372371
}
@@ -826,21 +825,11 @@ func libgit2PushError(err error) error {
826825
// --- events, metrics
827826

828827
func (r *ImageUpdateAutomationReconciler) event(ctx context.Context, auto imagev1.ImageUpdateAutomation, severity, msg string) {
829-
if r.EventRecorder != nil {
830-
r.EventRecorder.Event(&auto, "Normal", severity, msg)
831-
}
832-
if r.ExternalEventRecorder != nil {
833-
objRef, err := reference.GetReference(r.Scheme, &auto)
834-
if err != nil {
835-
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
836-
return
837-
}
838-
839-
if err := r.ExternalEventRecorder.Eventf(*objRef, nil, severity, severity, msg); err != nil {
840-
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
841-
return
842-
}
828+
eventtype := "Normal"
829+
if severity == events.EventSeverityError {
830+
eventtype = "Warning"
843831
}
832+
r.EventRecorder.Eventf(&auto, eventtype, severity, msg)
844833
}
845834

846835
func (r *ImageUpdateAutomationReconciler) recordReadinessMetric(ctx context.Context, auto *imagev1.ImageUpdateAutomation) {

0 commit comments

Comments
 (0)