Skip to content

Commit ffcb4d1

Browse files
authored
Merge pull request #647 from fluxcd/refactor
ImageUpdateAutomation v1beta2 API with refactored controller
2 parents 862e56c + d0a2494 commit ffcb4d1

38 files changed

+7898
-1821
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc.
142142
cd api; $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./..." output:crd:artifacts:config="../config/crd/bases"
143143

144144
api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
145-
$(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/v1beta1/image-automation.md
145+
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1beta2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/v1beta2/image-automation.md
146146

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

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ resources:
44
- group: image
55
kind: ImageUpdateAutomation
66
version: v1beta1
7+
- group: image
8+
kind: ImageUpdateAutomation
9+
version: v1beta2
710
version: "2"

api/v1beta1/imageupdateautomation_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav
133133
apimeta.SetStatusCondition(auto.GetStatusConditions(), newCondition)
134134
}
135135

136-
//+kubebuilder:storageversion
137136
//+kubebuilder:object:root=true
138137
//+kubebuilder:subresource:status
139138
//+kubebuilder:printcolumn:name="Last run",type=string,JSONPath=`.status.lastAutomationRunTime`

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/condition_types.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2024 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 v1beta2
18+
19+
const (
20+
// InvalidUpdateStrategyReason represents an invalid image update strategy
21+
// configuration.
22+
InvalidUpdateStrategyReason string = "InvalidUpdateStrategy"
23+
24+
// InvalidSourceConfigReason represents an invalid source configuration.
25+
InvalidSourceConfigReason string = "InvalidSourceConfiguration"
26+
27+
// SourceManagerFailedReason represents a failure in the SourceManager which
28+
// manages the source.
29+
SourceManagerFailedReason string = "SourceManagerFailed"
30+
31+
// GitOperationFailedReason represents a failure in Git source operation.
32+
GitOperationFailedReason string = "GitOperationFailed"
33+
34+
// UpdateFailedReason represents a failure during source update.
35+
UpdateFailedReason string = "UpdateFailed"
36+
37+
// InvalidPolicySelectorReason represents an invalid policy selector.
38+
InvalidPolicySelectorReason string = "InvalidPolicySelector"
39+
)
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Flux authors
2+
Copyright 2024 The Flux authors
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -14,22 +14,11 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package controller
18-
19-
import (
20-
"testing"
21-
22-
fuzz "github.com/AdaLogics/go-fuzz-headers"
23-
)
24-
25-
func Fuzz_templateMsg(f *testing.F) {
26-
f.Add("template", []byte{})
27-
f.Add("", []byte{})
28-
29-
f.Fuzz(func(t *testing.T, template string, seed []byte) {
30-
var values TemplateData
31-
fuzz.NewConsumer(seed).GenerateStruct(&values)
32-
33-
_, _ = templateMsg(template, &values)
34-
})
35-
}
17+
// Package v1beta2 contains API types for the image API group, version
18+
// v1beta2. The types here are concerned with automated updates to
19+
// git, based on metadata from OCI image registries gathered by the
20+
// image-reflector-controller.
21+
//
22+
// +kubebuilder:object:generate=true
23+
// +groupName=image.toolkit.fluxcd.io
24+
package v1beta2

api/v1beta2/git.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
Copyright 2024 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 v1beta2
18+
19+
import (
20+
"github.com/fluxcd/pkg/apis/meta"
21+
sourcev1 "github.com/fluxcd/source-controller/api/v1"
22+
)
23+
24+
type GitSpec struct {
25+
// Checkout gives the parameters for cloning the git repository,
26+
// ready to make changes. If not present, the `spec.ref` field from the
27+
// referenced `GitRepository` or its default will be used.
28+
// +optional
29+
Checkout *GitCheckoutSpec `json:"checkout,omitempty"`
30+
31+
// Commit specifies how to commit to the git repository.
32+
// +required
33+
Commit CommitSpec `json:"commit"`
34+
35+
// Push specifies how and where to push commits made by the
36+
// automation. If missing, commits are pushed (back) to
37+
// `.spec.checkout.branch` or its default.
38+
// +optional
39+
Push *PushSpec `json:"push,omitempty"`
40+
}
41+
42+
// HasRefspec returns if the GitSpec has a Refspec.
43+
func (gs GitSpec) HasRefspec() bool {
44+
if gs.Push == nil {
45+
return false
46+
}
47+
return gs.Push.Refspec != ""
48+
}
49+
50+
type GitCheckoutSpec struct {
51+
// Reference gives a branch, tag or commit to clone from the Git
52+
// repository.
53+
// +required
54+
Reference sourcev1.GitRepositoryRef `json:"ref"`
55+
}
56+
57+
// CommitSpec specifies how to commit changes to the git repository
58+
type CommitSpec struct {
59+
// Author gives the email and optionally the name to use as the
60+
// author of commits.
61+
// +required
62+
Author CommitUser `json:"author"`
63+
// SigningKey provides the option to sign commits with a GPG key
64+
// +optional
65+
SigningKey *SigningKey `json:"signingKey,omitempty"`
66+
// MessageTemplate provides a template for the commit message,
67+
// into which will be interpolated the details of the change made.
68+
// +optional
69+
MessageTemplate string `json:"messageTemplate,omitempty"`
70+
}
71+
72+
type CommitUser struct {
73+
// Name gives the name to provide when making a commit.
74+
// +optional
75+
Name string `json:"name,omitempty"`
76+
// Email gives the email to provide when making a commit.
77+
// +required
78+
Email string `json:"email"`
79+
}
80+
81+
// SigningKey references a Kubernetes secret that contains a GPG keypair
82+
type SigningKey struct {
83+
// SecretRef holds the name to a secret that contains a 'git.asc' key
84+
// corresponding to the ASCII Armored file containing the GPG signing
85+
// keypair as the value. It must be in the same namespace as the
86+
// ImageUpdateAutomation.
87+
// +required
88+
SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"`
89+
}
90+
91+
// PushSpec specifies how and where to push commits.
92+
type PushSpec struct {
93+
// Branch specifies that commits should be pushed to the branch
94+
// named. The branch is created using `.spec.checkout.branch` as the
95+
// starting point, if it doesn't already exist.
96+
// +optional
97+
Branch string `json:"branch,omitempty"`
98+
99+
// Refspec specifies the Git Refspec to use for a push operation.
100+
// If both Branch and Refspec are provided, then the commit is pushed
101+
// to the branch and also using the specified refspec.
102+
// For more details about Git Refspecs, see:
103+
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
104+
// +optional
105+
Refspec string `json:"refspec,omitempty"`
106+
107+
// Options specifies the push options that are sent to the Git
108+
// server when performing a push operation. For details, see:
109+
// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
110+
// +optional
111+
Options map[string]string `json:"options,omitempty"`
112+
}

api/v1beta2/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024 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 v1beta2 contains API Schema definitions for the image v1beta2 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=image.toolkit.fluxcd.io
20+
package v1beta2
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "image.toolkit.fluxcd.io", Version: "v1beta2"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)