Skip to content

Commit b277e8e

Browse files
committed
feat: add Artifact object
Signed-off-by: Guilhem Lettron <[email protected]>
1 parent fe7b1fe commit b277e8e

File tree

6 files changed

+260
-0
lines changed

6 files changed

+260
-0
lines changed

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ resources:
4040
- group: source
4141
kind: Bucket
4242
version: v1
43+
- group: source
44+
kind: Artifact
45+
version: v1alpha1
4346
version: "2"

api/v1alpha1/artifact_types.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2024 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 v1alpha1
18+
19+
import (
20+
"time"
21+
22+
v1 "github.com/fluxcd/source-controller/api/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
const (
27+
// BucketKind is the string representation of a Bucket.
28+
ArtifactKind = "Artifact"
29+
)
30+
31+
// ArtifactSpec defines the desired state of Artifact
32+
type ArtifactSpec struct {
33+
34+
// +kubebuilder:validation:Required
35+
// +kubebuilder:validation:MinLength=1
36+
CurrentVersion string `json:"currentVersion,omitempty"`
37+
38+
// +kubebuilder:validation:Required
39+
Versions map[string]*v1.Artifact `json:"versions,omitempty"`
40+
}
41+
42+
// ArtifactStatus defines the observed state of Artifact
43+
type ArtifactStatus struct {
44+
}
45+
46+
// +genclient
47+
// +kubebuilder:storageversion
48+
// +kubebuilder:object:root=true
49+
// +kubebuilder:subresource:status
50+
51+
// Artifact is the Schema for the artifacts API
52+
type Artifact struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ObjectMeta `json:"metadata,omitempty"`
55+
56+
Spec ArtifactSpec `json:"spec,omitempty"`
57+
Status ArtifactStatus `json:"status,omitempty"`
58+
}
59+
60+
// GetArtifact returns the latest Artifact from the Artifact if present in
61+
// the status sub-resource.
62+
func (in *Artifact) GetArtifact() *v1.Artifact {
63+
if in.Spec.CurrentVersion == "" {
64+
return nil
65+
}
66+
if in.Spec.Versions == nil {
67+
return nil
68+
}
69+
return in.Spec.Versions[in.Spec.CurrentVersion]
70+
}
71+
72+
func (in *Artifact) GetRequeueAfter() time.Duration {
73+
return time.Minute
74+
}
75+
76+
// +kubebuilder:object:root=true
77+
78+
// ArtifactList contains a list of Artifact
79+
type ArtifactList struct {
80+
metav1.TypeMeta `json:",inline"`
81+
metav1.ListMeta `json:"metadata,omitempty"`
82+
Items []Artifact `json:"items"`
83+
}
84+
85+
func init() {
86+
SchemeBuilder.Register(&Artifact{}, &ArtifactList{})
87+
}

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024 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 v1alpha1 contains API Schema definitions for the source v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=source.toolkit.fluxcd.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "source.toolkit.fluxcd.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ resources:
66
- bases/source.toolkit.fluxcd.io_helmcharts.yaml
77
- bases/source.toolkit.fluxcd.io_buckets.yaml
88
- bases/source.toolkit.fluxcd.io_ocirepositories.yaml
9+
- bases/source.toolkit.fluxcd.io_artifacts.yaml
910
# +kubebuilder:scaffold:crdkustomizeresource

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"github.com/fluxcd/pkg/runtime/probes"
5252

5353
"github.com/fluxcd/source-controller/api/v1"
54+
"github.com/fluxcd/source-controller/api/v1alpha1"
5455
"github.com/fluxcd/source-controller/api/v1beta2"
5556

5657
// +kubebuilder:scaffold:imports
@@ -85,6 +86,7 @@ func init() {
8586

8687
utilruntime.Must(v1beta2.AddToScheme(scheme))
8788
utilruntime.Must(v1.AddToScheme(scheme))
89+
utilruntime.Must(v1alpha1.AddToScheme(scheme))
8890
// +kubebuilder:scaffold:scheme
8991
}
9092

0 commit comments

Comments
 (0)