tests: introduce e2e suite (#422)
* mock: implement GetStatsSummary Signed-off-by: Paulo Pires <pjpires@gmail.com> * make: use skaffold to deploy vk Signed-off-by: Paulo Pires <pjpires@gmail.com> * test: add an e2e test suite Signed-off-by: Paulo Pires <pjpires@gmail.com> * test: add vendored code Signed-off-by: Paulo Pires <pjpires@gmail.com> * docs: update README.md Signed-off-by: Paulo Pires <pjpires@gmail.com> * ci: run e2e on circleci Signed-off-by: Paulo Pires <pjpires@gmail.com> * make: improve the skaffold target Signed-off-by: Paulo Pires <pjpires@gmail.com> * e2e: fix defer pod deletion Signed-off-by: Paulo Pires <pjpires@gmail.com> * e2e: improve instructions Signed-off-by: Paulo Pires <pjpires@gmail.com> * makefile: default shell is bash Signed-off-by: Paulo Pires <pjpires@gmail.com>
This commit is contained in:
@@ -7,15 +7,18 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
||||
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,6 +36,7 @@ type MockProvider struct {
|
||||
daemonEndpointPort int32
|
||||
pods map[string]*v1.Pod
|
||||
config MockConfig
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
// MockConfig contains a mock virtual-kubelet's configurable parameters.
|
||||
@@ -56,6 +60,7 @@ func NewMockProvider(providerConfig, nodeName, operatingSystem string, internalI
|
||||
daemonEndpointPort: daemonEndpointPort,
|
||||
pods: make(map[string]*v1.Pod),
|
||||
config: config,
|
||||
startTime: time.Now(),
|
||||
}
|
||||
return &provider, nil
|
||||
}
|
||||
@@ -326,6 +331,80 @@ func (p *MockProvider) OperatingSystem() string {
|
||||
return providers.OperatingSystemLinux
|
||||
}
|
||||
|
||||
// GetStatsSummary returns dummy stats for all pods known by this provider.
|
||||
func (p *MockProvider) GetStatsSummary(ctx context.Context) (*stats.Summary, error) {
|
||||
// Grab the current timestamp so we can report it as the time the stats were generated.
|
||||
time := metav1.NewTime(time.Now())
|
||||
|
||||
// Create the Summary object that will later be populated with node and pod stats.
|
||||
res := &stats.Summary{}
|
||||
|
||||
// Populate the Summary object with basic node stats.
|
||||
res.Node = stats.NodeStats{
|
||||
NodeName: p.nodeName,
|
||||
StartTime: metav1.NewTime(p.startTime),
|
||||
}
|
||||
|
||||
// Populate the Summary object with dummy stats for each pod known by this provider.
|
||||
for _, pod := range p.pods {
|
||||
var (
|
||||
// totalUsageNanoCores will be populated with the sum of the values of UsageNanoCores computes across all containers in the pod.
|
||||
totalUsageNanoCores uint64
|
||||
// totalUsageBytes will be populated with the sum of the values of UsageBytes computed across all containers in the pod.
|
||||
totalUsageBytes uint64
|
||||
)
|
||||
|
||||
// Create a PodStats object to populate with pod stats.
|
||||
pss := stats.PodStats{
|
||||
PodRef: stats.PodReference{
|
||||
Name: pod.Name,
|
||||
Namespace: pod.Namespace,
|
||||
UID: string(pod.UID),
|
||||
},
|
||||
StartTime: pod.CreationTimestamp,
|
||||
}
|
||||
|
||||
// Iterate over all containers in the current pod to compute dummy stats.
|
||||
for _, container := range pod.Spec.Containers {
|
||||
// Grab a dummy value to be used as the total CPU usage.
|
||||
// The value should fit a uint32 in order to avoid overflows later on when computing pod stats.
|
||||
dummyUsageNanoCores := uint64(rand.Uint32())
|
||||
totalUsageNanoCores += dummyUsageNanoCores
|
||||
// Create a dummy value to be used as the total RAM usage.
|
||||
// The value should fit a uint32 in order to avoid overflows later on when computing pod stats.
|
||||
dummyUsageBytes := uint64(rand.Uint32())
|
||||
totalUsageBytes += dummyUsageBytes
|
||||
// Append a ContainerStats object containing the dummy stats to the PodStats object.
|
||||
pss.Containers = append(pss.Containers, stats.ContainerStats{
|
||||
Name: container.Name,
|
||||
StartTime: pod.CreationTimestamp,
|
||||
CPU: &stats.CPUStats{
|
||||
Time: time,
|
||||
UsageNanoCores: &dummyUsageNanoCores,
|
||||
},
|
||||
Memory: &stats.MemoryStats{
|
||||
Time: time,
|
||||
UsageBytes: &dummyUsageBytes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Populate the CPU and RAM stats for the pod and append the PodsStats object to the Summary object to be returned.
|
||||
pss.CPU = &stats.CPUStats{
|
||||
Time: time,
|
||||
UsageNanoCores: &totalUsageNanoCores,
|
||||
}
|
||||
pss.Memory = &stats.MemoryStats{
|
||||
Time: time,
|
||||
UsageBytes: &totalUsageBytes,
|
||||
}
|
||||
res.Pods = append(res.Pods, pss)
|
||||
}
|
||||
|
||||
// Return the dummy stats.
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func buildKeyFromNames(namespace string, name string) (string, error) {
|
||||
return fmt.Sprintf("%s-%s", namespace, name), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user