Upload
stefan-schimanski
View
216
Download
1
Embed Size (px)
Citation preview
Kubernetes APIDEEP DIVE INTO THE APISERVER
Dr. StefanSchimansk i , sttts@redhat .com
RestfulhttpAPI
//version
/api/api/v1/pods/api/v1/pods/status
/apis/apis/batch/apis/batch/v1alpha1/apis/batch/v1alpha1/jobs/apis/batch/v1alpha1/cronjobs/apis/batch/v1beta1/apis/batch/v1beta1/jobs
kube-apiserver $kubectl create -ffoo.yaml
RestfulhttpAPI
//version
/api/api/v1/pods/api/v1/pods/status
/apis/apis/batch/apis/batch/v2alpha1/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs/apis/batch/v1beta1/apis/batch/v1beta1/jobs
RestfulhttpAPI
//version
/api/api/v1/pods/api/v1/pods/status
/apis/apis/batch/apis/batch/v2alpha1/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs/apis/batch/v1beta1/apis/batch/v1beta1/jobs
RestfulhttpAPI
//version
/api/api/v1/pods/api/v1/pods/status
/apis/apis/batch/apis/batch/v2alpha1/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs/apis/batch/v1beta1/apis/batch/v1beta1/jobs
/apis/batch/v2alpha1/jobs
GroupVersionResourceHTTPpaths:
InGo: gvk :=schema.GroupVersionKind{Group:“batch“,Version:“v2alpha1“,Kind:“Job“}obj :=api.Schema.New(gvk)codec :=api.Codecs.LegacyCodec(gvk.GroupVersion())codec.Decode(reqBody,gvk,obj)
typeJob struct {metav1.TypeMetametav1.ObjectMetaSpec JobSpecStatusJobStatus
}pkg/apis/batch/v2alpha1/types.go
typeTypeMeta struct {KindstringAPIVersion string
}
typeObjectMeta struct {Namestring...
}
RestfulhttpAPI
//version
/api/api/v1/pods/api/v1/pods/status
/apis/apis/batch/apis/batch/v2alpha1/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs/apis/batch/v1beta1/apis/batch/v1beta1/jobs
MaxInFlightLimit
Timeo
utForNon
LongRu
nningReq
uests
PanicRe
covery
CORS
Authen
tication
Audit
Impe
rson
ation
Authoriza
tion
k8s.io/apiserver/pkg/server.DefaultBuildHandlerChain
„Filters“
k8s.io/apiserver/pkg/server/routes/index.go – /k8s.io/apiserver/pkg/server/routes/version.go – /versionk8s.io/apiserver/pkg/server/routes/swagger.go – /swaggerapik8s.io/apiserver/pkg/server/routes/openapi.go – /swagger.json
„Routes“
mux
k8s.io/apiserver/pkg/endpoints.APIGroupVersion.InstallREST
AddSupportedResourcesWebService – /apis/batch/v2alpha1
k8s.io/apiserver/pkg/endpoints.APIInstaller.Install
/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs...
With
Requ
estIn
fo
ctx.RequestInfo
RestfulhttpAPI
mux
k8s.io/apiserver/pkg/endpoints.APIGroupVersion.InstallREST
AddSupportedResourcesWebService – /apis/batch/v2alpha1
k8s.io/apiserver/pkg/endpoints.APIInstaller.Install/apis/batch/v2alpha1/jobs/apis/batch/v2alpha1/cronjobs...
pkg/apis/batchtype Jobsstruct
pkg/apis/batch/v2alpha1type Jobsstruct
api.Schemek8s.io/apiserver
pkg/api api.Scheme.Convert(&internalJob,&v2alohaJob)
/apis/batch/v2alpha1/jobsGETPUTPOSTDELETE...
/status/scale/proxy...
subresources
RestfulhttpAPI
mux
pkg/apis/batchtype Jobsstruct
pkg/apis/batch/v2alpha1type Jobsstruct
api.Scheme api.Scheme.Convert(&job,&v1job)
POST/apis/batch/v2alpha1/jobs
k8s.io/apiserverpkg/endpoints/handlers.CreateNamedResource
binaryJSON
payload
Gostructv2alpha1.Job
HTTPRequest
Gostructinternal.Job
Storek8s.io/apiserver
pkg/registry/generic
Storagek8s.io/apiserverpkg/storage/etcd3
ProtoBufJob
Gostructv2alpha1.Job
etcd
type Scheme struct• AddKnownTypes(gv, obj Object) • Default(src Object)• Copy(src Object) Object• Convert(in, out interface{})• New(gvk) Object
ApiGrouppkg/apis/batchpkg/apis/batch/v1pkg/apis/batch/v2alpha1pkg/apis/batch/register.gopgk/apis/batch/install
GroupVersionKindResource
type Object interface• GetObjectKind() string
client-go/pkg/api.Schemeclient-go/pkg/api.Codecs
Discoverytype APIGroupList structtype APIVersions structtype APIResourceList struct
GroupVersionKind „gvk“GroupVersionResource
Unversioned typesUnstructuredList
Registry / Storagetype Storage interfacetype Lister interfacetype Updater interfacetype Getter interfacetype Deleter interface....
deepcopy-genconversion-gendefaulting-gen
Code Generation
type OwnerReference structtype ObjectReference structtype TypeMeta structtype ObjectMeta struct
Meta
api.Schemeapi.Codecsapi.Registryapi.GroupFactoryRegistry
Globals