mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Fix golint failures of e2e/framework/r*.go
This fixes golint failures of the following files: - test/e2e/framework/resource_usage_gatherer.go - test/e2e/framework/rs_util.go
This commit is contained in:
parent
c2877f862a
commit
c8f933c591
@ -34,22 +34,27 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/system"
|
"k8s.io/kubernetes/pkg/util/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ResourceConstraint is a struct to hold constraints.
|
||||||
type ResourceConstraint struct {
|
type ResourceConstraint struct {
|
||||||
CPUConstraint float64
|
CPUConstraint float64
|
||||||
MemoryConstraint uint64
|
MemoryConstraint uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SingleContainerSummary is a struct to hold single container summary.
|
||||||
type SingleContainerSummary struct {
|
type SingleContainerSummary struct {
|
||||||
Name string
|
Name string
|
||||||
Cpu float64
|
CPU float64
|
||||||
Mem uint64
|
Mem uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResourceUsageSummary is a struct to hold resource usage summary.
|
||||||
// we can't have int here, as JSON does not accept integer keys.
|
// we can't have int here, as JSON does not accept integer keys.
|
||||||
type ResourceUsageSummary map[string][]SingleContainerSummary
|
type ResourceUsageSummary map[string][]SingleContainerSummary
|
||||||
|
|
||||||
|
// NoCPUConstraint is the number of constraint for CPU.
|
||||||
const NoCPUConstraint = math.MaxFloat64
|
const NoCPUConstraint = math.MaxFloat64
|
||||||
|
|
||||||
|
// PrintHumanReadable prints resource usage summary in human readable.
|
||||||
func (s *ResourceUsageSummary) PrintHumanReadable() string {
|
func (s *ResourceUsageSummary) PrintHumanReadable() string {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
w := tabwriter.NewWriter(buf, 1, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(buf, 1, 0, 1, ' ', 0)
|
||||||
@ -57,17 +62,19 @@ func (s *ResourceUsageSummary) PrintHumanReadable() string {
|
|||||||
buf.WriteString(fmt.Sprintf("%v percentile:\n", perc))
|
buf.WriteString(fmt.Sprintf("%v percentile:\n", perc))
|
||||||
fmt.Fprintf(w, "container\tcpu(cores)\tmemory(MB)\n")
|
fmt.Fprintf(w, "container\tcpu(cores)\tmemory(MB)\n")
|
||||||
for _, summary := range summaries {
|
for _, summary := range summaries {
|
||||||
fmt.Fprintf(w, "%q\t%.3f\t%.2f\n", summary.Name, summary.Cpu, float64(summary.Mem)/(1024*1024))
|
fmt.Fprintf(w, "%q\t%.3f\t%.2f\n", summary.Name, summary.CPU, float64(summary.Mem)/(1024*1024))
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintJSON prints resource usage summary in JSON.
|
||||||
func (s *ResourceUsageSummary) PrintJSON() string {
|
func (s *ResourceUsageSummary) PrintJSON() string {
|
||||||
return PrettyPrintJSON(*s)
|
return PrettyPrintJSON(*s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SummaryKind returns string of ResourceUsageSummary
|
||||||
func (s *ResourceUsageSummary) SummaryKind() string {
|
func (s *ResourceUsageSummary) SummaryKind() string {
|
||||||
return "ResourceUsageSummary"
|
return "ResourceUsageSummary"
|
||||||
}
|
}
|
||||||
@ -193,6 +200,7 @@ func (w *resourceGatherWorker) gather(initialSleep time.Duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainerResourceGatherer is a struct for gathering container resource.
|
||||||
type ContainerResourceGatherer struct {
|
type ContainerResourceGatherer struct {
|
||||||
client clientset.Interface
|
client clientset.Interface
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
@ -202,6 +210,7 @@ type ContainerResourceGatherer struct {
|
|||||||
options ResourceGathererOptions
|
options ResourceGathererOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResourceGathererOptions is a struct to hold options for resource.
|
||||||
type ResourceGathererOptions struct {
|
type ResourceGathererOptions struct {
|
||||||
InKubemark bool
|
InKubemark bool
|
||||||
Nodes NodesSet
|
Nodes NodesSet
|
||||||
@ -210,14 +219,19 @@ type ResourceGathererOptions struct {
|
|||||||
PrintVerboseLogs bool
|
PrintVerboseLogs bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NodesSet is a value of nodes set.
|
||||||
type NodesSet int
|
type NodesSet int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AllNodes NodesSet = 0 // All containers on all nodes
|
// AllNodes means all containers on all nodes.
|
||||||
MasterNodes NodesSet = 1 // All containers on Master nodes only
|
AllNodes NodesSet = 0
|
||||||
MasterAndDNSNodes NodesSet = 2 // All containers on Master nodes and DNS containers on other nodes
|
// MasterNodes means all containers on Master nodes only.
|
||||||
|
MasterNodes NodesSet = 1
|
||||||
|
// MasterAndDNSNodes means all containers on Master nodes and DNS containers on other nodes.
|
||||||
|
MasterAndDNSNodes NodesSet = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewResourceUsageGatherer returns a new ContainerResourceGatherer.
|
||||||
func NewResourceUsageGatherer(c clientset.Interface, options ResourceGathererOptions, pods *v1.PodList) (*ContainerResourceGatherer, error) {
|
func NewResourceUsageGatherer(c clientset.Interface, options ResourceGathererOptions, pods *v1.PodList) (*ContainerResourceGatherer, error) {
|
||||||
g := ContainerResourceGatherer{
|
g := ContainerResourceGatherer{
|
||||||
client: c,
|
client: c,
|
||||||
@ -360,7 +374,7 @@ func (g *ContainerResourceGatherer) StopAndSummarize(percentiles []int, constrai
|
|||||||
usage := data[perc][name]
|
usage := data[perc][name]
|
||||||
summary[strconv.Itoa(perc)] = append(summary[strconv.Itoa(perc)], SingleContainerSummary{
|
summary[strconv.Itoa(perc)] = append(summary[strconv.Itoa(perc)], SingleContainerSummary{
|
||||||
Name: name,
|
Name: name,
|
||||||
Cpu: usage.CPUUsageInCores,
|
CPU: usage.CPUUsageInCores,
|
||||||
Mem: usage.MemoryWorkingSetInBytes,
|
Mem: usage.MemoryWorkingSetInBytes,
|
||||||
})
|
})
|
||||||
// Verifying 99th percentile of resource usage
|
// Verifying 99th percentile of resource usage
|
||||||
|
@ -19,7 +19,7 @@ package framework
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
"github.com/onsi/ginkgo"
|
||||||
|
|
||||||
apps "k8s.io/api/apps/v1"
|
apps "k8s.io/api/apps/v1"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
@ -33,6 +33,7 @@ import (
|
|||||||
|
|
||||||
type updateRsFunc func(d *apps.ReplicaSet)
|
type updateRsFunc func(d *apps.ReplicaSet)
|
||||||
|
|
||||||
|
// UpdateReplicaSetWithRetries updates replicaset template with retries.
|
||||||
func UpdateReplicaSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate testutils.UpdateReplicaSetFunc) (*apps.ReplicaSet, error) {
|
func UpdateReplicaSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate testutils.UpdateReplicaSetFunc) (*apps.ReplicaSet, error) {
|
||||||
return testutils.UpdateReplicaSetWithRetries(c, namespace, name, applyUpdate, Logf, Poll, pollShortTimeout)
|
return testutils.UpdateReplicaSetWithRetries(c, namespace, name, applyUpdate, Logf, Poll, pollShortTimeout)
|
||||||
}
|
}
|
||||||
@ -119,13 +120,15 @@ func WaitForReplicaSetTargetAvailableReplicas(c clientset.Interface, replicaSet
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunReplicaSet launches (and verifies correctness) of a replicaset.
|
||||||
func RunReplicaSet(config testutils.ReplicaSetConfig) error {
|
func RunReplicaSet(config testutils.ReplicaSetConfig) error {
|
||||||
By(fmt.Sprintf("creating replicaset %s in namespace %s", config.Name, config.Namespace))
|
ginkgo.By(fmt.Sprintf("creating replicaset %s in namespace %s", config.Name, config.Namespace))
|
||||||
config.NodeDumpFunc = DumpNodeDebugInfo
|
config.NodeDumpFunc = DumpNodeDebugInfo
|
||||||
config.ContainerDumpFunc = LogFailedContainers
|
config.ContainerDumpFunc = LogFailedContainers
|
||||||
return testutils.RunReplicaSet(config)
|
return testutils.RunReplicaSet(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplicaSet returns a new ReplicaSet.
|
||||||
func NewReplicaSet(name, namespace string, replicas int32, podLabels map[string]string, imageName, image string) *apps.ReplicaSet {
|
func NewReplicaSet(name, namespace string, replicas int32, podLabels map[string]string, imageName, image string) *apps.ReplicaSet {
|
||||||
return &apps.ReplicaSet{
|
return &apps.ReplicaSet{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Loading…
Reference in New Issue
Block a user