From d33e66b81b0f12a6ea83f6cdd0384d7d55c987dc Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Sat, 10 Sep 2022 17:56:23 +0200 Subject: [PATCH] e2e: reduce built time for framework Pulling the CreateKubeConfig function from the expensive to build test/utils/apiserver package had a considerable impact on the overall build time because that package depends on a lot of other packages. Because only that one function is needed by the framework, that extra build time can be avoided by moving it into its own package. --- test/e2e/framework/test_context.go | 4 ++-- test/utils/apiserver/testapiserver.go | 3 ++- test/utils/{apiserver => kubeconfig}/kubeconfig.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) rename test/utils/{apiserver => kubeconfig}/kubeconfig.go (99%) diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 022d1320241..f4bb80e0d8a 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -39,7 +39,7 @@ import ( "k8s.io/klog/v2" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" - testapiserver "k8s.io/kubernetes/test/utils/apiserver" + "k8s.io/kubernetes/test/utils/kubeconfig" ) const ( @@ -460,7 +460,7 @@ func AfterReadingAllFlags(t *TestContextType) { // Check if we can use the in-cluster config if clusterConfig, err := restclient.InClusterConfig(); err == nil { if tempFile, err := os.CreateTemp(os.TempDir(), "kubeconfig-"); err == nil { - kubeConfig := testapiserver.CreateKubeConfig(clusterConfig) + kubeConfig := kubeconfig.CreateKubeConfig(clusterConfig) clientcmd.WriteToFile(*kubeConfig, tempFile.Name()) t.KubeConfig = tempFile.Name() klog.V(4).Infof("Using a temporary kubeconfig file from in-cluster config : %s", tempFile.Name()) diff --git a/test/utils/apiserver/testapiserver.go b/test/utils/apiserver/testapiserver.go index b2b294134f9..a40baf7bd7e 100644 --- a/test/utils/apiserver/testapiserver.go +++ b/test/utils/apiserver/testapiserver.go @@ -29,6 +29,7 @@ import ( "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/util/cert" kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing" + "k8s.io/kubernetes/test/utils/kubeconfig" ) // TestAPIServer provides access to a running apiserver instance. @@ -90,7 +91,7 @@ func writeKubeConfigForWardleServerToKASConnection(t *testing.T, kubeClientConfi t.Logf("CA bundle %v\n", dynamiccertificates.GetHumanCertDetail(curr)) } - adminKubeConfig := CreateKubeConfig(wardleToKASKubeClientConfig) + adminKubeConfig := kubeconfig.CreateKubeConfig(wardleToKASKubeClientConfig) tmpDir := t.TempDir() kubeConfigFile := path.Join(tmpDir, "kube.config") if err := clientcmd.WriteToFile(*adminKubeConfig, kubeConfigFile); err != nil { diff --git a/test/utils/apiserver/kubeconfig.go b/test/utils/kubeconfig/kubeconfig.go similarity index 99% rename from test/utils/apiserver/kubeconfig.go rename to test/utils/kubeconfig/kubeconfig.go index a491726b414..809b40ed97c 100644 --- a/test/utils/apiserver/kubeconfig.go +++ b/test/utils/kubeconfig/kubeconfig.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package apiserver +package kubeconfig import ( "k8s.io/client-go/rest"