code
stringlengths
12
335k
docstring
stringlengths
20
20.8k
func_name
stringlengths
1
105
language
stringclasses
1 value
repo
stringclasses
498 values
path
stringlengths
5
172
url
stringlengths
43
235
license
stringclasses
4 values
func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTripper, error) { cfg, err := config.TransportConfig() if err != nil { return nil, err } return transport.HTTPWrappersForConfig(cfg, rt) }
HTTPWrappersForConfig wraps a round tripper with any relevant layered behavior from the config. Exposed to allow more clients that need HTTP-like behavior but then must hijack the underlying connection (like WebSocket or HTTP2 clients). Pure HTTP clients should use the higher level TransportFor or RESTClientFor methods.
HTTPWrappersForConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/transport.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/transport.go
Apache-2.0
func (c *Config) TransportConfig() (*transport.Config, error) { conf := &transport.Config{ UserAgent: c.UserAgent, Transport: c.Transport, WrapTransport: c.WrapTransport, DisableCompression: c.DisableCompression, TLS: transport.TLSConfig{ Insecure: c.Insecure, ServerName: c.ServerName, CAFile: c.CAFile, CAData: c.CAData, CertFile: c.CertFile, CertData: c.CertData, KeyFile: c.KeyFile, KeyData: c.KeyData, NextProtos: c.NextProtos, }, Username: c.Username, Password: c.Password, BearerToken: c.BearerToken, BearerTokenFile: c.BearerTokenFile, Impersonate: transport.ImpersonationConfig{ UserName: c.Impersonate.UserName, UID: c.Impersonate.UID, Groups: c.Impersonate.Groups, Extra: c.Impersonate.Extra, }, Proxy: c.Proxy, } if c.Dial != nil { conf.DialHolder = &transport.DialHolder{Dial: c.Dial} } if c.ExecProvider != nil && c.AuthProvider != nil { return nil, errors.New("execProvider and authProvider cannot be used in combination") } if c.ExecProvider != nil { var cluster *clientauthentication.Cluster if c.ExecProvider.ProvideClusterInfo { var err error cluster, err = ConfigToExecCluster(c) if err != nil { return nil, err } } provider, err := exec.GetAuthenticator(c.ExecProvider, cluster) if err != nil { return nil, err } if err := provider.UpdateTransportConfig(conf); err != nil { return nil, err } } if c.AuthProvider != nil { provider, err := GetAuthProvider(c.Host, c.AuthProvider, c.AuthConfigPersister) if err != nil { return nil, err } conf.Wrap(provider.WrapTransport) } return conf, nil }
TransportConfig converts a client config to an appropriate transport config.
TransportConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/transport.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/transport.go
Apache-2.0
func (c *Config) Wrap(fn transport.WrapperFunc) { c.WrapTransport = transport.Wrappers(c.WrapTransport, fn) }
Wrap adds a transport middleware function that will give the caller an opportunity to wrap the underlying http.RoundTripper prior to the first API call being made. The provided function is invoked after any existing transport wrappers are invoked.
Wrap
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/transport.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/transport.go
Apache-2.0
func checkWait(resp *http.Response) (int, bool) { switch r := resp.StatusCode; { // any 500 error code and 429 can trigger a wait case r == http.StatusTooManyRequests, r >= 500: default: return 0, false } i, ok := retryAfterSeconds(resp) return i, ok }
checkWait returns true along with a number of seconds if the server instructed us to wait before retrying.
checkWait
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/with_retry.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/with_retry.go
Apache-2.0
func (in *TLSClientConfig) DeepCopyInto(out *TLSClientConfig) { *out = *in if in.CertData != nil { in, out := &in.CertData, &out.CertData *out = make([]byte, len(*in)) copy(*out, *in) } if in.KeyData != nil { in, out := &in.KeyData, &out.KeyData *out = make([]byte, len(*in)) copy(*out, *in) } if in.CAData != nil { in, out := &in.CAData, &out.CAData *out = make([]byte, len(*in)) copy(*out, *in) } if in.NextProtos != nil { in, out := &in.NextProtos, &out.NextProtos *out = make([]string, len(*in)) copy(*out, *in) } return }
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
DeepCopyInto
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/zz_generated.deepcopy.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/zz_generated.deepcopy.go
Apache-2.0
func (in *TLSClientConfig) DeepCopy() *TLSClientConfig { if in == nil { return nil } out := new(TLSClientConfig) in.DeepCopyInto(out) return out }
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TLSClientConfig.
DeepCopy
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/zz_generated.deepcopy.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/zz_generated.deepcopy.go
Apache-2.0
func (c *Config) GoString() string { return c.String() }
GoString implements fmt.GoStringer and sanitizes sensitive fields of Config to prevent accidental leaking via logs.
GoString
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func (c *Config) String() string { if c == nil { return "<nil>" } cc := sanitizedConfig(CopyConfig(c)) // Explicitly mark non-empty credential fields as redacted. if cc.Password != "" { cc.Password = "--- REDACTED ---" } if cc.BearerToken != "" { cc.BearerToken = "--- REDACTED ---" } if cc.AuthConfigPersister != nil { cc.AuthConfigPersister = sanitizedAuthConfigPersister{cc.AuthConfigPersister} } if cc.ExecProvider != nil && cc.ExecProvider.Config != nil { cc.ExecProvider.Config = sanitizedObject{Object: cc.ExecProvider.Config} } return fmt.Sprintf("%#v", cc) }
String implements fmt.Stringer and sanitizes sensitive fields of Config to prevent accidental leaking via logs.
String
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func (c TLSClientConfig) GoString() string { return c.String() }
GoString implements fmt.GoStringer and sanitizes sensitive fields of TLSClientConfig to prevent accidental leaking via logs.
GoString
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func (c TLSClientConfig) String() string { cc := sanitizedTLSClientConfig{ Insecure: c.Insecure, ServerName: c.ServerName, CertFile: c.CertFile, KeyFile: c.KeyFile, CAFile: c.CAFile, CertData: c.CertData, KeyData: c.KeyData, CAData: c.CAData, NextProtos: c.NextProtos, } // Explicitly mark non-empty credential fields as redacted. if len(cc.CertData) != 0 { cc.CertData = []byte("--- TRUNCATED ---") } if len(cc.KeyData) != 0 { cc.KeyData = []byte("--- REDACTED ---") } return fmt.Sprintf("%#v", cc) }
String implements fmt.Stringer and sanitizes sensitive fields of TLSClientConfig to prevent accidental leaking via logs.
String
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func RESTClientFor(config *Config) (*RESTClient, error) { if config.GroupVersion == nil { return nil, fmt.Errorf("GroupVersion is required when initializing a RESTClient") } if config.NegotiatedSerializer == nil { return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient") } // Validate config.Host before constructing the transport/client so we can fail fast. // ServerURL will be obtained later in RESTClientForConfigAndClient() _, _, err := DefaultServerUrlFor(config) if err != nil { return nil, err } httpClient, err := HTTPClientFor(config) if err != nil { return nil, err } return RESTClientForConfigAndClient(config, httpClient) }
RESTClientFor returns a RESTClient that satisfies the requested attributes on a client Config object. Note that a RESTClient may require fields that are optional when initializing a Client. A RESTClient created by this method is generic - it expects to operate on an API that follows the Kubernetes conventions, but may not be the Kubernetes API. RESTClientFor is equivalent to calling RESTClientForConfigAndClient(config, httpClient), where httpClient was generated with HTTPClientFor(config).
RESTClientFor
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func RESTClientForConfigAndClient(config *Config, httpClient *http.Client) (*RESTClient, error) { if config.GroupVersion == nil { return nil, fmt.Errorf("GroupVersion is required when initializing a RESTClient") } if config.NegotiatedSerializer == nil { return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient") } baseURL, versionedAPIPath, err := DefaultServerUrlFor(config) if err != nil { return nil, err } rateLimiter := config.RateLimiter if rateLimiter == nil { qps := config.QPS if config.QPS == 0.0 { qps = DefaultQPS } burst := config.Burst if config.Burst == 0 { burst = DefaultBurst } if qps > 0 { rateLimiter = flowcontrol.NewTokenBucketRateLimiter(qps, burst) } } var gv schema.GroupVersion if config.GroupVersion != nil { gv = *config.GroupVersion } clientContent := ClientContentConfig{ AcceptContentTypes: config.AcceptContentTypes, ContentType: config.ContentType, GroupVersion: gv, Negotiator: runtime.NewClientNegotiator(config.NegotiatedSerializer, gv), } restClient, err := NewRESTClient(baseURL, versionedAPIPath, clientContent, rateLimiter, httpClient) if err == nil && config.WarningHandler != nil { restClient.warningHandler = config.WarningHandler } return restClient, err }
RESTClientForConfigAndClient returns a RESTClient that satisfies the requested attributes on a client Config object. Unlike RESTClientFor, RESTClientForConfigAndClient allows to pass an http.Client that is shared between all the API Groups and Versions. Note that the http client takes precedence over the transport values configured. The http client defaults to the `http.DefaultClient` if nil.
RESTClientForConfigAndClient
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func UnversionedRESTClientFor(config *Config) (*RESTClient, error) { if config.NegotiatedSerializer == nil { return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient") } // Validate config.Host before constructing the transport/client so we can fail fast. // ServerURL will be obtained later in UnversionedRESTClientForConfigAndClient() _, _, err := DefaultServerUrlFor(config) if err != nil { return nil, err } httpClient, err := HTTPClientFor(config) if err != nil { return nil, err } return UnversionedRESTClientForConfigAndClient(config, httpClient) }
UnversionedRESTClientFor is the same as RESTClientFor, except that it allows the config.Version to be empty.
UnversionedRESTClientFor
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func UnversionedRESTClientForConfigAndClient(config *Config, httpClient *http.Client) (*RESTClient, error) { if config.NegotiatedSerializer == nil { return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient") } baseURL, versionedAPIPath, err := DefaultServerUrlFor(config) if err != nil { return nil, err } rateLimiter := config.RateLimiter if rateLimiter == nil { qps := config.QPS if config.QPS == 0.0 { qps = DefaultQPS } burst := config.Burst if config.Burst == 0 { burst = DefaultBurst } if qps > 0 { rateLimiter = flowcontrol.NewTokenBucketRateLimiter(qps, burst) } } gv := metav1.SchemeGroupVersion if config.GroupVersion != nil { gv = *config.GroupVersion } clientContent := ClientContentConfig{ AcceptContentTypes: config.AcceptContentTypes, ContentType: config.ContentType, GroupVersion: gv, Negotiator: runtime.NewClientNegotiator(config.NegotiatedSerializer, gv), } restClient, err := NewRESTClient(baseURL, versionedAPIPath, clientContent, rateLimiter, httpClient) if err == nil && config.WarningHandler != nil { restClient.warningHandler = config.WarningHandler } return restClient, err }
UnversionedRESTClientForConfigAndClient is the same as RESTClientForConfigAndClient, except that it allows the config.Version to be empty.
UnversionedRESTClientForConfigAndClient
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func SetKubernetesDefaults(config *Config) error { if len(config.UserAgent) == 0 { config.UserAgent = DefaultKubernetesUserAgent() } return nil }
SetKubernetesDefaults sets default values on the provided client config for accessing the Kubernetes API or returns an error if any of the defaults are impossible or invalid.
SetKubernetesDefaults
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func adjustCommit(c string) string { if len(c) == 0 { return "unknown" } if len(c) > 7 { return c[:7] } return c }
adjustCommit returns sufficient significant figures of the commit's git hash.
adjustCommit
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func adjustVersion(v string) string { if len(v) == 0 { return "unknown" } seg := strings.SplitN(v, "-", 2) return seg[0] }
adjustVersion strips "alpha", "beta", etc. from version in form major.minor.patch-[alpha|beta|etc].
adjustVersion
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func adjustCommand(p string) string { // Unlikely, but better than returning "". if len(p) == 0 { return "unknown" } return filepath.Base(p) }
adjustCommand returns the last component of the OS-specific command path for use in User-Agent.
adjustCommand
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func buildUserAgent(command, version, os, arch, commit string) string { return fmt.Sprintf( "%s/%s (%s/%s) kubernetes/%s", command, version, os, arch, commit) }
buildUserAgent builds a User-Agent string from given args.
buildUserAgent
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func DefaultKubernetesUserAgent() string { return buildUserAgent( adjustCommand(os.Args[0]), adjustVersion(version.Get().GitVersion), gruntime.GOOS, gruntime.GOARCH, adjustCommit(version.Get().GitCommit)) }
DefaultKubernetesUserAgent returns a User-Agent string built from static global vars.
DefaultKubernetesUserAgent
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func InClusterConfig() (*Config, error) { const ( tokenFile = "/var/run/secrets/kubernetes.io/serviceaccount/token" rootCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ) host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT") if len(host) == 0 || len(port) == 0 { return nil, ErrNotInCluster } token, err := os.ReadFile(tokenFile) if err != nil { return nil, err } tlsClientConfig := TLSClientConfig{} if _, err := certutil.NewPool(rootCAFile); err != nil { klog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err) } else { tlsClientConfig.CAFile = rootCAFile } return &Config{ // TODO: switch to using cluster DNS. Host: "https://" + net.JoinHostPort(host, port), TLSClientConfig: tlsClientConfig, BearerToken: string(token), BearerTokenFile: tokenFile, }, nil }
InClusterConfig returns a config object which uses the service account kubernetes gives to pods. It's intended for clients that expect to be running inside a pod running on kubernetes. It will return ErrNotInCluster if called from a process not running in a kubernetes environment.
InClusterConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func IsConfigTransportTLS(config Config) bool { baseURL, _, err := DefaultServerUrlFor(&config) if err != nil { return false } return baseURL.Scheme == "https" }
IsConfigTransportTLS returns true if and only if the provided config will result in a protected connection to the server when it is passed to restclient.RESTClientFor(). Use to determine when to send credentials over the wire. Note: the Insecure flag is ignored when testing for this value, so MITM attacks are still possible.
IsConfigTransportTLS
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func LoadTLSFiles(c *Config) error { var err error c.CAData, err = dataFromSliceOrFile(c.CAData, c.CAFile) if err != nil { return err } c.CertData, err = dataFromSliceOrFile(c.CertData, c.CertFile) if err != nil { return err } c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile) return err }
LoadTLSFiles copies the data from the CertFile, KeyFile, and CAFile fields into the CertData, KeyData, and CAFile fields, or returns an error. If no error is returned, all three fields are either populated or were empty to start.
LoadTLSFiles
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func dataFromSliceOrFile(data []byte, file string) ([]byte, error) { if len(data) > 0 { return data, nil } if len(file) > 0 { fileData, err := os.ReadFile(file) if err != nil { return []byte{}, err } return fileData, nil } return nil, nil }
dataFromSliceOrFile returns data from the slice (if non-empty), or from the file, or an error if an error occurred reading the file
dataFromSliceOrFile
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func AnonymousClientConfig(config *Config) *Config { // copy only known safe fields return &Config{ Host: config.Host, APIPath: config.APIPath, ContentConfig: config.ContentConfig, TLSClientConfig: TLSClientConfig{ Insecure: config.Insecure, ServerName: config.ServerName, CAFile: config.TLSClientConfig.CAFile, CAData: config.TLSClientConfig.CAData, NextProtos: config.TLSClientConfig.NextProtos, }, RateLimiter: config.RateLimiter, WarningHandler: config.WarningHandler, UserAgent: config.UserAgent, DisableCompression: config.DisableCompression, QPS: config.QPS, Burst: config.Burst, Timeout: config.Timeout, Dial: config.Dial, Proxy: config.Proxy, } }
AnonymousClientConfig returns a copy of the given config with all user credentials (cert/key, bearer token, and username/password) and custom transports (WrapTransport, Transport) removed
AnonymousClientConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func CopyConfig(config *Config) *Config { c := &Config{ Host: config.Host, APIPath: config.APIPath, ContentConfig: config.ContentConfig, Username: config.Username, Password: config.Password, BearerToken: config.BearerToken, BearerTokenFile: config.BearerTokenFile, Impersonate: ImpersonationConfig{ UserName: config.Impersonate.UserName, UID: config.Impersonate.UID, Groups: config.Impersonate.Groups, Extra: config.Impersonate.Extra, }, AuthProvider: config.AuthProvider, AuthConfigPersister: config.AuthConfigPersister, ExecProvider: config.ExecProvider, TLSClientConfig: TLSClientConfig{ Insecure: config.TLSClientConfig.Insecure, ServerName: config.TLSClientConfig.ServerName, CertFile: config.TLSClientConfig.CertFile, KeyFile: config.TLSClientConfig.KeyFile, CAFile: config.TLSClientConfig.CAFile, CertData: config.TLSClientConfig.CertData, KeyData: config.TLSClientConfig.KeyData, CAData: config.TLSClientConfig.CAData, NextProtos: config.TLSClientConfig.NextProtos, }, UserAgent: config.UserAgent, DisableCompression: config.DisableCompression, Transport: config.Transport, WrapTransport: config.WrapTransport, QPS: config.QPS, Burst: config.Burst, RateLimiter: config.RateLimiter, WarningHandler: config.WarningHandler, Timeout: config.Timeout, Dial: config.Dial, Proxy: config.Proxy, } if config.ExecProvider != nil && config.ExecProvider.Config != nil { c.ExecProvider.Config = config.ExecProvider.Config.DeepCopyObject() } return c }
CopyConfig returns a copy of the given config
CopyConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/config.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/config.go
Apache-2.0
func CreateHTTPClient(roundTripper func(*http.Request) (*http.Response, error)) *http.Client { return &http.Client{ Transport: roundTripperFunc(roundTripper), } }
CreateHTTPClient creates an http.Client that will invoke the provided roundTripper func when a request is made.
CreateHTTPClient
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/fake/fake.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/fake/fake.go
Apache-2.0
func (c *RESTClient) do(req *http.Request) (*http.Response, error) { if c.Err != nil { return nil, c.Err } c.Req = req if c.Client != nil { return c.Client.Do(req) } return c.Resp, nil }
do is invoked when a Request() created by this client is executed.
do
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/fake/fake.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/fake/fake.go
Apache-2.0
func NewDecoder(decoder streaming.Decoder, embeddedDecoder runtime.Decoder) *Decoder { return &Decoder{ decoder: decoder, embeddedDecoder: embeddedDecoder, } }
NewDecoder creates an Decoder for the given writer and codec.
NewDecoder
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/watch/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/watch/decoder.go
Apache-2.0
func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) { var got metav1.WatchEvent res, _, err := d.decoder.Decode(nil, &got) if err != nil { return "", nil, err } if res != &got { return "", nil, fmt.Errorf("unable to decode to metav1.Event") } switch got.Type { case string(watch.Added), string(watch.Modified), string(watch.Deleted), string(watch.Error), string(watch.Bookmark): default: return "", nil, fmt.Errorf("got invalid watch event type: %v", got.Type) } obj, err := runtime.Decode(d.embeddedDecoder, got.Object.Raw) if err != nil { return "", nil, fmt.Errorf("unable to decode watch event: %v", err) } return watch.EventType(got.Type), obj, nil }
Decode blocks until it can return the next object in the reader. Returns an error if the reader is closed or an object can't be decoded.
Decode
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/watch/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/watch/decoder.go
Apache-2.0
func (d *Decoder) Close() { d.decoder.Close() }
Close closes the underlying r.
Close
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/watch/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/watch/decoder.go
Apache-2.0
func (e *Encoder) Encode(event *watch.Event) error { data, err := runtime.Encode(e.embeddedEncoder, event.Object) if err != nil { return err } // FIXME: get rid of json.RawMessage. return e.encoder.Encode(&metav1.WatchEvent{ Type: string(event.Type), Object: runtime.RawExtension{Raw: json.RawMessage(data)}, }) }
Encode writes an event to the writer. Returns an error if the writer is closed or an object can't be encoded.
Encode
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/rest/watch/encoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/rest/watch/encoder.go
Apache-2.0
func LoadFromFile(path string) (*Info, error) { var info Info if _, err := os.Stat(path); os.IsNotExist(err) { return nil, err } data, err := os.ReadFile(path) if err != nil { return nil, err } err = json.Unmarshal(data, &info) if err != nil { return nil, err } return &info, err }
LoadFromFile parses an Info object from a file path. If the file does not exist, then os.IsNotExist(err) == true
LoadFromFile
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/auth/clientauth.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/auth/clientauth.go
Apache-2.0
func (info Info) MergeWithConfig(c restclient.Config) (restclient.Config, error) { var config = c config.Username = info.User config.Password = info.Password config.CAFile = info.CAFile config.CertFile = info.CertFile config.KeyFile = info.KeyFile config.BearerToken = info.BearerToken if info.Insecure != nil { config.Insecure = *info.Insecure } return config, nil }
MergeWithConfig returns a copy of a client.Config with values from the Info. The fields of client.Config with a corresponding field in the Info are set with the value from the Info.
MergeWithConfig
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/auth/clientauth.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/auth/clientauth.go
Apache-2.0
func (info Info) Complete() bool { return len(info.User) > 0 || len(info.CertFile) > 0 || len(info.BearerToken) > 0 }
Complete returns true if the Kubernetes API authorization info is complete.
Complete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/auth/clientauth.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/auth/clientauth.go
Apache-2.0
func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*v1.ObjectReference, error) { if obj == nil { return nil, ErrNilObject } if ref, ok := obj.(*v1.ObjectReference); ok { // Don't make a reference to a reference. return ref, nil } // An object that implements only List has enough metadata to build a reference var listMeta metav1.Common objectMeta, err := meta.Accessor(obj) if err != nil { listMeta, err = meta.CommonAccessor(obj) if err != nil { return nil, err } } else { listMeta = objectMeta } gvk := obj.GetObjectKind().GroupVersionKind() // If object meta doesn't contain data about kind and/or version, // we are falling back to scheme. // // TODO: This doesn't work for CRDs, which are not registered in scheme. if gvk.Empty() { gvks, _, err := scheme.ObjectKinds(obj) if err != nil { return nil, err } if len(gvks) == 0 || gvks[0].Empty() { return nil, fmt.Errorf("unexpected gvks registered for object %T: %v", obj, gvks) } // TODO: The same object can be registered for multiple group versions // (although in practise this doesn't seem to be used). // In such case, the version set may not be correct. gvk = gvks[0] } kind := gvk.Kind version := gvk.GroupVersion().String() // only has list metadata if objectMeta == nil { return &v1.ObjectReference{ Kind: kind, APIVersion: version, ResourceVersion: listMeta.GetResourceVersion(), }, nil } return &v1.ObjectReference{ Kind: kind, APIVersion: version, Name: objectMeta.GetName(), Namespace: objectMeta.GetNamespace(), UID: objectMeta.GetUID(), ResourceVersion: objectMeta.GetResourceVersion(), }, nil }
GetReference returns an ObjectReference which refers to the given object, or an error if the object doesn't follow the conventions that would allow this. TODO: should take a meta.Interface see https://issue.k8s.io/7127
GetReference
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/reference/ref.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/reference/ref.go
Apache-2.0
func GetPartialReference(scheme *runtime.Scheme, obj runtime.Object, fieldPath string) (*v1.ObjectReference, error) { ref, err := GetReference(scheme, obj) if err != nil { return nil, err } ref.FieldPath = fieldPath return ref, nil }
GetPartialReference is exactly like GetReference, but allows you to set the FieldPath.
GetPartialReference
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/reference/ref.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/reference/ref.go
Apache-2.0
func (k KeyError) Error() string { return fmt.Sprintf("couldn't create key for object %+v: %v", k.Obj, k.Err) }
Error gives a human-readable description of the error.
Error
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (k KeyError) Unwrap() error { return k.Err }
Unwrap implements errors.Unwrap
Unwrap
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func MetaNamespaceKeyFunc(obj interface{}) (string, error) { if key, ok := obj.(ExplicitKey); ok { return string(key), nil } objName, err := ObjectToName(obj) if err != nil { return "", err } return objName.String(), nil }
MetaNamespaceKeyFunc is a convenient default KeyFunc which knows how to make keys for API objects which implement meta.Interface. The key uses the format <namespace>/<name> unless <namespace> is empty, then it's just <name>. Clients that want a structured alternative can use ObjectToName or MetaObjectToName. Note: this would not be a client that wants a key for a Store because those are necessarily strings. TODO maybe some day?: change Store to be keyed differently
MetaNamespaceKeyFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func ObjectToName(obj interface{}) (ObjectName, error) { meta, err := meta.Accessor(obj) if err != nil { return ObjectName{}, fmt.Errorf("object has no meta: %v", err) } return MetaObjectToName(meta), nil }
ObjectToName returns the structured name for the given object, if indeed it can be viewed as a metav1.Object.
ObjectToName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func MetaObjectToName(obj metav1.Object) ObjectName { if len(obj.GetNamespace()) > 0 { return ObjectName{Namespace: obj.GetNamespace(), Name: obj.GetName()} } return ObjectName{Namespace: "", Name: obj.GetName()} }
MetaObjectToName returns the structured name for the given object
MetaObjectToName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func SplitMetaNamespaceKey(key string) (namespace, name string, err error) { parts := strings.Split(key, "/") switch len(parts) { case 1: // name only, no namespace return "", parts[0], nil case 2: // namespace and name return parts[0], parts[1], nil } return "", "", fmt.Errorf("unexpected key format: %q", key) }
SplitMetaNamespaceKey returns the namespace and name that MetaNamespaceKeyFunc encoded into key. TODO: replace key-as-string with a key-as-struct so that this packing/unpacking won't be necessary.
SplitMetaNamespaceKey
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Add(obj interface{}) error { key, err := c.keyFunc(obj) if err != nil { return KeyError{obj, err} } c.cacheStorage.Add(key, obj) return nil }
Add inserts an item into the cache.
Add
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Update(obj interface{}) error { key, err := c.keyFunc(obj) if err != nil { return KeyError{obj, err} } c.cacheStorage.Update(key, obj) return nil }
Update sets an item in the cache to its updated state.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Delete(obj interface{}) error { key, err := c.keyFunc(obj) if err != nil { return KeyError{obj, err} } c.cacheStorage.Delete(key) return nil }
Delete removes an item from the cache.
Delete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) List() []interface{} { return c.cacheStorage.List() }
List returns a list of all the items. List is completely threadsafe as long as you treat all items as immutable.
List
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) ListKeys() []string { return c.cacheStorage.ListKeys() }
ListKeys returns a list of all the keys of the objects currently in the cache.
ListKeys
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) GetIndexers() Indexers { return c.cacheStorage.GetIndexers() }
GetIndexers returns the indexers of cache
GetIndexers
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Index(indexName string, obj interface{}) ([]interface{}, error) { return c.cacheStorage.Index(indexName, obj) }
Index returns a list of items that match on the index function Index is thread-safe so long as you treat all items as immutable
Index
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) IndexKeys(indexName, indexedValue string) ([]string, error) { return c.cacheStorage.IndexKeys(indexName, indexedValue) }
IndexKeys returns the storage keys of the stored objects whose set of indexed values for the named index includes the given indexed value. The returned keys are suitable to pass to GetByKey().
IndexKeys
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) ListIndexFuncValues(indexName string) []string { return c.cacheStorage.ListIndexFuncValues(indexName) }
ListIndexFuncValues returns the list of generated values of an Index func
ListIndexFuncValues
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) ByIndex(indexName, indexedValue string) ([]interface{}, error) { return c.cacheStorage.ByIndex(indexName, indexedValue) }
ByIndex returns the stored objects whose set of indexed values for the named index includes the given indexed value.
ByIndex
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Get(obj interface{}) (item interface{}, exists bool, err error) { key, err := c.keyFunc(obj) if err != nil { return nil, false, KeyError{obj, err} } return c.GetByKey(key) }
Get returns the requested item, or sets exists=false. Get is completely threadsafe as long as you treat all items as immutable.
Get
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) GetByKey(key string) (item interface{}, exists bool, err error) { item, exists = c.cacheStorage.Get(key) return item, exists, nil }
GetByKey returns the request item, or exists=false. GetByKey is completely threadsafe as long as you treat all items as immutable.
GetByKey
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Replace(list []interface{}, resourceVersion string) error { items := make(map[string]interface{}, len(list)) for _, item := range list { key, err := c.keyFunc(item) if err != nil { return KeyError{item, err} } items[key] = item } c.cacheStorage.Replace(items, resourceVersion) return nil }
Replace will delete the contents of 'c', using instead the given list. 'c' takes ownership of the list, you should not reference the list again after calling this function.
Replace
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (c *cache) Resync() error { return nil }
Resync is meaningless for one of these
Resync
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func NewStore(keyFunc KeyFunc) Store { return &cache{ cacheStorage: NewThreadSafeStore(Indexers{}, Indices{}), keyFunc: keyFunc, } }
NewStore returns a Store implemented simply with a map and a lock.
NewStore
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func NewIndexer(keyFunc KeyFunc, indexers Indexers) Indexer { return &cache{ cacheStorage: NewThreadSafeStore(indexers, Indices{}), keyFunc: keyFunc, } }
NewIndexer returns an Indexer implemented simply with a map and a lock.
NewIndexer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/store.go
Apache-2.0
func (i *storeIndex) updateIndices(oldObj interface{}, newObj interface{}, key string) { var oldIndexValues, indexValues []string var err error for name, indexFunc := range i.indexers { if oldObj != nil { oldIndexValues, err = indexFunc(oldObj) } else { oldIndexValues = oldIndexValues[:0] } if err != nil { panic(fmt.Errorf("unable to calculate an index entry for key %q on index %q: %v", key, name, err)) } if newObj != nil { indexValues, err = indexFunc(newObj) } else { indexValues = indexValues[:0] } if err != nil { panic(fmt.Errorf("unable to calculate an index entry for key %q on index %q: %v", key, name, err)) } index := i.indices[name] if index == nil { index = Index{} i.indices[name] = index } if len(indexValues) == 1 && len(oldIndexValues) == 1 && indexValues[0] == oldIndexValues[0] { // We optimize for the most common case where indexFunc returns a single value which has not been changed continue } for _, value := range oldIndexValues { i.deleteKeyFromIndex(key, value, index) } for _, value := range indexValues { i.addKeyToIndex(key, value, index) } } }
updateIndices modifies the objects location in the managed indexes: - for create you must provide only the newObj - for update you must provide both the oldObj and the newObj - for delete you must provide only the oldObj updateIndices must be called from a function that already has a lock on the cache
updateIndices
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func (c *threadSafeMap) ListKeys() []string { c.lock.RLock() defer c.lock.RUnlock() list := make([]string, 0, len(c.items)) for key := range c.items { list = append(list, key) } return list }
ListKeys returns a list of all the keys of the objects currently in the threadSafeMap.
ListKeys
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func (c *threadSafeMap) Index(indexName string, obj interface{}) ([]interface{}, error) { c.lock.RLock() defer c.lock.RUnlock() storeKeySet, err := c.index.getKeysFromIndex(indexName, obj) if err != nil { return nil, err } list := make([]interface{}, 0, storeKeySet.Len()) for storeKey := range storeKeySet { list = append(list, c.items[storeKey]) } return list, nil }
Index returns a list of items that match the given object on the index function. Index is thread-safe so long as you treat all items as immutable.
Index
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func (c *threadSafeMap) ByIndex(indexName, indexedValue string) ([]interface{}, error) { c.lock.RLock() defer c.lock.RUnlock() set, err := c.index.getKeysByIndex(indexName, indexedValue) if err != nil { return nil, err } list := make([]interface{}, 0, set.Len()) for key := range set { list = append(list, c.items[key]) } return list, nil }
ByIndex returns a list of the items whose indexed values in the given index include the given indexed value
ByIndex
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func (c *threadSafeMap) IndexKeys(indexName, indexedValue string) ([]string, error) { c.lock.RLock() defer c.lock.RUnlock() set, err := c.index.getKeysByIndex(indexName, indexedValue) if err != nil { return nil, err } return set.List(), nil }
IndexKeys returns a list of the Store keys of the objects whose indexed values in the given index include the given indexed value. IndexKeys is thread-safe so long as you treat all items as immutable.
IndexKeys
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func NewThreadSafeStore(indexers Indexers, indices Indices) ThreadSafeStore { return &threadSafeMap{ items: map[string]interface{}{}, index: &storeIndex{ indexers: indexers, indices: indices, }, } }
NewThreadSafeStore creates a new instance of ThreadSafeStore.
NewThreadSafeStore
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/thread_safe_store.go
Apache-2.0
func (h *heapData) Less(i, j int) bool { if i > len(h.queue) || j > len(h.queue) { return false } itemi, ok := h.items[h.queue[i]] if !ok { return false } itemj, ok := h.items[h.queue[j]] if !ok { return false } return h.lessFunc(itemi.obj, itemj.obj) }
Less compares two objects and returns true if the first one should go in front of the second one in the heap.
Less
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *heapData) Len() int { return len(h.queue) }
Len returns the number of items in the Heap.
Len
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *heapData) Swap(i, j int) { h.queue[i], h.queue[j] = h.queue[j], h.queue[i] item := h.items[h.queue[i]] item.index = i item = h.items[h.queue[j]] item.index = j }
Swap implements swapping of two elements in the heap. This is a part of standard heap interface and should never be called directly.
Swap
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *heapData) Push(kv interface{}) { keyValue := kv.(*itemKeyValue) n := len(h.queue) h.items[keyValue.key] = &heapItem{keyValue.obj, n} h.queue = append(h.queue, keyValue.key) }
Push is supposed to be called by heap.Push only.
Push
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *heapData) Pop() interface{} { key := h.queue[len(h.queue)-1] h.queue = h.queue[0 : len(h.queue)-1] item, ok := h.items[key] if !ok { // This is an error return nil } delete(h.items, key) return item.obj }
Pop is supposed to be called by heap.Pop only.
Pop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Close() { h.lock.Lock() defer h.lock.Unlock() h.closed = true h.cond.Broadcast() }
Close the Heap and signals condition variables that may be waiting to pop items from the heap.
Close
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Add(obj interface{}) error { key, err := h.data.keyFunc(obj) if err != nil { return KeyError{obj, err} } h.lock.Lock() defer h.lock.Unlock() if h.closed { return fmt.Errorf(closedMsg) } if _, exists := h.data.items[key]; exists { h.data.items[key].obj = obj heap.Fix(h.data, h.data.items[key].index) } else { h.addIfNotPresentLocked(key, obj) } h.cond.Broadcast() return nil }
Add inserts an item, and puts it in the queue. The item is updated if it already exists.
Add
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) BulkAdd(list []interface{}) error { h.lock.Lock() defer h.lock.Unlock() if h.closed { return fmt.Errorf(closedMsg) } for _, obj := range list { key, err := h.data.keyFunc(obj) if err != nil { return KeyError{obj, err} } if _, exists := h.data.items[key]; exists { h.data.items[key].obj = obj heap.Fix(h.data, h.data.items[key].index) } else { h.addIfNotPresentLocked(key, obj) } } h.cond.Broadcast() return nil }
BulkAdd adds all the items in the list to the queue and then signals the condition variable. It is useful when the caller would like to add all of the items to the queue before consumer starts processing them.
BulkAdd
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) AddIfNotPresent(obj interface{}) error { id, err := h.data.keyFunc(obj) if err != nil { return KeyError{obj, err} } h.lock.Lock() defer h.lock.Unlock() if h.closed { return fmt.Errorf(closedMsg) } h.addIfNotPresentLocked(id, obj) h.cond.Broadcast() return nil }
AddIfNotPresent inserts an item, and puts it in the queue. If an item with the key is present in the map, no changes is made to the item. This is useful in a single producer/consumer scenario so that the consumer can safely retry items without contending with the producer and potentially enqueueing stale items.
AddIfNotPresent
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) addIfNotPresentLocked(key string, obj interface{}) { if _, exists := h.data.items[key]; exists { return } heap.Push(h.data, &itemKeyValue{key, obj}) }
addIfNotPresentLocked assumes the lock is already held and adds the provided item to the queue if it does not already exist.
addIfNotPresentLocked
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Update(obj interface{}) error { return h.Add(obj) }
Update is the same as Add in this implementation. When the item does not exist, it is added.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Delete(obj interface{}) error { key, err := h.data.keyFunc(obj) if err != nil { return KeyError{obj, err} } h.lock.Lock() defer h.lock.Unlock() if item, ok := h.data.items[key]; ok { heap.Remove(h.data, item.index) return nil } return fmt.Errorf("object not found") }
Delete removes an item.
Delete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Pop() (interface{}, error) { h.lock.Lock() defer h.lock.Unlock() for len(h.data.queue) == 0 { // When the queue is empty, invocation of Pop() is blocked until new item is enqueued. // When Close() is called, the h.closed is set and the condition is broadcast, // which causes this loop to continue and return from the Pop(). if h.closed { return nil, fmt.Errorf("heap is closed") } h.cond.Wait() } obj := heap.Pop(h.data) if obj == nil { return nil, fmt.Errorf("object was removed from heap data") } return obj, nil }
Pop waits until an item is ready. If multiple items are ready, they are returned in the order given by Heap.data.lessFunc.
Pop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) List() []interface{} { h.lock.RLock() defer h.lock.RUnlock() list := make([]interface{}, 0, len(h.data.items)) for _, item := range h.data.items { list = append(list, item.obj) } return list }
List returns a list of all the items.
List
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) ListKeys() []string { h.lock.RLock() defer h.lock.RUnlock() list := make([]string, 0, len(h.data.items)) for key := range h.data.items { list = append(list, key) } return list }
ListKeys returns a list of all the keys of the objects currently in the Heap.
ListKeys
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) Get(obj interface{}) (interface{}, bool, error) { key, err := h.data.keyFunc(obj) if err != nil { return nil, false, KeyError{obj, err} } return h.GetByKey(key) }
Get returns the requested item, or sets exists=false.
Get
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) GetByKey(key string) (interface{}, bool, error) { h.lock.RLock() defer h.lock.RUnlock() item, exists := h.data.items[key] if !exists { return nil, false, nil } return item.obj, true, nil }
GetByKey returns the requested item, or sets exists=false.
GetByKey
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func (h *Heap) IsClosed() bool { h.lock.RLock() defer h.lock.RUnlock() return h.closed }
IsClosed returns true if the queue is closed.
IsClosed
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func NewHeap(keyFn KeyFunc, lessFn LessFunc) *Heap { h := &Heap{ data: &heapData{ items: map[string]*heapItem{}, queue: []string{}, keyFunc: keyFn, lessFunc: lessFn, }, } h.cond.L = &h.lock return h }
NewHeap returns a Heap which can be used to queue up items to process.
NewHeap
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/heap.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/heap.go
Apache-2.0
func New(c *Config) Controller { ctlr := &controller{ config: *c, clock: &clock.RealClock{}, } return ctlr }
New makes a new Controller from the given Config.
New
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (c *controller) Run(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() go func() { <-stopCh c.config.Queue.Close() }() r := NewReflectorWithOptions( c.config.ListerWatcher, c.config.ObjectType, c.config.Queue, ReflectorOptions{ ResyncPeriod: c.config.FullResyncPeriod, TypeDescription: c.config.ObjectDescription, Clock: c.clock, }, ) r.ShouldResync = c.config.ShouldResync r.WatchListPageSize = c.config.WatchListPageSize if c.config.WatchErrorHandler != nil { r.watchErrorHandler = c.config.WatchErrorHandler } c.reflectorMutex.Lock() c.reflector = r c.reflectorMutex.Unlock() var wg wait.Group wg.StartWithChannel(stopCh, r.Run) wait.Until(c.processLoop, time.Second, stopCh) wg.Wait() }
Run begins processing items, and will continue until a value is sent down stopCh or it is closed. It's an error to call Run more than once. Run blocks; call via go.
Run
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (c *controller) HasSynced() bool { return c.config.Queue.HasSynced() }
Returns true once this controller has completed an initial resource listing
HasSynced
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (c *controller) processLoop() { for { obj, err := c.config.Queue.Pop(PopProcessFunc(c.config.Process)) if err != nil { if err == ErrFIFOClosed { return } if c.config.RetryOnError { // This is the safe way to re-enqueue. c.config.Queue.AddIfNotPresent(obj) } } } }
processLoop drains the work queue. TODO: Consider doing the processing in parallel. This will require a little thought to make sure that we don't end up processing the same object multiple times concurrently. TODO: Plumb through the stopCh here (and down to the queue) so that this can actually exit when the controller is stopped. Or just give up on this stuff ever being stoppable. Converting this whole package to use Context would also be helpful.
processLoop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerFuncs) OnAdd(obj interface{}, isInInitialList bool) { if r.AddFunc != nil { r.AddFunc(obj) } }
OnAdd calls AddFunc if it's not nil.
OnAdd
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{}) { if r.UpdateFunc != nil { r.UpdateFunc(oldObj, newObj) } }
OnUpdate calls UpdateFunc if it's not nil.
OnUpdate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerFuncs) OnDelete(obj interface{}) { if r.DeleteFunc != nil { r.DeleteFunc(obj) } }
OnDelete calls DeleteFunc if it's not nil.
OnDelete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerDetailedFuncs) OnAdd(obj interface{}, isInInitialList bool) { if r.AddFunc != nil { r.AddFunc(obj, isInInitialList) } }
OnAdd calls AddFunc if it's not nil.
OnAdd
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerDetailedFuncs) OnUpdate(oldObj, newObj interface{}) { if r.UpdateFunc != nil { r.UpdateFunc(oldObj, newObj) } }
OnUpdate calls UpdateFunc if it's not nil.
OnUpdate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r ResourceEventHandlerDetailedFuncs) OnDelete(obj interface{}) { if r.DeleteFunc != nil { r.DeleteFunc(obj) } }
OnDelete calls DeleteFunc if it's not nil.
OnDelete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r FilteringResourceEventHandler) OnAdd(obj interface{}, isInInitialList bool) { if !r.FilterFunc(obj) { return } r.Handler.OnAdd(obj, isInInitialList) }
OnAdd calls the nested handler only if the filter succeeds
OnAdd
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r FilteringResourceEventHandler) OnUpdate(oldObj, newObj interface{}) { newer := r.FilterFunc(newObj) older := r.FilterFunc(oldObj) switch { case newer && older: r.Handler.OnUpdate(oldObj, newObj) case newer && !older: r.Handler.OnAdd(newObj, false) case !newer && older: r.Handler.OnDelete(oldObj) default: // do nothing } }
OnUpdate ensures the proper handler is called depending on whether the filter matches
OnUpdate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func (r FilteringResourceEventHandler) OnDelete(obj interface{}) { if !r.FilterFunc(obj) { return } r.Handler.OnDelete(obj) }
OnDelete calls the nested handler only if the filter succeeds
OnDelete
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func DeletionHandlingMetaNamespaceKeyFunc(obj interface{}) (string, error) { if d, ok := obj.(DeletedFinalStateUnknown); ok { return d.Key, nil } return MetaNamespaceKeyFunc(obj) }
DeletionHandlingMetaNamespaceKeyFunc checks for DeletedFinalStateUnknown objects before calling MetaNamespaceKeyFunc.
DeletionHandlingMetaNamespaceKeyFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func NewInformer( lw ListerWatcher, objType runtime.Object, resyncPeriod time.Duration, h ResourceEventHandler, ) (Store, Controller) { // This will hold the client state, as we know it. clientState := NewStore(DeletionHandlingMetaNamespaceKeyFunc) return clientState, newInformer(lw, objType, resyncPeriod, h, clientState, nil) }
NewInformer returns a Store and a controller for populating the store while also providing event notifications. You should only used the returned Store for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty. Parameters: - lw is list and watch functions for the source of the resource you want to be informed of. - objType is an object of the type that you expect to receive. - resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller). - h is the object you want notifications sent to.
NewInformer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0
func NewIndexerInformer( lw ListerWatcher, objType runtime.Object, resyncPeriod time.Duration, h ResourceEventHandler, indexers Indexers, ) (Indexer, Controller) { // This will hold the client state, as we know it. clientState := NewIndexer(DeletionHandlingMetaNamespaceKeyFunc, indexers) return clientState, newInformer(lw, objType, resyncPeriod, h, clientState, nil) }
NewIndexerInformer returns an Indexer and a Controller for populating the index while also providing event notifications. You should only used the returned Index for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty. Parameters: - lw is list and watch functions for the source of the resource you want to be informed of. - objType is an object of the type that you expect to receive. - resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller). - h is the object you want notifications sent to. - indexers is the indexer for the received object type.
NewIndexerInformer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/client-go/tools/cache/controller.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/client-go/tools/cache/controller.go
Apache-2.0