Skip to content

Commit 3f2f4d5

Browse files
authored
Merge pull request #158 from fluxcd/impl-meta-api
Implement `fluxcd/pkg/meta/api` in APIs
2 parents c5bf164 + 431ea05 commit 3f2f4d5

29 files changed

+339
-522
lines changed

Diff for: api/go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module github.com/fluxcd/source-controller/api
33
go 1.14
44

55
require (
6-
k8s.io/api v0.18.8
7-
k8s.io/apimachinery v0.18.8
8-
sigs.k8s.io/controller-runtime v0.6.2
6+
github.com/fluxcd/pkg/apis/meta v0.0.2
7+
k8s.io/api v0.18.9
8+
k8s.io/apimachinery v0.18.9
9+
sigs.k8s.io/controller-runtime v0.6.3
910
)

Diff for: api/go.sum

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
2525
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
2626
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
2727
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
28-
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
2928
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
3029
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
3130
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -58,10 +57,12 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb
5857
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
5958
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
6059
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
61-
github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc=
6260
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
6361
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
62+
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
6463
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
64+
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
65+
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
6566
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6667
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
6768
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -170,7 +171,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
170171
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
171172
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
172173
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
173-
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
174174
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
175175
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
176176
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@@ -419,12 +419,12 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
419419
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
420420
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
421421
k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI=
422-
k8s.io/api v0.18.8 h1:aIKUzJPb96f3fKec2lxtY7acZC9gQNDLVhfSGpxBAC4=
423-
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
422+
k8s.io/api v0.18.9 h1:7VDtivqwbvLOf8hmXSd/PDSSbpCBq49MELg84EYBYiQ=
423+
k8s.io/api v0.18.9/go.mod h1:9u/h6sUh6FxfErv7QqetX1EB3yBMIYOBXzdcf0Gf0rc=
424424
k8s.io/apiextensions-apiserver v0.18.6/go.mod h1:lv89S7fUysXjLZO7ke783xOwVTm6lKizADfvUM/SS/M=
425425
k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
426-
k8s.io/apimachinery v0.18.8 h1:jimPrycCqgx2QPearX3to1JePz7wSbVLq+7PdBTTwQ0=
427-
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
426+
k8s.io/apimachinery v0.18.9 h1:3ZABKQx3F3xPWlsGhCfUl8W+JXRRblV6Wo2A3zn0pvY=
427+
k8s.io/apimachinery v0.18.9/go.mod h1:PF5taHbXgTEJLU+xMypMmYTXTWPJ5LaW8bfsisxnEXk=
428428
k8s.io/apiserver v0.18.6/go.mod h1:Zt2XvTHuaZjBz6EFYzpp+X4hTmgWGy8AthNVnTdm3Wg=
429429
k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q=
430430
k8s.io/code-generator v0.18.6/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
@@ -440,8 +440,8 @@ k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C
440440
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
441441
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
442442
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0=
443-
sigs.k8s.io/controller-runtime v0.6.2 h1:jkAnfdTYBpFwlmBn3pS5HFO06SfxvnTZ1p5PeEF/zAA=
444-
sigs.k8s.io/controller-runtime v0.6.2/go.mod h1:vhcq/rlnENJ09SIRp3EveTaZ0yqH526hjf9iJdbUJ/E=
443+
sigs.k8s.io/controller-runtime v0.6.3 h1:SBbr+inLPEKhvlJtrvDcwIpm+uhDvp63Bl72xYJtoOE=
444+
sigs.k8s.io/controller-runtime v0.6.3/go.mod h1:WlZNXcM0++oyaQt4B7C2lEE5JYRs8vJUzRP4N4JpdAY=
445445
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
446446
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E=
447447
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=

Diff for: api/v1alpha1/artifact_types.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ type Artifact struct {
3333
// +required
3434
URL string `json:"url"`
3535

36-
// Revision is a human readable identifier traceable in the origin
37-
// source system. It can be a Git commit sha, Git tag, a Helm index
38-
// timestamp, a Helm chart version, etc.
36+
// Revision is a human readable identifier traceable in the origin source
37+
// system. It can be a Git commit sha, Git tag, a Helm index timestamp, a Helm
38+
// chart version, etc.
3939
// +optional
4040
Revision string `json:"revision"`
4141

4242
// Checksum is the SHA1 checksum of the artifact.
4343
// +optional
4444
Checksum string `json:"checksum"`
4545

46-
// LastUpdateTime is the timestamp corresponding to the last
47-
// update of this artifact.
46+
// LastUpdateTime is the timestamp corresponding to the last update of this
47+
// artifact.
4848
// +required
4949
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
5050
}
5151

