Skip to content

Commit

Permalink
feat: add Artifact object
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Lettron <[email protected]>
  • Loading branch information
guilhem committed Dec 23, 2024
1 parent fe7b1fe commit b277e8e
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ resources:
- group: source
kind: Bucket
version: v1
- group: source
kind: Artifact
version: v1alpha1
version: "2"
87 changes: 87 additions & 0 deletions api/v1alpha1/artifact_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"time"

v1 "github.com/fluxcd/source-controller/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// BucketKind is the string representation of a Bucket.
ArtifactKind = "Artifact"
)

// ArtifactSpec defines the desired state of Artifact
type ArtifactSpec struct {

// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
CurrentVersion string `json:"currentVersion,omitempty"`

// +kubebuilder:validation:Required
Versions map[string]*v1.Artifact `json:"versions,omitempty"`
}

// ArtifactStatus defines the observed state of Artifact
type ArtifactStatus struct {
}

// +genclient
// +kubebuilder:storageversion
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Artifact is the Schema for the artifacts API
type Artifact struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ArtifactSpec `json:"spec,omitempty"`
Status ArtifactStatus `json:"status,omitempty"`
}

// GetArtifact returns the latest Artifact from the Artifact if present in
// the status sub-resource.
func (in *Artifact) GetArtifact() *v1.Artifact {
if in.Spec.CurrentVersion == "" {
return nil
}
if in.Spec.Versions == nil {
return nil
}
return in.Spec.Versions[in.Spec.CurrentVersion]
}

func (in *Artifact) GetRequeueAfter() time.Duration {
return time.Minute
}

// +kubebuilder:object:root=true

// ArtifactList contains a list of Artifact
type ArtifactList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Artifact `json:"items"`
}

func init() {
SchemeBuilder.Register(&Artifact{}, &ArtifactList{})
}
36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the source v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=source.toolkit.fluxcd.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "source.toolkit.fluxcd.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
131 changes: 131 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ resources:
- bases/source.toolkit.fluxcd.io_helmcharts.yaml
- bases/source.toolkit.fluxcd.io_buckets.yaml
- bases/source.toolkit.fluxcd.io_ocirepositories.yaml
- bases/source.toolkit.fluxcd.io_artifacts.yaml
# +kubebuilder:scaffold:crdkustomizeresource
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/fluxcd/pkg/runtime/probes"

"github.com/fluxcd/source-controller/api/v1"
"github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/fluxcd/source-controller/api/v1beta2"

// +kubebuilder:scaffold:imports
Expand Down Expand Up @@ -85,6 +86,7 @@ func init() {

utilruntime.Must(v1beta2.AddToScheme(scheme))
utilruntime.Must(v1.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

Expand Down

0 comments on commit b277e8e

Please sign in to comment.