Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
876629f6
Commit
876629f6
authored
May 08, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move ConfigFlags to pkg/kubectl/genericclioptions
parent
5686fcfc
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
131 additions
and
92 deletions
+131
-92
.golint_failures
hack/.golint_failures
+1
-0
cmd.go
pkg/kubectl/cmd/cmd.go
+9
-2
config_test.go
pkg/kubectl/cmd/config/config_test.go
+1
-1
view_test.go
pkg/kubectl/cmd/config/view_test.go
+1
-1
set_test.go
pkg/kubectl/cmd/set/set_test.go
+1
-1
BUILD
pkg/kubectl/cmd/testing/BUILD
+1
-0
fake.go
pkg/kubectl/cmd/testing/fake.go
+2
-1
BUILD
pkg/kubectl/cmd/util/BUILD
+1
-4
factory_client_access.go
pkg/kubectl/cmd/util/factory_client_access.go
+0
-14
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+5
-4
BUILD
pkg/kubectl/genericclioptions/BUILD
+8
-0
config_flags.go
pkg/kubectl/genericclioptions/config_flags.go
+19
-63
config_flags_fake.go
pkg/kubectl/genericclioptions/config_flags_fake.go
+79
-0
BUILD
test/integration/apiserver/BUILD
+1
-0
print_test.go
test/integration/apiserver/print_test.go
+2
-1
No files found.
hack/.golint_failures
View file @
876629f6
...
@@ -151,6 +151,7 @@ pkg/kubectl/cmd/util
...
@@ -151,6 +151,7 @@ pkg/kubectl/cmd/util
pkg/kubectl/cmd/util/editor
pkg/kubectl/cmd/util/editor
pkg/kubectl/cmd/util/jsonmerge
pkg/kubectl/cmd/util/jsonmerge
pkg/kubectl/cmd/util/sanity
pkg/kubectl/cmd/util/sanity
pkg/kubectl/genericclioptions
pkg/kubectl/genericclioptions/resource
pkg/kubectl/genericclioptions/resource
pkg/kubectl/metricsutil
pkg/kubectl/metricsutil
pkg/kubectl/util
pkg/kubectl/util
...
...
pkg/kubectl/cmd/cmd.go
View file @
876629f6
...
@@ -274,8 +274,15 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
...
@@ -274,8 +274,15 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
BashCompletionFunction
:
bashCompletionFunc
,
BashCompletionFunction
:
bashCompletionFunc
,
}
}
kubeConfigFlags
:=
cmdutil
.
NewConfigFlags
()
flags
:=
cmds
.
PersistentFlags
()
kubeConfigFlags
.
AddFlags
(
cmds
.
PersistentFlags
())
flags
.
SetNormalizeFunc
(
utilflag
.
WarnWordSepNormalizeFunc
)
// Warn for "_" flags
// Normalize all flags that are coming from other packages or pre-configurations
// a.k.a. change all "_" to "-". e.g. glog package
flags
.
SetNormalizeFunc
(
utilflag
.
WordSepNormalizeFunc
)
kubeConfigFlags
:=
genericclioptions
.
NewConfigFlags
()
kubeConfigFlags
.
AddFlags
(
flags
)
matchVersionKubeConfigFlags
:=
cmdutil
.
NewMatchVersionFlags
(
kubeConfigFlags
)
matchVersionKubeConfigFlags
:=
cmdutil
.
NewMatchVersionFlags
(
kubeConfigFlags
)
matchVersionKubeConfigFlags
.
AddFlags
(
cmds
.
PersistentFlags
())
matchVersionKubeConfigFlags
.
AddFlags
(
cmds
.
PersistentFlags
())
...
...
pkg/kubectl/cmd/config/config_test.go
View file @
876629f6
...
@@ -864,7 +864,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *tes
...
@@ -864,7 +864,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *tes
argsToUse
=
append
(
argsToUse
,
args
...
)
argsToUse
=
append
(
argsToUse
,
args
...
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdConfig
(
cmdutil
.
NewFactory
(
cmdutil
.
NewTestConfigFlags
()),
clientcmd
.
NewDefaultPathOptions
(),
streams
)
cmd
:=
NewCmdConfig
(
cmdutil
.
NewFactory
(
genericclioptions
.
NewTestConfigFlags
()),
clientcmd
.
NewDefaultPathOptions
(),
streams
)
cmd
.
SetArgs
(
argsToUse
)
cmd
.
SetArgs
(
argsToUse
)
cmd
.
Execute
()
cmd
.
Execute
()
...
...
pkg/kubectl/cmd/config/view_test.go
View file @
876629f6
...
@@ -142,7 +142,7 @@ func (test viewClusterTest) run(t *testing.T) {
...
@@ -142,7 +142,7 @@ func (test viewClusterTest) run(t *testing.T) {
pathOptions
.
GlobalFile
=
fakeKubeFile
.
Name
()
pathOptions
.
GlobalFile
=
fakeKubeFile
.
Name
()
pathOptions
.
EnvVar
=
""
pathOptions
.
EnvVar
=
""
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdConfigView
(
cmdutil
.
NewFactory
(
cmdutil
.
NewTestConfigFlags
()),
streams
,
pathOptions
)
cmd
:=
NewCmdConfigView
(
cmdutil
.
NewFactory
(
genericclioptions
.
NewTestConfigFlags
()),
streams
,
pathOptions
)
cmd
.
Flags
()
.
Parse
(
test
.
flags
)
cmd
.
Flags
()
.
Parse
(
test
.
flags
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
t
.
Fatalf
(
"unexpected error executing command: %v,kubectl config view flags: %v"
,
err
,
test
.
flags
)
t
.
Fatalf
(
"unexpected error executing command: %v,kubectl config view flags: %v"
,
err
,
test
.
flags
)
...
...
pkg/kubectl/cmd/set/set_test.go
View file @
876629f6
...
@@ -26,7 +26,7 @@ import (
...
@@ -26,7 +26,7 @@ import (
)
)
func
TestLocalAndDryRunFlags
(
t
*
testing
.
T
)
{
func
TestLocalAndDryRunFlags
(
t
*
testing
.
T
)
{
f
:=
clientcmdutil
.
NewFactory
(
clientcmdutil
.
NewTestConfigFlags
())
f
:=
clientcmdutil
.
NewFactory
(
genericclioptions
.
NewTestConfigFlags
())
setCmd
:=
NewCmdSet
(
f
,
genericclioptions
.
NewTestIOStreamsDiscard
())
setCmd
:=
NewCmdSet
(
f
,
genericclioptions
.
NewTestIOStreamsDiscard
())
ensureLocalAndDryRunFlagsOnChildren
(
t
,
setCmd
,
""
)
ensureLocalAndDryRunFlagsOnChildren
(
t
,
setCmd
,
""
)
}
}
...
...
pkg/kubectl/cmd/testing/BUILD
View file @
876629f6
...
@@ -16,6 +16,7 @@ go_library(
...
@@ -16,6 +16,7 @@ go_library(
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/genericclioptions/resource:go_default_library",
"//pkg/kubectl/genericclioptions/resource:go_default_library",
"//pkg/kubectl/validation:go_default_library",
"//pkg/kubectl/validation:go_default_library",
"//pkg/printers:go_default_library",
"//pkg/printers:go_default_library",
...
...
pkg/kubectl/cmd/testing/fake.go
View file @
876629f6
...
@@ -50,6 +50,7 @@ import (
...
@@ -50,6 +50,7 @@ import (
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
openapitesting
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
openapitesting
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -267,7 +268,7 @@ func NewTestFactory() *TestFactory {
...
@@ -267,7 +268,7 @@ func NewTestFactory() *TestFactory {
fallbackReader
:=
bytes
.
NewBuffer
([]
byte
{})
fallbackReader
:=
bytes
.
NewBuffer
([]
byte
{})
clientConfig
:=
clientcmd
.
NewInteractiveDeferredLoadingClientConfig
(
loadingRules
,
overrides
,
fallbackReader
)
clientConfig
:=
clientcmd
.
NewInteractiveDeferredLoadingClientConfig
(
loadingRules
,
overrides
,
fallbackReader
)
configFlags
:=
cmdutil
.
NewTestConfigFlags
()
.
configFlags
:=
genericclioptions
.
NewTestConfigFlags
()
.
WithClientConfig
(
clientConfig
)
.
WithClientConfig
(
clientConfig
)
.
WithRESTMapper
(
testRESTMapper
())
WithRESTMapper
(
testRESTMapper
())
...
...
pkg/kubectl/cmd/util/BUILD
View file @
876629f6
...
@@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
...
@@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
srcs = [
srcs = [
"config_flags.go",
"conversion.go",
"conversion.go",
"factory.go",
"factory.go",
"factory_builder.go",
"factory_builder.go",
...
@@ -57,15 +56,12 @@ go_library(
...
@@ -57,15 +56,12 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//vendor/k8s.io/client-go/discovery:go_default_library",
"//vendor/k8s.io/client-go/discovery:go_default_library",
"//vendor/k8s.io/client-go/dynamic:go_default_library",
"//vendor/k8s.io/client-go/dynamic:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/restmapper:go_default_library",
"//vendor/k8s.io/client-go/scale:go_default_library",
"//vendor/k8s.io/client-go/scale:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
],
)
)
...
@@ -89,6 +85,7 @@ go_test(
...
@@ -89,6 +85,7 @@ go_test(
"//pkg/client/clientset_generated/internalclientset/fake:go_default_library",
"//pkg/client/clientset_generated/internalclientset/fake:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/kubectl:go_default_library",
"//pkg/kubectl:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
...
...
pkg/kubectl/cmd/util/factory_client_access.go
View file @
876629f6
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"io"
"io"
"os"
"os"
"path/filepath"
"path/filepath"
"regexp"
"strings"
"strings"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -578,19 +577,6 @@ func (f *ring0Factory) CanBeAutoscaled(kind schema.GroupKind) error {
...
@@ -578,19 +577,6 @@ func (f *ring0Factory) CanBeAutoscaled(kind schema.GroupKind) error {
return
nil
return
nil
}
}
// overlyCautiousIllegalFileCharacters matches characters that *might* not be supported. Windows is really restrictive, so this is really restrictive
var
overlyCautiousIllegalFileCharacters
=
regexp
.
MustCompile
(
`[^(\w/\.)]`
)
// computeDiscoverCacheDir takes the parentDir and the host and comes up with a "usually non-colliding" name.
func
computeDiscoverCacheDir
(
parentDir
,
host
string
)
string
{
// strip the optional scheme from host if its there:
schemelessHost
:=
strings
.
Replace
(
strings
.
Replace
(
host
,
"https://"
,
""
,
1
),
"http://"
,
""
,
1
)
// now do a simple collapse of non-AZ09 characters. Collisions are possible but unlikely. Even if we do collide the problem is short lived
safeHost
:=
overlyCautiousIllegalFileCharacters
.
ReplaceAllString
(
schemelessHost
,
"_"
)
return
filepath
.
Join
(
parentDir
,
safeHost
)
}
// this method exists to help us find the points still relying on internal types.
// this method exists to help us find the points still relying on internal types.
func
InternalVersionDecoder
()
runtime
.
Decoder
{
func
InternalVersionDecoder
()
runtime
.
Decoder
{
return
legacyscheme
.
Codecs
.
UniversalDecoder
()
return
legacyscheme
.
Codecs
.
UniversalDecoder
()
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
876629f6
...
@@ -37,10 +37,11 @@ import (
...
@@ -37,10 +37,11 @@ import (
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
)
)
func
TestPortsForObject
(
t
*
testing
.
T
)
{
func
TestPortsForObject
(
t
*
testing
.
T
)
{
f
:=
NewFactory
(
NewTestConfigFlags
())
f
:=
NewFactory
(
genericclioptions
.
NewTestConfigFlags
())
pod
:=
&
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
...
@@ -71,7 +72,7 @@ func TestPortsForObject(t *testing.T) {
...
@@ -71,7 +72,7 @@ func TestPortsForObject(t *testing.T) {
}
}
func
TestProtocolsForObject
(
t
*
testing
.
T
)
{
func
TestProtocolsForObject
(
t
*
testing
.
T
)
{
f
:=
NewFactory
(
NewTestConfigFlags
())
f
:=
NewFactory
(
genericclioptions
.
NewTestConfigFlags
())
pod
:=
&
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
...
@@ -109,7 +110,7 @@ func TestProtocolsForObject(t *testing.T) {
...
@@ -109,7 +110,7 @@ func TestProtocolsForObject(t *testing.T) {
}
}
func
TestLabelsForObject
(
t
*
testing
.
T
)
{
func
TestLabelsForObject
(
t
*
testing
.
T
)
{
f
:=
NewFactory
(
NewTestConfigFlags
())
f
:=
NewFactory
(
genericclioptions
.
NewTestConfigFlags
())
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
@@ -160,7 +161,7 @@ func TestLabelsForObject(t *testing.T) {
...
@@ -160,7 +161,7 @@ func TestLabelsForObject(t *testing.T) {
}
}
func
TestCanBeExposed
(
t
*
testing
.
T
)
{
func
TestCanBeExposed
(
t
*
testing
.
T
)
{
factory
:=
NewFactory
(
NewTestConfigFlags
())
factory
:=
NewFactory
(
genericclioptions
.
NewTestConfigFlags
())
tests
:=
[]
struct
{
tests
:=
[]
struct
{
kind
schema
.
GroupKind
kind
schema
.
GroupKind
expectErr
bool
expectErr
bool
...
...
pkg/kubectl/genericclioptions/BUILD
View file @
876629f6
...
@@ -3,6 +3,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
...
@@ -3,6 +3,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
srcs = [
srcs = [
"config_flags.go",
"config_flags_fake.go",
"doc.go",
"doc.go",
"io_options.go",
"io_options.go",
"record_flags.go",
"record_flags.go",
...
@@ -12,9 +14,15 @@ go_library(
...
@@ -12,9 +14,15 @@ go_library(
deps = [
deps = [
"//vendor/github.com/evanphx/json-patch:go_default_library",
"//vendor/github.com/evanphx/json-patch:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//vendor/k8s.io/client-go/discovery:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/restmapper:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
],
],
)
)
...
...
pkg/kubectl/
cmd/util
/config_flags.go
→
pkg/kubectl/
genericclioptions
/config_flags.go
View file @
876629f6
...
@@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
...
@@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
util
package
genericclioptions
import
(
import
(
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"regexp"
"strings"
"time"
"time"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
utilflag
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/restmapper"
...
@@ -54,8 +54,6 @@ const (
...
@@ -54,8 +54,6 @@ const (
var
defaultCacheDir
=
filepath
.
Join
(
homedir
.
HomeDir
(),
".kube"
,
"http-cache"
)
var
defaultCacheDir
=
filepath
.
Join
(
homedir
.
HomeDir
(),
".kube"
,
"http-cache"
)
// TODO(juanvallejo): move to pkg/kubectl/genericclioptions once
// the dependency on cmdutil is broken here.
// ConfigFlags composes the set of values necessary
// ConfigFlags composes the set of values necessary
// for obtaining a REST client config
// for obtaining a REST client config
type
ConfigFlags
struct
{
type
ConfigFlags
struct
{
...
@@ -88,6 +86,9 @@ func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
...
@@ -88,6 +86,9 @@ func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
return
f
.
ToRawKubeConfigLoader
()
.
ClientConfig
()
return
f
.
ToRawKubeConfigLoader
()
.
ClientConfig
()
}
}
// ToRawKubeConfigLoader binds config flag values to config overrides
// Returns an interactive clientConfig if the password flag is enabled,
// or a non-interactive clientConfig otherwise.
func
(
f
*
ConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
func
(
f
*
ConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
// use the standard defaults for this client command
// use the standard defaults for this client command
...
@@ -189,7 +190,7 @@ func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, e
...
@@ -189,7 +190,7 @@ func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, e
return
discovery
.
NewCachedDiscoveryClientForConfig
(
config
,
discoveryCacheDir
,
httpCacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
return
discovery
.
NewCachedDiscoveryClientForConfig
(
config
,
discoveryCacheDir
,
httpCacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
}
}
// RESTMapper returns a mapper.
//
To
RESTMapper returns a mapper.
func
(
f
*
ConfigFlags
)
ToRESTMapper
()
(
meta
.
RESTMapper
,
error
)
{
func
(
f
*
ConfigFlags
)
ToRESTMapper
()
(
meta
.
RESTMapper
,
error
)
{
discoveryClient
,
err
:=
f
.
ToDiscoveryClient
()
discoveryClient
,
err
:=
f
.
ToDiscoveryClient
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -201,13 +202,8 @@ func (f *ConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
...
@@ -201,13 +202,8 @@ func (f *ConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
return
expander
,
nil
return
expander
,
nil
}
}
// AddFlags binds client configuration flags to a given flagset
func
(
f
*
ConfigFlags
)
AddFlags
(
flags
*
pflag
.
FlagSet
)
{
func
(
f
*
ConfigFlags
)
AddFlags
(
flags
*
pflag
.
FlagSet
)
{
flags
.
SetNormalizeFunc
(
utilflag
.
WarnWordSepNormalizeFunc
)
// Warn for "_" flags
// Normalize all flags that are coming from other packages or pre-configurations
// a.k.a. change all "_" to "-". e.g. glog package
flags
.
SetNormalizeFunc
(
utilflag
.
WordSepNormalizeFunc
)
if
f
.
KubeConfig
!=
nil
{
if
f
.
KubeConfig
!=
nil
{
flags
.
StringVar
(
f
.
KubeConfig
,
"kubeconfig"
,
*
f
.
KubeConfig
,
"Path to the kubeconfig file to use for CLI requests."
)
flags
.
StringVar
(
f
.
KubeConfig
,
"kubeconfig"
,
*
f
.
KubeConfig
,
"Path to the kubeconfig file to use for CLI requests."
)
}
}
...
@@ -265,12 +261,14 @@ func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet) {
...
@@ -265,12 +261,14 @@ func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet) {
}
}
// WithDeprecatedPasswordFlag enables the username and password config flags
func
(
f
*
ConfigFlags
)
WithDeprecatedPasswordFlag
()
*
ConfigFlags
{
func
(
f
*
ConfigFlags
)
WithDeprecatedPasswordFlag
()
*
ConfigFlags
{
f
.
Username
=
stringptr
(
""
)
f
.
Username
=
stringptr
(
""
)
f
.
Password
=
stringptr
(
""
)
f
.
Password
=
stringptr
(
""
)
return
f
return
f
}
}
// NewConfigFlags returns ConfigFlags with default values set
func
NewConfigFlags
()
*
ConfigFlags
{
func
NewConfigFlags
()
*
ConfigFlags
{
impersonateGroup
:=
[]
string
{}
impersonateGroup
:=
[]
string
{}
insecure
:=
false
insecure
:=
false
...
@@ -299,56 +297,14 @@ func stringptr(val string) *string {
...
@@ -299,56 +297,14 @@ func stringptr(val string) *string {
return
&
val
return
&
val
}
}
// TODO(juanvallejo): move to separate file when config_flags are moved
// overlyCautiousIllegalFileCharacters matches characters that *might* not be supported. Windows is really restrictive, so this is really restrictive
// to pkg/kubectl/genericclioptions
var
overlyCautiousIllegalFileCharacters
=
regexp
.
MustCompile
(
`[^(\w/\.)]`
)
type
TestConfigFlags
struct
{
clientConfig
clientcmd
.
ClientConfig
discoveryClient
discovery
.
CachedDiscoveryInterface
restMapper
meta
.
RESTMapper
}
func
(
f
*
TestConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
if
f
.
clientConfig
==
nil
{
panic
(
"attempt to obtain a test RawKubeConfigLoader with no clientConfig specified"
)
}
return
f
.
clientConfig
}
func
(
f
*
TestConfigFlags
)
ToRESTConfig
()
(
*
rest
.
Config
,
error
)
{
return
f
.
ToRawKubeConfigLoader
()
.
ClientConfig
()
}
func
(
f
*
TestConfigFlags
)
ToDiscoveryClient
()
(
discovery
.
CachedDiscoveryInterface
,
error
)
{
return
f
.
discoveryClient
,
nil
}
func
(
f
*
TestConfigFlags
)
ToRESTMapper
()
(
meta
.
RESTMapper
,
error
)
{
if
f
.
restMapper
!=
nil
{
return
f
.
restMapper
,
nil
}
if
f
.
discoveryClient
!=
nil
{
mapper
:=
restmapper
.
NewDeferredDiscoveryRESTMapper
(
f
.
discoveryClient
)
expander
:=
restmapper
.
NewShortcutExpander
(
mapper
,
f
.
discoveryClient
)
return
expander
,
nil
}
return
nil
,
fmt
.
Errorf
(
"no restmapper"
)
}
func
(
f
*
TestConfigFlags
)
WithClientConfig
(
clientConfig
clientcmd
.
ClientConfig
)
*
TestConfigFlags
{
f
.
clientConfig
=
clientConfig
return
f
}
func
(
f
*
TestConfigFlags
)
WithRESTMapper
(
mapper
meta
.
RESTMapper
)
*
TestConfigFlags
{
f
.
restMapper
=
mapper
return
f
}
func
(
f
*
TestConfigFlags
)
WithDiscoveryClient
(
c
discovery
.
CachedDiscoveryInterface
)
*
TestConfigFlags
{
f
.
discoveryClient
=
c
return
f
}
func
NewTestConfigFlags
()
*
TestConfigFlags
{
// computeDiscoverCacheDir takes the parentDir and the host and comes up with a "usually non-colliding" name.
return
&
TestConfigFlags
{}
func
computeDiscoverCacheDir
(
parentDir
,
host
string
)
string
{
// strip the optional scheme from host if its there:
schemelessHost
:=
strings
.
Replace
(
strings
.
Replace
(
host
,
"https://"
,
""
,
1
),
"http://"
,
""
,
1
)
// now do a simple collapse of non-AZ09 characters. Collisions are possible but unlikely. Even if we do collide the problem is short lived
safeHost
:=
overlyCautiousIllegalFileCharacters
.
ReplaceAllString
(
schemelessHost
,
"_"
)
return
filepath
.
Join
(
parentDir
,
safeHost
)
}
}
pkg/kubectl/genericclioptions/config_flags_fake.go
0 → 100644
View file @
876629f6
/*
Copyright 2018 The Kubernetes 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
genericclioptions
import
(
"fmt"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd"
)
type
TestConfigFlags
struct
{
clientConfig
clientcmd
.
ClientConfig
discoveryClient
discovery
.
CachedDiscoveryInterface
restMapper
meta
.
RESTMapper
}
func
(
f
*
TestConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
if
f
.
clientConfig
==
nil
{
panic
(
"attempt to obtain a test RawKubeConfigLoader with no clientConfig specified"
)
}
return
f
.
clientConfig
}
func
(
f
*
TestConfigFlags
)
ToRESTConfig
()
(
*
rest
.
Config
,
error
)
{
return
f
.
ToRawKubeConfigLoader
()
.
ClientConfig
()
}
func
(
f
*
TestConfigFlags
)
ToDiscoveryClient
()
(
discovery
.
CachedDiscoveryInterface
,
error
)
{
return
f
.
discoveryClient
,
nil
}
func
(
f
*
TestConfigFlags
)
ToRESTMapper
()
(
meta
.
RESTMapper
,
error
)
{
if
f
.
restMapper
!=
nil
{
return
f
.
restMapper
,
nil
}
if
f
.
discoveryClient
!=
nil
{
mapper
:=
restmapper
.
NewDeferredDiscoveryRESTMapper
(
f
.
discoveryClient
)
expander
:=
restmapper
.
NewShortcutExpander
(
mapper
,
f
.
discoveryClient
)
return
expander
,
nil
}
return
nil
,
fmt
.
Errorf
(
"no restmapper"
)
}
func
(
f
*
TestConfigFlags
)
WithClientConfig
(
clientConfig
clientcmd
.
ClientConfig
)
*
TestConfigFlags
{
f
.
clientConfig
=
clientConfig
return
f
}
func
(
f
*
TestConfigFlags
)
WithRESTMapper
(
mapper
meta
.
RESTMapper
)
*
TestConfigFlags
{
f
.
restMapper
=
mapper
return
f
}
func
(
f
*
TestConfigFlags
)
WithDiscoveryClient
(
c
discovery
.
CachedDiscoveryInterface
)
*
TestConfigFlags
{
f
.
discoveryClient
=
c
return
f
}
func
NewTestConfigFlags
()
*
TestConfigFlags
{
return
&
TestConfigFlags
{}
}
test/integration/apiserver/BUILD
View file @
876629f6
...
@@ -23,6 +23,7 @@ go_test(
...
@@ -23,6 +23,7 @@ go_test(
"//pkg/api/testapi:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/master:go_default_library",
"//pkg/master:go_default_library",
"//pkg/printers:go_default_library",
"//pkg/printers:go_default_library",
"//pkg/printers/internalversion:go_default_library",
"//pkg/printers/internalversion:go_default_library",
...
...
test/integration/apiserver/print_test.go
View file @
876629f6
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"k8s.io/gengo/examples/set-gen/sets"
"k8s.io/gengo/examples/set-gen/sets"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
"k8s.io/kubernetes/test/integration/framework"
"k8s.io/kubernetes/test/integration/framework"
...
@@ -149,7 +150,7 @@ func TestServerSidePrint(t *testing.T) {
...
@@ -149,7 +150,7 @@ func TestServerSidePrint(t *testing.T) {
tableParam
:=
fmt
.
Sprintf
(
"application/json;as=Table;g=%s;v=%s, application/json"
,
metav1beta1
.
GroupName
,
metav1beta1
.
SchemeGroupVersion
.
Version
)
tableParam
:=
fmt
.
Sprintf
(
"application/json;as=Table;g=%s;v=%s, application/json"
,
metav1beta1
.
GroupName
,
metav1beta1
.
SchemeGroupVersion
.
Version
)
printer
:=
newFakePrinter
(
printersinternal
.
AddHandlers
)
printer
:=
newFakePrinter
(
printersinternal
.
AddHandlers
)
configFlags
:=
util
.
NewTestConfigFlags
()
.
configFlags
:=
genericclioptions
.
NewTestConfigFlags
()
.
WithClientConfig
(
clientcmd
.
NewDefaultClientConfig
(
*
createKubeConfig
(
s
.
URL
),
&
clientcmd
.
ConfigOverrides
{}))
WithClientConfig
(
clientcmd
.
NewDefaultClientConfig
(
*
createKubeConfig
(
s
.
URL
),
&
clientcmd
.
ConfigOverrides
{}))
restConfig
,
err
:=
configFlags
.
ToRESTConfig
()
restConfig
,
err
:=
configFlags
.
ToRESTConfig
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment