mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Remove test/images/* from hack/.golint_failures
This commit is contained in:
parent
224448b858
commit
d8390c4845
@ -746,14 +746,6 @@ test/e2e_node/environment
|
|||||||
test/e2e_node/remote
|
test/e2e_node/remote
|
||||||
test/e2e_node/runner/remote
|
test/e2e_node/runner/remote
|
||||||
test/e2e_node/services
|
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
|
||||||
test/integration/auth
|
test/integration/auth
|
||||||
test/integration/evictions
|
test/integration/evictions
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
// connection assigned here.
|
// connection assigned here.
|
||||||
var leakedConnection *net.TCPConn
|
var leakedConnection *net.TCPConn
|
||||||
|
|
||||||
// Server JSON options.
|
// CloseWaitServerOptions holds server JSON options.
|
||||||
type CloseWaitServerOptions struct {
|
type CloseWaitServerOptions struct {
|
||||||
// Address to bind for the test
|
// Address to bind for the test
|
||||||
LocalAddr string
|
LocalAddr string
|
||||||
@ -110,7 +110,7 @@ func (server *closeWaitServer) Run(logger *log.Logger, rawOptions interface{}) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client JSON options
|
// CloseWaitClientOptions holds client JSON options.
|
||||||
type CloseWaitClientOptions struct {
|
type CloseWaitClientOptions struct {
|
||||||
// RemoteAddr of the server to connect to.
|
// RemoteAddr of the server to connect to.
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
|
@ -80,7 +80,7 @@ func main() {
|
|||||||
|
|
||||||
func startHTTPServer(httpPort int) {
|
func startHTTPServer(httpPort int) {
|
||||||
http.HandleFunc("/", rootHandler)
|
http.HandleFunc("/", rootHandler)
|
||||||
http.HandleFunc("/clientip", clientIpHandler)
|
http.HandleFunc("/clientip", clientIPHandler)
|
||||||
http.HandleFunc("/echo", echoHandler)
|
http.HandleFunc("/echo", echoHandler)
|
||||||
http.HandleFunc("/exit", exitHandler)
|
http.HandleFunc("/exit", exitHandler)
|
||||||
http.HandleFunc("/hostname", hostnameHandler)
|
http.HandleFunc("/hostname", hostnameHandler)
|
||||||
@ -104,7 +104,7 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintf(w, "%s", r.FormValue("msg"))
|
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")
|
log.Printf("GET /clientip")
|
||||||
fmt.Fprintf(w, r.RemoteAddr)
|
fmt.Fprintf(w, r.RemoteAddr)
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ func (s *State) serveWrite(w http.ResponseWriter, r *http.Request) {
|
|||||||
if s.Received == nil {
|
if s.Received == nil {
|
||||||
s.Received = map[string]int{}
|
s.Received = map[string]int{}
|
||||||
}
|
}
|
||||||
s.Received[wp.Source] += 1
|
s.Received[wp.Source]++
|
||||||
}
|
}
|
||||||
s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
|
s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func (s *State) appendSuccessfulSend(toHostname string) {
|
|||||||
if s.Sent == nil {
|
if s.Sent == nil {
|
||||||
s.Sent = map[string]int{}
|
s.Sent = map[string]int{}
|
||||||
}
|
}
|
||||||
s.Sent[toHostname] += 1
|
s.Sent[toHostname]++
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -30,22 +30,22 @@ import (
|
|||||||
|
|
||||||
// This Pod's /checknosnat takes `target` and `ips` arguments, and queries {target}/checknosnat?ips={ips}
|
// This Pod's /checknosnat takes `target` and `ips` arguments, and queries {target}/checknosnat?ips={ips}
|
||||||
|
|
||||||
type MasqTestProxy struct {
|
type masqTestProxy struct {
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMasqTestProxy() *MasqTestProxy {
|
func newMasqTestProxy() *masqTestProxy {
|
||||||
return &MasqTestProxy{
|
return &masqTestProxy{
|
||||||
Port: "31235",
|
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.")
|
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat endpoint on.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
m := NewMasqTestProxy()
|
m := newMasqTestProxy()
|
||||||
m.AddFlags(pflag.CommandLine)
|
m.AddFlags(pflag.CommandLine)
|
||||||
|
|
||||||
flag.InitFlags()
|
flag.InitFlags()
|
||||||
@ -58,7 +58,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MasqTestProxy) Run() error {
|
func (m *masqTestProxy) Run() error {
|
||||||
// register handler
|
// register handler
|
||||||
http.HandleFunc("/checknosnat", checknosnat)
|
http.HandleFunc("/checknosnat", checknosnat)
|
||||||
|
|
||||||
|
@ -34,22 +34,22 @@ import (
|
|||||||
// pip = this pod's ip
|
// pip = this pod's ip
|
||||||
// nip = this node's ip
|
// nip = this node's ip
|
||||||
|
|
||||||
type MasqTester struct {
|
type masqTester struct {
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMasqTester() *MasqTester {
|
func newMasqTester() *masqTester {
|
||||||
return &MasqTester{
|
return &masqTester{
|
||||||
Port: "8080",
|
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.")
|
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat and /whoami endpoints on.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
m := NewMasqTester()
|
m := newMasqTester()
|
||||||
m.AddFlags(pflag.CommandLine)
|
m.AddFlags(pflag.CommandLine)
|
||||||
|
|
||||||
flag.InitFlags()
|
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
|
// pip is the current pod's IP and nip is the current node's IP
|
||||||
// pull the pip and nip out of the env
|
// pull the pip and nip out of the env
|
||||||
pip, ok := os.LookupEnv("POD_IP")
|
pip, ok := os.LookupEnv("POD_IP")
|
||||||
@ -145,9 +145,8 @@ func check(ip string, pip string, nip string) error {
|
|||||||
if rip != pip {
|
if rip != pip {
|
||||||
if rip == nip {
|
if rip == nip {
|
||||||
return fmt.Errorf("Returned ip %q != my Pod ip %q, == my Node ip %q - SNAT", rip, pip, 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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
// Constants related to Prometheus metrics.
|
||||||
const (
|
const (
|
||||||
ConsumeCPUAddress = "/ConsumeCPU"
|
ConsumeCPUAddress = "/ConsumeCPU"
|
||||||
ConsumeMemAddress = "/ConsumeMem"
|
ConsumeMemAddress = "/ConsumeMem"
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
. "k8s.io/kubernetes/test/images/resource-consumer/common"
|
"k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port = flag.Int("port", 8080, "Port number.")
|
var port = flag.Int("port", 8080, "Port number.")
|
||||||
@ -35,23 +35,23 @@ var consumerServiceNamespace = flag.String("consumer-service-namespace", "defaul
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
mgr := NewController()
|
mgr := newController()
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), mgr))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), mgr))
|
||||||
}
|
}
|
||||||
|
|
||||||
type Controller struct {
|
type controller struct {
|
||||||
responseWriterLock sync.Mutex
|
responseWriterLock sync.Mutex
|
||||||
waitGroup sync.WaitGroup
|
waitGroup sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController() *Controller {
|
func newController() *controller {
|
||||||
c := &Controller{}
|
c := &controller{}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (c *controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
if req.Method != "POST" {
|
if req.Method != "POST" {
|
||||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
http.Error(w, common.BadRequest, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// parsing POST request data and URL data
|
// parsing POST request data and URL data
|
||||||
@ -60,30 +60,30 @@ func (handler *Controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle consumeCPU
|
// handle consumeCPU
|
||||||
if req.URL.Path == ConsumeCPUAddress {
|
if req.URL.Path == common.ConsumeCPUAddress {
|
||||||
handler.handleConsumeCPU(w, req.Form)
|
c.handleConsumeCPU(w, req.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle consumeMem
|
// handle consumeMem
|
||||||
if req.URL.Path == ConsumeMemAddress {
|
if req.URL.Path == common.ConsumeMemAddress {
|
||||||
handler.handleConsumeMem(w, req.Form)
|
c.handleConsumeMem(w, req.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle bumpMetric
|
// handle bumpMetric
|
||||||
if req.URL.Path == BumpMetricAddress {
|
if req.URL.Path == common.BumpMetricAddress {
|
||||||
handler.handleBumpMetric(w, req.Form)
|
c.handleBumpMetric(w, req.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Error(w, UnknownFunction, http.StatusNotFound)
|
http.Error(w, common.UnknownFunction, http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
func (c *controller) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for consumeCPU
|
// getting string data for consumeCPU
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
millicoresString := query.Get(MillicoresQuery)
|
millicoresString := query.Get(common.MillicoresQuery)
|
||||||
requestSizeInMillicoresString := query.Get(RequestSizeInMillicoresQuery)
|
requestSizeInMillicoresString := query.Get(common.RequestSizeInMillicoresQuery)
|
||||||
if durationSecString == "" || millicoresString == "" || requestSizeInMillicoresString == "" {
|
if durationSecString == "" || millicoresString == "" || requestSizeInMillicoresString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Val
|
|||||||
millicores, millicoresError := strconv.Atoi(millicoresString)
|
millicores, millicoresError := strconv.Atoi(millicoresString)
|
||||||
requestSizeInMillicores, requestSizeInMillicoresError := strconv.Atoi(requestSizeInMillicoresString)
|
requestSizeInMillicores, requestSizeInMillicoresError := strconv.Atoi(requestSizeInMillicoresString)
|
||||||
if durationSecError != nil || millicoresError != nil || requestSizeInMillicoresError != nil || requestSizeInMillicores <= 0 {
|
if durationSecError != nil || millicoresError != nil || requestSizeInMillicoresError != nil || requestSizeInMillicores <= 0 {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,23 +100,23 @@ func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Val
|
|||||||
rest := millicores - count*requestSizeInMillicores
|
rest := millicores - count*requestSizeInMillicores
|
||||||
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v millicores each and 1 request to consume %v millicores\n", count, requestSizeInMillicores, rest)
|
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v millicores each and 1 request to consume %v millicores\n", count, requestSizeInMillicores, rest)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
handler.waitGroup.Add(count)
|
c.waitGroup.Add(count)
|
||||||
handler.sendConsumeCPURequests(w, count, requestSizeInMillicores, durationSec)
|
c.sendConsumeCPURequests(w, count, requestSizeInMillicores, durationSec)
|
||||||
}
|
}
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
handler.waitGroup.Add(1)
|
c.waitGroup.Add(1)
|
||||||
go handler.sendOneConsumeCPURequest(w, rest, durationSec)
|
go c.sendOneConsumeCPURequest(w, rest, durationSec)
|
||||||
}
|
}
|
||||||
handler.waitGroup.Wait()
|
c.waitGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
func (c *controller) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for consumeMem
|
// getting string data for consumeMem
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
megabytesString := query.Get(MegabytesQuery)
|
megabytesString := query.Get(common.MegabytesQuery)
|
||||||
requestSizeInMegabytesString := query.Get(RequestSizeInMegabytesQuery)
|
requestSizeInMegabytesString := query.Get(common.RequestSizeInMegabytesQuery)
|
||||||
if durationSecString == "" || megabytesString == "" || requestSizeInMegabytesString == "" {
|
if durationSecString == "" || megabytesString == "" || requestSizeInMegabytesString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Val
|
|||||||
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
||||||
requestSizeInMegabytes, requestSizeInMegabytesError := strconv.Atoi(requestSizeInMegabytesString)
|
requestSizeInMegabytes, requestSizeInMegabytesError := strconv.Atoi(requestSizeInMegabytesString)
|
||||||
if durationSecError != nil || megabytesError != nil || requestSizeInMegabytesError != nil || requestSizeInMegabytes <= 0 {
|
if durationSecError != nil || megabytesError != nil || requestSizeInMegabytesError != nil || requestSizeInMegabytes <= 0 {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,24 +133,24 @@ func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Val
|
|||||||
rest := megabytes - count*requestSizeInMegabytes
|
rest := megabytes - count*requestSizeInMegabytes
|
||||||
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v MB each and 1 request to consume %v MB\n", count, requestSizeInMegabytes, rest)
|
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v MB each and 1 request to consume %v MB\n", count, requestSizeInMegabytes, rest)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
handler.waitGroup.Add(count)
|
c.waitGroup.Add(count)
|
||||||
handler.sendConsumeMemRequests(w, count, requestSizeInMegabytes, durationSec)
|
c.sendConsumeMemRequests(w, count, requestSizeInMegabytes, durationSec)
|
||||||
}
|
}
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
handler.waitGroup.Add(1)
|
c.waitGroup.Add(1)
|
||||||
go handler.sendOneConsumeMemRequest(w, rest, durationSec)
|
go c.sendOneConsumeMemRequest(w, rest, durationSec)
|
||||||
}
|
}
|
||||||
handler.waitGroup.Wait()
|
c.waitGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
func (c *controller) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for handleBumpMetric
|
// getting string data for handleBumpMetric
|
||||||
metric := query.Get(MetricNameQuery)
|
metric := query.Get(common.MetricNameQuery)
|
||||||
deltaString := query.Get(DeltaQuery)
|
deltaString := query.Get(common.DeltaQuery)
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
requestSizeCustomMetricString := query.Get(RequestSizeCustomMetricQuery)
|
requestSizeCustomMetricString := query.Get(common.RequestSizeCustomMetricQuery)
|
||||||
if durationSecString == "" || metric == "" || deltaString == "" || requestSizeCustomMetricString == "" {
|
if durationSecString == "" || metric == "" || deltaString == "" || requestSizeCustomMetricString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Val
|
|||||||
delta, deltaError := strconv.Atoi(deltaString)
|
delta, deltaError := strconv.Atoi(deltaString)
|
||||||
requestSizeCustomMetric, requestSizeCustomMetricError := strconv.Atoi(requestSizeCustomMetricString)
|
requestSizeCustomMetric, requestSizeCustomMetricError := strconv.Atoi(requestSizeCustomMetricString)
|
||||||
if durationSecError != nil || deltaError != nil || requestSizeCustomMetricError != nil || requestSizeCustomMetric <= 0 {
|
if durationSecError != nil || deltaError != nil || requestSizeCustomMetricError != nil || requestSizeCustomMetric <= 0 {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,31 +167,31 @@ func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Val
|
|||||||
rest := delta - count*requestSizeCustomMetric
|
rest := delta - count*requestSizeCustomMetric
|
||||||
fmt.Fprintf(w, "RC manager: sending %v requests to bump custom metric by %v each and 1 request to bump by %v\n", count, requestSizeCustomMetric, rest)
|
fmt.Fprintf(w, "RC manager: sending %v requests to bump custom metric by %v each and 1 request to bump by %v\n", count, requestSizeCustomMetric, rest)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
handler.waitGroup.Add(count)
|
c.waitGroup.Add(count)
|
||||||
handler.sendConsumeCustomMetric(w, metric, count, requestSizeCustomMetric, durationSec)
|
c.sendConsumeCustomMetric(w, metric, count, requestSizeCustomMetric, durationSec)
|
||||||
}
|
}
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
handler.waitGroup.Add(1)
|
c.waitGroup.Add(1)
|
||||||
go handler.sendOneConsumeCustomMetric(w, metric, rest, durationSec)
|
go c.sendOneConsumeCustomMetric(w, metric, rest, durationSec)
|
||||||
}
|
}
|
||||||
handler.waitGroup.Wait()
|
c.waitGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *Controller) sendConsumeCPURequests(w http.ResponseWriter, requests, millicores, durationSec int) {
|
func (c *controller) sendConsumeCPURequests(w http.ResponseWriter, requests, millicores, durationSec int) {
|
||||||
for i := 0; i < requests; i++ {
|
for i := 0; i < requests; i++ {
|
||||||
go manager.sendOneConsumeCPURequest(w, millicores, durationSec)
|
go c.sendOneConsumeCPURequest(w, millicores, durationSec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *Controller) sendConsumeMemRequests(w http.ResponseWriter, requests, megabytes, durationSec int) {
|
func (c *controller) sendConsumeMemRequests(w http.ResponseWriter, requests, megabytes, durationSec int) {
|
||||||
for i := 0; i < requests; i++ {
|
for i := 0; i < requests; i++ {
|
||||||
go manager.sendOneConsumeMemRequest(w, megabytes, durationSec)
|
go c.sendOneConsumeMemRequest(w, megabytes, durationSec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *Controller) sendConsumeCustomMetric(w http.ResponseWriter, metric string, requests, delta, durationSec int) {
|
func (c *controller) sendConsumeCustomMetric(w http.ResponseWriter, metric string, requests, delta, durationSec int) {
|
||||||
for i := 0; i < requests; i++ {
|
for i := 0; i < requests; i++ {
|
||||||
go manager.sendOneConsumeCustomMetric(w, metric, delta, durationSec)
|
go c.sendOneConsumeCustomMetric(w, metric, delta, durationSec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,10 +200,10 @@ func createConsumerURL(suffix string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sendOneConsumeCPURequest sends POST request for cpu consumption
|
// sendOneConsumeCPURequest sends POST request for cpu consumption
|
||||||
func (c *Controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores int, durationSec int) {
|
func (c *controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores int, durationSec int) {
|
||||||
defer c.waitGroup.Done()
|
defer c.waitGroup.Done()
|
||||||
query := createConsumerURL(ConsumeCPUAddress)
|
query := createConsumerURL(common.ConsumeCPUAddress)
|
||||||
_, err := http.PostForm(query, url.Values{MillicoresQuery: {strconv.Itoa(millicores)}, DurationSecQuery: {strconv.Itoa(durationSec)}})
|
_, err := http.PostForm(query, url.Values{common.MillicoresQuery: {strconv.Itoa(millicores)}, common.DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||||
c.responseWriterLock.Lock()
|
c.responseWriterLock.Lock()
|
||||||
defer c.responseWriterLock.Unlock()
|
defer c.responseWriterLock.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,10 +214,10 @@ func (c *Controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sendOneConsumeMemRequest sends POST request for memory consumption
|
// sendOneConsumeMemRequest sends POST request for memory consumption
|
||||||
func (c *Controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes int, durationSec int) {
|
func (c *controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes int, durationSec int) {
|
||||||
defer c.waitGroup.Done()
|
defer c.waitGroup.Done()
|
||||||
query := createConsumerURL(ConsumeMemAddress)
|
query := createConsumerURL(common.ConsumeMemAddress)
|
||||||
_, err := http.PostForm(query, url.Values{MegabytesQuery: {strconv.Itoa(megabytes)}, DurationSecQuery: {strconv.Itoa(durationSec)}})
|
_, err := http.PostForm(query, url.Values{common.MegabytesQuery: {strconv.Itoa(megabytes)}, common.DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||||
c.responseWriterLock.Lock()
|
c.responseWriterLock.Lock()
|
||||||
defer c.responseWriterLock.Unlock()
|
defer c.responseWriterLock.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -228,11 +228,11 @@ func (c *Controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sendOneConsumeCustomMetric sends POST request for custom metric consumption
|
// sendOneConsumeCustomMetric sends POST request for custom metric consumption
|
||||||
func (c *Controller) sendOneConsumeCustomMetric(w http.ResponseWriter, customMetricName string, delta int, durationSec int) {
|
func (c *controller) sendOneConsumeCustomMetric(w http.ResponseWriter, customMetricName string, delta int, durationSec int) {
|
||||||
defer c.waitGroup.Done()
|
defer c.waitGroup.Done()
|
||||||
query := createConsumerURL(BumpMetricAddress)
|
query := createConsumerURL(common.BumpMetricAddress)
|
||||||
_, err := http.PostForm(query,
|
_, err := http.PostForm(query,
|
||||||
url.Values{MetricNameQuery: {customMetricName}, DurationSecQuery: {strconv.Itoa(durationSec)}, DeltaQuery: {strconv.Itoa(delta)}})
|
url.Values{common.MetricNameQuery: {customMetricName}, common.DurationSecQuery: {strconv.Itoa(durationSec)}, common.DeltaQuery: {strconv.Itoa(delta)}})
|
||||||
c.responseWriterLock.Lock()
|
c.responseWriterLock.Lock()
|
||||||
defer c.responseWriterLock.Unlock()
|
defer c.responseWriterLock.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,26 +24,28 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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 {
|
type ResourceConsumerHandler struct {
|
||||||
metrics map[string]float64
|
metrics map[string]float64
|
||||||
metricsLock sync.Mutex
|
metricsLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewResourceConsumerHandler creates and initializes a ResourceConsumerHandler to defaults.
|
||||||
func NewResourceConsumerHandler() *ResourceConsumerHandler {
|
func NewResourceConsumerHandler() *ResourceConsumerHandler {
|
||||||
return &ResourceConsumerHandler{metrics: map[string]float64{}}
|
return &ResourceConsumerHandler{metrics: map[string]float64{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// handle exposing metrics in Prometheus format (both GET & POST)
|
// handle exposing metrics in Prometheus format (both GET & POST)
|
||||||
if req.URL.Path == MetricsAddress {
|
if req.URL.Path == common.MetricsAddress {
|
||||||
handler.handleMetrics(w)
|
handler.handleMetrics(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Method != "POST" {
|
if req.Method != "POST" {
|
||||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
http.Error(w, common.BadRequest, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// parsing POST request data and URL data
|
// parsing POST request data and URL data
|
||||||
@ -52,34 +54,34 @@ func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *ht
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle consumeCPU
|
// handle consumeCPU
|
||||||
if req.URL.Path == ConsumeCPUAddress {
|
if req.URL.Path == common.ConsumeCPUAddress {
|
||||||
handler.handleConsumeCPU(w, req.Form)
|
handler.handleConsumeCPU(w, req.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle consumeMem
|
// handle consumeMem
|
||||||
if req.URL.Path == ConsumeMemAddress {
|
if req.URL.Path == common.ConsumeMemAddress {
|
||||||
handler.handleConsumeMem(w, req.Form)
|
handler.handleConsumeMem(w, req.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle getCurrentStatus
|
// handle getCurrentStatus
|
||||||
if req.URL.Path == GetCurrentStatusAddress {
|
if req.URL.Path == common.GetCurrentStatusAddress {
|
||||||
handler.handleGetCurrentStatus(w)
|
handler.handleGetCurrentStatus(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// handle bumpMetric
|
// handle bumpMetric
|
||||||
if req.URL.Path == BumpMetricAddress {
|
if req.URL.Path == common.BumpMetricAddress {
|
||||||
handler.handleBumpMetric(w, req.Form)
|
handler.handleBumpMetric(w, req.Form)
|
||||||
return
|
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) {
|
func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for consumeCPU
|
// getting string data for consumeCPU
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
millicoresString := query.Get(MillicoresQuery)
|
millicoresString := query.Get(common.MillicoresQuery)
|
||||||
if durationSecString == "" || millicoresString == "" {
|
if durationSecString == "" || millicoresString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,22 +89,22 @@ func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter,
|
|||||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||||
millicores, millicoresError := strconv.Atoi(millicoresString)
|
millicores, millicoresError := strconv.Atoi(millicoresString)
|
||||||
if durationSecError != nil || millicoresError != nil {
|
if durationSecError != nil || millicoresError != nil {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go ConsumeCPU(millicores, durationSec)
|
go ConsumeCPU(millicores, durationSec)
|
||||||
fmt.Fprintln(w, ConsumeCPUAddress[1:])
|
fmt.Fprintln(w, common.ConsumeCPUAddress[1:])
|
||||||
fmt.Fprintln(w, millicores, MillicoresQuery)
|
fmt.Fprintln(w, millicores, common.MillicoresQuery)
|
||||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for consumeMem
|
// getting string data for consumeMem
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
megabytesString := query.Get(MegabytesQuery)
|
megabytesString := query.Get(common.MegabytesQuery)
|
||||||
if durationSecString == "" || megabytesString == "" {
|
if durationSecString == "" || megabytesString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,20 +112,20 @@ func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter,
|
|||||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||||
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
||||||
if durationSecError != nil || megabytesError != nil {
|
if durationSecError != nil || megabytesError != nil {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go ConsumeMem(megabytes, durationSec)
|
go ConsumeMem(megabytes, durationSec)
|
||||||
fmt.Fprintln(w, ConsumeMemAddress[1:])
|
fmt.Fprintln(w, common.ConsumeMemAddress[1:])
|
||||||
fmt.Fprintln(w, megabytes, MegabytesQuery)
|
fmt.Fprintln(w, megabytes, common.MegabytesQuery)
|
||||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ResourceConsumerHandler) handleGetCurrentStatus(w http.ResponseWriter) {
|
func (handler *ResourceConsumerHandler) handleGetCurrentStatus(w http.ResponseWriter) {
|
||||||
GetCurrentStatus()
|
GetCurrentStatus()
|
||||||
fmt.Fprintln(w, "Warning: not implemented!")
|
fmt.Fprintln(w, "Warning: not implemented!")
|
||||||
fmt.Fprint(w, GetCurrentStatusAddress[1:])
|
fmt.Fprint(w, common.GetCurrentStatusAddress[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ResourceConsumerHandler) handleMetrics(w http.ResponseWriter) {
|
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) {
|
func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||||
// getting string data for handleBumpMetric
|
// getting string data for handleBumpMetric
|
||||||
metric := query.Get(MetricNameQuery)
|
metric := query.Get(common.MetricNameQuery)
|
||||||
deltaString := query.Get(DeltaQuery)
|
deltaString := query.Get(common.DeltaQuery)
|
||||||
durationSecString := query.Get(DurationSecQuery)
|
durationSecString := query.Get(common.DurationSecQuery)
|
||||||
if durationSecString == "" || metric == "" || deltaString == "" {
|
if durationSecString == "" || metric == "" || deltaString == "" {
|
||||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,13 +168,13 @@ func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter,
|
|||||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||||
delta, deltaError := strconv.ParseFloat(deltaString, 64)
|
delta, deltaError := strconv.ParseFloat(deltaString, 64)
|
||||||
if durationSecError != nil || deltaError != nil {
|
if durationSecError != nil || deltaError != nil {
|
||||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go handler.bumpMetric(metric, delta, time.Duration(durationSec)*time.Second)
|
go handler.bumpMetric(metric, delta, time.Duration(durationSec)*time.Second)
|
||||||
fmt.Fprintln(w, BumpMetricAddress[1:])
|
fmt.Fprintln(w, common.BumpMetricAddress[1:])
|
||||||
fmt.Fprintln(w, metric, MetricNameQuery)
|
fmt.Fprintln(w, metric, common.MetricNameQuery)
|
||||||
fmt.Fprintln(w, delta, DeltaQuery)
|
fmt.Fprintln(w, delta, common.DeltaQuery)
|
||||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ const (
|
|||||||
consumeMemBinary = "stress"
|
consumeMemBinary = "stress"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ConsumeCPU consumes a given number of millicores for the specified duration.
|
||||||
func ConsumeCPU(millicores int, durationSec int) {
|
func ConsumeCPU(millicores int, durationSec int) {
|
||||||
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
|
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
|
||||||
// creating new consume cpu process
|
// creating new consume cpu process
|
||||||
@ -37,6 +38,7 @@ func ConsumeCPU(millicores int, durationSec int) {
|
|||||||
consumeCPU.Run()
|
consumeCPU.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsumeMem consumes a given number of megabytes for the specified duration.
|
||||||
func ConsumeMem(megabytes int, durationSec int) {
|
func ConsumeMem(megabytes int, durationSec int) {
|
||||||
log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
|
log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
|
||||||
megabytesString := strconv.Itoa(megabytes) + "M"
|
megabytesString := strconv.Itoa(megabytes) + "M"
|
||||||
@ -46,6 +48,7 @@ func ConsumeMem(megabytes int, durationSec int) {
|
|||||||
consumeMem.Run()
|
consumeMem.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCurrentStatus prints out a no-op.
|
||||||
func GetCurrentStatus() {
|
func GetCurrentStatus() {
|
||||||
log.Printf("GetCurrentStatus")
|
log.Printf("GetCurrentStatus")
|
||||||
// not implemented
|
// not implemented
|
||||||
|
Loading…
Reference in New Issue
Block a user