util

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// WorkingModeCloud represents yurthub is working in cloud mode, which means yurthub is deployed on the cloud side.
	WorkingModeCloud WorkingMode = "cloud"
	// WorkingModeEdge represents yurthub is working in edge mode, which means yurthub is deployed on the edge side.
	WorkingModeEdge WorkingMode = "edge"

	// ProxyReqContentType represents request content type context key
	ProxyReqContentType ProxyKeyType = iota
	// ProxyRespContentType represents response content type context key
	ProxyRespContentType
	// ProxyClientComponent represents client component context key
	ProxyClientComponent
	// ProxyReqCanCache represents request can cache context key
	ProxyReqCanCache
	// ProxyListSelector represents label selector and filed selector string for list request
	ProxyListSelector
	// ProxyPoolScopedResource represents if this request is asking for pool-scoped resources
	ProxyPoolScopedResource
	// DefaultPoolCoordinatorEtcdSvcName represents default pool coordinator etcd service
	DefaultPoolCoordinatorEtcdSvcName = "pool-coordinator-etcd"
	// DefaultPoolCoordinatorAPIServerSvcName represents default pool coordinator apiServer service
	DefaultPoolCoordinatorAPIServerSvcName = "pool-coordinator-apiserver"
	// DefaultPoolCoordinatorEtcdSvcPort represents default pool coordinator etcd port
	DefaultPoolCoordinatorEtcdSvcPort = "2379"
	// DefaultPoolCoordinatorAPIServerSvcPort represents default pool coordinator apiServer port
	DefaultPoolCoordinatorAPIServerSvcPort = "443"

	YurtHubNamespace      = "kube-system"
	CacheUserAgentsKey    = "cache_agents"
	PoolScopeResourcesKey = "pool_scope_resources"

	YurtHubProxyPort       = 10261
	YurtHubPort            = 10267
	YurtHubProxySecurePort = 10268
)

Variables

View Source
var (
	DefaultCacheAgents   = []string{"kubelet", "kube-proxy", "flanneld", "coredns", projectinfo.GetAgentName(), projectinfo.GetHubName(), coordinatorconstants.DefaultPoolScopedUserAgent}
	YurthubConfigMapName = fmt.Sprintf("%s-hub-cfg", strings.TrimRightFunc(projectinfo.GetProjectPrefix(), func(c rune) bool { return c == '-' }))
)

Functions

func ClientComponentFrom

func ClientComponentFrom(ctx context.Context) (string, bool)

ClientComponentFrom returns the value of the client component key on the ctx

func FileExists

func FileExists(filename string) (bool, error)

FileExists checks if specified file exists.

func IfPoolScopedResourceFrom added in v1.2.0

func IfPoolScopedResourceFrom(ctx context.Context) (bool, bool)

IfPoolScopedResourceFrom returns the value of IfPoolScopedResource indicating whether this request is asking for pool-scoped resource.

func IsSupportedLBMode

func IsSupportedLBMode(lbMode string) bool

IsSupportedLBMode check lb mode is supported or not

func IsSupportedWorkingMode added in v0.5.0

func IsSupportedWorkingMode(workingMode WorkingMode) bool

IsSupportedWorkingMode check working mode is supported or not

func ListSelectorFrom

func ListSelectorFrom(ctx context.Context) (string, bool)

ListSelectorFrom returns the value of the list request selector string on the ctx

func NewDualReadCloser

func NewDualReadCloser(req *http.Request, rc io.ReadCloser, isRespBody bool) (io.ReadCloser, io.ReadCloser)

NewDualReadCloser create an dualReadCloser object

func NewGZipReaderCloser added in v0.7.0

func NewGZipReaderCloser(header http.Header, body io.ReadCloser, req *http.Request, caller string) (io.ReadCloser, bool)

func NewTripleReadCloser added in v1.2.0

func NewTripleReadCloser(req *http.Request, rc io.ReadCloser, isRespBody bool) (io.ReadCloser, io.ReadCloser, io.ReadCloser)

func ParseBearerToken added in v0.7.0

func ParseBearerToken(token string) string

func ParseTenantNs added in v0.7.0

func ParseTenantNs(certOrg string) string

func ParseTenantNsFromOrgs added in v0.7.0

func ParseTenantNsFromOrgs(orgs []string) string

func ReqCanCacheFrom

func ReqCanCacheFrom(ctx context.Context) (bool, bool)

ReqCanCacheFrom returns the value of the request can cache key on the ctx

func ReqContentTypeFrom

func ReqContentTypeFrom(ctx context.Context) (string, bool)

ReqContentTypeFrom returns the value of the request content type key on the ctx

func ReqInfoString

func ReqInfoString(info *apirequest.RequestInfo) string

ReqInfoString formats a string for request info

func ReqString

func ReqString(req *http.Request) string

ReqString formats a string for request

func RespContentTypeFrom

func RespContentTypeFrom(ctx context.Context) (string, bool)

RespContentTypeFrom returns the value of the response content type key on the ctx

func SplitKey

func SplitKey(key string) (comp, resource, ns, name string)

SplitKey split key into comp, resource, ns, name

func WithClientComponent

func WithClientComponent(parent context.Context, component string) context.Context

WithClientComponent returns a copy of parent in which the client component value is set

func WithIfPoolScopedResource added in v1.2.0

func WithIfPoolScopedResource(parent context.Context, ifPoolScoped bool) context.Context

WithIfPoolScopedResource returns a copy of parent in which IfPoolScopedResource is set, indicating whether this request is asking for pool-scoped resources.

func WithListSelector

func WithListSelector(parent context.Context, selector string) context.Context

WithListSelector returns a copy of parent in which the list request selector string is set

func WithReqCanCache

func WithReqCanCache(parent context.Context, canCache bool) context.Context

WithReqCanCache returns a copy of parent in which the request can cache value is set

func WithReqContentType

func WithReqContentType(parent context.Context, contentType string) context.Context

WithReqContentType returns a copy of parent in which the response content type value is set

func WithRespContentType

func WithRespContentType(parent context.Context, contentType string) context.Context

WithRespContentType returns a copy of parent in which the request content type value is set

func WithValue

func WithValue(parent context.Context, key interface{}, val interface{}) context.Context

WithValue returns a copy of parent in which the value associated with key is val.

func WriteObject

func WriteObject(statusCode int, obj runtime.Object, w http.ResponseWriter, req *http.Request) error

WriteObject write object to response writer

Types

type DialFunc

type DialFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialFunc is a shorthand for signature of net.DialContext.

type Dialer

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

Dialer opens connections through Dial and tracks them.

func NewDialer

func NewDialer(name string) *Dialer

NewDialer creates a new Dialer instance.

If dial is not nil, it will be used to create new underlying connections. Otherwise, net.DialContext is used.

func (*Dialer) Close

func (d *Dialer) Close(address string)

Close forcibly closes all tracked connections that specified by address.

Note: new connections may get created before Close returns.

func (*Dialer) CloseAll

func (d *Dialer) CloseAll()

CloseAll forcibly closes all tracked connections.

Note: new connections may get created before CloseAll returns.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial creates a new tracked connection.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext creates a new tracked connection.

func (*Dialer) Name

func (d *Dialer) Name() string

Name returns the name of dialer

type ProxyKeyType

type ProxyKeyType int

ProxyKeyType represents the key in proxy request context

type WorkingMode added in v0.5.0

type WorkingMode string

WorkingMode represents the working mode of yurthub.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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