Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
flux2
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
fluxcd
flux2
Commits
55303625
Commit
55303625
authored
5 years ago
by
stefanprodan
Browse files
Options
Downloads
Patches
Plain Diff
Add credentials export option for git sources
parent
f127adc8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/tk/export_kustomization.go
+7
-1
7 additions, 1 deletion
cmd/tk/export_kustomization.go
cmd/tk/export_source.go
+6
-0
6 additions, 0 deletions
cmd/tk/export_source.go
cmd/tk/export_source_git.go
+56
-3
56 additions, 3 deletions
cmd/tk/export_source_git.go
cmd/tk/utils.go
+2
-0
2 additions, 0 deletions
cmd/tk/utils.go
with
71 additions
and
4 deletions
cmd/tk/export_kustomization.go
+
7
−
1
View file @
55303625
...
...
@@ -16,7 +16,13 @@ var exportKsCmd = &cobra.Command{
Use
:
"kustomization [name]"
,
Aliases
:
[]
string
{
"ks"
},
Short
:
"Export kustomization in YAML format"
,
RunE
:
exportKsCmdRun
,
Example
:
` # Export all kustomizations
export kustomization --all > kustomizations.yaml
# Export a kustomization
export kustomization my-app > kustomization.yaml
`
,
RunE
:
exportKsCmdRun
,
}
func
init
()
{
...
...
This diff is collapsed.
Click to expand it.
cmd/tk/export_source.go
+
6
−
0
View file @
55303625
...
...
@@ -9,6 +9,12 @@ var exportSourceCmd = &cobra.Command{
Short
:
"Export source commands"
,
}
var
(
exportSourceWithCred
bool
)
func
init
()
{
exportSourceCmd
.
PersistentFlags
()
.
BoolVar
(
&
exportSourceWithCred
,
"with-credentials"
,
false
,
"include credential secrets"
)
exportCmd
.
AddCommand
(
exportSourceCmd
)
}
This diff is collapsed.
Click to expand it.
cmd/tk/export_source_git.go
+
56
−
3
View file @
55303625
...
...
@@ -6,6 +6,7 @@ import (
sourcev1
"github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
...
...
@@ -14,8 +15,14 @@ import (
var
exportSourceGitCmd
=
&
cobra
.
Command
{
Use
:
"git [name]"
,
Short
:
"Export git source in YAML format"
,
RunE
:
exportSourceGitCmdRun
,
Short
:
"Export git sources in YAML format"
,
Example
:
` # Export all git sources
export source git --all > sources.yaml
# Export a git source including the SSH keys or basic auth credentials
export source git my-private-repo --with-credentials > source.yaml
`
,
RunE
:
exportSourceGitCmdRun
,
}
func
init
()
{
...
...
@@ -51,6 +58,11 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
if
err
:=
exportGit
(
repository
);
err
!=
nil
{
return
err
}
if
exportSourceWithCred
{
if
err
:=
exportGitCredentials
(
ctx
,
kubeClient
,
repository
);
err
!=
nil
{
return
err
}
}
}
}
else
{
name
:=
args
[
0
]
...
...
@@ -63,7 +75,12 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
if
err
!=
nil
{
return
err
}
return
exportGit
(
repository
)
if
err
:=
exportGit
(
repository
);
err
!=
nil
{
return
err
}
if
exportSourceWithCred
{
return
exportGitCredentials
(
ctx
,
kubeClient
,
repository
)
}
}
return
nil
}
...
...
@@ -91,3 +108,39 @@ func exportGit(source sourcev1.GitRepository) error {
fmt
.
Println
(
string
(
data
))
return
nil
}
func
exportGitCredentials
(
ctx
context
.
Context
,
kubeClinet
client
.
Client
,
source
sourcev1
.
GitRepository
)
error
{
if
source
.
Spec
.
SecretRef
!=
nil
{
namespacedName
:=
types
.
NamespacedName
{
Namespace
:
source
.
Namespace
,
Name
:
source
.
Spec
.
SecretRef
.
Name
,
}
var
cred
corev1
.
Secret
err
:=
kubeClinet
.
Get
(
ctx
,
namespacedName
,
&
cred
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"get secret failed: %w"
,
err
)
}
exported
:=
corev1
.
Secret
{
TypeMeta
:
metav1
.
TypeMeta
{
APIVersion
:
"v1"
,
Kind
:
"Secret"
,
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
namespacedName
.
Name
,
Namespace
:
namespacedName
.
Namespace
,
},
Data
:
cred
.
Data
,
Type
:
cred
.
Type
,
}
data
,
err
:=
yaml
.
Marshal
(
exported
)
if
err
!=
nil
{
return
err
}
fmt
.
Println
(
"---"
)
fmt
.
Println
(
string
(
data
))
}
return
nil
}
This diff is collapsed.
Click to expand it.
cmd/tk/utils.go
+
2
−
0
View file @
55303625
...
...
@@ -12,6 +12,7 @@ import (
kustomizev1
"github.com/fluxcd/kustomize-controller/api/v1alpha1"
sourcev1
"github.com/fluxcd/source-controller/api/v1alpha1"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
...
...
@@ -98,6 +99,7 @@ func (*Utils) kubeClient(config string) (client.Client, error) {
}
scheme
:=
runtime
.
NewScheme
()
_
=
corev1
.
AddToScheme
(
scheme
)
_
=
sourcev1
.
AddToScheme
(
scheme
)
_
=
kustomizev1
.
AddToScheme
(
scheme
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment