Skip to content

Commit c863188

Browse files
authored
Merge pull request #133 from fluxcd/storage/atomic-file-write
2 parents d4830bc + f08febd commit c863188

26 files changed

+1502
-269
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
username: fluxcdbot
4141
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
4242
- name: Publish amd64 image
43-
uses: docker/build-push-action@v2-build-push
43+
uses: docker/build-push-action@v2
4444
with:
4545
push: ${{ github.event_name != 'pull_request' }}
4646
builder: ${{ steps.buildx.outputs.name }}
@@ -51,7 +51,7 @@ jobs:
5151
ghcr.io/fluxcd/source-controller:${{ steps.get_version.outputs.VERSION }}
5252
docker.io/fluxcd/source-controller:${{ steps.get_version.outputs.VERSION }}
5353
- name: Publish arm64 image
54-
uses: docker/build-push-action@v2-build-push
54+
uses: docker/build-push-action@v2
5555
with:
5656
push: ${{ github.event_name != 'pull_request' }}
5757
builder: ${{ steps.buildx.outputs.name }}

api/v1alpha1/gitrepository_types.go

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ type GitRepositoryVerification struct {
9999

100100
// GitRepositoryStatus defines the observed state of a Git repository.
101101
type GitRepositoryStatus struct {
102+
// ObservedGeneration is the last observed generation.
103+
// +optional
104+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
105+
106+
// Conditions holds the conditions for the GitRepository.
102107
// +optional
103108
Conditions []SourceCondition `json:"conditions,omitempty"`
104109

@@ -122,62 +127,46 @@ const (
122127
GitOperationFailedReason string = "GitOperationFailed"
123128
)
124129

125-
// GitRepositoryReady sets the given artifact and url on the
126-
// GitRepository and resets the conditions to SourceCondition of
127-
// type Ready with status true and the given reason and message.
128-
// It returns the modified GitRepository.
129-
func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository {
130-
repository.Status.Conditions = []SourceCondition{
131-
{
132-
Type: ReadyCondition,
133-
Status: corev1.ConditionTrue,
134-
LastTransitionTime: metav1.Now(),
135-
Reason: reason,
136-
Message: message,
137-
},
138-
}
139-
repository.Status.URL = url
140-
141-
if repository.Status.Artifact != nil {
142-
if repository.Status.Artifact.Path != artifact.Path {
143-
repository.Status.Artifact = &artifact
144-
}
145-
} else {
146-
repository.Status.Artifact = &artifact
147-
}
148-
149-
return repository
150-
}
151-
152130
// GitRepositoryProgressing resets the conditions of the GitRepository
153131
// to SourceCondition of type Ready with status unknown and
154132
// progressing reason and message. It returns the modified GitRepository.
155133
func GitRepositoryProgressing(repository GitRepository) GitRepository {
156-
repository.Status.Conditions = []SourceCondition{
157-
{
158-
Type: ReadyCondition,
159-
Status: corev1.ConditionUnknown,
160-
LastTransitionTime: metav1.Now(),
161-
Reason: ProgressingReason,
162-
Message: "reconciliation in progress",
163-
},
164-
}
134+
repository.Status.ObservedGeneration = repository.Generation
135+
repository.Status.URL = ""
136+
repository.Status.Artifact = nil
137+
repository.Status.Conditions = []SourceCondition{}
138+
SetGitRepositoryCondition(&repository, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
139+
return repository
140+
}
141+
142+
// SetGitRepositoryCondition sets the given condition with the given status, reason and message
143+
// on the GitRepository.
144+
func SetGitRepositoryCondition(repository *GitRepository, condition string, status corev1.ConditionStatus, reason, message string) {
145+
repository.Status.Conditions = filterOutSourceCondition(repository.Status.Conditions, condition)
146+
repository.Status.Conditions = append(repository.Status.Conditions, SourceCondition{
147+
Type: condition,
148+
Status: status,
149+
LastTransitionTime: metav1.Now(),
150+
Reason: reason,
151+
Message: message,
152+
})
153+
}
154+
155+
// GitRepositoryReady sets the given artifact and url on the GitRepository
156+
// and sets the ReadyCondition to True, with the given reason and
157+
// message. It returns the modified GitRepository.
158+
func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository {
159+
repository.Status.Artifact = &artifact
160+
repository.Status.URL = url
161+
SetGitRepositoryCondition(&repository, ReadyCondition, corev1.ConditionTrue, reason, message)
165162
return repository
166163
}
167164

168-
// GitRepositoryNotReady resets the conditions of the GitRepository
169-
// to SourceCondition of type Ready with status false and the given
170-
// reason and message. It returns the modified GitRepository.
165+
// GitRepositoryNotReady sets the ReadyCondition on the given GitRepository
166+
// to False, with the given reason and message. It returns the modified
167+
// GitRepository.
171168
func GitRepositoryNotReady(repository GitRepository, reason, message string) GitRepository {
172-
repository.Status.Conditions = []SourceCondition{
173-
{
174-
Type: ReadyCondition,
175-
Status: corev1.ConditionFalse,
176-
LastTransitionTime: metav1.Now(),
177-
Reason: reason,
178-
Message: message,
179-
},
180-
}
169+
SetGitRepositoryCondition(&repository, ReadyCondition, corev1.ConditionFalse, reason, message)
181170
return repository
182171
}
183172

api/v1alpha1/helmchart_types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ type LocalHelmChartSourceReference struct {
6262

6363
// HelmChartStatus defines the observed state of the HelmChart.
6464
type HelmChartStatus struct {
65+
// ObservedGeneration is the last observed generation.
66+
// +optional
67+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
68+
69+
// Conditions holds the conditions for the HelmChart.
6570
// +optional
6671
Conditions []SourceCondition `json:"conditions,omitempty"`
6772

@@ -92,9 +97,10 @@ const (
9297
ChartPackageSucceededReason string = "ChartPackageSucceeded"
9398
)
9499

95-
// HelmReleaseProgressing resets any failures and registers progress toward reconciling the given HelmRelease
100+
// HelmChartProgressing resets any failures and registers progress toward reconciling the given HelmChart
96101
// by setting the ReadyCondition to ConditionUnknown for ProgressingReason.
97102
func HelmChartProgressing(chart HelmChart) HelmChart {
103+
chart.Status.ObservedGeneration = chart.Generation
98104
chart.Status.URL = ""
99105
chart.Status.Artifact = nil
100106
chart.Status.Conditions = []SourceCondition{}

api/v1alpha1/helmrepository_types.go

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ type HelmRepositorySpec struct {
5454

5555
// HelmRepositoryStatus defines the observed state of the HelmRepository.
5656
type HelmRepositoryStatus struct {
57+
// ObservedGeneration is the last observed generation.
58+
// +optional
59+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
60+
61+
// Conditions holds the conditions for the HelmRepository.
5762
// +optional
5863
Conditions []SourceCondition `json:"conditions,omitempty"`
5964

@@ -76,62 +81,46 @@ const (
7681
IndexationSucceededReason string = "IndexationSucceed"
7782
)
7883

79-
// HelmRepositoryReady sets the given artifact and url on the
80-
// HelmRepository and resets the conditions to SourceCondition of
81-
// type Ready with status true and the given reason and message.
82-
// It returns the modified HelmRepository.
83-
func HelmRepositoryReady(repository HelmRepository, artifact Artifact, url, reason, message string) HelmRepository {
84-
repository.Status.Conditions = []SourceCondition{
85-
{
86-
Type: ReadyCondition,
87-
Status: corev1.ConditionTrue,
88-
LastTransitionTime: metav1.Now(),
89-
Reason: reason,
90-
Message: message,
91-
},
92-
}
93-
repository.Status.URL = url
94-
95-
if repository.Status.Artifact != nil {
96-
if repository.Status.Artifact.Path != artifact.Path {
97-
repository.Status.Artifact = &artifact
98-
}
99-
} else {
100-
repository.Status.Artifact = &artifact
101-
}
102-
103-
return repository
104-
}
105-
10684
// HelmRepositoryProgressing resets the conditions of the HelmRepository
10785
// to SourceCondition of type Ready with status unknown and
10886
// progressing reason and message. It returns the modified HelmRepository.
10987
func HelmRepositoryProgressing(repository HelmRepository) HelmRepository {
110-
repository.Status.Conditions = []SourceCondition{
111-
{
112-
Type: ReadyCondition,
113-
Status: corev1.ConditionUnknown,
114-
LastTransitionTime: metav1.Now(),
115-
Reason: ProgressingReason,
116-
Message: "reconciliation in progress",
117-
},
118-
}
88+
repository.Status.ObservedGeneration = repository.Generation
89+
repository.Status.URL = ""
90+
repository.Status.Artifact = nil
91+
repository.Status.Conditions = []SourceCondition{}
92+
SetHelmRepositoryCondition(&repository, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
93+
return repository
94+
}
95+
96+
// SetHelmRepositoryCondition sets the given condition with the given status,
97+
// reason and message on the HelmRepository.
98+
func SetHelmRepositoryCondition(repository *HelmRepository, condition string, status corev1.ConditionStatus, reason, message string) {
99+
repository.Status.Conditions = filterOutSourceCondition(repository.Status.Conditions, condition)
100+
repository.Status.Conditions = append(repository.Status.Conditions, SourceCondition{
101+
Type: condition,
102+
Status: status,
103+
LastTransitionTime: metav1.Now(),
104+
Reason: reason,
105+
Message: message,
106+
})
107+
}
108+
109+
// HelmRepositoryReady sets the given artifact and url on the HelmRepository
110+
// and sets the ReadyCondition to True, with the given reason and
111+
// message. It returns the modified HelmRepository.
112+
func HelmRepositoryReady(repository HelmRepository, artifact Artifact, url, reason, message string) HelmRepository {
113+
repository.Status.Artifact = &artifact
114+
repository.Status.URL = url
115+
SetHelmRepositoryCondition(&repository, ReadyCondition, corev1.ConditionTrue, reason, message)
119116
return repository
120117
}
121118

122-
// HelmRepositoryNotReady resets the conditions of the HelmRepository
123-
// to SourceCondition of type Ready with status false and the given
124-
// reason and message. It returns the modified HelmRepository.
119+
// HelmRepositoryNotReady sets the ReadyCondition on the given HelmRepository
120+
// to False, with the given reason and message. It returns the modified
121+
// HelmRepository.
125122
func HelmRepositoryNotReady(repository HelmRepository, reason, message string) HelmRepository {
126-
repository.Status.Conditions = []SourceCondition{
127-
{
128-
Type: ReadyCondition,
129-
Status: corev1.ConditionFalse,
130-
LastTransitionTime: metav1.Now(),
131-
Reason: reason,
132-
Message: message,
133-
},
134-
}
123+
SetHelmRepositoryCondition(&repository, ReadyCondition, corev1.ConditionFalse, reason, message)
135124
return repository
136125
}
137126

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ spec:
153153
- url
154154
type: object
155155
conditions:
156+
description: Conditions holds the conditions for the GitRepository.
156157
items:
157158
description: SourceCondition contains condition information for
158159
a source.
@@ -182,6 +183,10 @@ spec:
182183
- type
183184
type: object
184185
type: array
186+
observedGeneration:
187+
description: ObservedGeneration is the last observed generation.
188+
format: int64
189+
type: integer
185190
url:
186191
description: URL is the download link for the artifact output of the
187192
last repository sync.

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ spec:
125125
- url
126126
type: object
127127
conditions:
128+
description: Conditions holds the conditions for the HelmChart.
128129
items:
129130
description: SourceCondition contains condition information for
130131
a source.
@@ -154,6 +155,10 @@ spec:
154155
- type
155156
type: object
156157
type: array
158+
observedGeneration:
159+
description: ObservedGeneration is the last observed generation.
160+
format: int64
161+
type: integer
157162
url:
158163
description: URL is the download link for the last chart pulled.
159164
type: string

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ spec:
105105
- url
106106
type: object
107107
conditions:
108+
description: Conditions holds the conditions for the HelmRepository.
108109
items:
109110
description: SourceCondition contains condition information for
110111
a source.
@@ -134,6 +135,10 @@ spec:
134135
- type
135136
type: object
136137
type: array
138+
observedGeneration:
139+
description: ObservedGeneration is the last observed generation.
140+
format: int64
141+
type: integer
137142
url:
138143
description: URL is the download link for the last index fetched.
139144
type: string

0 commit comments

Comments
 (0)