mirror of https://github.com/k3s-io/k3s
pkg/api: Fix golint errors
parent
5c8ef7eb3b
commit
3fba36291c
|
@ -13,14 +13,6 @@ cmd/kubeadm/app/util/system
|
||||||
cmd/kubelet/app
|
cmd/kubelet/app
|
||||||
cmd/kubelet/app/options
|
cmd/kubelet/app/options
|
||||||
cmd/kubemark
|
cmd/kubemark
|
||||||
pkg/api/endpoints
|
|
||||||
pkg/api/ref
|
|
||||||
pkg/api/testapi
|
|
||||||
pkg/api/testing
|
|
||||||
pkg/api/testing/compat
|
|
||||||
pkg/api/v1/endpoints
|
|
||||||
pkg/api/v1/pod
|
|
||||||
pkg/api/v1/resource
|
|
||||||
pkg/apis/abac
|
pkg/apis/abac
|
||||||
pkg/apis/abac/latest
|
pkg/apis/abac/latest
|
||||||
pkg/apis/abac/v0
|
pkg/apis/abac/v0
|
||||||
|
|
|
@ -171,6 +171,7 @@ func (sl addrsReady) Less(i, j int) bool {
|
||||||
return lessAddrReady(sl[i], sl[j])
|
return lessAddrReady(sl[i], sl[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LessEndpointAddress compares IP addresses lexicographically and returns true if first argument is lesser than second
|
||||||
func LessEndpointAddress(a, b *api.EndpointAddress) bool {
|
func LessEndpointAddress(a, b *api.EndpointAddress) bool {
|
||||||
ipComparison := bytes.Compare([]byte(a.IP), []byte(b.IP))
|
ipComparison := bytes.Compare([]byte(a.IP), []byte(b.IP))
|
||||||
if ipComparison != 0 {
|
if ipComparison != 0 {
|
||||||
|
@ -190,8 +191,8 @@ func LessEndpointAddress(a, b *api.EndpointAddress) bool {
|
||||||
func SortSubsets(subsets []api.EndpointSubset) []api.EndpointSubset {
|
func SortSubsets(subsets []api.EndpointSubset) []api.EndpointSubset {
|
||||||
for i := range subsets {
|
for i := range subsets {
|
||||||
ss := &subsets[i]
|
ss := &subsets[i]
|
||||||
sort.Sort(addrsByIpAndUID(ss.Addresses))
|
sort.Sort(addrsByIPAndUID(ss.Addresses))
|
||||||
sort.Sort(addrsByIpAndUID(ss.NotReadyAddresses))
|
sort.Sort(addrsByIPAndUID(ss.NotReadyAddresses))
|
||||||
sort.Sort(portsByHash(ss.Ports))
|
sort.Sort(portsByHash(ss.Ports))
|
||||||
}
|
}
|
||||||
sort.Sort(subsetsByHash(subsets))
|
sort.Sort(subsetsByHash(subsets))
|
||||||
|
@ -214,11 +215,11 @@ func (sl subsetsByHash) Less(i, j int) bool {
|
||||||
return bytes.Compare(h1, h2) < 0
|
return bytes.Compare(h1, h2) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type addrsByIpAndUID []api.EndpointAddress
|
type addrsByIPAndUID []api.EndpointAddress
|
||||||
|
|
||||||
func (sl addrsByIpAndUID) Len() int { return len(sl) }
|
func (sl addrsByIPAndUID) Len() int { return len(sl) }
|
||||||
func (sl addrsByIpAndUID) Swap(i, j int) { sl[i], sl[j] = sl[j], sl[i] }
|
func (sl addrsByIPAndUID) Swap(i, j int) { sl[i], sl[j] = sl[j], sl[i] }
|
||||||
func (sl addrsByIpAndUID) Less(i, j int) bool {
|
func (sl addrsByIPAndUID) Less(i, j int) bool {
|
||||||
return LessEndpointAddress(&sl[i], &sl[j])
|
return LessEndpointAddress(&sl[i], &sl[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ import (
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// Errors that could be returned by GetReference.
|
// Errors that could be returned by GetReference.
|
||||||
|
var (
|
||||||
ErrNilObject = errors.New("can't reference a nil object")
|
ErrNilObject = errors.New("can't reference a nil object")
|
||||||
ErrNoSelfLink = errors.New("selfLink was empty, can't make reference")
|
ErrNoSelfLink = errors.New("selfLink was empty, can't make reference")
|
||||||
)
|
)
|
||||||
|
@ -80,12 +80,12 @@ func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*api.ObjectRefere
|
||||||
if len(selfLink) == 0 {
|
if len(selfLink) == 0 {
|
||||||
return nil, ErrNoSelfLink
|
return nil, ErrNoSelfLink
|
||||||
}
|
}
|
||||||
selfLinkUrl, err := url.Parse(selfLink)
|
selfLinkURL, err := url.Parse(selfLink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// example paths: /<prefix>/<version>/*
|
// example paths: /<prefix>/<version>/*
|
||||||
parts := strings.Split(selfLinkUrl.Path, "/")
|
parts := strings.Split(selfLinkURL.Path, "/")
|
||||||
if len(parts) < 3 {
|
if len(parts) < 3 {
|
||||||
return nil, fmt.Errorf("unexpected self link format: '%v'; got version '%v'", selfLink, version)
|
return nil, fmt.Errorf("unexpected self link format: '%v'; got version '%v'", selfLink, version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/apis/settings"
|
"k8s.io/kubernetes/pkg/apis/settings"
|
||||||
"k8s.io/kubernetes/pkg/apis/storage"
|
"k8s.io/kubernetes/pkg/apis/storage"
|
||||||
|
|
||||||
|
// Initialize install packages
|
||||||
_ "k8s.io/kubernetes/pkg/apis/admission/install"
|
_ "k8s.io/kubernetes/pkg/apis/admission/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
|
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
||||||
|
@ -74,6 +75,7 @@ import (
|
||||||
_ "k8s.io/kubernetes/pkg/apis/storage/install"
|
_ "k8s.io/kubernetes/pkg/apis/storage/install"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Variables to store GroupName
|
||||||
var (
|
var (
|
||||||
Groups = make(map[string]TestGroup)
|
Groups = make(map[string]TestGroup)
|
||||||
Default TestGroup
|
Default TestGroup
|
||||||
|
@ -90,6 +92,7 @@ var (
|
||||||
storageSerializer runtime.SerializerInfo
|
storageSerializer runtime.SerializerInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestGroup contains GroupVersion to uniquely identify the API
|
||||||
type TestGroup struct {
|
type TestGroup struct {
|
||||||
externalGroupVersion schema.GroupVersion
|
externalGroupVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
|
@ -276,6 +279,7 @@ func init() {
|
||||||
Admission = Groups[admission.GroupName]
|
Admission = Groups[admission.GroupName]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupVersion makes copy of schema.GroupVersion
|
||||||
func (g TestGroup) GroupVersion() *schema.GroupVersion {
|
func (g TestGroup) GroupVersion() *schema.GroupVersion {
|
||||||
copyOfGroupVersion := g.externalGroupVersion
|
copyOfGroupVersion := g.externalGroupVersion
|
||||||
return ©OfGroupVersion
|
return ©OfGroupVersion
|
||||||
|
@ -290,6 +294,7 @@ func (g TestGroup) Codec() runtime.Codec {
|
||||||
return legacyscheme.Codecs.CodecForVersions(serializer.Serializer, legacyscheme.Codecs.UniversalDeserializer(), schema.GroupVersions{g.externalGroupVersion}, nil)
|
return legacyscheme.Codecs.CodecForVersions(serializer.Serializer, legacyscheme.Codecs.UniversalDeserializer(), schema.GroupVersions{g.externalGroupVersion}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StorageMediaType finds media type set by KUBE_TEST_API_STORAGE_TYPE env var used to store objects in storage
|
||||||
func StorageMediaType() string {
|
func StorageMediaType() string {
|
||||||
return os.Getenv("KUBE_TEST_API_STORAGE_TYPE")
|
return os.Getenv("KUBE_TEST_API_STORAGE_TYPE")
|
||||||
}
|
}
|
||||||
|
@ -322,7 +327,7 @@ func (g TestGroup) SelfLink(resource, name string) string {
|
||||||
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersion.Version, resource)
|
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersion.Version, resource)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersion.Version, resource, name)
|
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersion.Version, resource, name)
|
||||||
} else {
|
}
|
||||||
// TODO: will need a /apis prefix once we have proper multi-group
|
// TODO: will need a /apis prefix once we have proper multi-group
|
||||||
// support
|
// support
|
||||||
if name == "" {
|
if name == "" {
|
||||||
|
@ -330,7 +335,6 @@ func (g TestGroup) SelfLink(resource, name string) string {
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource, name)
|
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource, name)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// ResourcePathWithPrefix returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name.
|
// ResourcePathWithPrefix returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name.
|
||||||
// For ex, this is of the form:
|
// For ex, this is of the form:
|
||||||
|
|
|
@ -31,11 +31,10 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Based on: https://github.com/openshift/origin/blob/master/pkg/api/compatibility_test.go
|
|
||||||
//
|
|
||||||
// TestCompatibility reencodes the input using the codec for the given
|
// TestCompatibility reencodes the input using the codec for the given
|
||||||
// version and checks for the presence of the expected keys and absent
|
// version and checks for the presence of the expected keys and absent
|
||||||
// keys in the resulting JSON.
|
// keys in the resulting JSON.
|
||||||
|
// Based on: https://github.com/openshift/origin/blob/master/pkg/api/compatibility_test.go
|
||||||
func TestCompatibility(
|
func TestCompatibility(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
version schema.GroupVersion,
|
version schema.GroupVersion,
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestSelectableFieldLabelConversions verifies that given resource have field
|
// TestSelectableFieldLabelConversionsOfKind verifies that given resource have field
|
||||||
// label conversion defined for each its selectable field.
|
// label conversion defined for each its selectable field.
|
||||||
// fields contains selectable fields of the resource.
|
// fields contains selectable fields of the resource.
|
||||||
// labelMap maps deprecated labels to their canonical names.
|
// labelMap maps deprecated labels to their canonical names.
|
||||||
|
|
|
@ -88,6 +88,7 @@ func overrideGenericFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FuzzerFuncs is a list of fuzzer functions
|
||||||
var FuzzerFuncs = fuzzer.MergeFuzzerFuncs(
|
var FuzzerFuncs = fuzzer.MergeFuzzerFuncs(
|
||||||
genericfuzzer.Funcs,
|
genericfuzzer.Funcs,
|
||||||
overrideGenericFuncs,
|
overrideGenericFuncs,
|
||||||
|
|
|
@ -65,7 +65,7 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
func Convert_v1beta1_ReplicaSet_to_api_ReplicationController(in *v1beta1.ReplicaSet, out *api.ReplicationController, s conversion.Scope) error {
|
func ConvertV1beta1ReplicaSetToAPIReplicationController(in *v1beta1.ReplicaSet, out *api.ReplicationController, s conversion.Scope) error {
|
||||||
intermediate1 := &extensions.ReplicaSet{}
|
intermediate1 := &extensions.ReplicaSet{}
|
||||||
if err := k8s_v1beta1.Convert_v1beta1_ReplicaSet_To_extensions_ReplicaSet(in, intermediate1, s); err != nil {
|
if err := k8s_v1beta1.Convert_v1beta1_ReplicaSet_To_extensions_ReplicaSet(in, intermediate1, s); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -80,7 +80,7 @@ func Convert_v1beta1_ReplicaSet_to_api_ReplicationController(in *v1beta1.Replica
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetControllerConversion(t *testing.T) {
|
func TestSetControllerConversion(t *testing.T) {
|
||||||
if err := legacyscheme.Scheme.AddConversionFuncs(Convert_v1beta1_ReplicaSet_to_api_ReplicationController); err != nil {
|
if err := legacyscheme.Scheme.AddConversionFuncs(ConvertV1beta1ReplicaSetToAPIReplicationController); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,7 @@ func (sl addrsReady) Less(i, j int) bool {
|
||||||
return lessAddrReady(sl[i], sl[j])
|
return lessAddrReady(sl[i], sl[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LessEndpointAddress compares IP addresses lexicographically and returns true if first argument is lesser than second
|
||||||
func LessEndpointAddress(a, b *v1.EndpointAddress) bool {
|
func LessEndpointAddress(a, b *v1.EndpointAddress) bool {
|
||||||
ipComparison := bytes.Compare([]byte(a.IP), []byte(b.IP))
|
ipComparison := bytes.Compare([]byte(a.IP), []byte(b.IP))
|
||||||
if ipComparison != 0 {
|
if ipComparison != 0 {
|
||||||
|
@ -191,8 +192,8 @@ func LessEndpointAddress(a, b *v1.EndpointAddress) bool {
|
||||||
func SortSubsets(subsets []v1.EndpointSubset) []v1.EndpointSubset {
|
func SortSubsets(subsets []v1.EndpointSubset) []v1.EndpointSubset {
|
||||||
for i := range subsets {
|
for i := range subsets {
|
||||||
ss := &subsets[i]
|
ss := &subsets[i]
|
||||||
sort.Sort(addrsByIpAndUID(ss.Addresses))
|
sort.Sort(addrsByIPAndUID(ss.Addresses))
|
||||||
sort.Sort(addrsByIpAndUID(ss.NotReadyAddresses))
|
sort.Sort(addrsByIPAndUID(ss.NotReadyAddresses))
|
||||||
sort.Sort(portsByHash(ss.Ports))
|
sort.Sort(portsByHash(ss.Ports))
|
||||||
}
|
}
|
||||||
sort.Sort(subsetsByHash(subsets))
|
sort.Sort(subsetsByHash(subsets))
|
||||||
|
@ -215,11 +216,11 @@ func (sl subsetsByHash) Less(i, j int) bool {
|
||||||
return bytes.Compare(h1, h2) < 0
|
return bytes.Compare(h1, h2) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type addrsByIpAndUID []v1.EndpointAddress
|
type addrsByIPAndUID []v1.EndpointAddress
|
||||||
|
|
||||||
func (sl addrsByIpAndUID) Len() int { return len(sl) }
|
func (sl addrsByIPAndUID) Len() int { return len(sl) }
|
||||||
func (sl addrsByIpAndUID) Swap(i, j int) { sl[i], sl[j] = sl[j], sl[i] }
|
func (sl addrsByIPAndUID) Swap(i, j int) { sl[i], sl[j] = sl[j], sl[i] }
|
||||||
func (sl addrsByIpAndUID) Less(i, j int) bool {
|
func (sl addrsByIPAndUID) Less(i, j int) bool {
|
||||||
return LessEndpointAddress(&sl[i], &sl[j])
|
return LessEndpointAddress(&sl[i], &sl[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,13 +238,13 @@ func IsPodReady(pod *v1.Pod) bool {
|
||||||
return IsPodReadyConditionTrue(pod.Status)
|
return IsPodReadyConditionTrue(pod.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPodReady returns true if a pod is ready; false otherwise.
|
// IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
|
||||||
func IsPodReadyConditionTrue(status v1.PodStatus) bool {
|
func IsPodReadyConditionTrue(status v1.PodStatus) bool {
|
||||||
condition := GetPodReadyCondition(status)
|
condition := GetPodReadyCondition(status)
|
||||||
return condition != nil && condition.Status == v1.ConditionTrue
|
return condition != nil && condition.Status == v1.ConditionTrue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracts the pod ready condition from the given status and returns that.
|
// GetPodReadyCondition extracts the pod ready condition from the given status and returns that.
|
||||||
// Returns nil if the condition is not present.
|
// Returns nil if the condition is not present.
|
||||||
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition {
|
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition {
|
||||||
_, condition := GetPodCondition(&status, v1.PodReady)
|
_, condition := GetPodCondition(&status, v1.PodReady)
|
||||||
|
@ -274,7 +274,7 @@ func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodC
|
||||||
return -1, nil
|
return -1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the
|
// UpdatePodCondition updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the
|
||||||
// status has changed.
|
// status has changed.
|
||||||
// Returns true if pod condition has changed or has been added.
|
// Returns true if pod condition has changed or has been added.
|
||||||
func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
|
func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
|
||||||
|
@ -286,7 +286,7 @@ func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
|
||||||
// We are adding new pod condition.
|
// We are adding new pod condition.
|
||||||
status.Conditions = append(status.Conditions, *condition)
|
status.Conditions = append(status.Conditions, *condition)
|
||||||
return true
|
return true
|
||||||
} else {
|
}
|
||||||
// We are updating an existing condition, so we need to check if it has changed.
|
// We are updating an existing condition, so we need to check if it has changed.
|
||||||
if condition.Status == oldCondition.Status {
|
if condition.Status == oldCondition.Status {
|
||||||
condition.LastTransitionTime = oldCondition.LastTransitionTime
|
condition.LastTransitionTime = oldCondition.LastTransitionTime
|
||||||
|
@ -302,4 +302,3 @@ func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
|
||||||
// Return true if one of the fields have changed.
|
// Return true if one of the fields have changed.
|
||||||
return !isEqual
|
return !isEqual
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ func PodRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// finds and returns the request for a specific resource.
|
// GetResourceRequest finds and returns the request for a specific resource.
|
||||||
func GetResourceRequest(pod *v1.Pod, resource v1.ResourceName) int64 {
|
func GetResourceRequest(pod *v1.Pod, resource v1.ResourceName) int64 {
|
||||||
if resource == v1.ResourcePods {
|
if resource == v1.ResourcePods {
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue