Skip to content

Commit 7c39649

Browse files
authored
Merge pull request #139 from fluxcd/v1alpha2-api
Add v1alpha2 API version
2 parents 448a313 + f746a11 commit 7c39649

18 files changed

+1908
-208
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ manifests: controller-gen
7676

7777
# Generate API reference documentation
7878
api-docs: gen-crd-api-reference-docs
79-
$(API_REF_GEN) -api-dir=./api/v1alpha1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/image-automation.md
79+
$(API_REF_GEN) -api-dir=./api/v1alpha2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/image-automation.md
8080

8181
# Run go mod tidy
8282
tidy:

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: v1alpha1
7+
- group: image
8+
kind: ImageUpdateAutomation
9+
version: v1alpha2
710
version: "2"

api/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.15
44

55
require (
66
github.com/fluxcd/pkg/apis/meta v0.8.0
7+
github.com/fluxcd/source-controller/api v0.10.0
78
k8s.io/apimachinery v0.20.2
89
sigs.k8s.io/controller-runtime v0.8.3
910
)

api/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
9090
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
9191
github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk=
9292
github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
93+
github.com/fluxcd/source-controller/api v0.10.0 h1:Mu4cAXtZ7yq/rIrab81q1jbbhWwUxxAZ2R5bZ1m8AxE=
94+
github.com/fluxcd/source-controller/api v0.10.0/go.mod h1:Vuw+7UqEUUOdkKBfTUPHwaQgbn6LL2FwqPDx2UAk7NE=
9395
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
9496
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
9597
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=

api/v1alpha2/doc.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2020 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 v1alpha2 contains API types for the image v1alpha2 API
18+
// group. The types here are concerned with automated updates to git,
19+
// based on metadata from OCI image registries gathered by the
20+
// image-reflector-controller. There is some rearrangement from
21+
// v1alpha1 to make room for future enhancements.
22+
//
23+
// +kubebuilder:object:generate=true
24+
// +groupName=image.toolkit.fluxcd.io
25+
package v1alpha2

