Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3fba3629
Commit
3fba3629
authored
Sep 07, 2018
by
Prasad Ghangal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/api: Fix golint errors
parent
5c8ef7eb
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
50 additions
and
53 deletions
+50
-53
.golint_failures
hack/.golint_failures
+0
-8
util.go
pkg/api/endpoints/util.go
+7
-6
ref.go
pkg/api/ref/ref.go
+3
-3
testapi.go
pkg/api/testapi/testapi.go
+11
-7
compatibility_tester.go
pkg/api/testing/compat/compatibility_tester.go
+1
-2
conversion.go
pkg/api/testing/conversion.go
+1
-1
fuzzer.go
pkg/api/testing/fuzzer.go
+1
-0
serialization_test.go
pkg/api/testing/serialization_test.go
+2
-2
util.go
pkg/api/v1/endpoints/util.go
+7
-6
util.go
pkg/api/v1/pod/util.go
+16
-17
helpers.go
pkg/api/v1/resource/helpers.go
+1
-1
No files found.
hack/.golint_failures
View file @
3fba3629
...
...
@@ -13,14 +13,6 @@ cmd/kubeadm/app/util/system
cmd/kubelet/app
cmd/kubelet/app/options
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/latest
pkg/apis/abac/v0
...
...
pkg/api/endpoints/util.go
View file @
3fba3629
...
...
@@ -171,6 +171,7 @@ func (sl addrsReady) Less(i, j int) bool {
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
{
ipComparison
:=
bytes
.
Compare
([]
byte
(
a
.
IP
),
[]
byte
(
b
.
IP
))
if
ipComparison
!=
0
{
...
...
@@ -190,8 +191,8 @@ func LessEndpointAddress(a, b *api.EndpointAddress) bool {
func
SortSubsets
(
subsets
[]
api
.
EndpointSubset
)
[]
api
.
EndpointSubset
{
for
i
:=
range
subsets
{
ss
:=
&
subsets
[
i
]
sort
.
Sort
(
addrsByI
p
AndUID
(
ss
.
Addresses
))
sort
.
Sort
(
addrsByI
p
AndUID
(
ss
.
NotReadyAddresses
))
sort
.
Sort
(
addrsByI
P
AndUID
(
ss
.
Addresses
))
sort
.
Sort
(
addrsByI
P
AndUID
(
ss
.
NotReadyAddresses
))
sort
.
Sort
(
portsByHash
(
ss
.
Ports
))
}
sort
.
Sort
(
subsetsByHash
(
subsets
))
...
...
@@ -214,11 +215,11 @@ func (sl subsetsByHash) Less(i, j int) bool {
return
bytes
.
Compare
(
h1
,
h2
)
<
0
}
type
addrsByI
p
AndUID
[]
api
.
EndpointAddress
type
addrsByI
P
AndUID
[]
api
.
EndpointAddress
func
(
sl
addrsByI
p
AndUID
)
Len
()
int
{
return
len
(
sl
)
}
func
(
sl
addrsByI
p
AndUID
)
Swap
(
i
,
j
int
)
{
sl
[
i
],
sl
[
j
]
=
sl
[
j
],
sl
[
i
]
}
func
(
sl
addrsByI
p
AndUID
)
Less
(
i
,
j
int
)
bool
{
func
(
sl
addrsByI
P
AndUID
)
Len
()
int
{
return
len
(
sl
)
}
func
(
sl
addrsByI
P
AndUID
)
Swap
(
i
,
j
int
)
{
sl
[
i
],
sl
[
j
]
=
sl
[
j
],
sl
[
i
]
}
func
(
sl
addrsByI
P
AndUID
)
Less
(
i
,
j
int
)
bool
{
return
LessEndpointAddress
(
&
sl
[
i
],
&
sl
[
j
])
}
...
...
pkg/api/ref/ref.go
View file @
3fba3629
...
...
@@ -28,8 +28,8 @@ import (
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Errors that could be returned by GetReference.
var
(
// Errors that could be returned by GetReference.
ErrNilObject
=
errors
.
New
(
"can't reference a nil object"
)
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
{
return
nil
,
ErrNoSelfLink
}
selfLinkU
rl
,
err
:=
url
.
Parse
(
selfLink
)
selfLinkU
RL
,
err
:=
url
.
Parse
(
selfLink
)
if
err
!=
nil
{
return
nil
,
err
}
// example paths: /<prefix>/<version>/*
parts
:=
strings
.
Split
(
selfLinkU
rl
.
Path
,
"/"
)
parts
:=
strings
.
Split
(
selfLinkU
RL
.
Path
,
"/"
)
if
len
(
parts
)
<
3
{
return
nil
,
fmt
.
Errorf
(
"unexpected self link format: '%v'; got version '%v'"
,
selfLink
,
version
)
}
...
...
pkg/api/testapi/testapi.go
View file @
3fba3629
...
...
@@ -53,6 +53,7 @@ import (
"k8s.io/kubernetes/pkg/apis/settings"
"k8s.io/kubernetes/pkg/apis/storage"
// Initialize install packages
_
"k8s.io/kubernetes/pkg/apis/admission/install"
_
"k8s.io/kubernetes/pkg/apis/admissionregistration/install"
_
"k8s.io/kubernetes/pkg/apis/apps/install"
...
...
@@ -74,6 +75,7 @@ import (
_
"k8s.io/kubernetes/pkg/apis/storage/install"
)
// Variables to store GroupName
var
(
Groups
=
make
(
map
[
string
]
TestGroup
)
Default
TestGroup
...
...
@@ -90,6 +92,7 @@ var (
storageSerializer
runtime
.
SerializerInfo
)
// TestGroup contains GroupVersion to uniquely identify the API
type
TestGroup
struct
{
externalGroupVersion
schema
.
GroupVersion
}
...
...
@@ -276,6 +279,7 @@ func init() {
Admission
=
Groups
[
admission
.
GroupName
]
}
// GroupVersion makes copy of schema.GroupVersion
func
(
g
TestGroup
)
GroupVersion
()
*
schema
.
GroupVersion
{
copyOfGroupVersion
:=
g
.
externalGroupVersion
return
&
copyOfGroupVersion
...
...
@@ -290,6 +294,7 @@ func (g TestGroup) Codec() runtime.Codec {
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
{
return
os
.
Getenv
(
"KUBE_TEST_API_STORAGE_TYPE"
)
}
...
...
@@ -322,14 +327,13 @@ func (g TestGroup) SelfLink(resource, name string) string {
return
fmt
.
Sprintf
(
"/api/%s/%s"
,
g
.
externalGroupVersion
.
Version
,
resource
)
}
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
// support
if
name
==
""
{
return
fmt
.
Sprintf
(
"/apis/%s/%s/%s"
,
g
.
externalGroupVersion
.
Group
,
g
.
externalGroupVersion
.
Version
,
resource
)
}
return
fmt
.
Sprintf
(
"/apis/%s/%s/%s/%s"
,
g
.
externalGroupVersion
.
Group
,
g
.
externalGroupVersion
.
Version
,
resource
,
name
)
}
// TODO: will need a /apis prefix once we have proper multi-group
// support
if
name
==
""
{
return
fmt
.
Sprintf
(
"/apis/%s/%s/%s"
,
g
.
externalGroupVersion
.
Group
,
g
.
externalGroupVersion
.
Version
,
resource
)
}
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.
...
...
pkg/api/testing/compat/compatibility_tester.go
View file @
3fba3629
...
...
@@ -31,11 +31,10 @@ import (
"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
// version and checks for the presence of the expected keys and absent
// keys in the resulting JSON.
// Based on: https://github.com/openshift/origin/blob/master/pkg/api/compatibility_test.go
func
TestCompatibility
(
t
*
testing
.
T
,
version
schema
.
GroupVersion
,
...
...
pkg/api/testing/conversion.go
View file @
3fba3629
...
...
@@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
)
// TestSelectableFieldLabelConversions verifies that given resource have field
// TestSelectableFieldLabelConversions
OfKind
verifies that given resource have field
// label conversion defined for each its selectable field.
// fields contains selectable fields of the resource.
// labelMap maps deprecated labels to their canonical names.
...
...
pkg/api/testing/fuzzer.go
View file @
3fba3629
...
...
@@ -88,6 +88,7 @@ func overrideGenericFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
}
}
// FuzzerFuncs is a list of fuzzer functions
var
FuzzerFuncs
=
fuzzer
.
MergeFuzzerFuncs
(
genericfuzzer
.
Funcs
,
overrideGenericFuncs
,
...
...
pkg/api/testing/serialization_test.go
View file @
3fba3629
...
...
@@ -65,7 +65,7 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
return
item
}
func
Convert
_v1beta1_ReplicaSet_to_api_
ReplicationController
(
in
*
v1beta1
.
ReplicaSet
,
out
*
api
.
ReplicationController
,
s
conversion
.
Scope
)
error
{
func
Convert
V1beta1ReplicaSetToAPI
ReplicationController
(
in
*
v1beta1
.
ReplicaSet
,
out
*
api
.
ReplicationController
,
s
conversion
.
Scope
)
error
{
intermediate1
:=
&
extensions
.
ReplicaSet
{}
if
err
:=
k8s_v1beta1
.
Convert_v1beta1_ReplicaSet_To_extensions_ReplicaSet
(
in
,
intermediate1
,
s
);
err
!=
nil
{
return
err
...
...
@@ -80,7 +80,7 @@ func Convert_v1beta1_ReplicaSet_to_api_ReplicationController(in *v1beta1.Replica
}
func
TestSetControllerConversion
(
t
*
testing
.
T
)
{
if
err
:=
legacyscheme
.
Scheme
.
AddConversionFuncs
(
Convert
_v1beta1_ReplicaSet_to_api_
ReplicationController
);
err
!=
nil
{
if
err
:=
legacyscheme
.
Scheme
.
AddConversionFuncs
(
Convert
V1beta1ReplicaSetToAPI
ReplicationController
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
pkg/api/v1/endpoints/util.go
View file @
3fba3629
...
...
@@ -172,6 +172,7 @@ func (sl addrsReady) Less(i, j int) bool {
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
{
ipComparison
:=
bytes
.
Compare
([]
byte
(
a
.
IP
),
[]
byte
(
b
.
IP
))
if
ipComparison
!=
0
{
...
...
@@ -191,8 +192,8 @@ func LessEndpointAddress(a, b *v1.EndpointAddress) bool {
func
SortSubsets
(
subsets
[]
v1
.
EndpointSubset
)
[]
v1
.
EndpointSubset
{
for
i
:=
range
subsets
{
ss
:=
&
subsets
[
i
]
sort
.
Sort
(
addrsByI
p
AndUID
(
ss
.
Addresses
))
sort
.
Sort
(
addrsByI
p
AndUID
(
ss
.
NotReadyAddresses
))
sort
.
Sort
(
addrsByI
P
AndUID
(
ss
.
Addresses
))
sort
.
Sort
(
addrsByI
P
AndUID
(
ss
.
NotReadyAddresses
))
sort
.
Sort
(
portsByHash
(
ss
.
Ports
))
}
sort
.
Sort
(
subsetsByHash
(
subsets
))
...
...
@@ -215,11 +216,11 @@ func (sl subsetsByHash) Less(i, j int) bool {
return
bytes
.
Compare
(
h1
,
h2
)
<
0
}
type
addrsByI
p
AndUID
[]
v1
.
EndpointAddress
type
addrsByI
P
AndUID
[]
v1
.
EndpointAddress
func
(
sl
addrsByI
p
AndUID
)
Len
()
int
{
return
len
(
sl
)
}
func
(
sl
addrsByI
p
AndUID
)
Swap
(
i
,
j
int
)
{
sl
[
i
],
sl
[
j
]
=
sl
[
j
],
sl
[
i
]
}
func
(
sl
addrsByI
p
AndUID
)
Less
(
i
,
j
int
)
bool
{
func
(
sl
addrsByI
P
AndUID
)
Len
()
int
{
return
len
(
sl
)
}
func
(
sl
addrsByI
P
AndUID
)
Swap
(
i
,
j
int
)
{
sl
[
i
],
sl
[
j
]
=
sl
[
j
],
sl
[
i
]
}
func
(
sl
addrsByI
P
AndUID
)
Less
(
i
,
j
int
)
bool
{
return
LessEndpointAddress
(
&
sl
[
i
],
&
sl
[
j
])
}
...
...
pkg/api/v1/pod/util.go
View file @
3fba3629
...
...
@@ -238,13 +238,13 @@ func IsPodReady(pod *v1.Pod) bool {
return
IsPodReadyConditionTrue
(
pod
.
Status
)
}
// IsPodReady returns true if a pod is ready; false otherwise.
// IsPodReady
ConditionTrue
returns true if a pod is ready; false otherwise.
func
IsPodReadyConditionTrue
(
status
v1
.
PodStatus
)
bool
{
condition
:=
GetPodReadyCondition
(
status
)
return
condition
!=
nil
&&
condition
.
Status
==
v1
.
ConditionTrue
}
//
E
xtracts the pod ready condition from the given status and returns that.
//
GetPodReadyCondition e
xtracts the pod ready condition from the given status and returns that.
// Returns nil if the condition is not present.
func
GetPodReadyCondition
(
status
v1
.
PodStatus
)
*
v1
.
PodCondition
{
_
,
condition
:=
GetPodCondition
(
&
status
,
v1
.
PodReady
)
...
...
@@ -274,7 +274,7 @@ func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodC
return
-
1
,
nil
}
// Updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the
// Update
PodCondition update
s existing pod condition or creates a new one. Sets LastTransitionTime to now if the
// status has changed.
// Returns true if pod condition has changed or has been added.
func
UpdatePodCondition
(
status
*
v1
.
PodStatus
,
condition
*
v1
.
PodCondition
)
bool
{
...
...
@@ -286,20 +286,19 @@ func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
// We are adding new pod condition.
status
.
Conditions
=
append
(
status
.
Conditions
,
*
condition
)
return
true
}
else
{
// We are updating an existing condition, so we need to check if it has changed.
if
condition
.
Status
==
oldCondition
.
Status
{
condition
.
LastTransitionTime
=
oldCondition
.
LastTransitionTime
}
}
// We are updating an existing condition, so we need to check if it has changed.
if
condition
.
Status
==
oldCondition
.
Status
{
condition
.
LastTransitionTime
=
oldCondition
.
LastTransitionTime
}
isEqual
:=
condition
.
Status
==
oldCondition
.
Status
&&
condition
.
Reason
==
oldCondition
.
Reason
&&
condition
.
Message
==
oldCondition
.
Message
&&
condition
.
LastProbeTime
.
Equal
(
&
oldCondition
.
LastProbeTime
)
&&
condition
.
LastTransitionTime
.
Equal
(
&
oldCondition
.
LastTransitionTime
)
isEqual
:=
condition
.
Status
==
oldCondition
.
Status
&&
condition
.
Reason
==
oldCondition
.
Reason
&&
condition
.
Message
==
oldCondition
.
Message
&&
condition
.
LastProbeTime
.
Equal
(
&
oldCondition
.
LastProbeTime
)
&&
condition
.
LastTransitionTime
.
Equal
(
&
oldCondition
.
LastTransitionTime
)
status
.
Conditions
[
conditionIndex
]
=
*
condition
// Return true if one of the fields have changed.
return
!
isEqual
}
status
.
Conditions
[
conditionIndex
]
=
*
condition
// Return true if one of the fields have changed.
return
!
isEqual
}
pkg/api/v1/resource/helpers.go
View file @
3fba3629
...
...
@@ -68,7 +68,7 @@ func PodRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList) {
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
{
if
resource
==
v1
.
ResourcePods
{
return
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment