client

package
v1.24.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWebSocketHandshakeTimeout = 45 * time.Second
)

Variables

This section is empty.

Functions

func ConfigAsTransport

func ConfigAsTransport(options *Config) *http.Transport

func ConfigAuthAsProxy

func ConfigAuthAsProxy(options *Config) func(*http.Request) (*url.URL, error)

func NewBasicAuth

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

func NewHTTPSigner

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

func NewProxyTransport

func NewProxyTransport(server *url.URL, tp http.RoundTripper) http.RoundTripper

NewProxyTransport return a transport that handle requests like it happens in the agent pod.

func NewRestDecoder

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

func NewReverseProxy

func NewReverseProxy(addr *url.URL, tp http.RoundTripper) *httputil.ReverseProxy

NewReverseProxy return a reverse proxy that proxy requests to the agent.

func NewTokenAuth

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

func TLSClientConfig added in v1.24.1

func TLSClientConfig(ca []byte) *tls.Config

func TLSConfigFrom

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

Types

type Auth

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

func (*Auth) IsEmpty

func (auth *Auth) IsEmpty() bool

type Config

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

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 NewTypedClient

func NewTypedClient(addr *url.URL, tp http.RoundTripper, 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) 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) 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

type WebsocketClient struct {
	BaseAddr *url.URL
	Dialer   *websocket.Dialer
}

func NewWebsocketClient

func NewWebsocketClient(options *Config) *WebsocketClient

func (WebsocketClient) DialPath

func (c WebsocketClient) DialPath(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