Unverified Commit 7db6ad1f authored by k8s-ci-robot's avatar k8s-ci-robot Committed by GitHub

Merge pull request #70781 from emwalker/68026-golint-fixes-4

Remove test/images/* from hack/.golint_failures
parents 6be4f1bb d8390c48
......@@ -746,14 +746,6 @@ test/e2e_node/environment
test/e2e_node/remote
test/e2e_node/runner/remote
test/e2e_node/services
test/images/net/nat
test/images/netexec
test/images/nettest
test/images/no-snat-test
test/images/no-snat-test-proxy
test/images/resource-consumer
test/images/resource-consumer/common
test/images/resource-consumer/controller
test/integration
test/integration/auth
test/integration/evictions
......
......@@ -40,7 +40,7 @@ import (
// connection assigned here.
var leakedConnection *net.TCPConn
// Server JSON options.
// CloseWaitServerOptions holds server JSON options.
type CloseWaitServerOptions struct {
// Address to bind for the test
LocalAddr string
......@@ -110,7 +110,7 @@ func (server *closeWaitServer) Run(logger *log.Logger, rawOptions interface{}) e
return nil
}
// Client JSON options
// CloseWaitClientOptions holds client JSON options.
type CloseWaitClientOptions struct {
// RemoteAddr of the server to connect to.
RemoteAddr string
......
......@@ -80,7 +80,7 @@ func main() {
func startHTTPServer(httpPort int) {
http.HandleFunc("/", rootHandler)
http.HandleFunc("/clientip", clientIpHandler)
http.HandleFunc("/clientip", clientIPHandler)
http.HandleFunc("/echo", echoHandler)
http.HandleFunc("/exit", exitHandler)
http.HandleFunc("/hostname", hostnameHandler)
......@@ -104,7 +104,7 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", r.FormValue("msg"))
}
func clientIpHandler(w http.ResponseWriter, r *http.Request) {
func clientIPHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("GET /clientip")
fmt.Fprintf(w, r.RemoteAddr)
}
......
......@@ -133,7 +133,7 @@ func (s *State) serveWrite(w http.ResponseWriter, r *http.Request) {
if s.Received == nil {
s.Received = map[string]int{}
}
s.Received[wp.Source] += 1
s.Received[wp.Source]++
}
s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
}
......@@ -164,7 +164,7 @@ func (s *State) appendSuccessfulSend(toHostname string) {
if s.Sent == nil {
s.Sent = map[string]int{}
}
s.Sent[toHostname] += 1
s.Sent[toHostname]++
}
var (
......
......@@ -30,22 +30,22 @@ import (
// This Pod's /checknosnat takes `target` and `ips` arguments, and queries {target}/checknosnat?ips={ips}
type MasqTestProxy struct {
type masqTestProxy struct {
Port string
}
func NewMasqTestProxy() *MasqTestProxy {
return &MasqTestProxy{
func newMasqTestProxy() *masqTestProxy {
return &masqTestProxy{
Port: "31235",
}
}
func (m *MasqTestProxy) AddFlags(fs *pflag.FlagSet) {
func (m *masqTestProxy) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat endpoint on.")
}
func main() {
m := NewMasqTestProxy()
m := newMasqTestProxy()
m.AddFlags(pflag.CommandLine)
flag.InitFlags()
......@@ -58,7 +58,7 @@ func main() {
}
}
func (m *MasqTestProxy) Run() error {
func (m *masqTestProxy) Run() error {
// register handler
http.HandleFunc("/checknosnat", checknosnat)
......
......@@ -34,22 +34,22 @@ import (
// pip = this pod's ip
// nip = this node's ip
type MasqTester struct {
type masqTester struct {
Port string
}
func NewMasqTester() *MasqTester {
return &MasqTester{
func newMasqTester() *masqTester {
return &masqTester{
Port: "8080",
}
}
func (m *MasqTester) AddFlags(fs *pflag.FlagSet) {
func (m *masqTester) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat and /whoami endpoints on.")
}
func main() {
m := NewMasqTester()
m := newMasqTester()
m.AddFlags(pflag.CommandLine)
flag.InitFlags()
......@@ -62,7 +62,7 @@ func main() {
}
}
func (m *MasqTester) Run() error {
func (m *masqTester) Run() error {
// pip is the current pod's IP and nip is the current node's IP
// pull the pip and nip out of the env
pip, ok := os.LookupEnv("POD_IP")
......@@ -145,9 +145,8 @@ func check(ip string, pip string, nip string) error {
if rip != pip {
if rip == nip {
return fmt.Errorf("Returned ip %q != my Pod ip %q, == my Node ip %q - SNAT", rip, pip, nip)
} else {
return fmt.Errorf("Returned ip %q != my Pod ip %q or my Node ip %q - SNAT to unexpected ip (possible SNAT through unexpected interface on the way into another node)", rip, pip, nip)
}
return fmt.Errorf("Returned ip %q != my Pod ip %q or my Node ip %q - SNAT to unexpected ip (possible SNAT through unexpected interface on the way into another node)", rip, pip, nip)
}
return nil
}
......@@ -16,6 +16,7 @@ limitations under the License.
package common
// Constants related to Prometheus metrics.
const (
ConsumeCPUAddress = "/ConsumeCPU"
ConsumeMemAddress = "/ConsumeMem"
......
......@@ -24,26 +24,28 @@ import (
"sync"
"time"
. "k8s.io/kubernetes/test/images/resource-consumer/common"
"k8s.io/kubernetes/test/images/resource-consumer/common"
)
// ResourceConsumerHandler holds metrics for a resource consumer.
type ResourceConsumerHandler struct {
metrics map[string]float64
metricsLock sync.Mutex
}
// NewResourceConsumerHandler creates and initializes a ResourceConsumerHandler to defaults.
func NewResourceConsumerHandler() *ResourceConsumerHandler {
return &ResourceConsumerHandler{metrics: map[string]float64{}}
}
func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// handle exposing metrics in Prometheus format (both GET & POST)
if req.URL.Path == MetricsAddress {
if req.URL.Path == common.MetricsAddress {
handler.handleMetrics(w)
return
}
if req.Method != "POST" {
http.Error(w, BadRequest, http.StatusBadRequest)
http.Error(w, common.BadRequest, http.StatusBadRequest)
return
}
// parsing POST request data and URL data
......@@ -52,34 +54,34 @@ func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *ht
return
}
// handle consumeCPU
if req.URL.Path == ConsumeCPUAddress {
if req.URL.Path == common.ConsumeCPUAddress {
handler.handleConsumeCPU(w, req.Form)
return
}
// handle consumeMem
if req.URL.Path == ConsumeMemAddress {
if req.URL.Path == common.ConsumeMemAddress {
handler.handleConsumeMem(w, req.Form)
return
}
// handle getCurrentStatus
if req.URL.Path == GetCurrentStatusAddress {
if req.URL.Path == common.GetCurrentStatusAddress {
handler.handleGetCurrentStatus(w)
return
}
// handle bumpMetric
if req.URL.Path == BumpMetricAddress {
if req.URL.Path == common.BumpMetricAddress {
handler.handleBumpMetric(w, req.Form)
return
}
http.Error(w, fmt.Sprintf("%s: %s", UnknownFunction, req.URL.Path), http.StatusNotFound)
http.Error(w, fmt.Sprintf("%s: %s", common.UnknownFunction, req.URL.Path), http.StatusNotFound)
}
func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
// getting string data for consumeCPU
durationSecString := query.Get(DurationSecQuery)
millicoresString := query.Get(MillicoresQuery)
durationSecString := query.Get(common.DurationSecQuery)
millicoresString := query.Get(common.MillicoresQuery)
if durationSecString == "" || millicoresString == "" {
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
return
}
......@@ -87,22 +89,22 @@ func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter,
durationSec, durationSecError := strconv.Atoi(durationSecString)
millicores, millicoresError := strconv.Atoi(millicoresString)
if durationSecError != nil || millicoresError != nil {
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
return
}
go ConsumeCPU(millicores, durationSec)
fmt.Fprintln(w, ConsumeCPUAddress[1:])
fmt.Fprintln(w, millicores, MillicoresQuery)
fmt.Fprintln(w, durationSec, DurationSecQuery)
fmt.Fprintln(w, common.ConsumeCPUAddress[1:])
fmt.Fprintln(w, millicores, common.MillicoresQuery)
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
}
func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter, query url.Values) {
// getting string data for consumeMem
durationSecString := query.Get(DurationSecQuery)
megabytesString := query.Get(MegabytesQuery)
durationSecString := query.Get(common.DurationSecQuery)
megabytesString := query.Get(common.MegabytesQuery)
if durationSecString == "" || megabytesString == "" {
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
return
}
......@@ -110,20 +112,20 @@ func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter,
durationSec, durationSecError := strconv.Atoi(durationSecString)
megabytes, megabytesError := strconv.Atoi(megabytesString)
if durationSecError != nil || megabytesError != nil {
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
return
}
go ConsumeMem(megabytes, durationSec)
fmt.Fprintln(w, ConsumeMemAddress[1:])
fmt.Fprintln(w, megabytes, MegabytesQuery)
fmt.Fprintln(w, durationSec, DurationSecQuery)
fmt.Fprintln(w, common.ConsumeMemAddress[1:])
fmt.Fprintln(w, megabytes, common.MegabytesQuery)
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
}
func (handler *ResourceConsumerHandler) handleGetCurrentStatus(w http.ResponseWriter) {
GetCurrentStatus()
fmt.Fprintln(w, "Warning: not implemented!")
fmt.Fprint(w, GetCurrentStatusAddress[1:])
fmt.Fprint(w, common.GetCurrentStatusAddress[1:])
}
func (handler *ResourceConsumerHandler) handleMetrics(w http.ResponseWriter) {
......@@ -154,11 +156,11 @@ func (handler *ResourceConsumerHandler) bumpMetric(metric string, delta float64,
func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter, query url.Values) {
// getting string data for handleBumpMetric
metric := query.Get(MetricNameQuery)
deltaString := query.Get(DeltaQuery)
durationSecString := query.Get(DurationSecQuery)
metric := query.Get(common.MetricNameQuery)
deltaString := query.Get(common.DeltaQuery)
durationSecString := query.Get(common.DurationSecQuery)
if durationSecString == "" || metric == "" || deltaString == "" {
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
return
}
......@@ -166,13 +168,13 @@ func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter,
durationSec, durationSecError := strconv.Atoi(durationSecString)
delta, deltaError := strconv.ParseFloat(deltaString, 64)
if durationSecError != nil || deltaError != nil {
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
return
}
go handler.bumpMetric(metric, delta, time.Duration(durationSec)*time.Second)
fmt.Fprintln(w, BumpMetricAddress[1:])
fmt.Fprintln(w, metric, MetricNameQuery)
fmt.Fprintln(w, delta, DeltaQuery)
fmt.Fprintln(w, durationSec, DurationSecQuery)
fmt.Fprintln(w, common.BumpMetricAddress[1:])
fmt.Fprintln(w, metric, common.MetricNameQuery)
fmt.Fprintln(w, delta, common.DeltaQuery)
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
}
......@@ -28,6 +28,7 @@ const (
consumeMemBinary = "stress"
)
// ConsumeCPU consumes a given number of millicores for the specified duration.
func ConsumeCPU(millicores int, durationSec int) {
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
// creating new consume cpu process
......@@ -37,6 +38,7 @@ func ConsumeCPU(millicores int, durationSec int) {
consumeCPU.Run()
}
// ConsumeMem consumes a given number of megabytes for the specified duration.
func ConsumeMem(megabytes int, durationSec int) {
log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
megabytesString := strconv.Itoa(megabytes) + "M"
......@@ -46,6 +48,7 @@ func ConsumeMem(megabytes int, durationSec int) {
consumeMem.Run()
}
// GetCurrentStatus prints out a no-op.
func GetCurrentStatus() {
log.Printf("GetCurrentStatus")
// not implemented
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment