Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1105 Внедрение механизмов обеспечения безопасности цепочки поставки программных проектов
Legacy
scanned-projects
helm
Commits
1a508ccd
Unverified
Commit
1a508ccd
authored
6 years ago
by
Adam Reese
Browse files
Options
Download
Patches
Plain Diff
ref(*): move kubeconfig flags to helm/environment
parent
2a97768b
main
Release
add-codeql
dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible
dependabot/go_modules/github.com/lib/pq-1.10.9
dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0
dependabot/go_modules/golang.org/x/crypto-0.9.0
dependabot/go_modules/golang.org/x/term-0.8.0
dependabot/go_modules/k8s.io/klog/v2-2.100.1
feat-v3/event-emitter-lua
release-3.0
release-3.1
release-3.10
release-3.11
release-3.12
release-3.2
release-3.3
release-3.4
release-3.5
release-3.6
release-3.6.1
release-3.6.2
release-3.7
release-3.8
release-3.9
release-v3.0.0-beta.4
v3.12.0
v3.12.0-rc.1
v3.12.0-dev.1
v3.11.3
v3.11.2
v3.11.1
v3.11.0
v3.11.0-rc.2
v3.11.0-rc.1
v3.10.3
v3.10.2
v3.10.1
v3.10.0
v3.10.0-rc.1
v3.9.4
v3.9.3
v3.9.2
v3.9.1
v3.9.0
v3.9.0-rc.1
v3.8.2
v3.8.1
v3.8.0
v3.8.0-rc.2
v3.8.0-rc.1
v3.7.2
v3.7.1
v3.7.0
v3.7.0-rc.3
v3.7.0-rc.2
v3.7.0-rc.1
v3.6.3
v3.6.2
v3.6.1
v3.6.0
v3.6.0-rc.1
v3.5.4
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.5.0-rc.2
v3.5.0-rc.1
v3.4.2
v3.4.1
v3.4.0
v3.4.0-rc.1
v3.3.4
v3.3.3
v3.3.2
v3.3.1
v3.3.0
v3.3.0-rc.2
v3.3.0-rc.1
v3.2.4
v3.2.3
v3.2.2
v3.2.1
v3.2.0
v3.2.0-rc.1
v3.1.3
v3.1.2
v3.1.1
v3.1.0
v3.1.0-rc.3
v3.1.0-rc.2
v3.1.0-rc.1
v3.0.3
v3.0.2
v3.0.1
v3.0.0
v3.0.0-rc.4
v3.0.0-rc.3
v3.0.0-rc.2
v3.0.0-rc.1
v3.0.0-beta.5
v3.0.0-beta.4
v3.0.0-beta.3
v3.0.0-beta.2
v3.0.0-beta.1
v3.0.0-alpha.2
v3.0.0-alpha.1
No related merge requests found
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
cmd/helm/get.go
+1
-3
cmd/helm/get.go
cmd/helm/helm.go
+13
-6
cmd/helm/helm.go
cmd/helm/history.go
+2
-4
cmd/helm/history.go
cmd/helm/install_test.go
+1
-0
cmd/helm/install_test.go
cmd/helm/list.go
+1
-3
cmd/helm/list.go
cmd/helm/status.go
+1
-3
cmd/helm/status.go
pkg/helm/environment/environment.go
+15
-5
pkg/helm/environment/environment.go
pkg/helm/environment/environment_test.go
+17
-13
pkg/helm/environment/environment_test.go
pkg/kube/config.go
+6
-10
pkg/kube/config.go
with
57 additions
and
47 deletions
+57
-47
cmd/helm/get.go
+
1
−
3
View file @
1a508ccd
...
...
@@ -62,9 +62,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
return
errReleaseRequired
}
get
.
release
=
args
[
0
]
if
get
.
client
==
nil
{
get
.
client
=
newClient
()
}
get
.
client
=
ensureHelmClient
(
get
.
client
)
return
get
.
run
()
},
}
...
...
This diff is collapsed.
Click to expand it.
cmd/helm/helm.go
+
13
−
6
View file @
1a508ccd
...
...
@@ -21,6 +21,7 @@ import (
"log"
"os"
"strings"
"sync"
"github.com/spf13/cobra"
// Import to initialize client auth plugins.
...
...
@@ -34,8 +35,9 @@ import (
)
var
(
settings
helm_env
.
EnvSettings
config
clientcmd
.
ClientConfig
settings
helm_env
.
EnvSettings
config
clientcmd
.
ClientConfig
configOnce
sync
.
Once
)
var
globalUsage
=
`The Kubernetes package manager
...
...
@@ -70,8 +72,6 @@ func newRootCmd(args []string) *cobra.Command {
settings
.
AddFlags
(
flags
)
config
=
kube
.
GetConfig
(
flags
)
out
:=
cmd
.
OutOrStdout
()
cmd
.
AddCommand
(
...
...
@@ -159,7 +159,7 @@ func ensureHelmClient(h helm.Interface) helm.Interface {
}
func
newClient
()
helm
.
Interface
{
kc
:=
kube
.
New
(
c
onfig
)
kc
:=
kube
.
New
(
kubeC
onfig
()
)
kc
.
Log
=
logf
clientset
,
err
:=
kc
.
KubernetesClientSet
()
...
...
@@ -178,8 +178,15 @@ func newClient() helm.Interface {
)
}
func
kubeConfig
()
clientcmd
.
ClientConfig
{
configOnce
.
Do
(
func
()
{
config
=
kube
.
GetConfig
(
settings
.
KubeConfig
,
settings
.
KubeContext
,
settings
.
Namespace
)
})
return
config
}
func
getNamespace
()
string
{
if
ns
,
_
,
err
:=
c
onfig
.
Namespace
();
err
==
nil
{
if
ns
,
_
,
err
:=
kubeC
onfig
()
.
Namespace
();
err
==
nil
{
return
ns
}
return
"default"
...
...
This diff is collapsed.
Click to expand it.
cmd/helm/history.go
+
2
−
4
View file @
1a508ccd
...
...
@@ -74,12 +74,10 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
Short
:
"fetch release history"
,
Aliases
:
[]
string
{
"hist"
},
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
switch
{
case
len
(
args
)
==
0
:
if
len
(
args
)
==
0
{
return
errReleaseRequired
case
his
.
helmc
==
nil
:
his
.
helmc
=
newClient
()
}
his
.
helmc
=
ensureHelmClient
(
his
.
helmc
)
his
.
rls
=
args
[
0
]
return
his
.
run
()
},
...
...
This diff is collapsed.
Click to expand it.
cmd/helm/install_test.go
+
1
−
0
View file @
1a508ccd
...
...
@@ -24,6 +24,7 @@ import (
"testing"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm"
)
...
...
This diff is collapsed.
Click to expand it.
cmd/helm/list.go
+
1
−
3
View file @
1a508ccd
...
...
@@ -90,9 +90,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
if
len
(
args
)
>
0
{
list
.
filter
=
strings
.
Join
(
args
,
" "
)
}
if
list
.
client
==
nil
{
list
.
client
=
newClient
()
}
list
.
client
=
ensureHelmClient
(
list
.
client
)
return
list
.
run
()
},
}
...
...
This diff is collapsed.
Click to expand it.
cmd/helm/status.go
+
1
−
3
View file @
1a508ccd
...
...
@@ -67,9 +67,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
return
errReleaseRequired
}
status
.
release
=
args
[
0
]
if
status
.
client
==
nil
{
status
.
client
=
newClient
()
}
status
.
client
=
ensureHelmClient
(
status
.
client
)
return
status
.
run
()
},
}
...
...
This diff is collapsed.
Click to expand it.
pkg/helm/environment/environment.go
+
15
−
5
View file @
1a508ccd
...
...
@@ -32,20 +32,29 @@ import (
"k8s.io/helm/pkg/helm/helmpath"
)
//
D
efaultHelmHome is the default HELM_HOME.
var
D
efaultHelmHome
=
filepath
.
Join
(
homedir
.
HomeDir
(),
".helm"
)
//
d
efaultHelmHome is the default HELM_HOME.
var
d
efaultHelmHome
=
filepath
.
Join
(
homedir
.
HomeDir
(),
".helm"
)
// EnvSettings describes all of the environment settings.
type
EnvSettings
struct
{
// Home is the local path to the Helm home directory.
Home
helmpath
.
Home
// Namespace is the namespace scope.
Namespace
string
// KubeConfig is the path to the kubeconfig file.
KubeConfig
string
// KubeContext is the name of the kubeconfig context.
KubeContext
string
// Debug indicates whether or not Helm is running in Debug mode.
Debug
bool
}
// AddFlags binds flags to the given flagset.
func
(
s
*
EnvSettings
)
AddFlags
(
fs
*
pflag
.
FlagSet
)
{
fs
.
StringVar
((
*
string
)(
&
s
.
Home
),
"home"
,
DefaultHelmHome
,
"location of your Helm config. Overrides $HELM_HOME"
)
fs
.
StringVar
((
*
string
)(
&
s
.
Home
),
"home"
,
defaultHelmHome
,
"location of your Helm config. Overrides $HELM_HOME"
)
fs
.
StringVarP
(
&
s
.
Namespace
,
"namespace"
,
"n"
,
""
,
"namespace scope for this request"
)
fs
.
StringVar
(
&
s
.
KubeConfig
,
"kubeconfig"
,
""
,
"path to the kubeconfig file"
)
fs
.
StringVar
(
&
s
.
KubeContext
,
"kube-context"
,
""
,
"name of the kubeconfig context to use"
)
fs
.
BoolVar
(
&
s
.
Debug
,
"debug"
,
false
,
"enable verbose output"
)
}
...
...
@@ -66,8 +75,9 @@ func (s EnvSettings) PluginDirs() string {
// envMap maps flag names to envvars
var
envMap
=
map
[
string
]
string
{
"debug"
:
"HELM_DEBUG"
,
"home"
:
"HELM_HOME"
,
"debug"
:
"HELM_DEBUG"
,
"home"
:
"HELM_HOME"
,
"namespace"
:
"HELM_NAMESPACE"
,
}
func
setFlagFromEnv
(
name
,
envar
string
,
fs
*
pflag
.
FlagSet
)
{
...
...
This diff is collapsed.
Click to expand it.
pkg/helm/environment/environment_test.go
+
17
−
13
View file @
1a508ccd
...
...
@@ -31,23 +31,22 @@ func TestEnvSettings(t *testing.T) {
name
string
// input
args
[]
string
args
string
envars
map
[
string
]
string
// expected values
home
,
ns
,
plugins
string
debug
bool
home
,
ns
,
kcontext
,
plugins
string
debug
bool
}{
{
name
:
"defaults"
,
args
:
[]
string
{},
home
:
DefaultHelmHome
,
plugins
:
helmpath
.
Home
(
DefaultHelmHome
)
.
Plugins
(),
ns
:
"kube-system"
,
home
:
defaultHelmHome
,
plugins
:
helmpath
.
Home
(
defaultHelmHome
)
.
Plugins
(),
ns
:
""
,
},
{
name
:
"with flags set"
,
args
:
[]
string
{
"--home"
,
"/foo"
,
"--debug"
}
,
args
:
"--home /foo --debug --namespace=myns"
,
home
:
"/foo"
,
plugins
:
helmpath
.
Home
(
"/foo"
)
.
Plugins
(),
ns
:
"myns"
,
...
...
@@ -55,8 +54,7 @@ func TestEnvSettings(t *testing.T) {
},
{
name
:
"with envvars set"
,
args
:
[]
string
{},
envars
:
map
[
string
]
string
{
"HELM_HOME"
:
"/bar"
,
"HELM_DEBUG"
:
"1"
},
envars
:
map
[
string
]
string
{
"HELM_HOME"
:
"/bar"
,
"HELM_DEBUG"
:
"1"
,
"HELM_NAMESPACE"
:
"yourns"
},
home
:
"/bar"
,
plugins
:
helmpath
.
Home
(
"/bar"
)
.
Plugins
(),
ns
:
"yourns"
,
...
...
@@ -64,8 +62,8 @@ func TestEnvSettings(t *testing.T) {
},
{
name
:
"with flags and envvars set"
,
args
:
[]
string
{
"--home"
,
"/foo"
,
"--debug"
}
,
envars
:
map
[
string
]
string
{
"HELM_HOME"
:
"/bar"
,
"HELM_DEBUG"
:
"1"
,
"HELM_PLUGIN"
:
"glade"
},
args
:
"--home /foo --debug --namespace=myns"
,
envars
:
map
[
string
]
string
{
"HELM_HOME"
:
"/bar"
,
"HELM_DEBUG"
:
"1"
,
"HELM_NAMESPACE"
:
"yourns"
,
"HELM_PLUGIN"
:
"glade"
},
home
:
"/foo"
,
plugins
:
"glade"
,
ns
:
"myns"
,
...
...
@@ -86,7 +84,7 @@ func TestEnvSettings(t *testing.T) {
settings
:=
&
EnvSettings
{}
settings
.
AddFlags
(
flags
)
flags
.
Parse
(
tt
.
args
)
flags
.
Parse
(
strings
.
Split
(
tt
.
args
,
" "
)
)
settings
.
Init
(
flags
)
...
...
@@ -99,6 +97,12 @@ func TestEnvSettings(t *testing.T) {
if
settings
.
Debug
!=
tt
.
debug
{
t
.
Errorf
(
"expected debug %t, got %t"
,
tt
.
debug
,
settings
.
Debug
)
}
if
settings
.
Namespace
!=
tt
.
ns
{
t
.
Errorf
(
"expected namespace %q, got %q"
,
tt
.
ns
,
settings
.
Namespace
)
}
if
settings
.
KubeContext
!=
tt
.
kcontext
{
t
.
Errorf
(
"expected kube-context %q, got %q"
,
tt
.
kcontext
,
settings
.
KubeContext
)
}
cleanup
()
})
...
...
This diff is collapsed.
Click to expand it.
pkg/kube/config.go
+
6
−
10
View file @
1a508ccd
...
...
@@ -16,21 +16,17 @@ limitations under the License.
package
kube
// import "k8s.io/helm/pkg/kube"
import
(
"github.com/spf13/pflag"
"k8s.io/client-go/tools/clientcmd"
)
import
"k8s.io/client-go/tools/clientcmd"
// GetConfig returns a Kubernetes client config
for a given context
.
func
GetConfig
(
flags
*
pflag
.
FlagSet
)
clientcmd
.
ClientConfig
{
// GetConfig returns a Kubernetes client config.
func
GetConfig
(
kubeconfig
,
context
,
namespace
string
)
clientcmd
.
ClientConfig
{
rules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
rules
.
DefaultClientConfig
=
&
clientcmd
.
DefaultClientConfig
flags
.
StringVar
(
&
rules
.
ExplicitPath
,
"kubeconfig"
,
""
,
"path to the kubeconfig file to use for CLI requests"
)
rules
.
ExplicitPath
=
kubeconfig
overrides
:=
&
clientcmd
.
ConfigOverrides
{
ClusterDefaults
:
clientcmd
.
ClusterDefaults
}
flags
.
StringVarP
(
&
overrides
.
Context
.
Namespace
,
"namespace"
,
"n"
,
""
,
"if present, the namespace scope for this CLI request"
)
flags
.
StringVar
(
&
overrides
.
CurrentContext
,
"context"
,
""
,
"the name of the kubeconfig context to use"
)
overrides
.
CurrentContext
=
context
overrides
.
Context
.
Namespace
=
namespace
return
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
rules
,
overrides
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets