diff --git a/cmd/flux/artifact.go b/cmd/flux/artifact.go new file mode 100644 index 00000000..a4ab2e9f --- /dev/null +++ b/cmd/flux/artifact.go @@ -0,0 +1,57 @@ +/* +Copyright 2025 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 main + +import ( + "sigs.k8s.io/controller-runtime/pkg/client" + + swapi "github.com/fluxcd/source-watcher/api/v2/v1beta1" +) + +// swapi.ArtifactGenerator + +var artifactGeneratorType = apiType{ + kind: swapi.ArtifactGeneratorKind, + humanKind: "artifactgenerator", + groupVersion: swapi.GroupVersion, +} + +type artifactGeneratorAdapter struct { + *swapi.ArtifactGenerator +} + +func (h artifactGeneratorAdapter) asClientObject() client.Object { + return h.ArtifactGenerator +} + +func (h artifactGeneratorAdapter) deepCopyClientObject() client.Object { + return h.ArtifactGenerator.DeepCopy() +} + +// swapi.ArtifactGeneratorList + +type artifactGeneratorListAdapter struct { + *swapi.ArtifactGeneratorList +} + +func (h artifactGeneratorListAdapter) asClientList() client.ObjectList { + return h.ArtifactGeneratorList +} + +func (h artifactGeneratorListAdapter) len() int { + return len(h.ArtifactGeneratorList.Items) +} diff --git a/cmd/flux/export_artifact.go b/cmd/flux/export_artifact.go new file mode 100644 index 00000000..b3917b6e --- /dev/null +++ b/cmd/flux/export_artifact.go @@ -0,0 +1,31 @@ +/* +Copyright 2025 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 main + +import ( + "github.com/spf13/cobra" +) + +var exportArtifactCmd = &cobra.Command{ + Use: "artifact", + Short: "Export artifact objects", + Long: `The export artifact sub-commands export artifacts objects in YAML format.`, +} + +func init() { + exportCmd.AddCommand(exportArtifactCmd) +} diff --git a/cmd/flux/export_artifact_generator.go b/cmd/flux/export_artifact_generator.go new file mode 100644 index 00000000..4f3ae90c --- /dev/null +++ b/cmd/flux/export_artifact_generator.go @@ -0,0 +1,72 @@ +/* +Copyright 2025 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 main + +import ( + "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + swapi "github.com/fluxcd/source-watcher/api/v2/v1beta1" +) + +var exportArtifactGeneratorCmd = &cobra.Command{ + Use: "generator [name]", + Short: "Export ArtifactGenerator resources in YAML format", + Long: "The export artifact generator command exports one or all ArtifactGenerator resources in YAML format.", + Example: ` # Export all ArtifactGenerator resources + flux export artifact generator --all > artifact-generators.yaml + + # Export a specific generator + flux export artifact generator my-generator > my-generator.yaml`, + ValidArgsFunction: resourceNamesCompletionFunc(swapi.GroupVersion.WithKind(swapi.ArtifactGeneratorKind)), + RunE: exportCommand{ + object: artifactGeneratorAdapter{&swapi.ArtifactGenerator{}}, + list: artifactGeneratorListAdapter{&swapi.ArtifactGeneratorList{}}, + }.run, +} + +func init() { + exportArtifactCmd.AddCommand(exportArtifactGeneratorCmd) +} + +// Export returns an ArtifactGenerator value which has +// extraneous information stripped out. +func exportArtifactGenerator(item *swapi.ArtifactGenerator) interface{} { + gvk := swapi.GroupVersion.WithKind(swapi.ArtifactGeneratorKind) + export := swapi.ArtifactGenerator{ + TypeMeta: metav1.TypeMeta{ + Kind: gvk.Kind, + APIVersion: gvk.GroupVersion().String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: item.Name, + Namespace: item.Namespace, + Labels: item.Labels, + Annotations: item.Annotations, + }, + Spec: item.Spec, + } + return export +} + +func (ex artifactGeneratorAdapter) export() interface{} { + return exportArtifactGenerator(ex.ArtifactGenerator) +} + +func (ex artifactGeneratorListAdapter) exportItem(i int) interface{} { + return exportArtifactGenerator(&ex.ArtifactGeneratorList.Items[i]) +} diff --git a/go.mod b/go.mod index 8a20a5c1..6c85ccaa 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/fluxcd/pkg/tar v0.14.0 github.com/fluxcd/pkg/version v0.10.0 github.com/fluxcd/source-controller/api v1.7.0 + github.com/fluxcd/source-watcher/api/v2 v2.0.0 github.com/go-git/go-git/v5 v5.16.2 github.com/go-logr/logr v1.4.3 github.com/gonvenience/bunt v1.4.2 diff --git a/go.sum b/go.sum index 568c183e..afb9874c 100644 --- a/go.sum +++ b/go.sum @@ -224,6 +224,8 @@ github.com/fluxcd/pkg/version v0.10.0 h1:WETlCRbfbocsDItkCCeh/4x4zQkZ5i/lUe7P7Va github.com/fluxcd/pkg/version v0.10.0/go.mod h1:dgmjEq4ykvBnqK1oVXM+hcXx3kAY/b4uZDYUn8XnHjk= github.com/fluxcd/source-controller/api v1.7.0 h1:y6vjvbkIN4JzianhmaJqujeghVpvQn3gcsVW/f1xMeA= github.com/fluxcd/source-controller/api v1.7.0/go.mod h1:UOIEs9AACxPW7fQFqGWw1/FN2QqYDLG6WkvPIyscHkw= +github.com/fluxcd/source-watcher/api/v2 v2.0.0 h1:7SBFX6fnnt/OrU17HkLkwuNXc+1GC2AbVS32cfxSFa0= +github.com/fluxcd/source-watcher/api/v2 v2.0.0/go.mod h1:w1Z6yxPqjerwwvh4ljcSGHkRMA5HmFEdu8EmhiQfWKs= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= diff --git a/internal/utils/utils.go b/internal/utils/utils.go index ce0040b9..67a6aa35 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -51,6 +51,7 @@ import ( runclient "github.com/fluxcd/pkg/runtime/client" "github.com/fluxcd/pkg/version" sourcev1 "github.com/fluxcd/source-controller/api/v1" + swapi "github.com/fluxcd/source-watcher/api/v2/v1beta1" "github.com/fluxcd/flux2/v2/pkg/manifestgen/install" ) @@ -134,6 +135,7 @@ func NewScheme() *apiruntime.Scheme { _ = notificationv1b3.AddToScheme(scheme) _ = imagereflectv1.AddToScheme(scheme) _ = imageautov1.AddToScheme(scheme) + _ = swapi.AddToScheme(scheme) return scheme }