kubernetes: github.com/erimatnor/kubernetes/pkg/apiserver Index | Files

package apiserver

import "github.com/erimatnor/kubernetes/pkg/apiserver"

Package apiserver contains the code that provides a rest.ful api service.


Package Files

api_installer.go apiserver.go authn.go authz.go doc.go errors.go handlers.go index.go mux_helper.go proxy.go redirect.go resthandler.go validator.go watch.go


const (
    ModeAlwaysAllow string = "AlwaysAllow"
    ModeAlwaysDeny  string = "AlwaysDeny"
    ModeABAC        string = "ABAC"
const RetryAfter = "1"

Constant for the retry-after interval on rate limiting. TODO: maybe make this dynamic? or user-adjustable?


var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABAC}

Keep this list in sync with constant list above.

func APIVersionHandler Uses

func APIVersionHandler(versions ...string) restful.RouteFunction

APIVersionHandler returns a handler which will list the provided versions as available.

func AddApiWebService Uses

func AddApiWebService(container *restful.Container, apiPrefix string, versions []string)

Adds a service to return the supported api versions.

func CORS Uses

func CORS(handler http.Handler, allowedOriginPatterns []*regexp.Regexp, allowedMethods []string, allowedHeaders []string, allowCredentials string) http.Handler

TODO: use restful.CrossOriginResourceSharing Simple CORS implementation that wraps an http Handler For a more detailed implementation use https://github.com/martini-contrib/cors or implement CORS at your proxy layer Pass nil for allowedMethods and allowedHeaders to use the defaults

func ConnectResource Uses

func ConnectResource(connecter rest.Connecter, scope RequestScope, connectOptionsKind string, subpath bool, subpathKey string) restful.RouteFunction

ConnectResource returns a function that handles a connect request on a rest.Storage object.

func CreateResource Uses

func CreateResource(r rest.Creater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction

CreateResource returns a function that will handle a resource creation.

func DeleteResource Uses

func DeleteResource(r rest.GracefulDeleter, checkBody bool, scope RequestScope, admit admission.Interface) restful.RouteFunction

DeleteResource returns a function that will handle a resource deletion

func GetResource Uses

func GetResource(r rest.Getter, scope RequestScope) restful.RouteFunction

GetResource returns a function that handles retrieving a single resource from a rest.Storage object.

func GetResourceWithOptions Uses

func GetResourceWithOptions(r rest.GetterWithOptions, scope RequestScope, getOptionsKind string, subpath bool, subpathKey string) restful.RouteFunction

GetResourceWithOptions returns a function that handles retrieving a single resource from a rest.Storage object.

func IndexHandler Uses

func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.ResponseWriter, *http.Request)

func InstallLogsSupport Uses

func InstallLogsSupport(mux Mux)

InstallLogsSupport registers the APIServer log support function into a mux.

func InstallServiceErrorHandler Uses

func InstallServiceErrorHandler(container *restful.Container, requestResolver *APIRequestInfoResolver, apiVersions []string)

func InstallSupport Uses

func InstallSupport(mux Mux, ws *restful.WebService)

TODO: document all handlers InstallSupport registers the APIServer support functions

func InstallValidator Uses

func InstallValidator(mux Mux, servers func() map[string]Server)

TODO: This endpoint is deprecated and should be removed at some point. Use "componentstatus" API instead.

func IsReadOnlyReq Uses

func IsReadOnlyReq(req http.Request) bool

IsReadOnlyReq() is true for any (or at least many) request which has no observable side effects on state of apiserver (though there may be internal side effects like caching and logging).

func ListResource Uses

func ListResource(r rest.Lister, rw rest.Watcher, scope RequestScope, forceWatch bool) restful.RouteFunction

ListResource returns a function that handles retrieving a list of resources from a rest.Storage object.

func MaxInFlightLimit Uses

func MaxInFlightLimit(c chan bool, longRunningRequestRE *regexp.Regexp, handler http.Handler) http.Handler

MaxInFlight limits the number of in-flight requests to buffer size of the passed in channel.

func NewAlwaysAllowAuthorizer Uses

func NewAlwaysAllowAuthorizer() authorizer.Authorizer

func NewAlwaysDenyAuthorizer Uses

func NewAlwaysDenyAuthorizer() authorizer.Authorizer

func NewAuthenticator Uses

func NewAuthenticator(basicAuthFile, clientCAFile, tokenFile string) (authenticator.Request, error)

NewAuthenticator returns an authenticator.Request or an error

func NewAuthorizerFromAuthorizationConfig Uses

func NewAuthorizerFromAuthorizationConfig(authorizationMode string, authorizationPolicyFile string) (authorizer.Authorizer, error)

NewAuthorizerFromAuthorizationConfig returns the right sort of authorizer.Authorizer based on the authorizationMode xor an error. authorizationMode should be one of AuthorizationModeChoices.

