genericapiserver

package
v1.3.0-rancher2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2016 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Overview

Package genericapiserver contains code to setup a generic kubernetes-like API server. This does not contain any kubernetes API specific code. Note that this is a work in progress. We are pulling out generic code (specifically from pkg/master and pkg/apiserver) here. We plan to move this package into a separate repo on github once it is done. For more details: https://github.com/kubernetes/kubernetes/issues/2742

Index

Constants

View Source
const AllResources = "*"

Variables

This section is empty.

Functions

func DefaultAndValidateRunOptions added in v1.3.0

func DefaultAndValidateRunOptions(options *options.ServerRunOptions)

func NewHandlerContainer

func NewHandlerContainer(mux *http.ServeMux, s runtime.NegotiatedSerializer) *restful.Container

func NewStorageCodec added in v1.3.0

func NewStorageCodec(storageMediaType string, ns runtime.StorageSerializer, storageVersion, memoryVersion unversioned.GroupVersion, config storagebackend.Config) (runtime.Codec, error)

NewStorageCodec assembles a storage codec for the provided storage media type, the provided serializer, and the requested storage and memory versions.

func ValidateRunOptions added in v1.3.0

func ValidateRunOptions(options *options.ServerRunOptions)

Types

type APIGroupInfo

type APIGroupInfo struct {
	GroupMeta apimachinery.GroupMeta
	// Info about the resources in this group. Its a map from version to resource to the storage.
	VersionedResourcesStorageMap map[string]map[string]rest.Storage
	// True, if this is the legacy group ("/v1").
	IsLegacyGroup bool
	// OptionsExternalVersion controls the APIVersion used for common objects in the
	// schema like api.Status, api.DeleteOptions, and api.ListOptions. Other implementors may
	// define a version "v1beta1" but want to use the Kubernetes "v1" internal objects.
	// If nil, defaults to groupMeta.GroupVersion.
	// TODO: Remove this when https://github.com/kubernetes/kubernetes/issues/19018 is fixed.
	OptionsExternalVersion *unversioned.GroupVersion

	// Scheme includes all of the types used by this group and how to convert between them (or
	// to convert objects from outside of this group that are accepted in this API).
	// TODO: replace with interfaces
	Scheme *runtime.Scheme
	// NegotiatedSerializer controls how this group encodes and decodes data
	NegotiatedSerializer runtime.NegotiatedSerializer
	// ParameterCodec performs conversions for query parameters passed to API calls
	ParameterCodec runtime.ParameterCodec

	// SubresourceGroupVersionKind contains the GroupVersionKind overrides for each subresource that is
	// accessible from this API group version. The GroupVersionKind is that of the external version of
	// the subresource. The key of this map should be the path of the subresource. The keys here should
	// match the keys in the Storage map above for subresources.
	SubresourceGroupVersionKind map[string]unversioned.GroupVersionKind
}

Info about an API group.

type APIResourceConfigSource added in v1.3.0

type APIResourceConfigSource interface {
	AnyVersionOfResourceEnabled(resource unversioned.GroupResource) bool
	ResourceEnabled(resource unversioned.GroupVersionResource) bool
	AllResourcesForVersionEnabled(version unversioned.GroupVersion) bool
	AnyResourcesForVersionEnabled(version unversioned.GroupVersion) bool
}

APIResourceConfigSource is the interface to determine which versions and resources are enabled

type AddressFunc added in v1.3.0

type AddressFunc func() (addresses []string, err error)

type Config

