Fix golint in test/e2e/instrumentation/monitoring

This commit is contained in:
danielqsj
2019-02-27 16:15:26 +08:00
parent 79e8a29544
commit 873fbf9112
8 changed files with 86 additions and 71 deletions

View File

@@ -17,52 +17,51 @@ limitations under the License.
package monitoring
import (
"time"
"golang.org/x/oauth2/google"
clientset "k8s.io/client-go/kubernetes"
"context"
"encoding/json"
"fmt"
. "github.com/onsi/ginkgo"
"io/ioutil"
"reflect"
"time"
"github.com/onsi/ginkgo"
"golang.org/x/oauth2/google"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
"reflect"
)
const (
// Time to wait after a pod creation for it's metadata to be exported
metadataWaitTime = 120 * time.Second
// Scope for Stackdriver Metadata API
// MonitoringScope is the scope for Stackdriver Metadata API
MonitoringScope = "https://www.googleapis.com/auth/monitoring"
)
var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
BeforeEach(func() {
ginkgo.BeforeEach(func() {
framework.SkipUnlessProviderIs("gce", "gke")
})
f := framework.NewDefaultFramework("stackdriver-monitoring")
var kubeClient clientset.Interface
It("should run Stackdriver Metadata Agent [Feature:StackdriverMetadataAgent]", func() {
ginkgo.It("should run Stackdriver Metadata Agent [Feature:StackdriverMetadataAgent]", func() {
kubeClient = f.ClientSet
testAgent(f, kubeClient)
})
})
func testAgent(f *framework.Framework, kubeClient clientset.Interface) {
projectId := framework.TestContext.CloudConfig.ProjectID
projectID := framework.TestContext.CloudConfig.ProjectID
resourceType := "k8s_container"
uniqueContainerName := fmt.Sprintf("test-container-%v", time.Now().Unix())
endpoint := fmt.Sprintf(
"https://stackdriver.googleapis.com/v1beta2/projects/%v/resourceMetadata?filter=resource.type%%3D%v+AND+resource.label.container_name%%3D%v",
projectId,
projectID,
resourceType,
uniqueContainerName)
@@ -101,10 +100,12 @@ func testAgent(f *framework.Framework, kubeClient clientset.Interface) {
}
}
// Metadata has the information fetched from Stackdriver metadata API.
type Metadata struct {
Results []map[string]interface{}
}
// Resource contains the resource type and labels from Stackdriver metadata API.
type Resource struct {
resourceType string
resourceLabels map[string]string
@@ -135,7 +136,7 @@ func verifyPodExists(response []byte, containerName string) (bool, error) {
}
func parseResource(resource interface{}) (*Resource, error) {
var labels map[string]string = map[string]string{}
var labels = map[string]string{}
resourceMap, ok := resource.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Resource entry is of type %s, expected map[string]interface{}", reflect.TypeOf(resource))