func NewValidator Uses

func NewValidator(servers func() map[string]Server) http.Handler

NewValidator creates a validator for a set of servers.

func PatchResource Uses

func PatchResource(r rest.Patcher, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface, converter runtime.ObjectConvertor) restful.RouteFunction

PatchResource returns a function that will handle a resource patch TODO: Eventually PatchResource should just use GuaranteedUpdate and this routine should be a bit cleaner

func RateLimit Uses

func RateLimit(rl util.RateLimiter, handler http.Handler) http.Handler

RateLimit uses rl to rate limit accepting requests to 'handler'.

func ReadOnly Uses

func ReadOnly(handler http.Handler) http.Handler

ReadOnly passes all GET requests on to handler, and returns an error on all other requests.

func RecoverPanics Uses

func RecoverPanics(handler http.Handler) http.Handler

RecoverPanics wraps an http Handler to recover and log panics.

func UpdateResource Uses

func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction

UpdateResource returns a function that will handle a resource update

func WithAuthorizationCheck Uses

func WithAuthorizationCheck(handler http.Handler, getAttribs RequestAttributeGetter, a authorizer.Authorizer) http.Handler

WithAuthorizationCheck passes all authorized requests on to handler, and returns a forbidden error otherwise.

type APIGroupVersion Uses

