k8s.io/kubernetes@v1.29.3/test/e2e_node/remote/cadvisor_e2e.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package remote
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"os/exec"
    23  	"time"
    24  
    25  	"k8s.io/klog/v2"
    26  	"k8s.io/kubernetes/test/utils"
    27  )
    28  
    29  // CAdvisorE2ERemote contains the specific functions in the cadvisor e2e test suite.
    30  type CAdvisorE2ERemote struct{}
    31  
    32  // init performs initialization for cadvisor remote testing
    33  func init() {
    34  	RegisterTestSuite("cadvisor", &CAdvisorE2ERemote{})
    35  }
    36  
    37  // SetupTestPackage implements TestSuite.SetupTestPackage
    38  func (n *CAdvisorE2ERemote) SetupTestPackage(tardir, systemSpecName string) error {
    39  	cadvisorRootDir, err := utils.GetCAdvisorRootDir()
    40  	if err != nil {
    41  		return err
    42  	}
    43  	// build the cadvisor binary and tests
    44  	if err := runCommand(fmt.Sprintf("%s/build/prow_e2e.sh", cadvisorRootDir)); err != nil {
    45  		return err
    46  	}
    47  	// transfer the entire directory to each node
    48  	if err := runCommand("cp", "-R", cadvisorRootDir, fmt.Sprintf("%s/", tardir)); err != nil {
    49  		return err
    50  	}
    51  	return nil
    52  }
    53  
    54  func runCommand(command string, args ...string) error {
    55  	cmd := exec.Command(command, args...)
    56  	cmd.Stdout = os.Stdout
    57  	cmd.Stderr = os.Stderr
    58  	err := cmd.Run()
    59  	if err != nil {
    60  		return fmt.Errorf("failed to run command %s. error: %w", command, err)
    61  	}
    62  	return nil
    63  }
    64  
    65  // RunTest implements TestSuite.RunTest
    66  func (n *CAdvisorE2ERemote) RunTest(host, workspace, _, _, _, _, _, _, _, _ string, timeout time.Duration) (string, error) {
    67  	// Kill any running node processes
    68  	cleanupNodeProcesses(host)
    69  
    70  	klog.V(2).Infof("Starting tests on %q", host)
    71  	return SSH(host, "sh", "-c", getSSHCommand(" && ",
    72  		fmt.Sprintf("cd %s/cadvisor", workspace),
    73  		fmt.Sprintf("timeout -k 30s %fs ./build/integration.sh ../results/cadvisor.log",
    74  			timeout.Seconds()),
    75  	))
    76  }