Allow to configure timeout for k8s client
It would be helpful to have a possibility to configure Timeout field, as well as others allowed. Change-Id: I1e0e895b7ca6a17e86a6ad36f405e2538775cbbb Closes: #553 Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
parent
c7d65d4114
commit
0c4d8b80bf
@ -30,12 +30,26 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ClientOption is a function that allows to modify ConfigFlags object which is used to create Client
|
||||||
|
type ClientOption func(*genericclioptions.ConfigFlags)
|
||||||
|
|
||||||
|
// SetTimeout sets Timeout option in ConfigFlags object
|
||||||
|
func SetTimeout(timeout string) ClientOption {
|
||||||
|
return func(co *genericclioptions.ConfigFlags) {
|
||||||
|
*co.Timeout = timeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FactoryFromKubeConfig returns a factory with the
|
// FactoryFromKubeConfig returns a factory with the
|
||||||
// default Kubernetes resources for the given kube config path and context
|
// default Kubernetes resources for the given kube config path and context
|
||||||
func FactoryFromKubeConfig(path, context string) cmdutil.Factory {
|
func FactoryFromKubeConfig(path, context string, opts ...ClientOption) cmdutil.Factory {
|
||||||
kf := genericclioptions.NewConfigFlags(false)
|
kf := genericclioptions.NewConfigFlags(false)
|
||||||
kf.KubeConfig = &path
|
kf.KubeConfig = &path
|
||||||
kf.Context = &context
|
kf.Context = &context
|
||||||
|
for _, o := range opts {
|
||||||
|
o(kf)
|
||||||
|
}
|
||||||
|
|
||||||
return cmdutil.NewFactory(cmdutil.NewMatchVersionFlags(&factory.CachingRESTClientGetter{
|
return cmdutil.NewFactory(cmdutil.NewMatchVersionFlags(&factory.CachingRESTClientGetter{
|
||||||
Delegate: kf,
|
Delegate: kf,
|
||||||
}))
|
}))
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
func TestDefaultManifestFactory(t *testing.T) {
|
func TestDefaultManifestFactory(t *testing.T) {
|
||||||
bundle, err := document.NewBundleByPath("testdata/source_bundle")
|
bundle, err := document.NewBundleByPath("testdata/source_bundle")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
mapper, err := FactoryFromKubeConfig("testdata/kubeconfig.yaml", "").ToRESTMapper()
|
mapper, err := FactoryFromKubeConfig("testdata/kubeconfig.yaml", "", SetTimeout("30s")).ToRESTMapper()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
reader := DefaultManifestReaderFactory(false, bundle, mapper)
|
reader := DefaultManifestReaderFactory(false, bundle, mapper)
|
||||||
require.NotNil(t, reader)
|
require.NotNil(t, reader)
|
||||||
|
Loading…
Reference in New Issue
Block a user