52-
// HasRevision returns true if the given revision matches the current
53-
// Revision of the Artifact.
52+
// HasRevision returns true if the given revision matches the current Revision
53+
// of the Artifact.
5454
func (in *Artifact) HasRevision(revision string) bool {
5555
if in == nil {
5656
return false

Diff for: api/v1alpha1/bucket_types.go

+42-39
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1alpha1
1919
import (
2020
"time"
2121

22+
"github.com/fluxcd/pkg/apis/meta"
2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
)
@@ -51,7 +52,8 @@ type BucketSpec struct {
5152
// +optional
5253
Region string `json:"region,omitempty"`
5354

54-
// The secret name containing the bucket accesskey and secretkey.
55+
// The name of the secret containing authentication credentials
56+
// for the Bucket.
5557
// +optional
5658
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
5759

@@ -63,8 +65,8 @@ type BucketSpec struct {
6365
// +optional
6466
Timeout *metav1.Duration `json:"timeout,omitempty"`
6567

66-
// Ignore overrides the set of excluded patterns in the .sourceignore
67-
// format (which is the same as .gitignore).
68+
// Ignore overrides the set of excluded patterns in the .sourceignore format
69+
// (which is the same as .gitignore).
6870
// +optional
6971
Ignore *string `json:"ignore,omitempty"`
7072
}
@@ -82,7 +84,7 @@ type BucketStatus struct {
8284

8385
// Conditions holds the conditions for the Bucket.
8486
// +optional
85-
Conditions []SourceCondition `json:"conditions,omitempty"`
87+
Conditions []meta.Condition `json:"conditions,omitempty"`
8688

8789
// URL is the download link for the artifact output of the last Bucket sync.
8890
// +optional
@@ -94,61 +96,62 @@ type BucketStatus struct {
9496
}
9597

9698
const (
97-
// BucketOperationSucceedReason represents the fact that the bucket listing
98-
// and download operations succeeded.
99+
// BucketOperationSucceedReason represents the fact that the bucket listing and
100+
// download operations succeeded.
99101
BucketOperationSucceedReason string = "BucketOperationSucceed"
100102

101-
// BucketOperationFailedReason represents the fact that the bucket listing
102-
// or download operations failed.
103+
// BucketOperationFailedReason represents the fact that the bucket listing or
104+
// download operations failed.
103105
BucketOperationFailedReason string = "BucketOperationFailed"
104106
)
105107

106-
// BucketProgressing resets the conditions of the Bucket
107-
// to SourceCondition of type Ready with status unknown and
108-
// progressing reason and message. It returns the modified Bucket.
108+
// BucketProgressing resets the conditions of the Bucket to meta.Condition of
109+
// type meta.ReadyCondition with status 'Unknown' and meta.ProgressingReason
110+
// reason and message. It returns the modified Bucket.
109111
func BucketProgressing(bucket Bucket) Bucket {
110112
bucket.Status.ObservedGeneration = bucket.Generation
111113
bucket.Status.URL = ""
112-
bucket.Status.Conditions = []SourceCondition{}
113-
SetBucketCondition(&bucket, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
114+
bucket.Status.Conditions = []meta.Condition{}
115+
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
114116
return bucket
115117
}
116118

117-
// SetBucketCondition sets the given condition with the given status, reason and message on the Bucket.
118-
func SetBucketCondition(bucket *Bucket, condition string, status corev1.ConditionStatus, reason, message string) {
119-
bucket.Status.Conditions = filterOutSourceCondition(bucket.Status.Conditions, condition)
120-
bucket.Status.Conditions = append(bucket.Status.Conditions, SourceCondition{
121-
Type: condition,
119+
// SetBucketCondition sets the given condition with the given status, reason and
120+
// message on the Bucket.
121+
func SetBucketCondition(bucket *Bucket, conditionType string, status corev1.ConditionStatus, reason, message string) {
122+
bucket.Status.Conditions = meta.FilterOutCondition(bucket.Status.Conditions, conditionType)
123+
bucket.Status.Conditions = append(bucket.Status.Conditions, meta.Condition{
124+
Type: conditionType,
122125
Status: status,
123126
LastTransitionTime: metav1.Now(),
124127
Reason: reason,
125128
Message: message,
126129
})
127130
}
128131

129-
// BucketReady sets the given artifact and url on the Bucket
130-
// and sets the ReadyCondition to True, with the given reason and
131-
// message. It returns the modified Bucket.
132-
func BucketReady(repository Bucket, artifact Artifact, url, reason, message string) Bucket {
133-
repository.Status.Artifact = &artifact
134-
repository.Status.URL = url
135-
SetBucketCondition(&repository, ReadyCondition, corev1.ConditionTrue, reason, message)
136-
return repository
132+
// BucketReady sets the given Artifact and URL on the Bucket and sets the
133+
// meta.ReadyCondition to 'True', with the given reason and message. It returns
134+
// the modified Bucket.
135+
func BucketReady(bucket Bucket, artifact Artifact, url, reason, message string) Bucket {
136+
bucket.Status.Artifact = &artifact
137+
bucket.Status.URL = url
138+
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionTrue, reason, message)
139+
return bucket
137140
}
138141

139-
// BucketNotReady sets the ReadyCondition on the given Bucket
140-
// to False, with the given reason and message. It returns the modified Bucket.
141-
func BucketNotReady(repository Bucket, reason, message string) Bucket {
142-
SetBucketCondition(&repository, ReadyCondition, corev1.ConditionFalse, reason, message)
143-
return repository
142+
// BucketNotReady sets the meta.ReadyCondition on the Bucket to 'False', with
143+
// the given reason and message. It returns the modified Bucket.
144+
func BucketNotReady(bucket Bucket, reason, message string) Bucket {
145+
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionFalse, reason, message)
146+
return bucket
144147
}
145148

146-
// BucketReadyMessage returns the message of the SourceCondition
147-
// of type Ready with status true if present, or an empty string.
148-
func BucketReadyMessage(repository Bucket) string {
149-
for _, condition := range repository.Status.Conditions {
150-
if condition.Type == ReadyCondition && condition.Status == corev1.ConditionTrue {
151-
return condition.Message
149+
// BucketReadyMessage returns the message of the meta.Condition of type
150+
// meta.ReadyCondition with status 'True' if present, or an empty string.
151+
func BucketReadyMessage(bucket Bucket) string {
152+
if c := meta.GetCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
153+
if c.Status == corev1.ConditionTrue {
154+
return c.Message
152155
}
153156
}
154157
return ""
@@ -162,8 +165,8 @@ func (in *Bucket) GetTimeout() time.Duration {
162165
return BucketTimeout
163166
}
164167

165-
// GetArtifact returns the latest artifact from the source
166-
// if present in the status sub-resource.
168+
// GetArtifact returns the latest artifact from the source if present in the
169+
// status sub-resource.
167170
func (in *Bucket) GetArtifact() *Artifact {
168171
return in.Status.Artifact
169172
}

Diff for: api/v1alpha1/condition_types.go

+2-55
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,9 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19-
import (
20-
corev1 "k8s.io/api/core/v1"
21-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
)
23-
2419
const SourceFinalizer = "finalizers.fluxcd.io"
2520

26-
// SourceCondition contains condition information for a source.
27-
type SourceCondition struct {
28-
// Type of the condition, currently ('Ready').
29-
// +required
30-
Type string `json:"type"`
31-
32-
// Status of the condition, one of ('True', 'False', 'Unknown').
33-
// +required
34-
Status corev1.ConditionStatus `json:"status"`
35-
36-
// LastTransitionTime is the timestamp corresponding to the last status
37-
// change of this condition.
38-
// +required
39-
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
40-
41-
// Reason is a brief machine readable explanation for the condition's last
42-
// transition.
43-
// +required
44-
Reason string `json:"reason,omitempty"`
45-
46-
// Message is a human readable description of the details of the last
47-
// transition, complementing reason.
48-
// +optional
49-
Message string `json:"message,omitempty"`
50-
}
51-
5221
const (
53-
// ReadyCondition represents the fact that a given source is in ready state.
54-
ReadyCondition string = "Ready"
55-
)
56-
57-
const (
58-
// InitializingReason represents the fact that a given source is being initialized.
59-
InitializingReason string = "Initializing"
60-
6122
// URLInvalidReason represents the fact that a given source has an invalid URL.
6223
URLInvalidReason string = "URLInvalid"
6324

@@ -68,21 +29,7 @@ const (
6829
// have the required fields or the provided credentials do not match.
6930
AuthenticationFailedReason string = "AuthenticationFailed"
7031

71-
// VerificationFailedReason represents the fact that the cryptographic provenance
72-
// verification for the source failed.
32+
// VerificationFailedReason represents the fact that the cryptographic
33+
// provenance verification for the source failed.
7334
VerificationFailedReason string = "VerificationFailed"
74-
75-
// ProgressingReason represents the fact that a source reconciliation
76-
// is underway.
77-
ProgressingReason string = "Progressing"
7835
)
79-
80-
// InReadyCondition returns if the given SourceCondition slice has a ReadyCondition with
81-
// a 'True' status.
82-
func InReadyCondition(conditions []SourceCondition) bool {
83-
condition := getCondition(conditions, ReadyCondition)
84-
if condition == nil {
85-
return false
86-
}
87-
return condition.Status == corev1.ConditionTrue
88-
}

0 commit comments

Comments
 (0)