agents

package
v1.23.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentModeApiServer = "apiServerProxy"
	AgentModeAHTTP     = "http"
	AgentModeHTTPS     = "https"
)
View Source
const (
	DefaultWebSocketHandshakeTimeout = 45 * time.Second
)

Variables

This section is empty.

Functions

func ApiServerProxyPath

func ApiServerProxyPath(namespace, schema, svcname, port string) string

func HeadersFrom

func HeadersFrom(kvs map[string]string) http.Header

func NewBasicAuth added in v1.23.8

func NewBasicAuth(username, password string) func(req *http.Request) error

func NewHTTPSigner added in v1.23.8

func NewHTTPSigner(basepath string) func(req *http.Request) error

func NewRestDecoder

func NewRestDecoder(r io.ReadCloser, newitemfunc func() client.Object) *restDecoder

func NewTokenAuth added in v1.23.8

func NewTokenAuth(token string) func(req *http.Request) error

func OptionAuthAsProxy added in v1.23.8

func OptionAuthAsProxy(options *ClientOptions) func(*http.Request) (*url.URL, error)

func QueryFrom

func QueryFrom(kvs map[string]string) url.Values

func ResponseBodyRewriter

func ResponseBodyRewriter(rewritefunc func(io.Reader, io.Writer) error) func(resp *http.Response) error

ResponseBodyRewriter 会正确处理 gzip 以及 deflate 的content-encodeing 以及response 的content-length 用于需要修改代理的响应体是非常有用

func RoundTripOf added in v1.23.8

func RoundTripOf(cli Client) http.RoundTripper

RoundTripOf

func TLSConfigFrom added in v1.23.8

func TLSConfigFrom(ca, cert, key []byte) (*tls.Config, error)

func WrappedResponse

func WrappedResponse(intodata interface{}) *response.Response

Types

type Auth added in v1.23.8

type Auth struct {
	EnableHttpSign *bool
	Token          string
	Username       string
	Password       string
}

func (*Auth) IsEmpty added in v1.23.8

func (auth *Auth) IsEmpty() bool

type Client

type Client interface {
	client.WithWatch
	DoRequest(ctx context.Context, req Request) error
	DoRawRequest(ctx context.Context, clientreq Request) (*http.Response, error)
	DialWebsocket(ctx context.Context, path string, headers http.Header) (*websocket.Conn, *http.Response, error)
	Extend() *ExtendClient
	Name() string
	BaseAddr() url.URL
	APIServerAddr() url.URL
	APIServerVersion() string
	// Deprecated: remove
	Proxy(ctx context.Context, obj client.Object, port int, req *http.Request, writer http.ResponseWriter, rewritefunc func(r *http.Response) error) error
}

func NewDelegateClientClient added in v1.23.8

func NewDelegateClientClient(options *ClientOptions, name string, apiserver *url.URL, discovery discovery.DiscoveryInterface, tracer trace.Tracer) Client

type ClientOptions added in v1.23.8

type ClientOptions struct {
	Addr *url.URL
	TLS  *tls.Config
	Auth Auth
}

type ClientSet

type ClientSet struct {
	// contains filtered or unexported fields
}

func NewClientSet

func NewClientSet(database *database.Database) (*ClientSet, error)

func (*ClientSet) ClientOf

func (h *ClientSet) ClientOf(ctx context.Context, name string) (Client, error)

func (*ClientSet) ClientOfManager added in v1.22.0

func (h *ClientSet) ClientOfManager(ctx context.Context) (Client, error)

func (*ClientSet) ClientOptionsFrom added in v1.23.8

func (h *ClientSet) ClientOptionsFrom(ctx context.Context, name string) (*ClientOptions, *rest.Config, error)

func (*ClientSet) Clusters

func (h *ClientSet) Clusters() []string

func (ClientSet) ExecuteInEachCluster

func (h ClientSet) ExecuteInEachCluster(ctx context.Context, f func(ctx context.Context, cli Client) error) error

ExecuteInEachCluster Execute in each cluster concurrently

func (*ClientSet) Initialize

func (h *ClientSet) Initialize(db *gorm.DB) error

Initialize for gorm plugin

func (*ClientSet) Invalidate added in v1.22.0

func (h *ClientSet) Invalidate(ctx context.Context, name string)

Invalidate a client of name cluster and recreate after.

func (*ClientSet) Name

func (h *ClientSet) Name() string

Name for gorm plugin

type DelegateClient

type DelegateClient struct {
	*TypedClient
	*ExtendClient
	*WebsocketClient
	// contains filtered or unexported fields
}

func (*DelegateClient) APIServerAddr

func (c *DelegateClient) APIServerAddr() url.URL

func (*DelegateClient) APIServerVersion

func (c *DelegateClient) APIServerVersion() string

func (*DelegateClient) BaseAddr

func (c *DelegateClient) BaseAddr() url.URL

func (*DelegateClient) Extend

func (c *DelegateClient) Extend() *ExtendClient

func (*DelegateClient) Name

func (c *DelegateClient) Name() string

type ExtendClient

type ExtendClient struct {
	Inner *TypedClient
}

func NewExtendClientFrom added in v1.23.8

func NewExtendClientFrom(from *TypedClient) *ExtendClient

func (*ExtendClient) CheckAlertmanagerConfig

func (c *ExtendClient) CheckAlertmanagerConfig(ctx context.Context, data *monitoringv1alpha1.AlertmanagerConfig) error

func (*ExtendClient) ClusterResourceStatistics

