mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Fixes golint errors in pkg/api
This commit is contained in:
parent
c25f44c137
commit
780c441d19
@ -42,6 +42,8 @@ func init() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddKnownTypes registers the types of the arguments to the marshaller of the package api.
|
||||||
|
// Encode() refuses the object unless its type is registered with AddKnownTypes.
|
||||||
func AddKnownTypes(types ...interface{}) {
|
func AddKnownTypes(types ...interface{}) {
|
||||||
for _, obj := range types {
|
for _, obj := range types {
|
||||||
t := reflect.TypeOf(obj)
|
t := reflect.TypeOf(obj)
|
||||||
@ -49,14 +51,14 @@ func AddKnownTypes(types ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes an arbitary api type, returns pointer to its JSONBase field.
|
// FindJSONBase takes an arbitary api type, returns pointer to its JSONBase field.
|
||||||
// obj must be a pointer to an api type.
|
// obj must be a pointer to an api type.
|
||||||
func FindJSONBase(obj interface{}) (*JSONBase, error) {
|
func FindJSONBase(obj interface{}) (*JSONBase, error) {
|
||||||
_, jsonBase, err := nameAndJSONBase(obj)
|
_, jsonBase, err := nameAndJSONBase(obj)
|
||||||
return jsonBase, err
|
return jsonBase, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes an arbitary api type, return a copy of its JSONBase field.
|
// FindJSONBaseRO takes an arbitary api type, return a copy of its JSONBase field.
|
||||||
// obj may be a pointer to an api type, or a non-pointer struct api type.
|
// obj may be a pointer to an api type, or a non-pointer struct api type.
|
||||||
func FindJSONBaseRO(obj interface{}) (JSONBase, error) {
|
func FindJSONBaseRO(obj interface{}) (JSONBase, error) {
|
||||||
v := reflect.ValueOf(obj)
|
v := reflect.ValueOf(obj)
|
||||||
@ -141,7 +143,7 @@ func Decode(data []byte) (interface{}, error) {
|
|||||||
// yaml is a superset of json, so we use it to decode here. That way, we understand both.
|
// yaml is a superset of json, so we use it to decode here. That way, we understand both.
|
||||||
err := yaml.Unmarshal(data, &findKind)
|
err := yaml.Unmarshal(data, &findKind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Couldn't get kind: %#v", err)
|
return nil, fmt.Errorf("couldn't get kind: %#v", err)
|
||||||
}
|
}
|
||||||
objType, found := knownTypes[findKind.Kind]
|
objType, found := knownTypes[findKind.Kind]
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -153,8 +153,10 @@ type JSONBase struct {
|
|||||||
ResourceVersion uint64 `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
ResourceVersion uint64 `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PodStatus represents a status of a pod.
|
||||||
type PodStatus string
|
type PodStatus string
|
||||||
|
|
||||||
|
// These are the valid statuses of pods.
|
||||||
const (
|
const (
|
||||||
PodRunning PodStatus = "Running"
|
PodRunning PodStatus = "Running"
|
||||||
PodPending PodStatus = "Pending"
|
PodPending PodStatus = "Pending"
|
||||||
@ -179,6 +181,7 @@ type PodState struct {
|
|||||||
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PodList is a list of Pods.
|
||||||
type PodList struct {
|
type PodList struct {
|
||||||
JSONBase `json:",inline" yaml:",inline"`
|
JSONBase `json:",inline" yaml:",inline"`
|
||||||
Items []Pod `json:"items" yaml:"items,omitempty"`
|
Items []Pod `json:"items" yaml:"items,omitempty"`
|
||||||
@ -199,6 +202,7 @@ type ReplicationControllerState struct {
|
|||||||
PodTemplate PodTemplate `json:"podTemplate,omitempty" yaml:"podTemplate,omitempty"`
|
PodTemplate PodTemplate `json:"podTemplate,omitempty" yaml:"podTemplate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReplicationControllerList is a collection of replication controllers.
|
||||||
type ReplicationControllerList struct {
|
type ReplicationControllerList struct {
|
||||||
JSONBase `json:",inline" yaml:",inline"`
|
JSONBase `json:",inline" yaml:",inline"`
|
||||||
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
|
Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"`
|
||||||
@ -223,7 +227,7 @@ type ServiceList struct {
|
|||||||
Items []Service `json:"items" yaml:"items"`
|
Items []Service `json:"items" yaml:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines a service abstraction by a name (for example, mysql) consisting of local port
|
// Service is a named abstraction of software service (for example, mysql) consisting of local port
|
||||||
// (for example 3306) that the proxy listens on, and the selector that determines which pods
|
// (for example 3306) that the proxy listens on, and the selector that determines which pods
|
||||||
// will answer requests sent through the proxy.
|
// will answer requests sent through the proxy.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
@ -238,22 +242,22 @@ type Service struct {
|
|||||||
CreateExternalLoadBalancer bool `json:"createExternalLoadBalancer,omitempty" yaml:"createExternalLoadBalancer,omitempty"`
|
CreateExternalLoadBalancer bool `json:"createExternalLoadBalancer,omitempty" yaml:"createExternalLoadBalancer,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines the endpoints that implement the actual service, for example:
|
// Endpoints is a collection of endpoints that implement the actual service, for example:
|
||||||
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
|
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
|
||||||
type Endpoints struct {
|
type Endpoints struct {
|
||||||
Name string
|
Name string
|
||||||
Endpoints []string
|
Endpoints []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information about a single Minion; the name of the minion according to etcd
|
// Minion is a worker node in Kubernetenes.
|
||||||
// is in JSONBase.ID.
|
// The name of the minion according to etcd is in JSONBase.ID.
|
||||||
type Minion struct {
|
type Minion struct {
|
||||||
JSONBase `json:",inline" yaml:",inline"`
|
JSONBase `json:",inline" yaml:",inline"`
|
||||||
// Queried from cloud provider, if available.
|
// Queried from cloud provider, if available.
|
||||||
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A list of minions.
|
// MinionList is a list of minions.
|
||||||
type MinionList struct {
|
type MinionList struct {
|
||||||
JSONBase `json:",inline" yaml:",inline"`
|
JSONBase `json:",inline" yaml:",inline"`
|
||||||
Items []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
|
Items []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
|
||||||
@ -282,12 +286,12 @@ const (
|
|||||||
StatusWorking = "working"
|
StatusWorking = "working"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Operation information, as delivered to API clients.
|
// ServerOp is an operation delivered to API clients.
|
||||||
type ServerOp struct {
|
type ServerOp struct {
|
||||||
JSONBase `yaml:",inline" json:",inline"`
|
JSONBase `yaml:",inline" json:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operation list, as delivered to API clients.
|
// ServerOpList is a list of operations, as delivered to API clients.
|
||||||
type ServerOpList struct {
|
type ServerOpList struct {
|
||||||
JSONBase `yaml:",inline" json:",inline"`
|
JSONBase `yaml:",inline" json:",inline"`
|
||||||
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
|
Items []ServerOp `yaml:"items,omitempty" json:"items,omitempty"`
|
||||||
|
@ -24,19 +24,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
supportedManifestVersions util.StringSet = util.NewStringSet("v1beta1", "v1beta2")
|
supportedManifestVersions = util.NewStringSet("v1beta1", "v1beta2")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validation errors.
|
// ValidationErrorEnum is a type of validation error.
|
||||||
type ValidationErrorEnum string
|
type ValidationErrorEnum string
|
||||||
|
|
||||||
|
// These are known errors of validation.
|
||||||
const (
|
const (
|
||||||
ErrTypeInvalid ValidationErrorEnum = "invalid value"
|
ErrTypeInvalid ValidationErrorEnum = "invalid value"
|
||||||
ErrTypeNotSupported ValidationErrorEnum = "unsupported value"
|
ErrTypeNotSupported ValidationErrorEnum = "unsupported value"
|
||||||
ErrTypeDuplicate ValidationErrorEnum = "duplicate value"
|
ErrTypeDuplicate ValidationErrorEnum = "duplicate value"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Implements the 'error' interface.
|
// ValidationError is an implementation of the 'error' interface, which represents an error of validation.
|
||||||
type ValidationError struct {
|
type ValidationError struct {
|
||||||
ErrorType ValidationErrorEnum
|
ErrorType ValidationErrorEnum
|
||||||
ErrorField string
|
ErrorField string
|
||||||
|
Loading…
Reference in New Issue
Block a user