目前该源码部分已全部转移至
https://github.com/kubernetes/apimachinery
具体可参考 https://www.cnblogs.com/aozhejin/p/16287804.html
Scheme, typing, encoding, decoding, and conversion packages for Kubernetes and Kubernetes-like API objects. apimachinery包含Kubernetes和类似Kubernetes的API对象的Scheme、typing、编码、解码和转换包。 该项目是由sig-api-machinery sig组来维护, 该sig组也维护很多其他项目. https://github.com/kubernetes/community/tree/master/sig-api-machinery 页面介绍该sig组的情况和项目 也请参看: https://www.cnblogs.com/aozhejin/p/16297616.html
翻看kubernetes代码会发现,apimachinery出现的地方只有这么两个地方,这样也比较好找和认识apimachinery的作用和测试.
目录为: E:\k8s源码\v1.19.0\kubernetes-1.19.0\vendor\k8s.io\apimachinery实际指向的是
E:\k8s源码\kubernetes-1.18.0\kubernetes-1.18.0\staging\src\k8s.io\apimachinery
注: 大量的代码会引用这个部分......
E:\k8s源码\v1.19.0\kubernetes-1.19.0\vendor\k8s.io\apimachinery\pkg\apis\meta\v1\meta.go
//核心接口
// Object lets you work with object metadata from any of the versioned or internal API objects. //Attempting to set or retrieve a field on an object that does not support that field (Name, UID, Namespace on lists) will be a no-op and return // a default value. type Object interface { GetNamespace() string SetNamespace(namespace string) GetName() string SetName(name string) GetGenerateName() string SetGenerateName(name string) GetUID() types.UID SetUID(uid types.UID) GetResourceVersion() string SetResourceVersion(version string) GetGeneration() int64 SetGeneration(generation int64) GetSelfLink() string SetSelfLink(selfLink string) GetCreationTimestamp() Time SetCreationTimestamp(timestamp Time) GetDeletionTimestamp() *Time SetDeletionTimestamp(timestamp *Time) GetDeletionGracePeriodSeconds() *int64 SetDeletionGracePeriodSeconds(*int64) GetLabels() map[string]string SetLabels(labels map[string]string) GetAnnotations() map[string]string SetAnnotations(annotations map[string]string) GetFinalizers() []string SetFinalizers(finalizers []string) GetOwnerReferences() []OwnerReference SetOwnerReferences([]OwnerReference) GetClusterName() string SetClusterName(clusterName string) GetManagedFields() []ManagedFieldsEntry SetManagedFields(managedFields []ManagedFieldsEntry) } type Common interface { GetResourceVersion() string SetResourceVersion(version string) GetSelfLink() string SetSelfLink(selfLink string) } type ListInterface interface { GetResourceVersion() string SetResourceVersion(version string) GetSelfLink() string SetSelfLink(selfLink string) GetContinue() string SetContinue(c string) GetRemainingItemCount() *int64 SetRemainingItemCount(c *int64) } type Type interface { GetAPIVersion() string SetAPIVersion(version string) GetKind() string SetKind(kind string) }
E:\k8s源码\v1.19.0\kubernetes-1.19.0\vendor\k8s.io\apimachinery\pkg\apis\meta\v1\types.go
package v1 import ( "fmt" "strings" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" ) type TypeMeta struct { Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"` } type ListMeta struct { SelfLink string `json:"selfLink,omitempty" protobuf:"bytes,1,opt,name=selfLink"` ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes,2,opt,name=resourceVersion"` Continue string `json:"continue,omitempty" protobuf:"bytes,3,opt,name=continue"` RemainingItemCount *int64 `json:"remainingItemCount,omitempty" protobuf:"bytes,4,opt,name=remainingItemCount"` } type ObjectMeta struct { Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` GenerateName string `json:"generateName,omitempty" protobuf:"bytes,2,opt,name=generateName"` Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"` SelfLink string `json:"selfLink,omitempty" protobuf:"bytes,4,opt,name=selfLink"` UID types.UID `json:"uid,omitempty" protobuf:"bytes,5,opt,name=uid,casttype=k8s.io/kubernetes/pkg/types.UID"` ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes,6,opt,name=resourceVersion"` CreationTimestamp Time `json:"creationTimestamp,omitempty" protobuf:"bytes,8,opt,name=creationTimestamp"` DeletionTimestamp *Time `json:"deletionTimestamp,omitempty" protobuf:"bytes,9,opt,name=deletionTimestamp"` DeletionGracePeriodSeconds *int64 `json:"deletionGracePeriodSeconds,omitempty" protobuf:"varint,10,opt,name=deletionGracePeriodSeconds"` Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"` Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"` OwnerReferences []OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid" protobuf:"bytes,13,rep,name=ownerReferences"` Finalizers []string `json:"finalizers,omitempty" patchStrategy:"merge" protobuf:"bytes,14,rep,name=finalizers"` ClusterName string `json:"clusterName,omitempty" protobuf:"bytes,15,opt,name=clusterName"` ManagedFields []ManagedFieldsEntry `json:"managedFields,omitempty" protobuf:"bytes,17,rep,name=managedFields"` } type OwnerReference struct { // API version of the referent. APIVersion string `json:"apiVersion" protobuf:"bytes,5,opt,name=apiVersion"` // Kind of the referent. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds Kind string `json:"kind" protobuf:"bytes,1,opt,name=kind"` // Name of the referent. // More info: http://kubernetes.io/docs/user-guide/identifiers#names Name string `json:"name" protobuf:"bytes,3,opt,name=name"` // UID of the referent. // More info: http://kubernetes.io/docs/user-guide/identifiers#uids UID types.UID `json:"uid" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/apimachinery/pkg/types.UID"` Controller *bool `json:"controller,omitempty" protobuf:"varint,6,opt,name=controller"` BlockOwnerDeletion *bool `json:"blockOwnerDeletion,omitempty" protobuf:"varint,7,opt,name=blockOwnerDeletion"` } // ListOptions is the query options to a standard REST list call. type ListOptions struct {...} // DeleteOptions may be provided when deleting an API object. type DeleteOptions struct {....} // CreateOptions may be provided when creating an API object. type CreateOptions struct { TypeMeta `json:",inline"` DryRun []string `json:"dryRun,omitempty" protobuf:"bytes,1,rep,name=dryRun"` FieldManager string `json:"fieldManager,omitempty" protobuf:"bytes,3,name=fieldManager"` } // UpdateOptions may be provided when updating an API object. // All fields in UpdateOptions should also be present in PatchOptions. type UpdateOptions struct { TypeMeta `json:",inline"` DryRun []string `json:"dryRun,omitempty" protobuf:"bytes,1,rep,name=dryRun"` FieldManager string `json:"fieldManager,omitempty" protobuf:"bytes,2,name=fieldManager"` } // Status is a return value for calls that don't return other objects. type Status struct { TypeMeta `json:",inline"` // Standard list metadata. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds // +optional ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // Status of the operation. // One of: "Success" or "Failure". // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status // +optional Status string `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"` // A human-readable description of the status of this operation. // +optional Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"` // A machine-readable description of why this operation is in the // "Failure" status. If this value is empty there // is no information available. A Reason clarifies an HTTP status // code but does not override it. // +optional Reason StatusReason `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason,casttype=StatusReason"` // Extended data associated with the reason. Each reason may define its // own extended details. This field is optional and the data returned // is not guaranteed to conform to any schema except that defined by // the reason type. // +optional Details *StatusDetails `json:"details,omitempty" protobuf:"bytes,5,opt,name=details"` // Suggested HTTP return code for this status, 0 if not set. // +optional Code int32 `json:"code,omitempty" protobuf:"varint,6,opt,name=code"` } // List holds a list of objects, which may not be known by the server. type List struct {...} type APIVersions struct {...} // APIGroup contains the name, the supported versions, and the preferred version // of a group. type APIGroup struct {...} // GroupVersion contains the "group/version" and "version" string of a version. // It is made a struct to keep extensibility. type GroupVersionForDiscovery struct { // groupVersion specifies the API group and version in the form "group/version" GroupVersion string `json:"groupVersion" protobuf:"bytes,1,opt,name=groupVersion"` // version specifies the version in the form of "version". This is to save // the clients the trouble of splitting the GroupVersion. Version string `json:"version" protobuf:"bytes,2,opt,name=version"` }
apimachinery metav1 —— API 结构体的基础设施
runtime.Object是所有API单体对象的根类(interface);
schema.ObjectKind是对API对象类型的抽象(interface);
metav1.Object是对API对象公共属性的抽象(interface);
metav1.ListInterface是对API对象列表公共属性的抽象(interface);
metav1.TypeMeta是schema.ObjectKind的一个实现,API对象类型继承之;
metav1.ObjectMeta是metav1.Object的一个实现,API对象类型继承之;
metav1.ListMeta是metav1.ListInterface的一个实现,API对象列表继承之;
type TypeMeta struct { // Kind 是一个字符串值,表示此对象所代表的 REST 资源。//服务器可以从客户端向其提交请求的端点推断出这一点。//无法更新。 Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` // APIVersion定义对象表示的版本化架构。服务器应将已识别的架构转换为最新的内部值,并且可能会拒绝未识别的值。 APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"` }
标签:apimachinery,omitempty,string,protobuf,bytes,json,源码,k8s,name From: https://www.cnblogs.com/aozhejin/p/16284228.html