mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #68409 from wgliang/feature/remove-chaosclien
Remove unused chaosclient
This commit is contained in:
commit
f149d2a2c2
@ -29,7 +29,6 @@ go_library(
|
|||||||
"//pkg/api/legacyscheme:go_default_library",
|
"//pkg/api/legacyscheme:go_default_library",
|
||||||
"//pkg/apis/core:go_default_library",
|
"//pkg/apis/core:go_default_library",
|
||||||
"//pkg/capabilities:go_default_library",
|
"//pkg/capabilities:go_default_library",
|
||||||
"//pkg/client/chaosclient:go_default_library",
|
|
||||||
"//pkg/cloudprovider:go_default_library",
|
"//pkg/cloudprovider:go_default_library",
|
||||||
"//pkg/cloudprovider/providers:go_default_library",
|
"//pkg/cloudprovider/providers:go_default_library",
|
||||||
"//pkg/credentialprovider:go_default_library",
|
"//pkg/credentialprovider:go_default_library",
|
||||||
|
@ -62,7 +62,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/capabilities"
|
"k8s.io/kubernetes/pkg/capabilities"
|
||||||
"k8s.io/kubernetes/pkg/client/chaosclient"
|
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
"k8s.io/kubernetes/pkg/credentialprovider"
|
"k8s.io/kubernetes/pkg/credentialprovider"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
@ -890,22 +889,9 @@ func createAPIServerClientConfig(s *options.KubeletServer) (*restclient.Config,
|
|||||||
clientConfig.QPS = float32(s.KubeAPIQPS)
|
clientConfig.QPS = float32(s.KubeAPIQPS)
|
||||||
clientConfig.Burst = int(s.KubeAPIBurst)
|
clientConfig.Burst = int(s.KubeAPIBurst)
|
||||||
|
|
||||||
addChaosToClientConfig(s, clientConfig)
|
|
||||||
return clientConfig, nil
|
return clientConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// addChaosToClientConfig injects random errors into client connections if configured.
|
|
||||||
func addChaosToClientConfig(s *options.KubeletServer, config *restclient.Config) {
|
|
||||||
if s.ChaosChance != 0.0 {
|
|
||||||
config.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
|
|
||||||
seed := chaosclient.NewSeed(1)
|
|
||||||
// TODO: introduce a standard chaos package with more tunables - this is just a proof of concept
|
|
||||||
// TODO: introduce random latency and stalls
|
|
||||||
return chaosclient.NewChaosRoundTripper(rt, chaosclient.LogChaos, seed.P(s.ChaosChance, chaosclient.ErrSimulatedConnectionResetByPeer))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunKubelet is responsible for setting up and running a kubelet. It is used in three different applications:
|
// RunKubelet is responsible for setting up and running a kubelet. It is used in three different applications:
|
||||||
// 1 Integration tests
|
// 1 Integration tests
|
||||||
// 2 Kubelet binary
|
// 2 Kubelet binary
|
||||||
|
@ -52,7 +52,6 @@ filegroup(
|
|||||||
"//pkg/auth/authorizer/abac:all-srcs",
|
"//pkg/auth/authorizer/abac:all-srcs",
|
||||||
"//pkg/auth/nodeidentifier:all-srcs",
|
"//pkg/auth/nodeidentifier:all-srcs",
|
||||||
"//pkg/capabilities:all-srcs",
|
"//pkg/capabilities:all-srcs",
|
||||||
"//pkg/client/chaosclient:all-srcs",
|
|
||||||
"//pkg/client/clientset_generated/internalclientset:all-srcs",
|
"//pkg/client/clientset_generated/internalclientset:all-srcs",
|
||||||
"//pkg/client/conditions:all-srcs",
|
"//pkg/client/conditions:all-srcs",
|
||||||
"//pkg/client/informers/informers_generated/internalversion:all-srcs",
|
"//pkg/client/informers/informers_generated/internalversion:all-srcs",
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
"go_test",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = ["chaosclient.go"],
|
|
||||||
importpath = "k8s.io/kubernetes/pkg/client/chaosclient",
|
|
||||||
deps = ["//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library"],
|
|
||||||
)
|
|
||||||
|
|
||||||
go_test(
|
|
||||||
name = "go_default_test",
|
|
||||||
srcs = ["chaosclient_test.go"],
|
|
||||||
embed = [":go_default_library"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [":package-srcs"],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
@ -1,6 +0,0 @@
|
|||||||
reviewers:
|
|
||||||
- smarterclayton
|
|
||||||
- liggitt
|
|
||||||
- davidopp
|
|
||||||
- eparis
|
|
||||||
- resouer
|
|
@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2015 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Package chaosclient makes it easy to simulate network latency, misbehaving
|
|
||||||
// servers, and random errors from servers. It is intended to stress test components
|
|
||||||
// under failure conditions and expose weaknesses in the error handling logic
|
|
||||||
// of the codebase.
|
|
||||||
package chaosclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// chaosrt provides the ability to perform simulations of HTTP client failures
|
|
||||||
// under the Golang http.Transport interface.
|
|
||||||
type chaosrt struct {
|
|
||||||
rt http.RoundTripper
|
|
||||||
notify ChaosNotifier
|
|
||||||
c []Chaos
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chaos intercepts requests to a remote HTTP endpoint and can inject arbitrary
|
|
||||||
// failures.
|
|
||||||
type Chaos interface {
|
|
||||||
// Intercept should return true if the normal flow should be skipped, and the
|
|
||||||
// return response and error used instead. Modifications to the request will
|
|
||||||
// be ignored, but may be used to make decisions about types of failures.
|
|
||||||
Intercept(req *http.Request) (bool, *http.Response, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChaosNotifier notifies another component that the ChaosRoundTripper has simulated
|
|
||||||
// a failure.
|
|
||||||
type ChaosNotifier interface {
|
|
||||||
// OnChaos is invoked when a chaotic outcome was triggered. fn is the
|
|
||||||
// source of Chaos and req was the outgoing request
|
|
||||||
OnChaos(req *http.Request, c Chaos)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChaosFunc takes an http.Request and decides whether to alter the response. It
|
|
||||||
// returns true if it wishes to mutate the response, with a http.Response or
|
|
||||||
// error.
|
|
||||||
type ChaosFunc func(req *http.Request) (bool, *http.Response, error)
|
|
||||||
|
|
||||||
// Intercept calls the nested method `Intercept`
|
|
||||||
func (fn ChaosFunc) Intercept(req *http.Request) (bool, *http.Response, error) {
|
|
||||||
return fn.Intercept(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fn ChaosFunc) String() string {
|
|
||||||
return runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewChaosRoundTripper creates an http.RoundTripper that will intercept requests
|
|
||||||
// based on the provided Chaos functions. The notifier is invoked when a Chaos
|
|
||||||
// Intercept is fired.
|
|
||||||
func NewChaosRoundTripper(rt http.RoundTripper, notify ChaosNotifier, c ...Chaos) http.RoundTripper {
|
|
||||||
return &chaosrt{rt, notify, c}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RoundTrip gives each ChaosFunc an opportunity to intercept the request. The first
|
|
||||||
// interceptor wins.
|
|
||||||
func (rt *chaosrt) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
||||||
for _, c := range rt.c {
|
|
||||||
if intercept, resp, err := c.Intercept(req); intercept {
|
|
||||||
rt.notify.OnChaos(req, c)
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rt.rt.RoundTrip(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = net.RoundTripperWrapper(&chaosrt{})
|
|
||||||
|
|
||||||
func (rt *chaosrt) WrappedRoundTripper() http.RoundTripper {
|
|
||||||
return rt.rt
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seed represents a consistent stream of chaos.
|
|
||||||
type Seed struct {
|
|
||||||
*rand.Rand
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSeed creates an object that assists in generating random chaotic events
|
|
||||||
// based on a deterministic seed.
|
|
||||||
func NewSeed(seed int64) Seed {
|
|
||||||
return Seed{rand.New(rand.NewSource(seed))}
|
|
||||||
}
|
|
||||||
|
|
||||||
type pIntercept struct {
|
|
||||||
Chaos
|
|
||||||
s Seed
|
|
||||||
p float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// P returns a ChaosFunc that fires with a probability of p (p between 0.0
|
|
||||||
// and 1.0 with 0.0 meaning never and 1.0 meaning always).
|
|
||||||
func (s Seed) P(p float64, c Chaos) Chaos {
|
|
||||||
return pIntercept{c, s, p}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intercept intercepts requests with the provided probability p.
|
|
||||||
func (c pIntercept) Intercept(req *http.Request) (bool, *http.Response, error) {
|
|
||||||
if c.s.Float64() < c.p {
|
|
||||||
return c.Chaos.Intercept(req)
|
|
||||||
}
|
|
||||||
return false, nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c pIntercept) String() string {
|
|
||||||
return fmt.Sprintf("P{%f %s}", c.p, c.Chaos)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrSimulatedConnectionResetByPeer emulates the golang net error when a connection
|
|
||||||
// is reset by a peer.
|
|
||||||
// TODO: make this more accurate
|
|
||||||
// TODO: add other error types
|
|
||||||
// TODO: add a helper for returning multiple errors randomly.
|
|
||||||
var ErrSimulatedConnectionResetByPeer = Error{errors.New("connection reset by peer")}
|
|
||||||
|
|
||||||
// Error returns the nested error when C() is invoked.
|
|
||||||
type Error struct {
|
|
||||||
error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intercept returns the nested error
|
|
||||||
func (e Error) Intercept(_ *http.Request) (bool, *http.Response, error) {
|
|
||||||
return true, nil, e.error
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogChaos is the default ChaosNotifier and writes a message to the Golang log.
|
|
||||||
var LogChaos = ChaosNotifier(logChaos{})
|
|
||||||
|
|
||||||
type logChaos struct{}
|
|
||||||
|
|
||||||
func (logChaos) OnChaos(req *http.Request, c Chaos) {
|
|
||||||
log.Printf("Triggered chaotic behavior for %s %s: %v", req.Method, req.URL.String(), c)
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2015 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package chaosclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TestLogChaos struct {
|
|
||||||
*testing.T
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TestLogChaos) OnChaos(req *http.Request, c Chaos) {
|
|
||||||
t.Logf("CHAOS: chaotic behavior for %s %s: %v", req.Method, req.URL.String(), c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func unwrapURLError(err error) error {
|
|
||||||
if urlErr, ok := err.(*url.Error); ok && urlErr != nil {
|
|
||||||
return urlErr.Err
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestChaos(t *testing.T) {
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
client := http.Client{
|
|
||||||
Transport: NewChaosRoundTripper(http.DefaultTransport, TestLogChaos{t}, ErrSimulatedConnectionResetByPeer),
|
|
||||||
}
|
|
||||||
resp, err := client.Get(server.URL)
|
|
||||||
if unwrapURLError(err) != ErrSimulatedConnectionResetByPeer.error {
|
|
||||||
t.Fatalf("expected reset by peer: %v", err)
|
|
||||||
}
|
|
||||||
if resp != nil {
|
|
||||||
t.Fatalf("expected no response object: %#v", resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPartialChaos(t *testing.T) {
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
seed := NewSeed(1)
|
|
||||||
client := http.Client{
|
|
||||||
Transport: NewChaosRoundTripper(
|
|
||||||
http.DefaultTransport, TestLogChaos{t},
|
|
||||||
seed.P(0.5, ErrSimulatedConnectionResetByPeer),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
success, fail := 0, 0
|
|
||||||
for {
|
|
||||||
_, err := client.Get(server.URL)
|
|
||||||
if err != nil {
|
|
||||||
fail++
|
|
||||||
} else {
|
|
||||||
success++
|
|
||||||
}
|
|
||||||
if success > 1 && fail > 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -574,7 +574,6 @@ k8s.io/kubernetes/pkg/apis/rbac/v1alpha1,liggitt,0,
|
|||||||
k8s.io/kubernetes/pkg/apis/rbac/validation,erictune,0,
|
k8s.io/kubernetes/pkg/apis/rbac/validation,erictune,0,
|
||||||
k8s.io/kubernetes/pkg/apis/storage/validation,caesarxuchao,1,
|
k8s.io/kubernetes/pkg/apis/storage/validation,caesarxuchao,1,
|
||||||
k8s.io/kubernetes/pkg/auth/authorizer/abac,liggitt,0,
|
k8s.io/kubernetes/pkg/auth/authorizer/abac,liggitt,0,
|
||||||
k8s.io/kubernetes/pkg/client/chaosclient,deads2k,1,
|
|
||||||
k8s.io/kubernetes/pkg/client/legacylisters,jsafrane,1,
|
k8s.io/kubernetes/pkg/client/legacylisters,jsafrane,1,
|
||||||
k8s.io/kubernetes/pkg/client/listers/batch/internalversion,mqliang,0,
|
k8s.io/kubernetes/pkg/client/listers/batch/internalversion,mqliang,0,
|
||||||
k8s.io/kubernetes/pkg/client/listers/extensions/internalversion,eparis,1,
|
k8s.io/kubernetes/pkg/client/listers/extensions/internalversion,eparis,1,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user