Skip to content

Commit 5711c59

Browse files
authored
Merge pull request #191 from fluxcd/api-v1beta1
Graduate to v1beta1
2 parents c1533ea + fd52463 commit 5711c59

21 files changed

+1525
-75
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
notes
22

3-
# This is downloaded in the Makefile
3+
# Thes are downloaded in the Makefile
4+
cache/*
45
controllers/testdata/crds/*
56

67
# Binaries for programs and plugins

Makefile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ IMG ?= fluxcd/image-automation-controller:latest
33
# Produce CRDs that work back to Kubernetes 1.16
44
CRD_OPTIONS ?= crd:crdVersions=v1
55

6+
# Directory with versioned, downloaded things
7+
CACHE:=cache
8+
69
# Version of the source-controller from which to get the GitRepository CRD.
710
# Change this if you bump the source-controller/api version in go.mod.
811
SOURCE_VER ?= v0.15.2
912

1013
# Version of the image-reflector-controller from which to get the ImagePolicy CRD.
1114
# Change this if you bump the image-reflector-controller/api version in go.mod.
12-
REFLECTOR_VER ?= v0.10.0
15+
REFLECTOR_VER ?= v0.11.0
1316

1417
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1518
ifeq (,$(shell go env GOBIN))
@@ -26,20 +29,28 @@ LOG_LEVEL?=info
2629
all: manager
2730

2831
# Running the tests requires the source.toolkit.fluxcd.io CRDs
29-
test_deps: ${TEST_CRDS}/imagepolicies_${REFLECTOR_VER}.yaml ${TEST_CRDS}/gitrepositories_${SOURCE_VER}.yaml
32+
test_deps: ${TEST_CRDS}/imagepolicies.yaml ${TEST_CRDS}/gitrepositories.yaml
3033

3134
clean_test_deps:
3235
rm -r ${TEST_CRDS}
3336

34-
${TEST_CRDS}/gitrepositories_${SOURCE_VER}.yaml:
37+
${TEST_CRDS}/imagepolicies.yaml: ${CACHE}/imagepolicies_${REFLECTOR_VER}.yaml
3538
mkdir -p ${TEST_CRDS}
36-
curl -s --fail https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER}/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml \
37-
-o ${TEST_CRDS}/gitrepositories_${SOURCE_VER}.yaml
39+
cp $^ $@
3840

39-
${TEST_CRDS}/imagepolicies_${REFLECTOR_VER}.yaml:
41+
${TEST_CRDS}/gitrepositories.yaml: ${CACHE}/gitrepositories_${SOURCE_VER}.yaml
4042
mkdir -p ${TEST_CRDS}
43+
cp $^ $@
44+
45+
${CACHE}/gitrepositories_${SOURCE_VER}.yaml:
46+
mkdir -p ${CACHE}
47+
curl -s --fail https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER}/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml \
48+
-o ${CACHE}/gitrepositories_${SOURCE_VER}.yaml
49+
50+
${CACHE}/imagepolicies_${REFLECTOR_VER}.yaml:
51+
mkdir -p ${CACHE}
4152
curl -s --fail https://raw.githubusercontent.com/fluxcd/image-reflector-controller/${REFLECTOR_VER}/config/crd/bases/image.toolkit.fluxcd.io_imagepolicies.yaml \
42-
-o ${TEST_CRDS}/imagepolicies_${REFLECTOR_VER}.yaml
53+
-o ${CACHE}/imagepolicies_${REFLECTOR_VER}.yaml
4354

4455
# Run tests
4556
test: test_deps generate fmt vet manifests api-docs
@@ -79,7 +90,7 @@ manifests: controller-gen
7990

8091
# Generate API reference documentation
8192
api-docs: gen-crd-api-reference-docs
82-
$(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
93+
$(API_REF_GEN) -api-dir=./api/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/image-automation.md
8394

8495
# Run go mod tidy
8596
tidy:

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ resources:
77
- group: image
88
kind: ImageUpdateAutomation
99
version: v1alpha2
10+
- group: image
11+
kind: ImageUpdateAutomation
12+
version: v1beta1
1013
version: "2"

api/v1alpha2/imageupdateautomation_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func SetImageUpdateAutomationReadiness(auto *ImageUpdateAutomation, status metav
119119
meta.SetResourceCondition(auto, meta.ReadyCondition, status, reason, message)
120120
}
121121

122-
//+kubebuilder:storageversion
123122
//+kubebuilder:object:root=true
124123
//+kubebuilder:subresource:status
125124
//+kubebuilder:printcolumn:name="Last run",type=string,JSONPath=`.status.lastAutomationRunTime`

api/v1beta1/doc.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 v1beta1 contains API types for the image API group, version
18+
// v1beta1. 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. v1alpha2 did some rearrangement from
21+
// v1alpha1 to make room for future enhancements; v1beta1 does not
22+
// change the schema from v1alpha2.
23+
//
24+
// +kubebuilder:object:generate=true
25+
// +groupName=image.toolkit.fluxcd.io
26+
package v1beta1

api/v1beta1/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 v1beta1
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/v1beta1/groupversion_info.go

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

0 commit comments

Comments
 (0)