k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/pkg/provider/util.go (about)

     1  /*
     2  Copyright 2020 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 provider
    18  
    19  import (
    20  	"errors"
    21  	"fmt"
    22  
    23  	sshutil "k8s.io/kubernetes/test/e2e/framework/ssh"
    24  )
    25  
    26  var (
    27  	ErrNoManagedPrometheus = errors.New("no managed Prometheus service for this cloud provider")
    28  )
    29  
    30  func getComponentProtocolAndPort(componentName string) (string, int, error) {
    31  	switch componentName {
    32  	case "etcd":
    33  		return "https://", 2379, nil
    34  	case "kube-apiserver":
    35  		return "https://", 443, nil
    36  	case "kube-controller-manager":
    37  		return "https://", 10257, nil
    38  	case "kube-scheduler":
    39  		return "https://", 10259, nil
    40  	}
    41  	return "", -1, fmt.Errorf("port for component %v unknown", componentName)
    42  }
    43  
    44  func runSSHCommand(cmd, host string) (string, string, int, error) {
    45  	// skeleton provider takes ssh key from KUBE_SSH_KEY_PATH and KUBE_SSH_KEY.
    46  	r, err := sshutil.SSH(cmd, host, "skeleton")
    47  	return r.Stdout, r.Stderr, r.Code, err
    48  }