@@ -19,6 +19,7 @@ package v1alpha1
1919import (
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
9698const (
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.
109111func 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.
167170func (in * Bucket ) GetArtifact () * Artifact {
168171 return in .Status .Artifact
169172}
0 commit comments