Skip to content

Commit 19d7f83

Browse files
authored
Merge pull request fluxcd#412 from fluxcd/bucket-reconciler
2 parents 5d43bcc + 29f207d commit 19d7f83

10 files changed

+1240
-421
lines changed

api/v1beta1/bucket_types.go

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"time"
2121

2222
"github.com/fluxcd/pkg/apis/meta"
23-
"github.com/fluxcd/pkg/runtime/conditions"
24-
apimeta "k8s.io/apimachinery/pkg/api/meta"
2523
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2624
)
2725

@@ -30,6 +28,11 @@ const (
3028
BucketKind = "Bucket"
3129
)
3230

31+
const (
32+
GenericBucketProvider string = "generic"
33+
AmazonBucketProvider string = "aws"
34+
)
35+
3336
// BucketSpec defines the desired state of an S3 compatible bucket
3437
type BucketSpec struct {
3538
// The S3 compatible storage provider name, default ('generic').
@@ -79,11 +82,6 @@ type BucketSpec struct {
7982
Suspend bool `json:"suspend,omitempty"`
8083
}
8184

82-
const (
83-
GenericBucketProvider string = "generic"
84-
AmazonBucketProvider string = "aws"
85-
)
86-
8785
// BucketStatus defines the observed state of a bucket
8886
type BucketStatus struct {
8987
// ObservedGeneration is the last observed generation.
@@ -115,45 +113,6 @@ const (
115113
BucketOperationFailedReason string = "BucketOperationFailed"
116114
)
117115

118-
// BucketProgressing resets the conditions of the Bucket to metav1.Condition of
119-
// type meta.ReadyCondition with status 'Unknown' and meta.ProgressingReason
120-
// reason and message. It returns the modified Bucket.
121-
func BucketProgressing(bucket Bucket) Bucket {
122-
bucket.Status.ObservedGeneration = bucket.Generation
123-
bucket.Status.URL = ""
124-
bucket.Status.Conditions = []metav1.Condition{}
125-
conditions.MarkUnknown(&bucket, meta.ReadyCondition, meta.ProgressingReason, "reconciliation in progress")
126-
return bucket
127-
}
128-
129-
// BucketReady sets the given Artifact and URL on the Bucket and sets the
130-
// meta.ReadyCondition to 'True', with the given reason and message. It returns
131-
// the modified Bucket.
132-
func BucketReady(bucket Bucket, artifact Artifact, url, reason, message string) Bucket {
133-
bucket.Status.Artifact = &artifact
134-
bucket.Status.URL = url
135-
conditions.MarkTrue(&bucket, meta.ReadyCondition, reason, message)
136-
return bucket
137-
}
138-
139-
// BucketNotReady sets the meta.ReadyCondition on the Bucket to 'False', with
140-
// the given reason and message. It returns the modified Bucket.
141-
func BucketNotReady(bucket Bucket, reason, message string) Bucket {
142-
conditions.MarkFalse(&bucket, meta.ReadyCondition, reason, message)
143-
return bucket
144-
}
145-
146-
// BucketReadyMessage returns the message of the metav1.Condition of type
147-
// meta.ReadyCondition with status 'True' if present, or an empty string.
148-
func BucketReadyMessage(bucket Bucket) string {
149-
if c := apimeta.FindStatusCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
150-
if c.Status == metav1.ConditionTrue {
151-
return c.Message
152-
}
153-
}
154-
return ""
155-
}
156-
157116
// GetConditions returns the status conditions of the object.
158117
func (in Bucket) GetConditions() []metav1.Condition {
159118
return in.Status.Conditions

api/v1beta1/condition_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ package v1beta1
1818

1919
const SourceFinalizer = "finalizers.fluxcd.io"
2020

21+
const (
22+
// ArtifactUnavailableCondition indicates there is no Artifact available for the Source.
23+
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
24+
ArtifactUnavailableCondition string = "ArtifactUnavailable"
25+
26+
// ArtifactOutdatedCondition indicates the current Artifact of the Source is outdated.
27+
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
28+
ArtifactOutdatedCondition string = "ArtifactOutdated"
29+
30+
// FetchFailedCondition indicates a transient or persistent fetch failure of an upstream Source.
31+
// If True, observations on the upstream Source revision may be impossible, and the Artifact available for the
32+
// Source may be outdated.
33+
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
34+
FetchFailedCondition string = "FetchFailed"
35+
)
36+
2137
const (
2238
// URLInvalidReason represents the fact that a given source has an invalid URL.
2339
URLInvalidReason string = "URLInvalid"

api/v1beta1/gitrepository_types.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ const (
3434
)
3535

3636
const (
37-
// ArtifactUnavailableCondition indicates there is no Artifact available for the Source.
38-
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
39-
ArtifactUnavailableCondition string = "ArtifactUnavailable"
40-
41-
// CheckoutFailedCondition indicates a transient or persistent checkout failure. If True, observations on the
42-
// upstream Source revision are not possible, and the Artifact available for the Source may be outdated.
43-
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
44-
CheckoutFailedCondition string = "CheckoutFailed"
45-
4637
// SourceVerifiedCondition indicates the integrity of the Source has been verified. If True, the integrity check
4738
// succeeded. If False, it failed. The Condition is only present on the resource if the integrity has been verified.
4839
SourceVerifiedCondition string = "SourceVerified"
@@ -51,10 +42,6 @@ const (
5142
// exist, or does not have an Artifact.
5243
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
5344
IncludeUnavailableCondition string = "IncludeUnavailable"
54-
55-
// ArtifactOutdatedCondition indicates the current Artifact of the Source is outdated.
56-
// This is a "negative polarity" or "abnormal-true" type, and is only present on the resource if it is True.
57-
ArtifactOutdatedCondition string = "ArtifactOutdated"
5845
)
5946

6047
// GitRepositorySpec defines the desired state of a Git repository.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2021 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 controllers
18+
19+
import (
20+
"fmt"
21+
22+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
23+
. "github.com/onsi/gomega"
24+
"github.com/onsi/gomega/types"
25+
)
26+
27+
// MatchArtifact returns a custom matcher to check equality of a v1beta1.Artifact, the timestamp and URL are ignored.
28+
func MatchArtifact(expected *sourcev1.Artifact) types.GomegaMatcher {
29+
return &matchArtifact{
30+
expected: expected,
31+
}
32+
}
33+
34+
type matchArtifact struct {
35+
expected *sourcev1.Artifact
36+
}
37+
38+
func (m matchArtifact) Match(actual interface{}) (success bool, err error) {
39+
actualArtifact, ok := actual.(*sourcev1.Artifact)
40+
if !ok {
41+
return false, fmt.Errorf("actual should be a pointer to an Artifact")
42+
}
43+
44+
if ok, _ := BeNil().Match(m.expected); ok {
45+
return BeNil().Match(actual)
46+
}
47+
48+
if ok, err = Equal(m.expected.Path).Match(actualArtifact.Path); !ok {
49+
return ok, err
50+
}
51+
if ok, err = Equal(m.expected.Revision).Match(actualArtifact.Revision); !ok {
52+
return ok, err
53+
}
54+
if ok, err = Equal(m.expected.Checksum).Match(actualArtifact.Checksum); !ok {
55+
return ok, err
56+
}
57+
58+
return ok, err
59+
}
60+
61+
func (m matchArtifact) FailureMessage(actual interface{}) (message string) {
62+
return fmt.Sprintf("expected\n\t%#v\nto match\n\t%#v\n", actual, m.expected)
63+
}
64+
65+
func (m matchArtifact) NegatedFailureMessage(actual interface{}) (message string) {
66+
return fmt.Sprintf("expected\n\t%#v\nto not match\n\t%#v\n", actual, m.expected)
67+
}

0 commit comments

Comments
 (0)