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

     1  /*
     2  Copyright 2022 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  	clientset "k8s.io/client-go/kubernetes"
    21  	"k8s.io/klog/v2"
    22  	sshutil "k8s.io/kubernetes/test/e2e/framework/ssh"
    23  	prom "k8s.io/perf-tests/clusterloader2/pkg/prometheus/clients"
    24  )
    25  
    26  type GKEKubemarkProvider struct {
    27  	features Features
    28  	config   Config
    29  }
    30  
    31  func NewGKEKubemarkProvider(config map[string]string) *GKEKubemarkProvider {
    32  	supportEnablePrometheusServer := true
    33  	if config[RootKubeConfigKey] == "" {
    34  		klog.Warningf("no kubemark-root-kubeconfig path specified. SupportEnablePrometheusServer will be false.")
    35  		supportEnablePrometheusServer = false
    36  	}
    37  	return &GKEKubemarkProvider{
    38  		features: Features{
    39  			IsKubemarkProvider:                  true,
    40  			SupportEnablePrometheusServer:       supportEnablePrometheusServer,
    41  			SupportAccessAPIServerPprofEndpoint: true,
    42  			SupportSnapshotPrometheusDisk:       true,
    43  			ShouldScrapeKubeProxy:               false,
    44  			SupportResourceUsageMetering:        true,
    45  			ShouldPrometheusScrapeApiserverOnly: true,
    46  		},
    47  		config: config,
    48  	}
    49  }
    50  
    51  func (p *GKEKubemarkProvider) Name() string {
    52  	return GKEKubemarkName
    53  }
    54  
    55  func (p *GKEKubemarkProvider) Features() *Features {
    56  	return &p.features
    57  }
    58  
    59  func (p *GKEKubemarkProvider) GetComponentProtocolAndPort(componentName string) (string, int, error) {
    60  	return getComponentProtocolAndPort(componentName)
    61  }
    62  
    63  func (p *GKEKubemarkProvider) GetConfig() Config {
    64  	return p.config
    65  }
    66  
    67  func (p *GKEKubemarkProvider) RunSSHCommand(cmd, host string) (string, string, int, error) {
    68  	// gke provider takes ssh key from GCE_SSH_KEY.
    69  	r, err := sshutil.SSH(cmd, host, "gke")
    70  	return r.Stdout, r.Stderr, r.Code, err
    71  }
    72  
    73  func (p *GKEKubemarkProvider) Metadata(client clientset.Interface) (map[string]string, error) {
    74  	return nil, nil
    75  }
    76  
    77  func (p *GKEKubemarkProvider) GetManagedPrometheusClient() (prom.Client, error) {
    78  	return prom.NewGCPManagedPrometheusClient()
    79  }