type Config struct {
	// The storage factory for other objects
	StorageFactory StorageFactory
	// allow downstream consumers to disable the core controller loops
	EnableLogsSupport bool
	EnableUISupport   bool
	// Allow downstream consumers to disable swagger.
	// This includes returning the generated swagger spec at /swaggerapi and swagger ui at /swagger-ui.
	EnableSwaggerSupport bool
	// Allow downstream consumers to disable swagger ui.
	// Note that this is ignored if either EnableSwaggerSupport or EnableUISupport is false.
	EnableSwaggerUI bool
	// Allows api group versions or specific resources to be conditionally enabled/disabled.
	APIResourceConfigSource APIResourceConfigSource
	// allow downstream consumers to disable the index route
	EnableIndex           bool
	EnableProfiling       bool
	EnableWatchCache      bool
	APIPrefix             string
	APIGroupPrefix        string
	CorsAllowedOriginList []string
	Authenticator         authenticator.Request
	// TODO(roberthbailey): Remove once the server no longer supports http basic auth.
	SupportsBasicAuth      bool
	Authorizer             authorizer.Authorizer
	AdmissionControl       admission.Interface
	MasterServiceNamespace string
	// TODO(ericchiang): Determine if policy escalation checks should be an admission controller.
	AuthorizerRBACSuperUser string

	// Map requests to contexts. Exported so downstream consumers can provider their own mappers
	RequestContextMapper api.RequestContextMapper

	// Required, the interface for serializing and converting objects to and from the wire
	Serializer runtime.NegotiatedSerializer

	// If specified, all web services will be registered into this container
	RestfulContainer *restful.Container

	// If specified, requests will be allocated a random timeout between this value, and twice this value.
	// Note that it is up to the request handlers to ignore or honor this timeout. In seconds.
	MinRequestTimeout int

	// Number of masters running; all masters must be started with the
	// same value for this field. (Numbers > 1 currently untested.)
	MasterCount int

	// The port on PublicAddress where a read-write server will be installed.
	// Defaults to 6443 if not set.
	ReadWritePort int

	// ExternalHost is the host name to use for external (public internet) facing URLs (e.g. Swagger)
	ExternalHost string

	// PublicAddress is the IP address where members of the cluster (kubelet,
	// kube-proxy, services, etc.) can reach the GenericAPIServer.
	// If nil or 0.0.0.0, the host's default interface will be used.
	PublicAddress net.IP

	// Control the interval that pod, node IP, and node heath status caches
	// expire.
	CacheTimeout time.Duration

	// The range of IPs to be assigned to services with type=ClusterIP or greater
	ServiceClusterIPRange *net.IPNet

	// The IP address for the GenericAPIServer service (must be inside ServiceClusterIPRange)
	ServiceReadWriteIP net.IP

	// Port for the apiserver service.
	ServiceReadWritePort int

	// The range of ports to be assigned to services with type=NodePort or greater
	ServiceNodePortRange utilnet.PortRange

	// Used to customize default proxy dial/tls options
	ProxyDialer          apiserver.ProxyDialerFunc
	ProxyTLSClientConfig *tls.Config

	// Additional ports to be exposed on the GenericAPIServer service
	// extraServicePorts is injectable in the event that more ports
	// (other than the default 443/tcp) are exposed on the GenericAPIServer
	// and those ports need to be load balanced by the GenericAPIServer
	// service because this pkg is linked by out-of-tree projects
	// like openshift which want to use the GenericAPIServer but also do
	// more stuff.
	ExtraServicePorts []api.ServicePort
	// Additional ports to be exposed on the GenericAPIServer endpoints
	// Port names should align with ports defined in ExtraServicePorts
	ExtraEndpointPorts []api.EndpointPort

	KubernetesServiceNodePort int
}

Config is a structure used to configure a GenericAPIServer.

func NewConfig added in v1.3.0

func NewConfig(options *options.ServerRunOptions) *Config

type DefaultResourceEncodingConfig added in v1.3.0

type DefaultResourceEncodingConfig struct {
	Groups map[string]*GroupResourceEncodingConfig
}

func NewDefaultResourceEncodingConfig added in v1.3.0

func NewDefaultResourceEncodingConfig() *DefaultResourceEncodingConfig

func (*DefaultResourceEncodingConfig) InMemoryEncodingFor added in v1.3.0

func (*DefaultResourceEncodingConfig) SetResourceEncoding added in v1.3.0

func (o *DefaultResourceEncodingConfig) SetResourceEncoding(resourceBeingStored unversioned.GroupResource, externalEncodingVersion, internalVersion unversioned.GroupVersion)

func (*DefaultResourceEncodingConfig) SetVersionEncoding added in v1.3.0

func (o *DefaultResourceEncodingConfig) SetVersionEncoding(group string, externalEncodingVersion, internalVersion unversioned.GroupVersion)

func (*DefaultResourceEncodingConfig) StorageEncodingFor added in v1.3.0

type DefaultStorageFactory added in v1.3.0

type DefaultStorageFactory struct {
	// StorageConfig describes how to create a storage backend in general.
	// Its authentication information will be used for every storage.Interface returned.
	StorageConfig storagebackend.Config

	Overrides map[unversioned.GroupResource]groupResourceOverrides

	// DefaultMediaType is the media type used to store resources. If it is not set, "application/json" is used.
	DefaultMediaType string

	// DefaultSerializer is used to create encoders and decoders for the storage.Interface.
	DefaultSerializer runtime.StorageSerializer

	// ResourceEncodingConfig describes how to encode a particular GroupVersionResource
	ResourceEncodingConfig ResourceEncodingConfig

	// APIResourceConfigSource indicates whether the *storage* is enabled, NOT the API
	// This is discrete from resource enablement because those are separate concerns.  How this source is configured
	// is left to the caller.
	APIResourceConfigSource APIResourceConfigSource
	// contains filtered or unexported fields
}

