Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pkg/runtime and apis/meta #325

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ CACHE := cache

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

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

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

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

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

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

run: $(LIBGIT2) generate fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config
go run $(GO_STATIC_FLAGS) ./main.go --log-level=${LOG_LEVEL} --log-encoding=console
Expand Down Expand Up @@ -172,8 +172,8 @@ api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
$(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

tidy: ## Run go mod tidy
cd api; rm -f go.sum; go mod tidy
rm -f go.sum; go mod tidy
cd api; rm -f go.sum; go mod tidy -compat=1.17
rm -f go.sum; go mod tidy -compat=1.17

fmt: ## Run go fmt against code
go fmt ./...
Expand Down
10 changes: 5 additions & 5 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/fluxcd/image-automation-controller/api
go 1.17

require (
github.com/fluxcd/pkg/apis/meta v0.10.2
github.com/fluxcd/source-controller/api v0.21.0
k8s.io/apimachinery v0.23.1
sigs.k8s.io/controller-runtime v0.11.0
github.com/fluxcd/pkg/apis/meta v0.12.1
github.com/fluxcd/source-controller/api v0.22.0
k8s.io/apimachinery v0.23.4
sigs.k8s.io/controller-runtime v0.11.1
)

require (
Expand All @@ -25,5 +25,5 @@ require (
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
695 changes: 11 additions & 684 deletions api/go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion api/v1alpha1/imageupdateautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -169,7 +170,13 @@ const (
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: status,
Reason: reason,
Message: message,
}
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
}

// +kubebuilder:object:root=true
Expand Down
9 changes: 8 additions & 1 deletion api/v1alpha2/imageupdateautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha2

import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -116,7 +117,13 @@ const (
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: status,
Reason: reason,
Message: message,
}
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
}

//+kubebuilder:object:root=true
Expand Down
27 changes: 27 additions & 0 deletions api/v1beta1/condition_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2022 The Flux authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

const (
// ReconciliationSucceededReason represents the fact that
// the reconciliation succeeded.
ReconciliationSucceededReason string = "ReconciliationSucceeded"

// ReconciliationFailedReason represents the fact that
// the reconciliation failed.
ReconciliationFailedReason string = "ReconciliationFailed"
)
2 changes: 1 addition & 1 deletion api/v1beta1/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1beta1

import (
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
)

type GitSpec struct {
Expand Down
9 changes: 8 additions & 1 deletion api/v1beta1/imageupdateautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -116,7 +117,13 @@ const (
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: status,
Reason: reason,
Message: message,
}
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
}

//+kubebuilder:storageversion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
details to a git repository to update files in.
properties:
name:
description: Name of the referent
description: Name of the referent.
type: string
required:
- name
Expand Down Expand Up @@ -91,7 +91,7 @@ spec:
be in the same namespace as the ImageUpdateAutomation.
properties:
name:
description: Name of the referent
description: Name of the referent.
type: string
required:
- name
Expand Down Expand Up @@ -228,7 +228,8 @@ spec:
type: string
lastHandledReconcileAt:
description: LastHandledReconcileAt holds the value of the most recent
reconcile request value, so a change can be detected.
reconcile request value, so a change of the annotation value can
be detected.
type: string
lastPushCommit:
description: LastPushCommit records the SHA1 of the last commit made
Expand Down Expand Up @@ -340,7 +341,7 @@ spec:
value. It must be in the same namespace as the ImageUpdateAutomation.
properties:
name:
description: Name of the referent
description: Name of the referent.
type: string
required:
- name
Expand Down Expand Up @@ -499,7 +500,8 @@ spec:
type: string
lastHandledReconcileAt:
description: LastHandledReconcileAt holds the value of the most recent
reconcile request value, so a change can be detected.
reconcile request value, so a change of the annotation value can
be detected.
type: string
lastPushCommit:
description: LastPushCommit records the SHA1 of the last commit made
Expand Down Expand Up @@ -559,19 +561,24 @@ spec:
from the Git repository.
properties:
branch:
description: The Git branch to checkout, defaults to master.
description: "Branch to check out, defaults to 'master'
if no other field is defined. \n When GitRepositorySpec.GitImplementation
is set to 'go-git', a shallow clone of the specified
branch is performed."
type: string
commit:
description: The Git commit SHA to checkout, if specified
Tag filters will be ignored.
description: "Commit SHA to check out, takes precedence
over all reference fields. \n When GitRepositorySpec.GitImplementation
is set to 'go-git', this can be combined with Branch
to shallow clone the branch, in which the commit is
expected to exist."
type: string
semver:
description: The Git tag semver expression, takes precedence
over Tag.
description: SemVer tag expression to check out, takes
precedence over Tag.
type: string
tag:
description: The Git tag to checkout, takes precedence
over Branch.
description: Tag to check out, takes precedence over Branch.
type: string
type: object
required:
Expand Down Expand Up @@ -611,7 +618,7 @@ spec:
value. It must be in the same namespace as the ImageUpdateAutomation.
properties:
name:
description: Name of the referent
description: Name of the referent.
type: string
required:
- name
Expand Down Expand Up @@ -776,7 +783,8 @@ spec:
type: string
lastHandledReconcileAt:
description: LastHandledReconcileAt holds the value of the most recent
reconcile request value, so a change can be detected.
reconcile request value, so a change of the annotation value can
be detected.
type: string
lastPushCommit:
description: LastPushCommit records the SHA1 of the last commit made
Expand Down
33 changes: 11 additions & 22 deletions controllers/imageupdateautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import (
"github.com/fluxcd/pkg/runtime/logger"
"github.com/fluxcd/pkg/runtime/metrics"
"github.com/fluxcd/pkg/runtime/predicates"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/source-controller/pkg/git"
gitlibgit2 "github.com/fluxcd/source-controller/pkg/git/libgit2"
gitstrat "github.com/fluxcd/source-controller/pkg/git/strategy"
Expand All @@ -86,11 +86,10 @@ type TemplateData struct {
// ImageUpdateAutomationReconciler reconciles a ImageUpdateAutomation object
type ImageUpdateAutomationReconciler struct {
client.Client
Scheme *runtime.Scheme
EventRecorder kuberecorder.EventRecorder
ExternalEventRecorder *events.Recorder
MetricsRecorder *metrics.Recorder
NoCrossNamespaceRef bool
Scheme *runtime.Scheme
EventRecorder kuberecorder.EventRecorder
MetricsRecorder *metrics.Recorder
NoCrossNamespaceRef bool
}

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

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

func (r *ImageUpdateAutomationReconciler) event(ctx context.Context, auto imagev1.ImageUpdateAutomation, severity, msg string) {
if r.EventRecorder != nil {
r.EventRecorder.Event(&auto, "Normal", severity, msg)
}
if r.ExternalEventRecorder != nil {
objRef, err := reference.GetReference(r.Scheme, &auto)
if err != nil {
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
return
}

if err := r.ExternalEventRecorder.Eventf(*objRef, nil, severity, severity, msg); err != nil {
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
return
}
eventtype := "Normal"
if severity == events.EventSeverityError {
eventtype = "Warning"
}
r.EventRecorder.Eventf(&auto, eventtype, severity, msg)
}

func (r *ImageUpdateAutomationReconciler) recordReadinessMetric(ctx context.Context, auto *imagev1.ImageUpdateAutomation) {
Expand Down
8 changes: 5 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"

imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
// +kubebuilder:scaffold:imports
Expand Down Expand Up @@ -87,9 +87,11 @@ var _ = BeforeSuite(func(done Done) {
})
Expect(err).ToNot(HaveOccurred())

controllerName := "image-automation-controller"
imageAutoReconciler = &ImageUpdateAutomationReconciler{
Client: k8sManager.GetClient(),
Scheme: scheme.Scheme,
Client: k8sManager.GetClient(),
Scheme: scheme.Scheme,
EventRecorder: k8sManager.GetEventRecorderFor(controllerName),
}
Expect(imageAutoReconciler.SetupWithManager(k8sManager, ImageUpdateAutomationReconcilerOptions{})).To(Succeed())

Expand Down
2 changes: 1 addition & 1 deletion controllers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/gittestserver"
"github.com/fluxcd/pkg/ssh"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"

imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
"github.com/fluxcd/image-automation-controller/pkg/test"
Expand Down
4 changes: 1 addition & 3 deletions docs/api/image-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ string
<td>
<code>ref</code><br>
<em>
<a href="https://godoc.org/github.com/fluxcd/source-controller/api/v1beta1#GitRepositoryRef">
Source /v1beta1.GitRepositoryRef
</a>
Source /v1beta2.GitRepositoryRef
</em>
</td>
<td>
Expand Down
Loading