diff --git a/pkg/k8s/utils/utils.go b/pkg/k8s/utils/utils.go index 70da642f5..f90cc9250 100644 --- a/pkg/k8s/utils/utils.go +++ b/pkg/k8s/utils/utils.go @@ -30,12 +30,26 @@ import ( "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 // 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.KubeConfig = &path kf.Context = &context + for _, o := range opts { + o(kf) + } + return cmdutil.NewFactory(cmdutil.NewMatchVersionFlags(&factory.CachingRESTClientGetter{ Delegate: kf, })) diff --git a/pkg/k8s/utils/utils_test.go b/pkg/k8s/utils/utils_test.go index 30cb0585c..22ae19917 100644 --- a/pkg/k8s/utils/utils_test.go +++ b/pkg/k8s/utils/utils_test.go @@ -29,7 +29,7 @@ import ( func TestDefaultManifestFactory(t *testing.T) { bundle, err := document.NewBundleByPath("testdata/source_bundle") require.NoError(t, err) - mapper, err := FactoryFromKubeConfig("testdata/kubeconfig.yaml", "").ToRESTMapper() + mapper, err := FactoryFromKubeConfig("testdata/kubeconfig.yaml", "", SetTimeout("30s")).ToRESTMapper() require.NoError(t, err) reader := DefaultManifestReaderFactory(false, bundle, mapper) require.NotNil(t, reader)