func (c *ExtendClient) ClusterResourceStatistics(ctx context.Context, ret interface{}) error

func (*ExtendClient) ClusterStatistics added in v1.23.0

func (c *ExtendClient) ClusterStatistics(ctx context.Context, ret interface{}) error

func (*ExtendClient) ClusterWorkloadStatistics

func (c *ExtendClient) ClusterWorkloadStatistics(ctx context.Context, ret interface{}) error

statistics.system/v1

func (*ExtendClient) GetLokiAlertRules

func (c *ExtendClient) GetLokiAlertRules(ctx context.Context) (map[string]prometheus.RealTimeAlertRule, error)

func (*ExtendClient) GetPromeAlertRules

func (c *ExtendClient) GetPromeAlertRules(ctx context.Context, name string) (map[string]prometheus.RealTimeAlertRule, error)

func (*ExtendClient) GetPrometheusLabelNames

func (c *ExtendClient) GetPrometheusLabelNames(ctx context.Context, matchs []string, start, end string) ([]string, error)

func (*ExtendClient) GetPrometheusLabelValues

func (c *ExtendClient) GetPrometheusLabelValues(ctx context.Context, matchs []string, label, start, end string) ([]string, error)

func (*ExtendClient) Healthy

func (c *ExtendClient) Healthy(ctx context.Context) error

health.system/v1

func (*ExtendClient) LokiQuery

func (c *ExtendClient) LokiQuery(ctx context.Context, logql string) (loki.QueryResponseData, error)

func (*ExtendClient) PrometheusQueryRange

func (c *ExtendClient) PrometheusQueryRange(ctx context.Context, query, start, end, step string) (prommodel.Matrix, error)

func (*ExtendClient) PrometheusTargets added in v1.22.0

func (c *ExtendClient) PrometheusTargets(ctx context.Context) (*promv1.TargetsResult, error)

func (*ExtendClient) PrometheusVector

func (c *ExtendClient) PrometheusVector(ctx context.Context, query string) (prommodel.Vector, error)

type Request

type Request struct {
	Method  string
	Path    string // queries 可以放在 path 中
	Query   url.Values
	Headers http.Header
	Body    interface{}
	Into    interface{}
}

type RoundTripperFunc added in v1.23.8

type RoundTripperFunc func(req *http.Request) (*http.Response, error)

func (RoundTripperFunc) RoundTrip added in v1.23.8

func (c RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

type StatusTypedClient

type StatusTypedClient struct {
	// contains filtered or unexported fields
}

func (*StatusTypedClient) Patch

func (c *StatusTypedClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

func (*StatusTypedClient) Update

func (c *StatusTypedClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

type TypedClient

type TypedClient struct {
	BaseAddr      *url.URL
	RuntimeScheme *runtime.Scheme
	HTTPClient    *http.Client
	// contains filtered or unexported fields
}

func NewSimpleTypedClient added in v1.23.0

func NewSimpleTypedClient(baseaddr string) (*TypedClient, error)

func NewTypedClient added in v1.23.8

func NewTypedClient(options *ClientOptions, scheme *runtime.Scheme) *TypedClient

func (TypedClient) Create

func (c TypedClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create saves the object obj in the Kubernetes cluster.

func (TypedClient) Delete

func (c TypedClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete deletes the given obj from Kubernetes cluster.

func (TypedClient) DeleteAllOf

func (c TypedClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf deletes all objects of the given type matching the given options.

func (TypedClient) DoRawRequest

func (c TypedClient) DoRawRequest(ctx context.Context, clientreq Request) (*http.Response, error)

func (TypedClient) DoRequest

func (c TypedClient) DoRequest(ctx context.Context, req Request) error

func (TypedClient) Get

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

func (TypedClient) List

func (c TypedClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

func (TypedClient) Patch

func (c TypedClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (TypedClient) Proxy

func (c TypedClient) Proxy(ctx context.Context, obj client.Object, port int, req *http.Request, writer http.ResponseWriter, rewritefunc func(r *http.Response) error) error

func (TypedClient) RESTMapper

func (c TypedClient) RESTMapper() meta.RESTMapper

func (TypedClient) Scheme

func (c TypedClient) Scheme() *runtime.Scheme

func (TypedClient) Status

func (c TypedClient) Status() client.StatusWriter

func (TypedClient) Update

func (c TypedClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (TypedClient) Watch

不知道如何正确使用 watch.Interface,参考k8s源码:

https://github.com/kubernetes/kubernetes/blob/release-1.20/pkg/volume/csi/csi_attacher.go#L444-L487

或者:

watcher, err := cli.Watch(ctx, objctList)
if err != nil {
	return fmt.Errorf("watch error:%v", err)
}
defer watcher.Stop()

for {
	select {
	case event, ok := <-watcher.ResultChan():
		if !ok {
			log.Warningf("watch channel had been closed")
			break
		}

		switch event.Type {
		case watch.Added, watch.Modified:
			...
		case watch.Deleted:
			...
		case watch.Error:
			log.Warningf("received watch error: %v", event)
		}

	case <-ctx.Done():
		log.Warningf("watch channel closed")
		break
	}
}

type WebsocketClient added in v1.23.8

type WebsocketClient struct {
	// contains filtered or unexported fields
}

func NewWebsocketClient added in v1.23.8

func NewWebsocketClient(options *ClientOptions) *WebsocketClient

func (WebsocketClient) DialWebsocket added in v1.23.8

func (c WebsocketClient) DialWebsocket(ctx context.Context, rpath string, headers http.Header) (*websocket.Conn, *http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL