-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Artifact object #1703
Draft
guilhem
wants to merge
1
commit into
fluxcd:main
Choose a base branch
from
guilhem:artifact
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||||||||||||||
} | ||||||||||||||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is how we track versions in Flux APIs, the first entry is the current version, all this logic is already in helm-controller. |
||||||||||||||
|
||||||||||||||
// +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{}) | ||||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really part of the discussion.
Having only the latest artifact in spec makes it simpler, but also points some problems:
With everything in spec, it makes things trusty and "backupable":
I don't see that many usages of "Status" for an object like an Artifact (but I may be wrong).
But events produced by “consumers” can be a great thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure, no user should relay on anything from this custom resource, status or not is irelevant. This custom resource is a side-efect of some 3rd-party source-controller that should fully manage the artifact. This type of object is not "desired state" it shouldn't be included in the backup. You should backup what ever custom resource your controller uses for "desired state".
source-controller-x would reconcile
GitRepositoryX
objects and would create/update/deleteArtifactX
objects. If you want to pin your source to a Git commit, the user will do this in theGitRepositoryX
. Users will never interact withArtifactX
as the artifact is a result of the reconciliation, it's not the "desired state", the artifact is the "actual state".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok for me, just wanted to know if the desired state should be managed by source controller and just an information storage :)
And yes, I'm developing a source-controller for Omaha / Nebraska, so I will need a way to interact with consumers controllers :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flux source-controller plays no role here, this
ArtifactX
type is to enable other source controllers to feed data to Flux kustomize-controller. We discussed this in the dev meetings, the artifact for the native Flux sources will remain unchanged, it's part of the.status
. For 3rd-party source controllers, they will have to generate the artifact in a standalone object that can be referenced in Flux Kustomizations.