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
d0138ca3
Commit
d0138ca3
authored
Feb 23, 2019
by
WanLinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
This commit does two things in pkg package:
1. Remove unused ptr functions. 2. Replace ptr functions with k8s.io/utils/pointer
parent
4a1da48d
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
75 additions
and
97 deletions
+75
-97
BUILD
pkg/apis/auditregistration/validation/BUILD
+1
-0
validation_test.go
pkg/apis/auditregistration/validation/validation_test.go
+17
-18
validation_test.go
pkg/apis/core/validation/validation_test.go
+5
-9
BUILD
pkg/controller/cronjob/BUILD
+1
-0
utils_test.go
pkg/controller/cronjob/utils_test.go
+5
-6
BUILD
pkg/controller/daemon/util/BUILD
+1
-0
daemonset_util_test.go
pkg/controller/daemon/util/daemonset_util_test.go
+5
-9
BUILD
pkg/controller/ttlafterfinished/BUILD
+1
-0
ttlafterfinished_controller_test.go
...ller/ttlafterfinished/ttlafterfinished_controller_test.go
+8
-11
BUILD
pkg/kubectl/BUILD
+1
-0
BUILD
pkg/kubectl/cmd/apply/BUILD
+1
-0
apply_test.go
pkg/kubectl/cmd/apply/apply_test.go
+2
-1
BUILD
pkg/kubectl/cmd/drain/BUILD
+1
-0
drain_test.go
pkg/kubectl/cmd/drain/drain_test.go
+15
-16
util.go
pkg/kubectl/cmd/testing/util.go
+0
-5
describe_test.go
pkg/kubectl/describe/versioned/describe_test.go
+2
-8
rolling_updater.go
pkg/kubectl/rolling_updater.go
+4
-8
BUILD
pkg/proxy/iptables/BUILD
+1
-0
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+3
-6
import-restrictions.yaml
staging/publishing/import-restrictions.yaml
+1
-0
No files found.
pkg/apis/auditregistration/validation/BUILD
View file @
d0138ca3
...
...
@@ -23,6 +23,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/apis/auditregistration/validation/validation_test.go
View file @
d0138ca3
...
...
@@ -24,6 +24,7 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/apis/auditregistration"
utilpointer
"k8s.io/utils/pointer"
)
func
TestValidateAuditSink
(
t
*
testing
.
T
)
{
...
...
@@ -133,8 +134,6 @@ func TestValidatePolicy(t *testing.T) {
}
}
func
strPtr
(
s
string
)
*
string
{
return
&
s
}
func
TestValidateWebhookConfiguration
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
@@ -157,7 +156,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Name
:
"n"
,
Port
:
443
,
},
URL
:
str
Ptr
(
"example.com/k8s/webhook"
),
URL
:
utilpointer
.
String
Ptr
(
"example.com/k8s/webhook"
),
},
},
expectedError
:
`webhook.clientConfig: Required value: exactly one of url or service is required`
,
...
...
@@ -166,7 +165,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"blank URL"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
""
),
URL
:
utilpointer
.
String
Ptr
(
""
),
},
},
expectedError
:
`webhook.clientConfig.url: Invalid value: "": host must be provided`
,
...
...
@@ -175,7 +174,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"missing host"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
"https:///fancy/webhook"
),
URL
:
utilpointer
.
String
Ptr
(
"https:///fancy/webhook"
),
},
},
expectedError
:
`host must be provided`
,
...
...
@@ -184,7 +183,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"fragment"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
"https://example.com/#bookmark"
),
URL
:
utilpointer
.
String
Ptr
(
"https://example.com/#bookmark"
),
},
},
expectedError
:
`"bookmark": fragments are not permitted`
,
...
...
@@ -193,7 +192,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"query"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
"https://example.com?arg=value"
),
URL
:
utilpointer
.
String
Ptr
(
"https://example.com?arg=value"
),
},
},
expectedError
:
`"arg=value": query parameters are not permitted`
,
...
...
@@ -202,7 +201,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"user"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
"https://harry.potter@example.com/"
),
URL
:
utilpointer
.
String
Ptr
(
"https://harry.potter@example.com/"
),
},
},
expectedError
:
`"harry.potter": user information is not permitted`
,
...
...
@@ -211,7 +210,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
name
:
"just totally wrong"
,
config
:
auditregistration
.
Webhook
{
ClientConfig
:
auditregistration
.
WebhookClientConfig
{
URL
:
str
Ptr
(
"arg#backwards=thisis?html.index/port:host//:https"
),
URL
:
utilpointer
.
String
Ptr
(
"arg#backwards=thisis?html.index/port:host//:https"
),
},
},
expectedError
:
`host must be provided`
,
...
...
@@ -223,7 +222,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"foo/"
),
Path
:
utilpointer
.
String
Ptr
(
"foo/"
),
Port
:
443
,
},
},
...
...
@@ -237,7 +236,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"foo/"
),
Path
:
utilpointer
.
String
Ptr
(
"foo/"
),
Port
:
65536
,
},
},
...
...
@@ -251,7 +250,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"foo/"
),
Path
:
utilpointer
.
String
Ptr
(
"foo/"
),
Port
:
0
,
},
},
...
...
@@ -265,7 +264,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"/"
),
Path
:
utilpointer
.
String
Ptr
(
"/"
),
Port
:
443
,
},
},
...
...
@@ -279,7 +278,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"/foo"
),
Path
:
utilpointer
.
String
Ptr
(
"/foo"
),
Port
:
443
,
},
},
...
...
@@ -293,7 +292,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"//"
),
Path
:
utilpointer
.
String
Ptr
(
"//"
),
Port
:
443
,
},
},
...
...
@@ -307,7 +306,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"/foo//bar/"
),
Path
:
utilpointer
.
String
Ptr
(
"/foo//bar/"
),
Port
:
443
,
},
},
...
...
@@ -320,7 +319,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"/foo/bar//"
),
Path
:
utilpointer
.
String
Ptr
(
"/foo/bar//"
),
Port
:
443
,
},
},
...
...
@@ -334,7 +333,7 @@ func TestValidateWebhookConfiguration(t *testing.T) {
Service
:
&
auditregistration
.
ServiceReference
{
Namespace
:
"ns"
,
Name
:
"n"
,
Path
:
str
Ptr
(
"/apis/foo.bar/v1alpha1/--bad"
),
Path
:
utilpointer
.
String
Ptr
(
"/apis/foo.bar/v1alpha1/--bad"
),
Port
:
443
,
},
},
...
...
pkg/apis/core/validation/validation_test.go
View file @
d0138ca3
...
...
@@ -12560,7 +12560,7 @@ func TestValidateSecurityContext(t *testing.T) {
runAsUser
:=
int64
(
1
)
fullValidSC
:=
func
()
*
core
.
SecurityContext
{
return
&
core
.
SecurityContext
{
Privileged
:
b
oolPtr
(
false
),
Privileged
:
utilpointer
.
B
oolPtr
(
false
),
Capabilities
:
&
core
.
Capabilities
{
Add
:
[]
core
.
Capability
{
"foo"
},
Drop
:
[]
core
.
Capability
{
"bar"
},
...
...
@@ -12605,19 +12605,19 @@ func TestValidateSecurityContext(t *testing.T) {
}
privRequestWithGlobalDeny
:=
fullValidSC
()
privRequestWithGlobalDeny
.
Privileged
=
b
oolPtr
(
true
)
privRequestWithGlobalDeny
.
Privileged
=
utilpointer
.
B
oolPtr
(
true
)
negativeRunAsUser
:=
fullValidSC
()
negativeUser
:=
int64
(
-
1
)
negativeRunAsUser
.
RunAsUser
=
&
negativeUser
privWithoutEscalation
:=
fullValidSC
()
privWithoutEscalation
.
Privileged
=
b
oolPtr
(
true
)
privWithoutEscalation
.
AllowPrivilegeEscalation
=
b
oolPtr
(
false
)
privWithoutEscalation
.
Privileged
=
utilpointer
.
B
oolPtr
(
true
)
privWithoutEscalation
.
AllowPrivilegeEscalation
=
utilpointer
.
B
oolPtr
(
false
)
capSysAdminWithoutEscalation
:=
fullValidSC
()
capSysAdminWithoutEscalation
.
Capabilities
.
Add
=
[]
core
.
Capability
{
"CAP_SYS_ADMIN"
}
capSysAdminWithoutEscalation
.
AllowPrivilegeEscalation
=
b
oolPtr
(
false
)
capSysAdminWithoutEscalation
.
AllowPrivilegeEscalation
=
utilpointer
.
B
oolPtr
(
false
)
errorCases
:=
map
[
string
]
struct
{
sc
*
core
.
SecurityContext
...
...
@@ -13145,7 +13145,3 @@ func TestValidateOrSetClientIPAffinityConfig(t *testing.T) {
}
}
}
func
boolPtr
(
b
bool
)
*
bool
{
return
&
b
}
pkg/controller/cronjob/BUILD
View file @
d0138ca3
...
...
@@ -55,6 +55,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/controller/cronjob/utils_test.go
View file @
d0138ca3
...
...
@@ -28,10 +28,9 @@ import (
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilpointer
"k8s.io/utils/pointer"
)
func
boolptr
(
b
bool
)
*
bool
{
return
&
b
}
func
TestGetJobFromTemplate
(
t
*
testing
.
T
)
{
// getJobFromTemplate() needs to take the job template and copy the labels and annotations
// and other fields, and add a created-by reference.
...
...
@@ -134,7 +133,7 @@ func TestGetParentUIDFromJob(t *testing.T) {
{
Kind
:
"CronJob"
,
UID
:
types
.
UID
(
"5ef034e0-1890-11e6-8935-42010af0003e"
),
Controller
:
boolp
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
})
...
...
@@ -158,19 +157,19 @@ func TestGroupJobsByParent(t *testing.T) {
ownerReference1
:=
metav1
.
OwnerReference
{
Kind
:
"CronJob"
,
UID
:
uid1
,
Controller
:
boolp
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
}
ownerReference2
:=
metav1
.
OwnerReference
{
Kind
:
"CronJob"
,
UID
:
uid2
,
Controller
:
boolp
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
}
ownerReference3
:=
metav1
.
OwnerReference
{
Kind
:
"CronJob"
,
UID
:
uid3
,
Controller
:
boolp
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
}
{
...
...
pkg/controller/daemon/util/BUILD
View file @
d0138ca3
...
...
@@ -46,5 +46,6 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
pkg/controller/daemon/util/daemonset_util_test.go
View file @
d0138ca3
...
...
@@ -28,6 +28,7 @@ import (
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
"k8s.io/kubernetes/pkg/features"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
utilpointer
"k8s.io/utils/pointer"
)
func
newPod
(
podName
string
,
nodeName
string
,
label
map
[
string
]
string
)
*
v1
.
Pod
{
...
...
@@ -51,8 +52,8 @@ func newPod(podName string, nodeName string, label map[string]string) *v1.Pod {
}
func
TestIsPodUpdated
(
t
*
testing
.
T
)
{
templateGeneration
:=
i
nt64Ptr
(
12345
)
badGeneration
:=
i
nt64Ptr
(
12345
)
templateGeneration
:=
utilpointer
.
I
nt64Ptr
(
12345
)
badGeneration
:=
utilpointer
.
I
nt64Ptr
(
12345
)
hash
:=
"55555"
labels
:=
map
[
string
]
string
{
extensions
.
DaemonSetTemplateGenerationKey
:
fmt
.
Sprint
(
templateGeneration
),
extensions
.
DefaultDaemonSetUniqueLabelKey
:
hash
}
labelsNoHash
:=
map
[
string
]
string
{
extensions
.
DaemonSetTemplateGenerationKey
:
fmt
.
Sprint
(
templateGeneration
)}
...
...
@@ -148,8 +149,8 @@ func TestCreatePodTemplate(t *testing.T) {
hash
string
expectUniqueLabel
bool
}{
{
i
nt64Ptr
(
1
),
""
,
false
},
{
i
nt64Ptr
(
2
),
"3242341807"
,
true
},
{
utilpointer
.
I
nt64Ptr
(
1
),
""
,
false
},
{
utilpointer
.
I
nt64Ptr
(
2
),
"3242341807"
,
true
},
}
for
_
,
test
:=
range
tests
{
podTemplateSpec
:=
v1
.
PodTemplateSpec
{}
...
...
@@ -168,11 +169,6 @@ func TestCreatePodTemplate(t *testing.T) {
}
}
func
int64Ptr
(
i
int
)
*
int64
{
li
:=
int64
(
i
)
return
&
li
}
func
TestReplaceDaemonSetPodNodeNameNodeAffinity
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
affinity
*
v1
.
Affinity
...
...
pkg/controller/ttlafterfinished/BUILD
View file @
d0138ca3
...
...
@@ -36,6 +36,7 @@ go_test(
"//staging/src/k8s.io/api/batch/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/controller/ttlafterfinished/ttlafterfinished_controller_test.go
View file @
d0138ca3
...
...
@@ -24,6 +24,7 @@ import (
batch
"k8s.io/api/batch/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
utilpointer
"k8s.io/utils/pointer"
)
func
newJob
(
completionTime
,
failedTime
metav1
.
Time
,
ttl
*
int32
)
*
batch
.
Job
{
...
...
@@ -74,10 +75,6 @@ func durationPointer(n int) *time.Duration {
return
&
s
}
func
int32Ptr
(
n
int32
)
*
int32
{
return
&
n
}
func
TestTimeLeft
(
t
*
testing
.
T
)
{
now
:=
metav1
.
Now
()
...
...
@@ -93,7 +90,7 @@ func TestTimeLeft(t *testing.T) {
}{
{
name
:
"Error case: Job unfinished"
,
ttl
:
i
nt32Ptr
(
100
),
ttl
:
utilpointer
.
I
nt32Ptr
(
100
),
since
:
&
now
.
Time
,
expectErr
:
true
,
expectErrStr
:
"should not be cleaned up"
,
...
...
@@ -108,21 +105,21 @@ func TestTimeLeft(t *testing.T) {
{
name
:
"Job completed now, 0s TTL"
,
completionTime
:
now
,
ttl
:
i
nt32Ptr
(
0
),
ttl
:
utilpointer
.
I
nt32Ptr
(
0
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
0
),
},
{
name
:
"Job completed now, 10s TTL"
,
completionTime
:
now
,
ttl
:
i
nt32Ptr
(
10
),
ttl
:
utilpointer
.
I
nt32Ptr
(
10
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
10
),
},
{
name
:
"Job completed 10s ago, 15s TTL"
,
completionTime
:
metav1
.
NewTime
(
now
.
Add
(
-
10
*
time
.
Second
)),
ttl
:
i
nt32Ptr
(
15
),
ttl
:
utilpointer
.
I
nt32Ptr
(
15
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
5
),
},
...
...
@@ -136,21 +133,21 @@ func TestTimeLeft(t *testing.T) {
{
name
:
"Job failed now, 0s TTL"
,
failedTime
:
now
,
ttl
:
i
nt32Ptr
(
0
),
ttl
:
utilpointer
.
I
nt32Ptr
(
0
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
0
),
},
{
name
:
"Job failed now, 10s TTL"
,
failedTime
:
now
,
ttl
:
i
nt32Ptr
(
10
),
ttl
:
utilpointer
.
I
nt32Ptr
(
10
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
10
),
},
{
name
:
"Job failed 10s ago, 15s TTL"
,
failedTime
:
metav1
.
NewTime
(
now
.
Add
(
-
10
*
time
.
Second
)),
ttl
:
i
nt32Ptr
(
15
),
ttl
:
utilpointer
.
I
nt32Ptr
(
15
),
since
:
&
now
.
Time
,
expectedTimeLeft
:
durationPointer
(
5
),
},
...
...
pkg/kubectl/BUILD
View file @
d0138ca3
...
...
@@ -89,6 +89,7 @@ go_library(
"//staging/src/k8s.io/client-go/scale:go_default_library",
"//staging/src/k8s.io/client-go/util/retry:go_default_library",
"//vendor/k8s.io/utils/integer:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/kubectl/cmd/apply/BUILD
View file @
d0138ca3
...
...
@@ -75,6 +75,7 @@ go_test(
"//staging/src/k8s.io/client-go/testing:go_default_library",
"//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/kubectl/cmd/apply/apply_test.go
View file @
d0138ca3
...
...
@@ -50,6 +50,7 @@ import (
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/scheme"
utilpointer
"k8s.io/utils/pointer"
)
var
(
...
...
@@ -1251,7 +1252,7 @@ func TestForceApply(t *testing.T) {
var
bodyRC
io
.
ReadCloser
if
isScaledDownToZero
{
rcObj
:=
readReplicationControllerFromFile
(
t
,
filenameRC
)
rcObj
.
Spec
.
Replicas
=
cmdtesting
.
Int32p
tr
(
0
)
rcObj
.
Spec
.
Replicas
=
utilpointer
.
Int32P
tr
(
0
)
rcBytes
,
err
:=
runtime
.
Encode
(
codec
,
rcObj
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
pkg/kubectl/cmd/drain/BUILD
View file @
d0138ca3
...
...
@@ -50,6 +50,7 @@ go_test(
"//staging/src/k8s.io/cli-runtime/pkg/printers:go_default_library",
"//staging/src/k8s.io/client-go/rest/fake:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/kubectl/cmd/drain/drain_test.go
View file @
d0138ca3
...
...
@@ -51,6 +51,7 @@ import (
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/drain"
"k8s.io/kubernetes/pkg/kubectl/scheme"
utilpointer
"k8s.io/utils/pointer"
)
const
(
...
...
@@ -61,8 +62,6 @@ const (
var
node
*
corev1
.
Node
var
cordonedNode
*
corev1
.
Node
func
boolptr
(
b
bool
)
*
bool
{
return
&
b
}
func
TestMain
(
m
*
testing
.
M
)
{
// Create a node.
node
=
&
corev1
.
Node
{
...
...
@@ -286,8 +285,8 @@ func TestDrain(t *testing.T) {
Kind
:
"ReplicationController"
,
Name
:
"rc"
,
UID
:
"123"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -318,8 +317,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"apps/v1"
,
Kind
:
"DaemonSet"
,
Name
:
"ds"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -339,8 +338,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"apps/v1"
,
Kind
:
"DaemonSet"
,
Name
:
"ds"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -363,8 +362,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"apps/v1"
,
Kind
:
"DaemonSet"
,
Name
:
"ds"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -413,8 +412,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"v1"
,
Kind
:
"Job"
,
Name
:
"job"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -440,8 +439,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"v1"
,
Kind
:
"Job"
,
Name
:
"job"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
@@ -482,8 +481,8 @@ func TestDrain(t *testing.T) {
APIVersion
:
"v1"
,
Kind
:
"ReplicaSet"
,
Name
:
"rs"
,
BlockOwnerDeletion
:
boolp
tr
(
true
),
Controller
:
boolp
tr
(
true
),
BlockOwnerDeletion
:
utilpointer
.
BoolP
tr
(
true
),
Controller
:
utilpointer
.
BoolP
tr
(
true
),
},
},
},
...
...
pkg/kubectl/cmd/testing/util.go
View file @
d0138ca3
...
...
@@ -139,8 +139,3 @@ func InitTestErrorHandler(t *testing.T) {
t
.
Errorf
(
"Error running command (exit code %d): %s"
,
code
,
str
)
})
}
func
Int32ptr
(
val
int
)
*
int32
{
t
:=
int32
(
val
)
return
&
t
}
pkg/kubectl/describe/versioned/describe_test.go
View file @
d0138ca3
...
...
@@ -3088,12 +3088,6 @@ func TestDescribeStatefulSet(t *testing.T) {
}
}
// boolPtr returns a pointer to a bool
func
boolPtr
(
b
bool
)
*
bool
{
o
:=
b
return
&
o
}
func
TestControllerRef
(
t
*
testing
.
T
)
{
var
replicas
int32
=
1
f
:=
fake
.
NewSimpleClientset
(
...
...
@@ -3123,7 +3117,7 @@ func TestControllerRef(t *testing.T) {
Name
:
"barpod"
,
Namespace
:
"foo"
,
Labels
:
map
[
string
]
string
{
"abc"
:
"xyz"
},
OwnerReferences
:
[]
metav1
.
OwnerReference
{{
Name
:
"bar"
,
UID
:
"123456"
,
Controller
:
b
oolPtr
(
true
)}},
OwnerReferences
:
[]
metav1
.
OwnerReference
{{
Name
:
"bar"
,
UID
:
"123456"
,
Controller
:
utilpointer
.
B
oolPtr
(
true
)}},
},
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Pod"
,
...
...
@@ -3160,7 +3154,7 @@ func TestControllerRef(t *testing.T) {
Name
:
"buzpod"
,
Namespace
:
"foo"
,
Labels
:
map
[
string
]
string
{
"abc"
:
"xyz"
},
OwnerReferences
:
[]
metav1
.
OwnerReference
{{
Name
:
"buz"
,
UID
:
"654321"
,
Controller
:
b
oolPtr
(
true
)}},
OwnerReferences
:
[]
metav1
.
OwnerReference
{{
Name
:
"buz"
,
UID
:
"654321"
,
Controller
:
utilpointer
.
B
oolPtr
(
true
)}},
},
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Pod"
,
...
...
pkg/kubectl/rolling_updater.go
View file @
d0138ca3
...
...
@@ -38,13 +38,9 @@ import (
deploymentutil
"k8s.io/kubernetes/pkg/kubectl/util/deployment"
"k8s.io/kubernetes/pkg/kubectl/util/podutils"
"k8s.io/utils/integer"
utilpointer
"k8s.io/utils/pointer"
)
func
newInt32Ptr
(
val
int
)
*
int32
{
ret
:=
int32
(
val
)
return
&
ret
}
func
valOrZero
(
val
*
int32
)
int32
{
if
val
==
nil
{
return
int32
(
0
)
...
...
@@ -393,12 +389,12 @@ func (r *RollingUpdater) scaleDown(newRc, oldRc *corev1.ReplicationController, d
nextOldVal
:=
valOrZero
(
oldRc
.
Spec
.
Replicas
)
-
decrement
oldRc
.
Spec
.
Replicas
=
&
nextOldVal
if
valOrZero
(
oldRc
.
Spec
.
Replicas
)
<
0
{
oldRc
.
Spec
.
Replicas
=
new
Int32Ptr
(
0
)
oldRc
.
Spec
.
Replicas
=
utilpointer
.
Int32Ptr
(
0
)
}
// If the new is already fully scaled and available up to the desired size, go
// ahead and scale old all the way down.
if
valOrZero
(
newRc
.
Spec
.
Replicas
)
==
desired
&&
newAvailable
==
desired
{
oldRc
.
Spec
.
Replicas
=
new
Int32Ptr
(
0
)
oldRc
.
Spec
.
Replicas
=
utilpointer
.
Int32Ptr
(
0
)
}
// Perform the scale-down.
fmt
.
Fprintf
(
config
.
Out
,
"Scaling %s down to %d
\n
"
,
oldRc
.
Name
,
valOrZero
(
oldRc
.
Spec
.
Replicas
))
...
...
@@ -482,7 +478,7 @@ func (r *RollingUpdater) getOrCreateTargetControllerWithClient(controller *corev
}
controller
.
Annotations
[
desiredReplicasAnnotation
]
=
fmt
.
Sprintf
(
"%d"
,
valOrZero
(
controller
.
Spec
.
Replicas
))
controller
.
Annotations
[
sourceIDAnnotation
]
=
sourceID
controller
.
Spec
.
Replicas
=
new
Int32Ptr
(
0
)
controller
.
Spec
.
Replicas
=
utilpointer
.
Int32Ptr
(
0
)
newRc
,
err
:=
r
.
rcClient
.
ReplicationControllers
(
r
.
ns
)
.
Create
(
controller
)
return
newRc
,
false
,
err
}
...
...
pkg/proxy/iptables/BUILD
View file @
d0138ca3
...
...
@@ -49,6 +49,7 @@ go_test(
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/exec/testing:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
],
)
...
...
pkg/proxy/iptables/proxier_test.go
View file @
d0138ca3
...
...
@@ -41,6 +41,7 @@ import (
iptablestest
"k8s.io/kubernetes/pkg/util/iptables/testing"
"k8s.io/utils/exec"
fakeexec
"k8s.io/utils/exec/testing"
utilpointer
"k8s.io/utils/pointer"
)
func
checkAllLines
(
t
*
testing
.
T
,
table
utiliptables
.
Table
,
save
[]
byte
,
expectedLines
map
[
utiliptables
.
Chain
]
string
)
{
...
...
@@ -845,10 +846,6 @@ func TestNodePortReject(t *testing.T) {
}
}
func
strPtr
(
s
string
)
*
string
{
return
&
s
}
func
TestOnlyLocalLoadBalancing
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
)
...
...
@@ -895,7 +892,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
NodeName
:
nil
,
},
{
IP
:
epIP2
,
NodeName
:
str
Ptr
(
testHostname
),
NodeName
:
utilpointer
.
String
Ptr
(
testHostname
),
}},
Ports
:
[]
v1
.
EndpointPort
{{
Name
:
svcPortName
.
Port
,
...
...
@@ -989,7 +986,7 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
NodeName
:
nil
,
},
{
IP
:
epIP2
,
NodeName
:
str
Ptr
(
testHostname
),
NodeName
:
utilpointer
.
String
Ptr
(
testHostname
),
}},
Ports
:
[]
v1
.
EndpointPort
{{
Name
:
svcPortName
.
Port
,
...
...
staging/publishing/import-restrictions.yaml
View file @
d0138ca3
...
...
@@ -28,6 +28,7 @@
-
k8s.io/cli-runtime/pkg/printers
-
k8s.io/cli-runtime/pkg/resource
-
k8s.io/cli-runtime/pkg/kustomize
-
k8s.io/utils/pointer
-
baseImportPath
:
"
./vendor/k8s.io/apimachinery/"
allowedImports
:
...
...
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