Skip to content

Commit

Permalink
Add integration tests for kubelet, proxy, and scheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakerouse committed May 4, 2020
1 parent 2ea6576 commit 9275f8b
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 619 deletions.
612 changes: 0 additions & 612 deletions dev-tools/mage/kuberemote.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package mage
package kubernetes

import (
"fmt"
Expand Down
5 changes: 2 additions & 3 deletions dev-tools/mage/kubernetes/kuberemote.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ type KubeRemote struct {
publicKey []byte
}

// New creates a new kubernetes remote runner.
func New(kubeconfig string, namespace string, name string, workDir string, destDir string, syncDir string) (*KubeRemote, error) {
// NewKubeRemote creates a new kubernetes remote runner.
func NewKubeRemote(kubeconfig string, namespace string, name string, workDir string, destDir string, syncDir string) (*KubeRemote, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -437,7 +437,6 @@ func createPodManifest(name string, image string, env map[string]string, cmd []s
{
Name: "ssh",
Protocol: apiv1.ProtocolTCP,
HostPort: 22,
ContainerPort: 22,
},
},
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/mage/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ func (d *KubernetesIntegrationTester) Test(dir string, mageTarget string, env ma

// Apply the manifest from the dir. This is the requirements for the tests that will
// run inside the cluster.
if err := mage.KubectlApply(env, stdOut, stdErr, manifestPath); err != nil {
if err := KubectlApply(env, stdOut, stdErr, manifestPath); err != nil {
return errors.Wrapf(err, "failed to apply manifest %s", manifestPath)
}
defer func() {
if mg.Verbose() {
fmt.Println(">> Deleting module manifest from cluster...")
}
if err := mage.KubectlDelete(env, stdOut, stdErr, manifestPath); err != nil {
if err := KubectlDelete(env, stdOut, stdErr, manifestPath); err != nil {
log.Printf("%s", errors.Wrapf(err, "failed to apply manifest %s", manifestPath))
}
}()
Expand All @@ -125,7 +125,7 @@ func (d *KubernetesIntegrationTester) Test(dir string, mageTarget string, env ma

destDir := filepath.Join("/go/src", repo.CanonicalRootImportPath)
workDir := filepath.Join(destDir, repo.SubDir)
remote, err := mage.NewKubeRemote(kubeConfig, "default", kubernetesPodName(), workDir, destDir, repo.RootDir)
remote, err := NewKubeRemote(kubeConfig, "default", kubernetesPodName(), workDir, destDir, repo.RootDir)
if err != nil {
return err
}
Expand Down
38 changes: 38 additions & 0 deletions metricbeat/module/kubernetes/node/node_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package node

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetKubeletConfig(t, "node")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}
38 changes: 38 additions & 0 deletions metricbeat/module/kubernetes/pod/pod_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package pod

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetKubeletConfig(t, "pod")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}
38 changes: 38 additions & 0 deletions metricbeat/module/kubernetes/proxy/proxy_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package proxy

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetKubeProxyConfig(t, "proxy")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package scheduler

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetSchedulerConfig(t, "scheduler")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}
38 changes: 38 additions & 0 deletions metricbeat/module/kubernetes/system/system_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package system

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetKubeletConfig(t, "system")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}
22 changes: 22 additions & 0 deletions metricbeat/module/kubernetes/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,25 @@ func GetKubeletConfig(t *testing.T, metricSetName string) map[string]interface{}
}
}

// GetKubeProxyConfig function returns configuration for talking to kube-proxy.
func GetKubeProxyConfig(t *testing.T, metricSetName string) map[string]interface{} {
t.Helper()
return map[string]interface{}{
"module": "kubernetes",
"metricsets": []string{metricSetName},
"host": "${NODE_NAME}",
"hosts": []string{"localhost:10252"},
}
}

// GetSchedulerConfig function returns configuration for talking to kube-proxy.
func GetSchedulerConfig(t *testing.T, metricSetName string) map[string]interface{} {
t.Helper()
return map[string]interface{}{
"module": "kubernetes",
"metricsets": []string{metricSetName},
"host": "${NODE_NAME}",
"hosts": []string{"localhost:10251"},
}
}

38 changes: 38 additions & 0 deletions metricbeat/module/kubernetes/volume/volume_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build integration,linux

package volume

import (
"github.com/stretchr/testify/assert"
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/test"
)

func TestFetchMetricset(t *testing.T) {
config := test.GetKubeletConfig(t, "volume")
metricSet := mbtest.NewFetcher(t, config)
events, errs := metricSet.FetchEvents()
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
}

0 comments on commit 9275f8b

Please sign in to comment.