Skip to content

Commit 7a80807

Browse files
authored
Merge pull request #8 from fluxcd/artifact-status
Add artifact type to API
2 parents fa6bccb + f9a35a6 commit 7a80807

11 files changed

+329
-187
lines changed

api/v1alpha1/artifact.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2020 The Flux CD contributors.
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 v1alpha1
18+
19+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
21+
// Artifact represents the output of a source synchronisation
22+
type Artifact struct {
23+
// Path is the local file path of this artifact.
24+
// +required
25+
Path string `json:"path"`
26+
27+
// URL is the HTTP address of this artifact.
28+
// +required
29+
URL string `json:"url"`
30+
31+
// Revision is a human readable identifier traceable in the origin source system.
32+
// It can be a commit sha, git tag, a helm index timestamp,
33+
// a helm chart version, a checksum, etc.
34+
// +optional
35+
Revision string `json:"revision"`
36+
37+
// LastUpdateTime is the timestamp corresponding to the last
38+
// update of this artifact.
39+
// +required
40+
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
41+
}

api/v1alpha1/condition_types.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2020 The Flux CD contributors.
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+
117
package v1alpha1
218

319
import (

api/v1alpha1/gitrepository_types.go

+49-5
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ type GitRepositoryStatus struct {
6767
// +optional
6868
Conditions []SourceCondition `json:"conditions,omitempty"`
6969

70-
// LastUpdateTime is the timestamp corresponding to the last status
71-
// change of this repository.
70+
// URL is the download link for the artifact output of the last repository sync.
7271
// +optional
73-
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
72+
URL string `json:"url,omitempty"`
7473

75-
// Path to the artifact output of the last repository sync.
74+
// Artifact represents the output of the last successful repository sync.
7675
// +optional
77-
Artifact string `json:"artifacts,omitempty"`
76+
Artifact *Artifact `json:"artifact,omitempty"`
7877
}
7978

8079
// +kubebuilder:object:root=true
@@ -109,3 +108,48 @@ const (
109108
GitOperationSucceedReason string = "GitOperationSucceed"
110109
GitOperationFailedReason string = "GitOperationFailed"
111110
)
111+
112+
func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository {
113+
repository.Status.Conditions = []SourceCondition{
114+
{
115+
Type: ReadyCondition,
116+
Status: corev1.ConditionTrue,
117+
LastTransitionTime: metav1.Now(),
118+
Reason: reason,
119+
Message: message,
120+
},
121+
}
122+
repository.Status.URL = url
123+
124+
if repository.Status.Artifact != nil {
125+
if repository.Status.Artifact.Path != artifact.Path {
126+
repository.Status.Artifact = &artifact
127+
}
128+
} else {
129+
repository.Status.Artifact = &artifact
130+
}
131+
132+
return repository
133+
}
134+
135+
func GitRepositoryNotReady(repository GitRepository, reason, message string) GitRepository {
136+
repository.Status.Conditions = []SourceCondition{
137+
{
138+
Type: ReadyCondition,
139+
Status: corev1.ConditionFalse,
140+
LastTransitionTime: metav1.Now(),
141+
Reason: reason,
142+
Message: message,
143+
},
144+
}
145+
return repository
146+
}
147+
148+
func GitRepositoryReadyMessage(repository GitRepository) string {
149+
for _, condition := range repository.Status.Conditions {
150+
if condition.Type == ReadyCondition {
151+
return condition.Message
152+
}
153+
}
154+
return ""
155+
}

api/v1alpha1/helmrepository_types.go

+50-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -37,14 +38,13 @@ type HelmRepositoryStatus struct {
3738
// +optional
3839
Conditions []SourceCondition `json:"conditions,omitempty"`
3940

40-
// LastUpdateTime is the timestamp corresponding to the last status
41-
// change of this repository.
41+
// URL is the download link for the last index fetched.
4242
// +optional
43-
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
43+
URL string `json:"url,omitempty"`
4444

45-
// Path to the artifact of the last repository index.
45+
// Artifact represents the output of the last successful repository sync.
4646
// +optional
47-
Artifact string `json:"artifact,omitempty"`
47+
Artifact *Artifact `json:"artifact,omitempty"`
4848
}
4949

5050
// +kubebuilder:object:root=true
@@ -84,3 +84,48 @@ const (
8484
// of the given Helm repository succeeded.
8585
IndexationSucceededReason string = "IndexationSucceed"
8686
)
87+
88+
func HelmRepositoryReady(repository HelmRepository, artifact Artifact, url, reason, message string) HelmRepository {
89+
repository.Status.Conditions = []SourceCondition{
90+
{
91+
Type: ReadyCondition,
92+
Status: corev1.ConditionTrue,
93+
LastTransitionTime: metav1.Now(),
94+
Reason: reason,
95+
Message: message,
96+
},
97+
}
98+
repository.Status.URL = url
99+
100+
if repository.Status.Artifact != nil {
101+
if repository.Status.Artifact.Path != artifact.Path {
102+
repository.Status.Artifact = &artifact
103+
}
104+
} else {
105+
repository.Status.Artifact = &artifact
106+
}
107+
108+
return repository
109+
}
110+
111+
func HelmRepositoryNotReady(repository HelmRepository, reason, message string) HelmRepository {
112+
repository.Status.Conditions = []SourceCondition{
113+
{
114+
Type: ReadyCondition,
115+
Status: corev1.ConditionFalse,
116+
LastTransitionTime: metav1.Now(),
117+
Reason: reason,
118+
Message: message,
119+
},
120+
}
121+
return repository
122+
}
123+
124+
func HelmRepositoryReadyMessage(repository HelmRepository) string {
125+
for _, condition := range repository.Status.Conditions {
126+
if condition.Type == ReadyCondition {
127+
return condition.Message
128+
}
129+
}
130+
return ""
131+
}

api/v1alpha1/zz_generated.deepcopy.go

+24-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+27-7
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,30 @@ spec:
9393
status:
9494
description: GitRepositoryStatus defines the observed state of GitRepository
9595
properties:
96-
artifacts:
97-
description: Path to the artifact output of the last repository sync.
98-
type: string
96+
artifact:
97+
description: Artifact represents the output of the last successful repository
98+
sync.
99+
properties:
100+
lastUpdateTime:
101+
description: LastUpdateTime is the timestamp corresponding to the
102+
last update of this artifact.
103+
format: date-time
104+
type: string
105+
path:
106+
description: Path is the local file path of this artifact.
107+
type: string
108+
revision:
109+
description: Revision is a human readable identifier traceable in
110+
the origin source system. It can be a commit sha, git tag, a helm
111+
index timestamp, a helm chart version, a checksum, etc.
112+
type: string
113+
url:
114+
description: URL is the HTTP address of this artifact.
115+
type: string
116+
required:
117+
- path
118+
- url
119+
type: object
99120
conditions:
100121
items:
101122
description: SourceCondition contains condition information for a
@@ -126,10 +147,9 @@ spec:
126147
- type
127148
type: object
128149
type: array
129-
lastUpdateTime:
130-
description: LastUpdateTime is the timestamp corresponding to the last
131-
status change of this repository.
132-
format: date-time
150+
url:
151+
description: URL is the download link for the artifact output of the
152+
last repository sync.
133153
type: string
134154
type: object
135155
type: object

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

+25-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,29 @@ spec:
6464
description: HelmRepositoryStatus defines the observed state of HelmRepository
6565
properties:
6666
artifact:
67-
description: Path to the artifact of the last repository index.
68-
type: string
67+
description: Artifact represents the output of the last successful repository
68+
sync.
69+
properties:
70+
lastUpdateTime:
71+
description: LastUpdateTime is the timestamp corresponding to the
72+
last update of this artifact.
73+
format: date-time
74+
type: string
75+
path:
76+
description: Path is the local file path of this artifact.
77+
type: string
78+
revision:
79+
description: Revision is a human readable identifier traceable in
80+
the origin source system. It can be a commit sha, git tag, a helm
81+
index timestamp, a helm chart version, a checksum, etc.
82+
type: string
83+
url:
84+
description: URL is the HTTP address of this artifact.
85+
type: string
86+
required:
87+
- path
88+
- url
89+
type: object
6990
conditions:
7091
items:
7192
description: SourceCondition contains condition information for a
@@ -96,10 +117,8 @@ spec:
96117
- type
97118
type: object
98119
type: array
99-
lastUpdateTime:
100-
description: LastUpdateTime is the timestamp corresponding to the last
101-
status change of this repository.
102-
format: date-time
120+
url:
121+
description: URL is the download link for the last index fetched.
103122
type: string
104123
type: object
105124
type: object

controllers/conditions.go

-44
This file was deleted.

0 commit comments

Comments
 (0)