mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Fixed e2e tests
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
influxdb "github.com/influxdb/influxdb/client"
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@@ -30,14 +29,7 @@ var _ = Describe("Initial Resources [Skipped] ", func() {
|
|||||||
f := NewFramework("initial-resources")
|
f := NewFramework("initial-resources")
|
||||||
|
|
||||||
It("should set initial resources based on historical data", func() {
|
It("should set initial resources based on historical data", func() {
|
||||||
// Cleanup data in InfluxDB that left from previous tests.
|
// TODO(piosz): Add cleanup data in InfluxDB that left from previous tests.
|
||||||
influxdbClient, err := getInfluxdbClient(f.Client)
|
|
||||||
expectNoError(err, "failed to create influxdb client")
|
|
||||||
_, err = influxdbClient.Query("drop series autoscaling.cpu.usage.2m", influxdb.Second)
|
|
||||||
expectNoError(err)
|
|
||||||
_, err = influxdbClient.Query("drop series autoscaling.memory.usage.2m", influxdb.Second)
|
|
||||||
expectNoError(err)
|
|
||||||
|
|
||||||
cpu := 100
|
cpu := 100
|
||||||
mem := 200
|
mem := 200
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
@@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@@ -49,10 +51,8 @@ var _ = Describe("[Flaky] Monitoring", func() {
|
|||||||
const (
|
const (
|
||||||
influxdbService = "monitoring-influxdb"
|
influxdbService = "monitoring-influxdb"
|
||||||
influxdbDatabaseName = "k8s"
|
influxdbDatabaseName = "k8s"
|
||||||
influxdbUser = "root"
|
podlistQuery = "show tag values from \"cpu/usage\" with key = pod_id"
|
||||||
influxdbPW = "root"
|
nodelistQuery = "show tag values from \"cpu/usage\" with key = hostname"
|
||||||
podlistQuery = "select distinct(pod_id) from \"cpu/usage_ns_cumulative\""
|
|
||||||
nodelistQuery = "select distinct(hostname) from \"cpu/usage_ns_cumulative\""
|
|
||||||
sleepBetweenAttempts = 5 * time.Second
|
sleepBetweenAttempts = 5 * time.Second
|
||||||
testTimeout = 5 * time.Minute
|
testTimeout = 5 * time.Minute
|
||||||
)
|
)
|
||||||
@@ -65,6 +65,35 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Query sends a command to the server and returns the Response
|
||||||
|
func Query(c *client.Client, query string) (*influxdb.Response, error) {
|
||||||
|
result, err := c.Get().
|
||||||
|
Prefix("proxy").
|
||||||
|
Namespace("kube-system").
|
||||||
|
Resource("services").
|
||||||
|
Name(influxdbService+":api").
|
||||||
|
Suffix("query").
|
||||||
|
Param("q", query).
|
||||||
|
Param("db", influxdbDatabaseName).
|
||||||
|
Param("epoch", "s").
|
||||||
|
Do().
|
||||||
|
Raw()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var response influxdb.Response
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(result))
|
||||||
|
dec.UseNumber()
|
||||||
|
err = dec.Decode(&response)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &response, nil
|
||||||
|
}
|
||||||
|
|
||||||
func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error) {
|
func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error) {
|
||||||
expectedPods := []string{}
|
expectedPods := []string{}
|
||||||
// Iterate over the labels that identify the replication controllers that we
|
// Iterate over the labels that identify the replication controllers that we
|
||||||
@@ -135,41 +164,24 @@ func getAllNodesInCluster(c *client.Client) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInfluxdbClient(c *client.Client) (*influxdb.Client, error) {
|
func getInfluxdbData(c *client.Client, query string, tag string) (map[string]bool, error) {
|
||||||
proxyUrl := fmt.Sprintf("%s/api/v1/proxy/namespaces/%s/services/%s:api/", getMasterHost(), api.NamespaceSystem, influxdbService)
|
response, err := Query(c, query)
|
||||||
config := &influxdb.ClientConfig{
|
|
||||||
Host: proxyUrl,
|
|
||||||
// TODO(vishh): Infer username and pw from the Pod spec.
|
|
||||||
Username: influxdbUser,
|
|
||||||
Password: influxdbPW,
|
|
||||||
Database: influxdbDatabaseName,
|
|
||||||
HttpClient: c.Client,
|
|
||||||
IsSecure: true,
|
|
||||||
}
|
|
||||||
return influxdb.NewClient(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInfluxdbData(c *influxdb.Client, query string) (map[string]bool, error) {
|
|
||||||
series, err := c.Query(query, influxdb.Second)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(series) != 1 {
|
if len(response.Results) != 1 {
|
||||||
return nil, fmt.Errorf("expected only one series from Influxdb for query %q. Got %+v", query, series)
|
return nil, fmt.Errorf("expected only one result from Influxdb for query %q. Got %+v", query, response)
|
||||||
}
|
}
|
||||||
if len(series[0].GetColumns()) != 2 {
|
if len(response.Results[0].Series) != 1 {
|
||||||
Failf("Expected two columns for query %q. Found %v", query, series[0].GetColumns())
|
return nil, fmt.Errorf("expected exactly one series for query %q.", query)
|
||||||
|
}
|
||||||
|
if len(response.Results[0].Series[0].Columns) != 1 {
|
||||||
|
Failf("Expected one column for query %q. Found %v", query, response.Results[0].Series[0].Columns)
|
||||||
}
|
}
|
||||||
result := map[string]bool{}
|
result := map[string]bool{}
|
||||||
for _, point := range series[0].GetPoints() {
|
for _, value := range response.Results[0].Series[0].Values {
|
||||||
if len(point) != 2 {
|
name := value[0].(string)
|
||||||
Failf("Expected only two entries in a point for query %q. Got %v", query, point)
|
result[name] = true
|
||||||
}
|
|
||||||
name, ok := point[1].(string)
|
|
||||||
if !ok {
|
|
||||||
Failf("expected %v to be a string, but it is %T", point[1], point[1])
|
|
||||||
}
|
|
||||||
result[name] = false
|
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
@@ -186,14 +198,14 @@ func expectedItemsExist(expectedItems []string, actualItems map[string]bool) boo
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePodsAndNodes(influxdbClient *influxdb.Client, expectedPods, expectedNodes []string) bool {
|
func validatePodsAndNodes(c *client.Client, expectedPods, expectedNodes []string) bool {
|
||||||
pods, err := getInfluxdbData(influxdbClient, podlistQuery)
|
pods, err := getInfluxdbData(c, podlistQuery, "pod_id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We don't fail the test here because the influxdb service might still not be running.
|
// We don't fail the test here because the influxdb service might still not be running.
|
||||||
Logf("failed to query list of pods from influxdb. Query: %q, Err: %v", podlistQuery, err)
|
Logf("failed to query list of pods from influxdb. Query: %q, Err: %v", podlistQuery, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
nodes, err := getInfluxdbData(influxdbClient, nodelistQuery)
|
nodes, err := getInfluxdbData(c, nodelistQuery, "hostname")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logf("failed to query list of nodes from influxdb. Query: %q, Err: %v", nodelistQuery, err)
|
Logf("failed to query list of nodes from influxdb. Query: %q, Err: %v", nodelistQuery, err)
|
||||||
return false
|
return false
|
||||||
@@ -222,14 +234,11 @@ func testMonitoringUsingHeapsterInfluxdb(c *client.Client) {
|
|||||||
expectNoError(expectedServicesExist(c))
|
expectNoError(expectedServicesExist(c))
|
||||||
// TODO: Wait for all pods and services to be running.
|
// TODO: Wait for all pods and services to be running.
|
||||||
|
|
||||||
influxdbClient, err := getInfluxdbClient(c)
|
|
||||||
expectNoError(err, "failed to create influxdb client")
|
|
||||||
|
|
||||||
expectedNodes, err := getAllNodesInCluster(c)
|
expectedNodes, err := getAllNodesInCluster(c)
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
for {
|
for {
|
||||||
if validatePodsAndNodes(influxdbClient, expectedPods, expectedNodes) {
|
if validatePodsAndNodes(c, expectedPods, expectedNodes) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if time.Since(startTime) >= testTimeout {
|
if time.Since(startTime) >= testTimeout {
|
||||||
|
Reference in New Issue
Block a user