func (tc *CustomMetricTestCase) Run() {
	projectID := framework.TestContext.CloudConfig.ProjectID

	ctx := context.Background()
	client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)

	// Hack for running tests locally, needed to authenticate in Stackdriver
	// If this is your use case, create application default credentials:
	// $ gcloud auth application-default login
	// and uncomment following lines:
	/*
		ts, err := google.DefaultTokenSource(oauth2.NoContext)
		framework.Logf("Couldn't get application default credentials, %v", err)
		if err != nil {
			framework.Failf("Error accessing application default credentials, %v", err)
		}
		client := oauth2.NewClient(oauth2.NoContext, ts)
	*/

	gcmService, err := gcm.New(client)
	if err != nil {
		framework.Failf("Failed to create gcm service, %v", err)
	}

	// Set up a cluster: create a custom metric and set up k8s-sd adapter
	err = monitoring.CreateDescriptors(gcmService, projectID)
	if err != nil {
		framework.Failf("Failed to create metric descriptor: %v", err)
	}
	defer monitoring.CleanupDescriptors(gcmService, projectID)

	err = monitoring.CreateAdapter(tc.framework.Namespace.ObjectMeta.Name, monitoring.AdapterDefault)
	if err != nil {
		framework.Failf("Failed to set up: %v", err)
	}
	defer monitoring.CleanupAdapter(tc.framework.Namespace.ObjectMeta.Name, monitoring.AdapterDefault)

	// Run application that exports the metric
	err = createDeploymentToScale(tc.framework, tc.kubeClient, tc.deployment, tc.pod)
	if err != nil {
		framework.Failf("Failed to create stackdriver-exporter pod: %v", err)
	}
	defer cleanupDeploymentsToScale(tc.framework, tc.kubeClient, tc.deployment, tc.pod)

	// Wait for the deployment to run
	waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.initialReplicas)

	// Autoscale the deployment
	_, err = tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Create(context.TODO(), tc.hpa, metav1.CreateOptions{})
	if err != nil {
		framework.Failf("Failed to create HPA: %v", err)
	}
	defer tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Delete(context.TODO(), tc.hpa.ObjectMeta.Name, metav1.DeleteOptions{})

	waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.scaledReplicas)
}
// Run starts test case.
Run starts test case.
// Run starts test case .
func (tc *CustomMetricTestCase) Run() {
	projectID := framework.TestContext.CloudConfig.ProjectID
	ctx := context.Background()
	client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)
	gcmService, err := gcm.New(client)
	if err != nil {
		framework.Failf("Failed to create gcm service, %v", err)
	}
	err = monitoring.CreateDescriptors(gcmService, projectID)
	if err != nil {
		framework.Failf("Failed to create metric descriptor: %v", err)
	}
	defer monitoring.CleanupDescriptors(gcmService, projectID)
	err = monitoring.CreateAdapter(tc.framework.Namespace.ObjectMeta.Name, monitoring.AdapterDefault)
	if err != nil {
		framework.Failf("Failed to set up: %v", err)
	}
	defer monitoring.CleanupAdapter(tc.framework.Namespace.ObjectMeta.Name, monitoring.AdapterDefault)
	err = createDeploymentToScale(tc.framework, tc.kubeClient, tc.deployment, tc.pod)
	if err != nil {
		framework.Failf("Failed to create stackdriver-exporter pod: %v", err)
	}
	defer cleanupDeploymentsToScale(tc.framework, tc.kubeClient, tc.deployment, tc.pod)
	waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.initialReplicas)
	_, err = tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Create(context.TODO(), tc.hpa, metav1.CreateOptions{})
	if err != nil {
		framework.Failf("Failed to create HPA: %v", err)
	}
	defer tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Delete(context.TODO(), tc.hpa.ObjectMeta.Name, metav1.DeleteOptions{})
	waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.scaledReplicas)
}
func ( tc * CustomMetricTestCase ) Run ( ) { projectID := framework . TestContext . CloudConfig . ProjectID ctx := context . Background ( ) client , err := google . DefaultClient ( ctx , gcm . CloudPlatformScope ) gcmService , err := gcm . New ( client ) if err != nil { framework . Failf ( " " , err ) } err = monitoring . CreateDescriptors ( gcmService , projectID ) if err != nil { framework . Failf ( " " , err ) } defer monitoring . CleanupDescriptors ( gcmService , projectID ) err = monitoring . CreateAdapter ( tc . framework . Namespace . ObjectMeta . Name , monitoring . AdapterDefault ) if err != nil { framework . Failf ( " " , err ) } defer monitoring . CleanupAdapter ( tc . framework . Namespace . ObjectMeta . Name , monitoring . AdapterDefault ) err = createDeploymentToScale ( tc . framework , tc . kubeClient , tc . deployment , tc . pod ) if err != nil { framework . Failf ( " " , err ) } defer cleanupDeploymentsToScale ( tc . framework , tc . kubeClient , tc . deployment , tc . pod ) waitForReplicas ( tc . deployment . ObjectMeta . Name , tc . framework . Namespace . ObjectMeta . Name , tc . kubeClient , 15 * time . Minute , tc . initialReplicas ) _ , err = tc . kubeClient . AutoscalingV2beta1 ( ) . HorizontalPodAutoscalers ( tc . framework . Namespace . ObjectMeta . Name ) . Create ( context . TODO ( ) , tc . hpa , metav1 . CreateOptions { } ) if err != nil { framework . Failf ( " " , err ) } defer tc . kubeClient . AutoscalingV2beta1 ( ) . HorizontalPodAutoscalers ( tc . framework . Namespace . ObjectMeta . Name ) . Delete ( context . TODO ( ) , tc . hpa . ObjectMeta . Name , metav1 . DeleteOptions { } ) waitForReplicas ( tc . deployment . ObjectMeta . Name , tc . framework . Namespace . ObjectMeta . Name , tc . kubeClient , 15 * time . Minute , tc . scaledReplicas ) }
Run starts test case.
Run starts test case .
// Hack for running tests locally, needed to authenticate in Stackdriver // If this is your use case, create application default credentials: // $ gcloud auth application-default login // and uncomment following lines: /*
		ts, err := google.DefaultTokenSource(oauth2.NoContext)
		framework.Logf("Couldn't get application default credentials, %v", err)
		if err != nil {
			framework.Failf("Error accessing application default credentials, %v", err)
		}
		client := oauth2.NewClient(oauth2.NoContext, ts)
	*/ // Set up a cluster: create a custom metric and set up k8s-sd adapter // Run application that exports the metric // Wait for the deployment to run // Autoscale the deployment