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.
This commit is contained in:
Patrick Ohly 2022-09-10 17:56:23 +02:00
parent d9f21e55df
commit d33e66b81b
3 changed files with 5 additions and 4 deletions

View File

@ -39,7 +39,7 @@ import (
"k8s.io/klog/v2" "k8s.io/klog/v2"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
testapiserver "k8s.io/kubernetes/test/utils/apiserver" "k8s.io/kubernetes/test/utils/kubeconfig"
) )
const ( const (
@ -460,7 +460,7 @@ func AfterReadingAllFlags(t *TestContextType) {
// Check if we can use the in-cluster config // Check if we can use the in-cluster config
if clusterConfig, err := restclient.InClusterConfig(); err == nil { if clusterConfig, err := restclient.InClusterConfig(); err == nil {
if tempFile, err := os.CreateTemp(os.TempDir(), "kubeconfig-"); 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()) clientcmd.WriteToFile(*kubeConfig, tempFile.Name())
t.KubeConfig = tempFile.Name() t.KubeConfig = tempFile.Name()
klog.V(4).Infof("Using a temporary kubeconfig file from in-cluster config : %s", tempFile.Name()) klog.V(4).Infof("Using a temporary kubeconfig file from in-cluster config : %s", tempFile.Name())

View File

@ -29,6 +29,7 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/cert" "k8s.io/client-go/util/cert"
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing" kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
"k8s.io/kubernetes/test/utils/kubeconfig"
) )
// TestAPIServer provides access to a running apiserver instance. // 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)) t.Logf("CA bundle %v\n", dynamiccertificates.GetHumanCertDetail(curr))
} }
adminKubeConfig := CreateKubeConfig(wardleToKASKubeClientConfig) adminKubeConfig := kubeconfig.CreateKubeConfig(wardleToKASKubeClientConfig)
tmpDir := t.TempDir() tmpDir := t.TempDir()
kubeConfigFile := path.Join(tmpDir, "kube.config") kubeConfigFile := path.Join(tmpDir, "kube.config")
if err := clientcmd.WriteToFile(*adminKubeConfig, kubeConfigFile); err != nil { if err := clientcmd.WriteToFile(*adminKubeConfig, kubeConfigFile); err != nil {

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package apiserver package kubeconfig
import ( import (
"k8s.io/client-go/rest" "k8s.io/client-go/rest"