DefaultStorageFactory takes a GroupResource and returns back its storage interface. This result includes: 1. Merged etcd config, including: auth, server locations, prefixes 2. Resource encodings for storage: group,version,kind to store as 3. Cohabitating default: some resources like hpa are exposed through multiple APIs. They must agree on 1 and 2

func BuildDefaultStorageFactory added in v1.3.0

func BuildDefaultStorageFactory(storageConfig storagebackend.Config, defaultMediaType string, serializer runtime.StorageSerializer,
	defaultResourceEncoding *DefaultResourceEncodingConfig, storageEncodingOverrides map[string]unversioned.GroupVersion, defaultAPIResourceConfig *ResourceConfig, resourceConfigOverrides config.ConfigurationMap) (*DefaultStorageFactory, error)

Builds the DefaultStorageFactory. Merges defaultResourceConfig with the user specified overrides and merges defaultAPIResourceConfig with the corresponding user specified overrides as well.

func NewDefaultStorageFactory added in v1.3.0

func NewDefaultStorageFactory(config storagebackend.Config, defaultMediaType string, defaultSerializer runtime.StorageSerializer, resourceEncodingConfig ResourceEncodingConfig, resourceConfig APIResourceConfigSource) *DefaultStorageFactory

func (*DefaultStorageFactory) AddCohabitatingResources added in v1.3.0

func (s *DefaultStorageFactory) AddCohabitatingResources(groupResources ...unversioned.GroupResource)

AddCohabitatingResources links resources together the order of the slice matters! its the priority order of lookup for finding a storage location

func (*DefaultStorageFactory) Backends added in v1.3.0

func (s *DefaultStorageFactory) Backends() []string

Get all backends for all registered storage destinations. Used for getting all instances for health validations.

func (*DefaultStorageFactory) New added in v1.3.0

New finds the storage destination for the given group and resource. It will return an error if the group has no storage destination configured.

func (*DefaultStorageFactory) SetEtcdLocation added in v1.3.0

func (s *DefaultStorageFactory) SetEtcdLocation(groupResource unversioned.GroupResource, location []string)

func (*DefaultStorageFactory) SetEtcdPrefix added in v1.3.0

func (s *DefaultStorageFactory) SetEtcdPrefix(groupResource unversioned.GroupResource, prefix string)

func (*DefaultStorageFactory) SetSerializer added in v1.3.0

func (s *DefaultStorageFactory) SetSerializer(groupResource unversioned.GroupResource, mediaType string, serializer runtime.StorageSerializer)

type GenericAPIServer

type GenericAPIServer struct {
	// "Inputs", Copied from Config
	ServiceClusterIPRange *net.IPNet
	ServiceNodePortRange  utilnet.PortRange

	MinRequestTimeout time.Duration

	MuxHelper        *apiserver.MuxHelper
	HandlerContainer *restful.Container
	RootWebService   *restful.WebService

	APIPrefix      string
	APIGroupPrefix string

	AdmissionControl     admission.Interface
	MasterCount          int
	RequestContextMapper api.RequestContextMapper

	// ExternalAddress is the address (hostname or IP and port) that should be used in
	// external (public internet) URLs for this GenericAPIServer.
	ExternalAddress string
	// ClusterIP is the IP address of the GenericAPIServer within the cluster.
	ClusterIP            net.IP
	PublicReadWritePort  int
	ServiceReadWriteIP   net.IP
	ServiceReadWritePort int

	ExtraServicePorts  []api.ServicePort
	ExtraEndpointPorts []api.EndpointPort

	// Serializer controls how common API objects not in a group/version prefix are serialized for this server.
	// Individual APIGroups may define their own serializers.
	Serializer runtime.NegotiatedSerializer

	// "Outputs"
	Handler         http.Handler
	InsecureHandler http.Handler

	// Used for custom proxy dialing, and proxy TLS options
	ProxyTransport http.RoundTripper

	KubernetesServiceNodePort int
	// contains filtered or unexported fields
}

GenericAPIServer contains state for a Kubernetes cluster api server.

func New

func New(c *Config) (*GenericAPIServer, error)

New returns a new instance of GenericAPIServer from the given config. Certain config fields will be set to a default value if unset, including:

