Skip to content

Commit c4851aa

Browse files
committed
Adding export source external
Signed-off-by: Daniel Guns <[email protected]>
1 parent 9f18062 commit c4851aa

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

cmd/flux/export_source_external.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2025 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 main
18+
19+
import (
20+
"github.com/spf13/cobra"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/types"
23+
24+
sourcev1 "github.com/fluxcd/source-controller/api/v1"
25+
)
26+
27+
var exportSourceExternalCmd = &cobra.Command{
28+
Use: "external [name]",
29+
Short: "Export ExternalArtifact sources in YAML format",
30+
Long: "The export source external command exports one or all ExternalArtifact sources in YAML format.",
31+
Example: ` # Export all ExternalArtifact sources
32+
flux export source external --all > sources.yaml
33+
34+
# Export a specific ExternalArtifact
35+
flux export source external my-artifact > source.yaml`,
36+
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.ExternalArtifactKind)),
37+
RunE: exportWithSecretCommand{
38+
list: externalArtifactListAdapter{&sourcev1.ExternalArtifactList{}},
39+
object: externalArtifactAdapter{&sourcev1.ExternalArtifact{}},
40+
}.run,
41+
}
42+
43+
func init() {
44+
exportSourceCmd.AddCommand(exportSourceExternalCmd)
45+
}
46+
47+
func exportExternalArtifact(source *sourcev1.ExternalArtifact) interface{} {
48+
gvk := sourcev1.GroupVersion.WithKind(sourcev1.ExternalArtifactKind)
49+
export := sourcev1.ExternalArtifact{
50+
TypeMeta: metav1.TypeMeta{
51+
Kind: gvk.Kind,
52+
APIVersion: gvk.GroupVersion().String(),
53+
},
54+
ObjectMeta: metav1.ObjectMeta{
55+
Name: source.Name,
56+
Namespace: source.Namespace,
57+
Labels: source.Labels,
58+
Annotations: source.Annotations,
59+
},
60+
Spec: source.Spec,
61+
}
62+
return export
63+
}
64+
65+
func getExternalArtifactSecret(source *sourcev1.ExternalArtifact) *types.NamespacedName {
66+
// ExternalArtifact does not have a secretRef in its spec, this satisfies the interface
67+
return nil
68+
}
69+
70+
func (ex externalArtifactAdapter) secret() *types.NamespacedName {
71+
return getExternalArtifactSecret(ex.ExternalArtifact)
72+
}
73+
74+
func (ex externalArtifactListAdapter) secretItem(i int) *types.NamespacedName {
75+
return getExternalArtifactSecret(&ex.ExternalArtifactList.Items[i])
76+
}
77+
78+
func (ex externalArtifactAdapter) export() interface{} {
79+
return exportExternalArtifact(ex.ExternalArtifact)
80+
}
81+
82+
func (ex externalArtifactListAdapter) exportItem(i int) interface{} {
83+
return exportExternalArtifact(&ex.ExternalArtifactList.Items[i])
84+
}

0 commit comments

Comments
 (0)