api/v1alpha2/git.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2020 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 v1alpha2
18+
19+
import (
20+
"github.com/fluxcd/pkg/apis/meta"
21+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
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+
type GitCheckoutSpec struct {
43+
// Reference gives a branch, tag or commit to clone from the Git
44+
// repository.
45+
// +required
46+
Reference sourcev1.GitRepositoryRef `json:"ref"`
47+
}
48+
49+
// CommitSpec specifies how to commit changes to the git repository
50+
type CommitSpec struct {
51+
// Author gives the email and optionally the name to use as the
52+
// author of commits.
53+
// +required
54+
Author CommitUser `json:"author"`
55+
// SigningKey provides the option to sign commits with a GPG key
56+
// +optional
57+
SigningKey *SigningKey `json:"signingKey,omitempty"`
58+
// MessageTemplate provides a template for the commit message,
59+
// into which will be interpolated the details of the change made.
60+
// +optional
61+
MessageTemplate string `json:"messageTemplate,omitempty"`
62+
}
63+
64+
type CommitUser struct {
65+
// Name gives the name to provide when making a commit.
66+
// +optional
67+
Name string `json:"name,omitempty"`
68+
// Email gives the email to provide when making a commit.
69+
// +required
70+
Email string `json:"email"`
71+
}
72+
73+
// SigningKey references a Kubernetes secret that contains a GPG keypair
74+
type SigningKey struct {
75+
// SecretRef holds the name to a secret that contains a 'git.asc' key
76+
// corresponding to the ASCII Armored file containing the GPG signing
77+
// keypair as the value. It must be in the same namespace as the
78+
// ImageUpdateAutomation.
79+
// +required
80+
SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"`
81+
}
82+
83+
// PushSpec specifies how and where to push commits.
84+
type PushSpec struct {
85+
// Branch specifies that commits should be pushed to the branch
86+
// named. The branch is created using `.spec.checkout.branch` as the
87+
// starting point, if it doesn't already exist.
88+
// +required
89+
Branch string `json:"branch"`
90+
}

api/v1alpha2/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2020 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 v1alpha2 contains API Schema definitions for the image v1alpha2 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=image.toolkit.fluxcd.io
20+
package v1alpha2
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: "v1alpha2"}
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+
)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Copyright 2020 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 v1alpha2
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
"github.com/fluxcd/pkg/apis/meta"
23+
)
24+
25+
const ImageUpdateAutomationKind = "ImageUpdateAutomation"
26+
27+
// ImageUpdateAutomationSpec defines the desired state of ImageUpdateAutomation
28+
type ImageUpdateAutomationSpec struct {
29+
// SourceRef refers to the resource giving access details
30+
// to a git repository.
31+
// +required
32+
SourceRef SourceReference `json:"sourceRef"`
33+
// GitSpec contains all the git-specific definitions. This is
34+
// technically optional, but in practice mandatory until there are
35+
// other kinds of source allowed.
36+
// +optional
37+
GitSpec *GitSpec `json:"git,omitempty"`
38+
39+
// Interval gives an lower bound for how often the automation
40+
// run should be attempted.
41+
// +required
42+
Interval metav1.Duration `json:"interval"`
43+
44+
// Update gives the specification for how to update the files in
45+
// the repository. This can be left empty, to use the default
46+
// value.
47+
// +kubebuilder:default={"strategy":"Setters"}
48+
Update *UpdateStrategy `json:"update,omitempty"`
49+
50+
// Suspend tells the controller to not run this automation, until
51+
// it is unset (or set to false). Defaults to false.
52+
// +optional
53+
Suspend bool `json:"suspend,omitempty"`
54+
}
55+
56+
// UpdateStrategyName is the type for names that go in
57+
// .update.strategy. NB the value in the const immediately below.
58+
// +kubebuilder:validation:Enum=Setters
59+
type UpdateStrategyName string
60+
61+
const (
62+
// UpdateStrategySetters is the name of the update strategy that
63+
// uses kyaml setters. NB the value in the enum annotation for the
64+
// type, above.
65+
UpdateStrategySetters UpdateStrategyName = "Setters"
66+
)
67+
68+
// UpdateStrategy is a union of the various strategies for updating
69+
// the Git repository. Parameters for each strategy (if any) can be
70+
// inlined here.
71+
type UpdateStrategy struct {
72+
// Strategy names the strategy to be used.
73+
// +required
74+
// +kubebuilder:default=Setters
75+
Strategy UpdateStrategyName `json:"strategy"`
76+
77+
// Path to the directory containing the manifests to be updated.
78+
// Defaults to 'None', which translates to the root path
79+
// of the GitRepositoryRef.
80+
// +optional
81+
Path string `json:"path,omitempty"`
82+
}
83+
84+
// ImageUpdateAutomationStatus defines the observed state of ImageUpdateAutomation
85+
type ImageUpdateAutomationStatus struct {
86+
// LastAutomationRunTime records the last time the controller ran
87+
// this automation through to completion (even if no updates were
88+
// made).
89+
// +optional
90+
LastAutomationRunTime *metav1.Time `json:"lastAutomationRunTime,omitempty"`
91+
// LastPushCommit records the SHA1 of the last commit made by the
92+
// controller, for this automation object
93+
// +optional
94+
LastPushCommit string `json:"lastPushCommit,omitempty"`
95+
// LastPushTime records the time of the last pushed change.
96+
// +optional
97+
LastPushTime *metav1.Time `json:"lastPushTime,omitempty"`
98+
// +optional
99+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
100+
// +optional
101+
Conditions []metav1.Condition `json:"conditions,omitempty"`
102+
meta.ReconcileRequestStatus `json:",inline"`
103+
}
104+
105+
const (
106+
// GitNotAvailableReason is used for ConditionReady when the
107+
// automation run cannot proceed because the git repository is
108+
// missing or cannot be cloned.
109+
GitNotAvailableReason = "GitRepositoryNotAvailable"
110+
// NoStrategyReason is used for ConditionReady when the automation
111+
// run cannot proceed because there is no update strategy given in
112+
// the spec.
113+
NoStrategyReason = "MissingUpdateStrategy"
114+
)
115+
116+
// SetImageUpdateAutomationReadiness sets the ready condition with the given status, reason and message.
117+
func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav1.ConditionStatus, reason, message string) {
118+
auto.Status.ObservedGeneration = auto.ObjectMeta.Generation
119+
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
120+
}
121+
122+
//+kubebuilder:storageversion
123+
//+kubebuilder:object:root=true
124+
//+kubebuilder:subresource:status
125+
//+kubebuilder:printcolumn:name="Last run",type=string,JSONPath=`.status.lastAutomationRunTime`
126+
127+
// ImageUpdateAutomation is the Schema for the imageupdateautomations API
128+
type ImageUpdateAutomation struct {
129+
metav1.TypeMeta `json:",inline"`
130+
metav1.ObjectMeta `json:"metadata,omitempty"`
131+
132+
Spec ImageUpdateAutomationSpec `json:"spec,omitempty"`
133+
Status ImageUpdateAutomationStatus `json:"status,omitempty"`
134+
}
135+
136+
func (auto *ImageUpdateAutomation) GetStatusConditions() *[]metav1.Condition {
137+
return &auto.Status.Conditions
138+
}
139+
140+
//+kubebuilder:object:root=true
141+
142+
// ImageUpdateAutomationList contains a list of ImageUpdateAutomation
143+
type ImageUpdateAutomationList struct {
144+
metav1.TypeMeta `json:",inline"`
145+
metav1.ListMeta `json:"metadata,omitempty"`
146+
Items []ImageUpdateAutomation `json:"items"`
147+
}
148+
149+
func init() {
150+
SchemeBuilder.Register(&ImageUpdateAutomation{}, &ImageUpdateAutomationList{})
151+
}

api/v1alpha2/reference.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2020 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 v1alpha2
18+
19+
// SourceReference contains enough information to let you locate the
20+
// typed, referenced source object.
21+
type SourceReference struct {
22+
// API version of the referent
23+
// +optional
24+
APIVersion string `json:"apiVersion,omitempty"`
25+
26+
// Kind of the referent
27+
// +kubebuilder:validation:Enum=GitRepository
28+
// +kubebuilder:default=GitRepository
29+
// +required
30+
Kind string `json:"kind"`
31+
32+
// Name of the referent
33+
// +required
34+
Name string `json:"name"`
35+
}

0 commit comments

Comments
 (0)