ServiceClusterIPRange
ServiceNodePortRange
MasterCount
ReadWritePort
PublicAddress

Public fields:

Handler -- The returned GenericAPIServer has a field TopHandler which is an
http.Handler which handles all the endpoints provided by the GenericAPIServer,
including the API, the UI, and miscellaneous debugging endpoints.  All
these are subject to authorization and authentication.
InsecureHandler -- an http.Handler which handles all the same
endpoints as Handler, but no authorization and authentication is done.

Public methods:

HandleWithAuth -- Allows caller to add an http.Handler for an endpoint
that uses the same authentication and authorization (if any is configured)
as the GenericAPIServer's built-in endpoints.
If the caller wants to add additional endpoints not using the GenericAPIServer's
auth, then the caller should create a handler for those endpoints, which delegates the
any unhandled paths to "Handler".

func (*GenericAPIServer) AddAPIGroupForDiscovery

func (s *GenericAPIServer) AddAPIGroupForDiscovery(apiGroup unversioned.APIGroup)

func (*GenericAPIServer) HandleFuncWithAuth

func (s *GenericAPIServer) HandleFuncWithAuth(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFuncWithAuth adds an http.Handler for pattern to an http.ServeMux Applies the same authentication and authorization (if any is configured) to the request is used for the GenericAPIServer's built-in endpoints.

func (*GenericAPIServer) HandleWithAuth

func (s *GenericAPIServer) HandleWithAuth(pattern string, handler http.Handler)

HandleWithAuth adds an http.Handler for pattern to an http.ServeMux Applies the same authentication and authorization (if any is configured) to the request is used for the GenericAPIServer's built-in endpoints.

func (*GenericAPIServer) InstallAPIGroup added in v1.3.0

func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error

Exposes the given group version in API.

func (*GenericAPIServer) InstallAPIGroups

func (s *GenericAPIServer) InstallAPIGroups(groupsInfo []APIGroupInfo) error

Exposes the given group versions in API. Helper method to install multiple group versions at once.

func (*GenericAPIServer) InstallSwaggerAPI

func (s *GenericAPIServer) InstallSwaggerAPI()

InstallSwaggerAPI installs the /swaggerapi/ endpoint to allow schema discovery and traversal. It is optional to allow consumers of the Kubernetes GenericAPIServer to register their own web services into the Kubernetes mux prior to initialization of swagger, so that other resource types show up in the documentation.

func (*GenericAPIServer) NewRequestInfoResolver

func (s *GenericAPIServer) NewRequestInfoResolver() *apiserver.RequestInfoResolver

func (*GenericAPIServer) RemoveAPIGroupForDiscovery

func (s *GenericAPIServer) RemoveAPIGroupForDiscovery(groupName string)

func (*GenericAPIServer) Run

func (s *GenericAPIServer) Run(options *options.ServerRunOptions)

func (*GenericAPIServer) StorageDecorator

func (s *GenericAPIServer) StorageDecorator() generic.StorageDecorator

type GroupResourceEncodingConfig added in v1.3.0

type GroupResourceEncodingConfig struct {
	DefaultExternalEncoding   unversioned.GroupVersion
	ExternalResourceEncodings map[string]unversioned.GroupVersion

	DefaultInternalEncoding   unversioned.GroupVersion
	InternalResourceEncodings map[string]unversioned.GroupVersion
}

type GroupVersionResourceConfig added in v1.3.0

type GroupVersionResourceConfig struct {
	// Whether to enable or disable this entire group version.  This dominates any enablement check.
	// Enable=true means the group version is enabled, and EnabledResources/DisabledResources are considered.
	// Enable=false means the group version is disabled, and EnabledResources/DisabledResources are not considered.
	Enable bool

	// DisabledResources lists the resources that are specifically disabled for a group/version
	// DisabledResources trumps EnabledResources
	DisabledResources sets.String

	// EnabledResources lists the resources that should be enabled by default.  This is a little
	// unusual, but we need it for compatibility with old code for now.  An empty set means
	// enable all, a non-empty set means that all other resources are disabled.
	EnabledResources sets.String
}

Specifies the overrides for various API group versions. This can be used to enable/disable entire group versions or specific resources.

func NewGroupVersionResourceConfig added in v1.3.0

func NewGroupVersionResourceConfig() *GroupVersionResourceConfig

type InstallSSHKey added in v1.3.0

type InstallSSHKey func(user string, data []byte) error

type ResourceConfig added in v1.3.0

type ResourceConfig struct {
	GroupVersionResourceConfigs map[unversioned.GroupVersion]*GroupVersionResourceConfig
}

func NewResourceConfig added in v1.3.0

func NewResourceConfig() *ResourceConfig

func (*ResourceConfig) AllResourcesForVersionEnabled added in v1.3.0

func (o *ResourceConfig) AllResourcesForVersionEnabled(version unversioned.GroupVersion) bool

func (*ResourceConfig) AnyResourcesForVersionEnabled added in v1.3.0

func (o *ResourceConfig) AnyResourcesForVersionEnabled(version unversioned.GroupVersion) bool

func (*ResourceConfig) AnyVersionOfResourceEnabled added in v1.3.0

func (o *ResourceConfig) AnyVersionOfResourceEnabled(resource unversioned.GroupResource) bool

AnyResourcesForVersionEnabled only considers matches based on exactly group/resource lexical matching. This means that resource renames across versions are NOT considered to be the same resource by this method. You'll need to manually check using the ResourceEnabled function.

func (*ResourceConfig) DisableResources added in v1.3.0

func (o *ResourceConfig) DisableResources(resources ...unversioned.GroupVersionResource)

func (*ResourceConfig) DisableVersions added in v1.3.0

func (o *ResourceConfig) DisableVersions(versions ...unversioned.GroupVersion)

DisableVersions disables the versions entirely. No resources (even those whitelisted in EnabledResources) will be enabled

func (*ResourceConfig) EnableResources added in v1.3.0

func (o *ResourceConfig) EnableResources(resources ...unversioned.GroupVersionResource)

func (*ResourceConfig) EnableVersions added in v1.3.0

func (o *ResourceConfig) EnableVersions(versions ...unversioned.GroupVersion)

func (*ResourceConfig) ResourceEnabled added in v1.3.0

func (o *ResourceConfig) ResourceEnabled(resource unversioned.GroupVersionResource) bool

type ResourceEncodingConfig added in v1.3.0

type ResourceEncodingConfig interface {
	// StorageEncoding returns the serialization format for the resource.
	// TODO this should actually return a GroupVersionKind since you can logically have multiple "matching" Kinds
	// For now, it returns just the GroupVersion for consistency with old behavior
	StorageEncodingFor(unversioned.GroupResource) (unversioned.GroupVersion, error)

	// InMemoryEncodingFor returns the groupVersion for the in memory representation the storage should convert to.
	InMemoryEncodingFor(unversioned.GroupResource) (unversioned.GroupVersion, error)
}

type SSHTunneler added in v1.3.0

type SSHTunneler struct {
	SSHUser        string
	SSHKeyfile     string
	InstallSSHKey  InstallSSHKey
	HealthCheckURL *url.URL
	// contains filtered or unexported fields
}

func (*SSHTunneler) Dial added in v1.3.0

func (c *SSHTunneler) Dial(net, addr string) (net.Conn, error)

func (*SSHTunneler) Run added in v1.3.0

func (c *SSHTunneler) Run(getAddresses AddressFunc)

Run establishes tunnel loops and returns

func (*SSHTunneler) SecondsSinceSSHKeySync added in v1.3.0

func (c *SSHTunneler) SecondsSinceSSHKeySync() int64

func (*SSHTunneler) SecondsSinceSync added in v1.3.0

func (c *SSHTunneler) SecondsSinceSync() int64

func (*SSHTunneler) Stop added in v1.3.0

func (c *SSHTunneler) Stop()

Stop gracefully shuts down the tunneler

type StorageFactory added in v1.3.0

type StorageFactory interface {
	// New finds the storage destination for the given group and resource. It will
	// return an error if the group has no storage destination configured.
	New(groupResource unversioned.GroupResource) (storage.Interface, error)
	// Backends gets all backends for all registered storage destinations.
	// Used for getting all instances for health validations.
	Backends() []string
}

StorageFactory is the interface to locate the storage for a given GroupResource

type Tunneler added in v1.3.0

type Tunneler interface {
	Run(AddressFunc)
	Stop()
	Dial(net, addr string) (net.Conn, error)
	SecondsSinceSync() int64
	SecondsSinceSSHKeySync() int64
}

func NewSSHTunneler added in v1.3.0

func NewSSHTunneler(sshUser, sshKeyfile string, healthCheckURL *url.URL, installSSHKey InstallSSHKey) Tunneler

Directories

Path Synopsis
package options is the public flags and options used by a generic api server.
package options is the public flags and options used by a generic api server.

Jump to

Keyboard shortcuts

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