type APIGroupVersion struct {
    Storage map[string]rest.Storage

    Root    string
    Version string

    // ServerVersion controls the Kubernetes APIVersion used for common objects in the apiserver
    // schema like api.Status, api.DeleteOptions, and api.ListOptions. Other implementors may
    // define a version "v1beta1" but want to use the Kubernetes "v1beta3" internal objects. If
    // empty, defaults to Version.
    ServerVersion string

    Mapper meta.RESTMapper

    Codec     runtime.Codec
    Typer     runtime.ObjectTyper
    Creater   runtime.ObjectCreater
    Convertor runtime.ObjectConvertor
    Linker    runtime.SelfLinker

    Admit   admission.Interface
    Context api.RequestContextMapper

APIGroupVersion is a helper for exposing rest.Storage objects as http.Handlers via go-restful It handles URLs of the form: /${storage_key}[/${object_name}] Where 'storage_key' points to a rest.Storage object stored in storage.

func (*APIGroupVersion) InstallREST Uses

func (g *APIGroupVersion) InstallREST(container *restful.Container) error

InstallREST registers the REST handlers (storage, watch, proxy and redirect) into a restful Container. It is expected that the provided path root prefix will serve all operations. Root MUST NOT end in a slash. A restful WebService is created for the group and version.

type APIInstaller Uses

type APIInstaller struct {
    // contains filtered or unexported fields

func (*APIInstaller) Install Uses

func (a *APIInstaller) Install() (ws *restful.WebService, errors []error)

Installs handlers for API resources.

type APIRequestInfo Uses

type APIRequestInfo struct {
    // Verb is the kube verb associated with the request, not the http verb.  This includes things like list and watch.
    Verb       string
    APIVersion string
    Namespace  string
    // Resource is the name of the resource being requested.  This is not the kind.  For example: pods
    Resource string
    // Subresource is the name of the subresource being requested.  This is a different resource, scoped to the parent resource, but it may have a different kind.
    // For instance, /pods has the resource "pods" and the kind "Pod", while /pods/foo/status has the resource "pods", the sub resource "status", and the kind "Pod"
    // (because status operates on pods). The binding resource for a pod though may be /pods/foo/binding, which has resource "pods", subresource "binding", and kind "Binding".
    Subresource string
    // Kind is the type of object being manipulated.  For example: Pod
    Kind string
    // Name is empty for some verbs, but if the request directly indicates a name (not in body content) then this field is filled in.
    Name string
    // Parts are the path parts for the request, always starting with /{resource}/{name}
    Parts []string
    // Raw is the unparsed form of everything other than parts.
    // Raw + Parts = complete URL path
    Raw []string

APIRequestInfo holds information parsed from the http.Request

type APIRequestInfoResolver Uses

type APIRequestInfoResolver struct {
    APIPrefixes util.StringSet
    RestMapper  meta.RESTMapper

func (*APIRequestInfoResolver) GetAPIRequestInfo Uses

func (r *APIRequestInfoResolver) GetAPIRequestInfo(req *http.Request) (APIRequestInfo, error)

TODO write an integration test against the swagger doc to test the APIRequestInfo and match up behavior to responses GetAPIRequestInfo returns the information from the http request. If error is not nil, APIRequestInfo holds the information as best it is known before the failure Valid Inputs: Storage paths /namespaces /namespaces/{namespace} /namespaces/{namespace}/{resource} /namespaces/{namespace}/{resource}/{resourceName} /{resource} /{resource}/{resourceName} /{resource}/{resourceName}?namespace={namespace} /{resource}?namespace={namespace}

Special verbs: /proxy/{resource}/{resourceName} /proxy/namespaces/{namespace}/{resource}/{resourceName} /redirect/namespaces/{namespace}/{resource}/{resourceName} /redirect/{resource}/{resourceName} /watch/{resource} /watch/namespaces/{namespace}/{resource}

Fully qualified paths for above: /api/{version}/* /api/{version}/*

type Attributes Uses

type Attributes struct {

Attributes implements authorizer.Attributes interface.

type ContextFunc Uses

type ContextFunc func(req *restful.Request) api.Context

ContextFunc returns a Context given a request - a context must be returned

type Mux Uses

type Mux interface {
    Handle(pattern string, handler http.Handler)
    HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

mux is an object that can register http handlers.

type MuxHelper Uses

type MuxHelper struct {
    Mux             Mux
    RegisteredPaths []string

Offers additional functionality over ServeMux, for ex: supports listing registered paths.

func (*MuxHelper) Handle Uses

func (m *MuxHelper) Handle(path string, handler http.Handler)

func (*MuxHelper) HandleFunc Uses

func (m *MuxHelper) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request))

type ProxyHandler Uses

type ProxyHandler struct {
    // contains filtered or unexported fields

ProxyHandler provides a http.Handler which will proxy traffic to locations specified by items implementing Redirector.

func (*ProxyHandler) ServeHTTP Uses

func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RedirectHandler Uses

type RedirectHandler struct {
    // contains filtered or unexported fields

func (*RedirectHandler) ServeHTTP Uses

func (r *RedirectHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RequestAttributeGetter Uses

type RequestAttributeGetter interface {
    GetAttribs(req *http.Request) (attribs authorizer.Attributes)

RequestAttributeGetter is a function that extracts authorizer.Attributes from an http.Request

func NewRequestAttributeGetter Uses

func NewRequestAttributeGetter(requestContextMapper api.RequestContextMapper, restMapper meta.RESTMapper, apiRoots ...string) RequestAttributeGetter

NewAttributeGetter returns an object which implements the RequestAttributeGetter interface.

type RequestScope Uses

type RequestScope struct {
    Namer ScopeNamer
    Creater   runtime.ObjectCreater
    Convertor runtime.ObjectConvertor

    Resource   string
    Kind       string
    APIVersion string

    // The version of apiserver resources to use
    ServerAPIVersion string

RequestScope encapsulates common fields across all RESTful handler methods.

type ScopeNamer Uses

type ScopeNamer interface {
    // Namespace returns the appropriate namespace value from the request (may be empty) or an
    // error.
    Namespace(req *restful.Request) (namespace string, err error)
    // Name returns the name from the request, and an optional namespace value if this is a namespace
    // scoped call. An error is returned if the name is not available.
    Name(req *restful.Request) (namespace, name string, err error)
    // ObjectName returns the namespace and name from an object if they exist, or an error if the object
    // does not support names.
    ObjectName(obj runtime.Object) (namespace, name string, err error)
    // SetSelfLink sets the provided URL onto the object. The method should return nil if the object
    // does not support selfLinks.
    SetSelfLink(obj runtime.Object, url string) error
    // GenerateLink creates a path and query for a given runtime object that represents the canonical path.
    GenerateLink(req *restful.Request, obj runtime.Object) (path, query string, err error)
    // GenerateLink creates a path and query for a list that represents the canonical path.
    GenerateListLink(req *restful.Request) (path, query string, err error)

ScopeNamer handles accessing names from requests and objects

type Server Uses

type Server struct {
    Addr        string
    Port        int
    Path        string
    EnableHTTPS bool

func (*Server) DoServerCheck Uses

func (server *Server) DoServerCheck(rt http.RoundTripper) (probe.Result, string, error)

TODO: can this use pkg/probe/http

type ServerStatus Uses

type ServerStatus struct {
    Component  string       `json:"component,omitempty"`
    Health     string       `json:"health,omitempty"`
    HealthCode probe.Result `json:"healthCode,omitempty"`
    Msg        string       `json:"msg,omitempty"`
    Err        string       `json:"err,omitempty"`

type WatchServer Uses

type WatchServer struct {
    // contains filtered or unexported fields

WatchServer serves a watch.Interface over a websocket or vanilla HTTP.

func (*WatchServer) HandleWS Uses

func (w *WatchServer) HandleWS(ws *websocket.Conn)

HandleWS implements a websocket handler.

func (*WatchServer) ServeHTTP Uses

func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP serves a series of JSON encoded events via straight HTTP with Transfer-Encoding: chunked.

Package apiserver imports 56 packages (graph). Updated 2017-05-11. Refresh now. Tools for package owners.