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
d0577ace
Commit
d0577ace
authored
Oct 19, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup extensions->apps references
parent
b502bc09
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
218 additions
and
219 deletions
+218
-219
.import-restrictions
cmd/kubeadm/.import-restrictions
+1
-0
import-restrictions.yaml
hack/import-restrictions.yaml
+2
-2
validation.go
pkg/apis/policy/validation/validation.go
+5
-5
describe.go
pkg/printers/internalversion/describe.go
+7
-7
describe_test.go
pkg/printers/internalversion/describe_test.go
+2
-3
printers.go
pkg/printers/internalversion/printers.go
+6
-6
printers_test.go
pkg/printers/internalversion/printers_test.go
+12
-12
storage.go
pkg/registry/apps/daemonset/storage/storage.go
+5
-5
storage_test.go
pkg/registry/apps/daemonset/storage/storage_test.go
+14
-14
strategy.go
pkg/registry/apps/daemonset/strategy.go
+13
-13
strategy_test.go
pkg/registry/apps/daemonset/strategy_test.go
+6
-6
storage.go
pkg/registry/apps/deployment/storage/storage.go
+24
-24
storage_test.go
pkg/registry/apps/deployment/storage/storage_test.go
+34
-34
strategy.go
pkg/registry/apps/deployment/strategy.go
+12
-12
strategy_test.go
pkg/registry/apps/deployment/strategy_test.go
+12
-12
storage.go
pkg/registry/apps/replicaset/storage/storage.go
+12
-12
storage_test.go
pkg/registry/apps/replicaset/storage/storage_test.go
+21
-21
strategy.go
pkg/registry/apps/replicaset/strategy.go
+15
-15
strategy_test.go
pkg/registry/apps/replicaset/strategy_test.go
+14
-14
storage.go
pkg/registry/apps/statefulset/storage/storage.go
+1
-2
No files found.
cmd/kubeadm/.import-restrictions
View file @
d0577ace
...
@@ -50,6 +50,7 @@
...
@@ -50,6 +50,7 @@
"k8s.io/kubernetes/pkg/apis/autoscaling",
"k8s.io/kubernetes/pkg/apis/autoscaling",
"k8s.io/kubernetes/pkg/apis/core",
"k8s.io/kubernetes/pkg/apis/core",
"k8s.io/kubernetes/pkg/api/service",
"k8s.io/kubernetes/pkg/api/service",
"k8s.io/kubernetes/pkg/apis/apps",
"k8s.io/kubernetes/pkg/apis/extensions",
"k8s.io/kubernetes/pkg/apis/extensions",
"k8s.io/kubernetes/pkg/apis/networking",
"k8s.io/kubernetes/pkg/apis/networking",
"k8s.io/kubernetes/pkg/apis/policy",
"k8s.io/kubernetes/pkg/apis/policy",
...
...
hack/import-restrictions.yaml
View file @
d0577ace
...
@@ -11,10 +11,10 @@
...
@@ -11,10 +11,10 @@
# the following are temporary and should go away. Think twice (or more) before adding anything here.
# the following are temporary and should go away. Think twice (or more) before adding anything here.
# Main goal: pkg/apis should be as self-contained as possible.
# Main goal: pkg/apis should be as self-contained as possible.
-
k8s.io/kubernetes/pkg/apis/
extension
s
-
k8s.io/kubernetes/pkg/apis/
app
s
-
k8s.io/kubernetes/pkg/api/legacyscheme
-
k8s.io/kubernetes/pkg/api/legacyscheme
-
k8s.io/kubernetes/pkg/api/testapi
-
k8s.io/kubernetes/pkg/api/testapi
-
k8s.io/api/
extensions/v1beta
1
-
k8s.io/api/
apps/v
1
ignoredSubTrees
:
ignoredSubTrees
:
-
"
./pkg/apis/core/validation"
-
"
./pkg/apis/core/validation"
...
...
pkg/apis/policy/validation/validation.go
View file @
d0577ace
...
@@ -27,9 +27,9 @@ import (
...
@@ -27,9 +27,9 @@ import (
unversionedvalidation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
unversionedvalidation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
appsvalidation
"k8s.io/kubernetes/pkg/apis/apps/validation"
core
"k8s.io/kubernetes/pkg/apis/core"
core
"k8s.io/kubernetes/pkg/apis/core"
apivalidation
"k8s.io/kubernetes/pkg/apis/core/validation"
apivalidation
"k8s.io/kubernetes/pkg/apis/core/validation"
extensionsvalidation
"k8s.io/kubernetes/pkg/apis/extensions/validation"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/security/apparmor"
"k8s.io/kubernetes/pkg/security/apparmor"
...
@@ -68,13 +68,13 @@ func ValidatePodDisruptionBudgetSpec(spec policy.PodDisruptionBudgetSpec, fldPat
...
@@ -68,13 +68,13 @@ func ValidatePodDisruptionBudgetSpec(spec policy.PodDisruptionBudgetSpec, fldPat
}
}
if
spec
.
MinAvailable
!=
nil
{
if
spec
.
MinAvailable
!=
nil
{
allErrs
=
append
(
allErrs
,
extension
svalidation
.
ValidatePositiveIntOrPercent
(
*
spec
.
MinAvailable
,
fldPath
.
Child
(
"minAvailable"
))
...
)
allErrs
=
append
(
allErrs
,
app
svalidation
.
ValidatePositiveIntOrPercent
(
*
spec
.
MinAvailable
,
fldPath
.
Child
(
"minAvailable"
))
...
)
allErrs
=
append
(
allErrs
,
extension
svalidation
.
IsNotMoreThan100Percent
(
*
spec
.
MinAvailable
,
fldPath
.
Child
(
"minAvailable"
))
...
)
allErrs
=
append
(
allErrs
,
app
svalidation
.
IsNotMoreThan100Percent
(
*
spec
.
MinAvailable
,
fldPath
.
Child
(
"minAvailable"
))
...
)
}
}
if
spec
.
MaxUnavailable
!=
nil
{
if
spec
.
MaxUnavailable
!=
nil
{
allErrs
=
append
(
allErrs
,
extension
svalidation
.
ValidatePositiveIntOrPercent
(
*
spec
.
MaxUnavailable
,
fldPath
.
Child
(
"maxUnavailable"
))
...
)
allErrs
=
append
(
allErrs
,
app
svalidation
.
ValidatePositiveIntOrPercent
(
*
spec
.
MaxUnavailable
,
fldPath
.
Child
(
"maxUnavailable"
))
...
)
allErrs
=
append
(
allErrs
,
extension
svalidation
.
IsNotMoreThan100Percent
(
*
spec
.
MaxUnavailable
,
fldPath
.
Child
(
"maxUnavailable"
))
...
)
allErrs
=
append
(
allErrs
,
app
svalidation
.
IsNotMoreThan100Percent
(
*
spec
.
MaxUnavailable
,
fldPath
.
Child
(
"maxUnavailable"
))
...
)
}
}
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabelSelector
(
spec
.
Selector
,
fldPath
.
Child
(
"selector"
))
...
)
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabelSelector
(
spec
.
Selector
,
fldPath
.
Child
(
"selector"
))
...
)
...
...
pkg/printers/internalversion/describe.go
View file @
d0577ace
...
@@ -1872,7 +1872,7 @@ type ReplicaSetDescriber struct {
...
@@ -1872,7 +1872,7 @@ type ReplicaSetDescriber struct {
}
}
func
(
d
*
ReplicaSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ReplicaSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
string
,
error
)
{
rsc
:=
d
.
Extension
s
()
.
ReplicaSets
(
namespace
)
rsc
:=
d
.
App
s
()
.
ReplicaSets
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
rs
,
err
:=
rsc
.
Get
(
name
,
metav1
.
GetOptions
{})
rs
,
err
:=
rsc
.
Get
(
name
,
metav1
.
GetOptions
{})
...
@@ -1895,7 +1895,7 @@ func (d *ReplicaSetDescriber) Describe(namespace, name string, describerSettings
...
@@ -1895,7 +1895,7 @@ func (d *ReplicaSetDescriber) Describe(namespace, name string, describerSettings
return
describeReplicaSet
(
rs
,
events
,
running
,
waiting
,
succeeded
,
failed
,
getPodErr
)
return
describeReplicaSet
(
rs
,
events
,
running
,
waiting
,
succeeded
,
failed
,
getPodErr
)
}
}
func
describeReplicaSet
(
rs
*
extension
s
.
ReplicaSet
,
events
*
api
.
EventList
,
running
,
waiting
,
succeeded
,
failed
int
,
getPodErr
error
)
(
string
,
error
)
{
func
describeReplicaSet
(
rs
*
app
s
.
ReplicaSet
,
events
*
api
.
EventList
,
running
,
waiting
,
succeeded
,
failed
int
,
getPodErr
error
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
rs
.
Name
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
rs
.
Name
)
...
@@ -2085,7 +2085,7 @@ type DaemonSetDescriber struct {
...
@@ -2085,7 +2085,7 @@ type DaemonSetDescriber struct {
}
}
func
(
d
*
DaemonSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
DaemonSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
string
,
error
)
{
dc
:=
d
.
Extension
s
()
.
DaemonSets
(
namespace
)
dc
:=
d
.
App
s
()
.
DaemonSets
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
daemon
,
err
:=
dc
.
Get
(
name
,
metav1
.
GetOptions
{})
daemon
,
err
:=
dc
.
Get
(
name
,
metav1
.
GetOptions
{})
...
@@ -2110,7 +2110,7 @@ func (d *DaemonSetDescriber) Describe(namespace, name string, describerSettings
...
@@ -2110,7 +2110,7 @@ func (d *DaemonSetDescriber) Describe(namespace, name string, describerSettings
return
describeDaemonSet
(
daemon
,
events
,
running
,
waiting
,
succeeded
,
failed
)
return
describeDaemonSet
(
daemon
,
events
,
running
,
waiting
,
succeeded
,
failed
)
}
}
func
describeDaemonSet
(
daemon
*
extension
s
.
DaemonSet
,
events
*
api
.
EventList
,
running
,
waiting
,
succeeded
,
failed
int
)
(
string
,
error
)
{
func
describeDaemonSet
(
daemon
*
app
s
.
DaemonSet
,
events
*
api
.
EventList
,
running
,
waiting
,
succeeded
,
failed
int
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
daemon
.
Name
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
daemon
.
Name
)
...
@@ -3224,8 +3224,8 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
...
@@ -3224,8 +3224,8 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
internalDeployment
:=
&
extension
s
.
Deployment
{}
internalDeployment
:=
&
app
s
.
Deployment
{}
if
err
:=
legacyscheme
.
Scheme
.
Convert
(
d
,
internalDeployment
,
extension
s
.
SchemeGroupVersion
);
err
!=
nil
{
if
err
:=
legacyscheme
.
Scheme
.
Convert
(
d
,
internalDeployment
,
app
s
.
SchemeGroupVersion
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -3237,7 +3237,7 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
...
@@ -3237,7 +3237,7 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
return
describeDeployment
(
d
,
selector
,
internalDeployment
,
events
,
dd
)
return
describeDeployment
(
d
,
selector
,
internalDeployment
,
events
,
dd
)
}
}
func
describeDeployment
(
d
*
appsv1
.
Deployment
,
selector
labels
.
Selector
,
internalDeployment
*
extension
s
.
Deployment
,
events
*
api
.
EventList
,
dd
*
DeploymentDescriber
)
(
string
,
error
)
{
func
describeDeployment
(
d
*
appsv1
.
Deployment
,
selector
labels
.
Selector
,
internalDeployment
*
app
s
.
Deployment
,
events
*
api
.
EventList
,
dd
*
DeploymentDescriber
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
d
.
ObjectMeta
.
Name
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
d
.
ObjectMeta
.
Name
)
...
...
pkg/printers/internalversion/describe_test.go
View file @
d0577ace
...
@@ -36,7 +36,6 @@ import (
...
@@ -36,7 +36,6 @@ import (
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/networking"
"k8s.io/kubernetes/pkg/apis/networking"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
...
@@ -2188,7 +2187,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -2188,7 +2187,7 @@ func TestDescribeEvents(t *testing.T) {
m
:=
map
[
string
]
printers
.
Describer
{
m
:=
map
[
string
]
printers
.
Describer
{
"DaemonSetDescriber"
:
&
DaemonSetDescriber
{
"DaemonSetDescriber"
:
&
DaemonSetDescriber
{
fake
.
NewSimpleClientset
(
&
extension
s
.
DaemonSet
{
fake
.
NewSimpleClientset
(
&
app
s
.
DaemonSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -2245,7 +2244,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -2245,7 +2244,7 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"ReplicaSetDescriber"
:
&
ReplicaSetDescriber
{
"ReplicaSetDescriber"
:
&
ReplicaSetDescriber
{
fake
.
NewSimpleClientset
(
&
extension
s
.
ReplicaSet
{
fake
.
NewSimpleClientset
(
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
...
pkg/printers/internalversion/printers.go
View file @
d0577ace
...
@@ -769,7 +769,7 @@ func printReplicationControllerList(list *api.ReplicationControllerList, options
...
@@ -769,7 +769,7 @@ func printReplicationControllerList(list *api.ReplicationControllerList, options
return
rows
,
nil
return
rows
,
nil
}
}
func
printReplicaSet
(
obj
*
extension
s
.
ReplicaSet
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printReplicaSet
(
obj
*
app
s
.
ReplicaSet
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
row
:=
metav1beta1
.
TableRow
{
row
:=
metav1beta1
.
TableRow
{
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
}
}
...
@@ -786,7 +786,7 @@ func printReplicaSet(obj *extensions.ReplicaSet, options printers.PrintOptions)
...
@@ -786,7 +786,7 @@ func printReplicaSet(obj *extensions.ReplicaSet, options printers.PrintOptions)
return
[]
metav1beta1
.
TableRow
{
row
},
nil
return
[]
metav1beta1
.
TableRow
{
row
},
nil
}
}
func
printReplicaSetList
(
list
*
extension
s
.
ReplicaSetList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printReplicaSetList
(
list
*
app
s
.
ReplicaSetList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
for
i
:=
range
list
.
Items
{
for
i
:=
range
list
.
Items
{
r
,
err
:=
printReplicaSet
(
&
list
.
Items
[
i
],
options
)
r
,
err
:=
printReplicaSet
(
&
list
.
Items
[
i
],
options
)
...
@@ -1063,7 +1063,7 @@ func printStatefulSetList(list *apps.StatefulSetList, options printers.PrintOpti
...
@@ -1063,7 +1063,7 @@ func printStatefulSetList(list *apps.StatefulSetList, options printers.PrintOpti
return
rows
,
nil
return
rows
,
nil
}
}
func
printDaemonSet
(
obj
*
extension
s
.
DaemonSet
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printDaemonSet
(
obj
*
app
s
.
DaemonSet
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
row
:=
metav1beta1
.
TableRow
{
row
:=
metav1beta1
.
TableRow
{
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
}
}
...
@@ -1082,7 +1082,7 @@ func printDaemonSet(obj *extensions.DaemonSet, options printers.PrintOptions) ([
...
@@ -1082,7 +1082,7 @@ func printDaemonSet(obj *extensions.DaemonSet, options printers.PrintOptions) ([
return
[]
metav1beta1
.
TableRow
{
row
},
nil
return
[]
metav1beta1
.
TableRow
{
row
},
nil
}
}
func
printDaemonSetList
(
list
*
extension
s
.
DaemonSetList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printDaemonSetList
(
list
*
app
s
.
DaemonSetList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
for
i
:=
range
list
.
Items
{
for
i
:=
range
list
.
Items
{
r
,
err
:=
printDaemonSet
(
&
list
.
Items
[
i
],
options
)
r
,
err
:=
printDaemonSet
(
&
list
.
Items
[
i
],
options
)
...
@@ -1555,7 +1555,7 @@ func truncate(str string, maxLen int) string {
...
@@ -1555,7 +1555,7 @@ func truncate(str string, maxLen int) string {
return
str
return
str
}
}
func
printDeployment
(
obj
*
extension
s
.
Deployment
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printDeployment
(
obj
*
app
s
.
Deployment
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
row
:=
metav1beta1
.
TableRow
{
row
:=
metav1beta1
.
TableRow
{
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
Object
:
runtime
.
RawExtension
{
Object
:
obj
},
}
}
...
@@ -1578,7 +1578,7 @@ func printDeployment(obj *extensions.Deployment, options printers.PrintOptions)
...
@@ -1578,7 +1578,7 @@ func printDeployment(obj *extensions.Deployment, options printers.PrintOptions)
return
[]
metav1beta1
.
TableRow
{
row
},
nil
return
[]
metav1beta1
.
TableRow
{
row
},
nil
}
}
func
printDeploymentList
(
list
*
extension
s
.
DeploymentList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
func
printDeploymentList
(
list
*
app
s
.
DeploymentList
,
options
printers
.
PrintOptions
)
([]
metav1beta1
.
TableRow
,
error
)
{
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
rows
:=
make
([]
metav1beta1
.
TableRow
,
0
,
len
(
list
.
Items
))
for
i
:=
range
list
.
Items
{
for
i
:=
range
list
.
Items
{
r
,
err
:=
printDeployment
(
&
list
.
Items
[
i
],
options
)
r
,
err
:=
printDeployment
(
&
list
.
Items
[
i
],
options
)
...
...
pkg/printers/internalversion/printers_test.go
View file @
d0577ace
...
@@ -1971,17 +1971,17 @@ func TestTranslateTimestampUntil(t *testing.T) {
...
@@ -1971,17 +1971,17 @@ func TestTranslateTimestampUntil(t *testing.T) {
func
TestPrintDeployment
(
t
*
testing
.
T
)
{
func
TestPrintDeployment
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
deployment
extension
s
.
Deployment
deployment
app
s
.
Deployment
expect
string
expect
string
wideExpect
string
wideExpect
string
}{
}{
{
{
extension
s
.
Deployment
{
app
s
.
Deployment
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test1"
,
Name
:
"test1"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
},
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Replicas
:
5
,
Replicas
:
5
,
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
...
@@ -1999,7 +1999,7 @@ func TestPrintDeployment(t *testing.T) {
...
@@ -1999,7 +1999,7 @@ func TestPrintDeployment(t *testing.T) {
},
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
},
},
Status
:
extension
s
.
DeploymentStatus
{
Status
:
app
s
.
DeploymentStatus
{
Replicas
:
10
,
Replicas
:
10
,
UpdatedReplicas
:
2
,
UpdatedReplicas
:
2
,
AvailableReplicas
:
1
,
AvailableReplicas
:
1
,
...
@@ -2040,21 +2040,21 @@ func TestPrintDeployment(t *testing.T) {
...
@@ -2040,21 +2040,21 @@ func TestPrintDeployment(t *testing.T) {
func
TestPrintDaemonSet
(
t
*
testing
.
T
)
{
func
TestPrintDaemonSet
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
ds
extension
s
.
DaemonSet
ds
app
s
.
DaemonSet
startsWith
string
startsWith
string
}{
}{
{
{
extension
s
.
DaemonSet
{
app
s
.
DaemonSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test1"
,
Name
:
"test1"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
},
Spec
:
extension
s
.
DaemonSetSpec
{
Spec
:
app
s
.
DaemonSetSpec
{
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Containers
:
make
([]
api
.
Container
,
2
)},
Spec
:
api
.
PodSpec
{
Containers
:
make
([]
api
.
Container
,
2
)},
},
},
},
},
Status
:
extension
s
.
DaemonSetStatus
{
Status
:
app
s
.
DaemonSetStatus
{
CurrentNumberScheduled
:
2
,
CurrentNumberScheduled
:
2
,
DesiredNumberScheduled
:
3
,
DesiredNumberScheduled
:
3
,
NumberReady
:
1
,
NumberReady
:
1
,
...
@@ -3154,17 +3154,17 @@ func boolP(b bool) *bool {
...
@@ -3154,17 +3154,17 @@ func boolP(b bool) *bool {
func
TestPrintReplicaSet
(
t
*
testing
.
T
)
{
func
TestPrintReplicaSet
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
replicaSet
extension
s
.
ReplicaSet
replicaSet
app
s
.
ReplicaSet
expect
string
expect
string
wideExpect
string
wideExpect
string
}{
}{
{
{
extension
s
.
ReplicaSet
{
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test1"
,
Name
:
"test1"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Replicas
:
5
,
Replicas
:
5
,
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
...
@@ -3182,7 +3182,7 @@ func TestPrintReplicaSet(t *testing.T) {
...
@@ -3182,7 +3182,7 @@ func TestPrintReplicaSet(t *testing.T) {
},
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
5
,
Replicas
:
5
,
ReadyReplicas
:
2
,
ReadyReplicas
:
2
,
},
},
...
...
pkg/registry/apps/daemonset/storage/storage.go
View file @
d0577ace
...
@@ -24,7 +24,7 @@ import (
...
@@ -24,7 +24,7 @@ import (
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/
extension
s"
"k8s.io/kubernetes/pkg/apis/
app
s"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
...
@@ -40,9 +40,9 @@ type REST struct {
...
@@ -40,9 +40,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against DaemonSets.
// NewREST returns a RESTStorage object that will work against DaemonSets.
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
)
{
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
)
{
store
:=
&
genericregistry
.
Store
{
store
:=
&
genericregistry
.
Store
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
DaemonSet
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
DaemonSet
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
DaemonSetList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
DaemonSetList
{}
},
DefaultQualifiedResource
:
extension
s
.
Resource
(
"daemonsets"
),
DefaultQualifiedResource
:
app
s
.
Resource
(
"daemonsets"
),
CreateStrategy
:
daemonset
.
Strategy
,
CreateStrategy
:
daemonset
.
Strategy
,
UpdateStrategy
:
daemonset
.
Strategy
,
UpdateStrategy
:
daemonset
.
Strategy
,
...
@@ -87,7 +87,7 @@ type StatusREST struct {
...
@@ -87,7 +87,7 @@ type StatusREST struct {
}
}
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
return
&
extension
s
.
DaemonSet
{}
return
&
app
s
.
DaemonSet
{}
}
}
// Get retrieves the object from the storage. It is required to support Patch.
// Get retrieves the object from the storage. It is required to support Patch.
...
...
pkg/registry/apps/daemonset/storage/storage_test.go
View file @
d0577ace
...
@@ -26,13 +26,13 @@ import (
...
@@ -26,13 +26,13 @@ import (
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic"
genericregistrytest
"k8s.io/apiserver/pkg/registry/generic/testing"
genericregistrytest
"k8s.io/apiserver/pkg/registry/generic/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/apis/apps"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
)
)
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
etcdtesting
.
EtcdTestServer
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
etcdtesting
.
EtcdTestServer
)
{
etcdStorage
,
server
:=
registrytest
.
NewEtcdStorage
(
t
,
extension
s
.
GroupName
)
etcdStorage
,
server
:=
registrytest
.
NewEtcdStorage
(
t
,
app
s
.
GroupName
)
restOptions
:=
generic
.
RESTOptions
{
restOptions
:=
generic
.
RESTOptions
{
StorageConfig
:
etcdStorage
,
StorageConfig
:
etcdStorage
,
Decorator
:
generic
.
UndecoratedStorage
,
Decorator
:
generic
.
UndecoratedStorage
,
...
@@ -43,15 +43,15 @@ func newStorage(t *testing.T) (*REST, *StatusREST, *etcdtesting.EtcdTestServer)
...
@@ -43,15 +43,15 @@ func newStorage(t *testing.T) (*REST, *StatusREST, *etcdtesting.EtcdTestServer)
return
daemonSetStorage
,
statusStorage
,
server
return
daemonSetStorage
,
statusStorage
,
server
}
}
func
newValidDaemonSet
()
*
extension
s
.
DaemonSet
{
func
newValidDaemonSet
()
*
app
s
.
DaemonSet
{
return
&
extension
s
.
DaemonSet
{
return
&
app
s
.
DaemonSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
Namespace
:
metav1
.
NamespaceDefault
,
Namespace
:
metav1
.
NamespaceDefault
,
},
},
Spec
:
extension
s
.
DaemonSetSpec
{
Spec
:
app
s
.
DaemonSetSpec
{
UpdateStrategy
:
extension
s
.
DaemonSetUpdateStrategy
{
UpdateStrategy
:
app
s
.
DaemonSetUpdateStrategy
{
Type
:
extension
s
.
OnDeleteDaemonSetStrategyType
,
Type
:
app
s
.
OnDeleteDaemonSetStrategyType
,
},
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
...
@@ -88,15 +88,15 @@ func TestCreate(t *testing.T) {
...
@@ -88,15 +88,15 @@ func TestCreate(t *testing.T) {
// valid
// valid
ds
,
ds
,
// invalid (invalid selector)
// invalid (invalid selector)
&
extension
s
.
DaemonSet
{
&
app
s
.
DaemonSet
{
Spec
:
extension
s
.
DaemonSetSpec
{
Spec
:
app
s
.
DaemonSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Template
:
validDaemonSet
.
Spec
.
Template
,
Template
:
validDaemonSet
.
Spec
.
Template
,
},
},
},
},
// invalid update strategy
// invalid update strategy
&
extension
s
.
DaemonSet
{
&
app
s
.
DaemonSet
{
Spec
:
extension
s
.
DaemonSetSpec
{
Spec
:
app
s
.
DaemonSetSpec
{
Selector
:
validDaemonSet
.
Spec
.
Selector
,
Selector
:
validDaemonSet
.
Spec
.
Selector
,
Template
:
validDaemonSet
.
Spec
.
Template
,
Template
:
validDaemonSet
.
Spec
.
Template
,
},
},
...
@@ -114,19 +114,19 @@ func TestUpdate(t *testing.T) {
...
@@ -114,19 +114,19 @@ func TestUpdate(t *testing.T) {
newValidDaemonSet
(),
newValidDaemonSet
(),
// updateFunc
// updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
DaemonSet
)
object
:=
obj
.
(
*
app
s
.
DaemonSet
)
object
.
Spec
.
Template
.
Spec
.
NodeSelector
=
map
[
string
]
string
{
"c"
:
"d"
}
object
.
Spec
.
Template
.
Spec
.
NodeSelector
=
map
[
string
]
string
{
"c"
:
"d"
}
object
.
Spec
.
Template
.
Spec
.
DNSPolicy
=
api
.
DNSDefault
object
.
Spec
.
Template
.
Spec
.
DNSPolicy
=
api
.
DNSDefault
return
object
return
object
},
},
// invalid updateFunc
// invalid updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
DaemonSet
)
object
:=
obj
.
(
*
app
s
.
DaemonSet
)
object
.
Name
=
""
object
.
Name
=
""
return
object
return
object
},
},
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
DaemonSet
)
object
:=
obj
.
(
*
app
s
.
DaemonSet
)
object
.
Spec
.
Template
.
Spec
.
RestartPolicy
=
api
.
RestartPolicyOnFailure
object
.
Spec
.
Template
.
Spec
.
RestartPolicy
=
api
.
RestartPolicyOnFailure
return
object
return
object
},
},
...
...
pkg/registry/apps/daemonset/strategy.go
View file @
d0577ace
...
@@ -31,8 +31,8 @@ import (
...
@@ -31,8 +31,8 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/apis/
extension
s"
"k8s.io/kubernetes/pkg/apis/
app
s"
"k8s.io/kubernetes/pkg/apis/
extension
s/validation"
"k8s.io/kubernetes/pkg/apis/
app
s/validation"
)
)
// daemonSetStrategy implements verification logic for daemon sets.
// daemonSetStrategy implements verification logic for daemon sets.
...
@@ -66,8 +66,8 @@ func (daemonSetStrategy) NamespaceScoped() bool {
...
@@ -66,8 +66,8 @@ func (daemonSetStrategy) NamespaceScoped() bool {
// PrepareForCreate clears the status of a daemon set before creation.
// PrepareForCreate clears the status of a daemon set before creation.
func
(
daemonSetStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
func
(
daemonSetStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
daemonSet
:=
obj
.
(
*
extension
s
.
DaemonSet
)
daemonSet
:=
obj
.
(
*
app
s
.
DaemonSet
)
daemonSet
.
Status
=
extension
s
.
DaemonSetStatus
{}
daemonSet
.
Status
=
app
s
.
DaemonSetStatus
{}
daemonSet
.
Generation
=
1
daemonSet
.
Generation
=
1
if
daemonSet
.
Spec
.
TemplateGeneration
<
1
{
if
daemonSet
.
Spec
.
TemplateGeneration
<
1
{
...
@@ -79,8 +79,8 @@ func (daemonSetStrategy) PrepareForCreate(ctx context.Context, obj runtime.Objec
...
@@ -79,8 +79,8 @@ func (daemonSetStrategy) PrepareForCreate(ctx context.Context, obj runtime.Objec
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
daemonSetStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
daemonSetStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDaemonSet
:=
obj
.
(
*
extension
s
.
DaemonSet
)
newDaemonSet
:=
obj
.
(
*
app
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extension
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
app
s
.
DaemonSet
)
pod
.
DropDisabledAlphaFields
(
&
newDaemonSet
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledAlphaFields
(
&
newDaemonSet
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledAlphaFields
(
&
oldDaemonSet
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledAlphaFields
(
&
oldDaemonSet
.
Spec
.
Template
.
Spec
)
...
@@ -114,7 +114,7 @@ func (daemonSetStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
...
@@ -114,7 +114,7 @@ func (daemonSetStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
// Validate validates a new daemon set.
// Validate validates a new daemon set.
func
(
daemonSetStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
daemonSet
:=
obj
.
(
*
extension
s
.
DaemonSet
)
daemonSet
:=
obj
.
(
*
app
s
.
DaemonSet
)
return
validation
.
ValidateDaemonSet
(
daemonSet
)
return
validation
.
ValidateDaemonSet
(
daemonSet
)
}
}
...
@@ -130,9 +130,9 @@ func (daemonSetStrategy) AllowCreateOnUpdate() bool {
...
@@ -130,9 +130,9 @@ func (daemonSetStrategy) AllowCreateOnUpdate() bool {
// ValidateUpdate is the default update validation for an end user.
// ValidateUpdate is the default update validation for an end user.
func
(
daemonSetStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newDaemonSet
:=
obj
.
(
*
extension
s
.
DaemonSet
)
newDaemonSet
:=
obj
.
(
*
app
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extension
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
app
s
.
DaemonSet
)
allErrs
:=
validation
.
ValidateDaemonSet
(
obj
.
(
*
extension
s
.
DaemonSet
))
allErrs
:=
validation
.
ValidateDaemonSet
(
obj
.
(
*
app
s
.
DaemonSet
))
allErrs
=
append
(
allErrs
,
validation
.
ValidateDaemonSetUpdate
(
newDaemonSet
,
oldDaemonSet
)
...
)
allErrs
=
append
(
allErrs
,
validation
.
ValidateDaemonSetUpdate
(
newDaemonSet
,
oldDaemonSet
)
...
)
// Update is not allowed to set Spec.Selector for apps/v1 and apps/v1beta2 (allowed for extensions/v1beta1).
// Update is not allowed to set Spec.Selector for apps/v1 and apps/v1beta2 (allowed for extensions/v1beta1).
...
@@ -165,11 +165,11 @@ type daemonSetStatusStrategy struct {
...
@@ -165,11 +165,11 @@ type daemonSetStatusStrategy struct {
var
StatusStrategy
=
daemonSetStatusStrategy
{
Strategy
}
var
StatusStrategy
=
daemonSetStatusStrategy
{
Strategy
}
func
(
daemonSetStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
daemonSetStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDaemonSet
:=
obj
.
(
*
extension
s
.
DaemonSet
)
newDaemonSet
:=
obj
.
(
*
app
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extension
s
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
app
s
.
DaemonSet
)
newDaemonSet
.
Spec
=
oldDaemonSet
.
Spec
newDaemonSet
.
Spec
=
oldDaemonSet
.
Spec
}
}
func
(
daemonSetStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateDaemonSetStatusUpdate
(
obj
.
(
*
extensions
.
DaemonSet
),
old
.
(
*
extension
s
.
DaemonSet
))
return
validation
.
ValidateDaemonSetStatusUpdate
(
obj
.
(
*
apps
.
DaemonSet
),
old
.
(
*
app
s
.
DaemonSet
))
}
}
pkg/registry/apps/daemonset/strategy_test.go
View file @
d0577ace
...
@@ -24,8 +24,8 @@ import (
...
@@ -24,8 +24,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/apps"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
)
)
const
(
const
(
...
@@ -160,20 +160,20 @@ func TestSelectorImmutability(t *testing.T) {
...
@@ -160,20 +160,20 @@ func TestSelectorImmutability(t *testing.T) {
}
}
}
}
func
newDaemonSetWithSelectorLabels
(
selectorLabels
map
[
string
]
string
,
templateGeneration
int64
)
*
extension
s
.
DaemonSet
{
func
newDaemonSetWithSelectorLabels
(
selectorLabels
map
[
string
]
string
,
templateGeneration
int64
)
*
app
s
.
DaemonSet
{
return
&
extension
s
.
DaemonSet
{
return
&
app
s
.
DaemonSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
daemonsetName
,
Name
:
daemonsetName
,
Namespace
:
namespace
,
Namespace
:
namespace
,
ResourceVersion
:
"1"
,
ResourceVersion
:
"1"
,
},
},
Spec
:
extension
s
.
DaemonSetSpec
{
Spec
:
app
s
.
DaemonSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
selectorLabels
,
MatchLabels
:
selectorLabels
,
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
},
},
UpdateStrategy
:
extension
s
.
DaemonSetUpdateStrategy
{
UpdateStrategy
:
app
s
.
DaemonSetUpdateStrategy
{
Type
:
extension
s
.
OnDeleteDaemonSetStrategyType
,
Type
:
app
s
.
OnDeleteDaemonSetStrategyType
,
},
},
TemplateGeneration
:
templateGeneration
,
TemplateGeneration
:
templateGeneration
,
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
...
...
pkg/registry/apps/deployment/storage/storage.go
View file @
d0577ace
...
@@ -31,14 +31,14 @@ import (
...
@@ -31,14 +31,14 @@ import (
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage"
storeerr
"k8s.io/apiserver/pkg/storage/errors"
storeerr
"k8s.io/apiserver/pkg/storage/errors"
"k8s.io/apiserver/pkg/util/dryrun"
"k8s.io/apiserver/pkg/util/dryrun"
"k8s.io/kubernetes/pkg/apis/apps"
appsv1beta1
"k8s.io/kubernetes/pkg/apis/apps/v1beta1"
appsv1beta1
"k8s.io/kubernetes/pkg/apis/apps/v1beta1"
appsv1beta2
"k8s.io/kubernetes/pkg/apis/apps/v1beta2"
appsv1beta2
"k8s.io/kubernetes/pkg/apis/apps/v1beta2"
appsvalidation
"k8s.io/kubernetes/pkg/apis/apps/validation"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
"k8s.io/kubernetes/pkg/apis/extensions"
extensionsv1beta1
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
extensionsv1beta1
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
extvalidation
"k8s.io/kubernetes/pkg/apis/extensions/validation"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
...
@@ -72,9 +72,9 @@ type REST struct {
...
@@ -72,9 +72,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against deployments.
// NewREST returns a RESTStorage object that will work against deployments.
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
,
*
RollbackREST
)
{
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
,
*
RollbackREST
)
{
store
:=
&
genericregistry
.
Store
{
store
:=
&
genericregistry
.
Store
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
Deployment
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
Deployment
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
DeploymentList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
DeploymentList
{}
},
DefaultQualifiedResource
:
extension
s
.
Resource
(
"deployments"
),
DefaultQualifiedResource
:
app
s
.
Resource
(
"deployments"
),
CreateStrategy
:
deployment
.
Strategy
,
CreateStrategy
:
deployment
.
Strategy
,
UpdateStrategy
:
deployment
.
Strategy
,
UpdateStrategy
:
deployment
.
Strategy
,
...
@@ -119,7 +119,7 @@ type StatusREST struct {
...
@@ -119,7 +119,7 @@ type StatusREST struct {
}
}
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
return
&
extension
s
.
Deployment
{}
return
&
app
s
.
Deployment
{}
}
}
// Get retrieves the object from the storage. It is required to support Patch.
// Get retrieves the object from the storage. It is required to support Patch.
...
@@ -155,19 +155,19 @@ var _ = rest.StorageMetadata(&RollbackREST{})
...
@@ -155,19 +155,19 @@ var _ = rest.StorageMetadata(&RollbackREST{})
// New creates a rollback
// New creates a rollback
func
(
r
*
RollbackREST
)
New
()
runtime
.
Object
{
func
(
r
*
RollbackREST
)
New
()
runtime
.
Object
{
return
&
extension
s
.
DeploymentRollback
{}
return
&
app
s
.
DeploymentRollback
{}
}
}
var
_
=
rest
.
Creater
(
&
RollbackREST
{})
var
_
=
rest
.
Creater
(
&
RollbackREST
{})
func
(
r
*
RollbackREST
)
Create
(
ctx
context
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
options
*
metav1
.
CreateOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
RollbackREST
)
Create
(
ctx
context
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
options
*
metav1
.
CreateOptions
)
(
runtime
.
Object
,
error
)
{
rollback
,
ok
:=
obj
.
(
*
extension
s
.
DeploymentRollback
)
rollback
,
ok
:=
obj
.
(
*
app
s
.
DeploymentRollback
)
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a DeploymentRollback: %#v"
,
obj
))
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a DeploymentRollback: %#v"
,
obj
))
}
}
if
errs
:=
ext
validation
.
ValidateDeploymentRollback
(
rollback
);
len
(
errs
)
!=
0
{
if
errs
:=
apps
validation
.
ValidateDeploymentRollback
(
rollback
);
len
(
errs
)
!=
0
{
return
nil
,
errors
.
NewInvalid
(
extension
s
.
Kind
(
"DeploymentRollback"
),
rollback
.
Name
,
errs
)
return
nil
,
errors
.
NewInvalid
(
app
s
.
Kind
(
"DeploymentRollback"
),
rollback
.
Name
,
errs
)
}
}
// Update the Deployment with information in DeploymentRollback to trigger rollback
// Update the Deployment with information in DeploymentRollback to trigger rollback
...
@@ -182,10 +182,10 @@ func (r *RollbackREST) Create(ctx context.Context, obj runtime.Object, createVal
...
@@ -182,10 +182,10 @@ func (r *RollbackREST) Create(ctx context.Context, obj runtime.Object, createVal
},
nil
},
nil
}
}
func
(
r
*
RollbackREST
)
rollbackDeployment
(
ctx
context
.
Context
,
deploymentID
string
,
config
*
extension
s
.
RollbackConfig
,
annotations
map
[
string
]
string
,
dryRun
bool
)
error
{
func
(
r
*
RollbackREST
)
rollbackDeployment
(
ctx
context
.
Context
,
deploymentID
string
,
config
*
app
s
.
RollbackConfig
,
annotations
map
[
string
]
string
,
dryRun
bool
)
error
{
if
_
,
err
:=
r
.
setDeploymentRollback
(
ctx
,
deploymentID
,
config
,
annotations
,
dryRun
);
err
!=
nil
{
if
_
,
err
:=
r
.
setDeploymentRollback
(
ctx
,
deploymentID
,
config
,
annotations
,
dryRun
);
err
!=
nil
{
err
=
storeerr
.
InterpretGetError
(
err
,
extension
s
.
Resource
(
"deployments"
),
deploymentID
)
err
=
storeerr
.
InterpretGetError
(
err
,
app
s
.
Resource
(
"deployments"
),
deploymentID
)
err
=
storeerr
.
InterpretUpdateError
(
err
,
extension
s
.
Resource
(
"deployments"
),
deploymentID
)
err
=
storeerr
.
InterpretUpdateError
(
err
,
app
s
.
Resource
(
"deployments"
),
deploymentID
)
if
_
,
ok
:=
err
.
(
*
errors
.
StatusError
);
!
ok
{
if
_
,
ok
:=
err
.
(
*
errors
.
StatusError
);
!
ok
{
err
=
errors
.
NewInternalError
(
err
)
err
=
errors
.
NewInternalError
(
err
)
}
}
...
@@ -194,14 +194,14 @@ func (r *RollbackREST) rollbackDeployment(ctx context.Context, deploymentID stri
...
@@ -194,14 +194,14 @@ func (r *RollbackREST) rollbackDeployment(ctx context.Context, deploymentID stri
return
nil
return
nil
}
}
func
(
r
*
RollbackREST
)
setDeploymentRollback
(
ctx
context
.
Context
,
deploymentID
string
,
config
*
extensions
.
RollbackConfig
,
annotations
map
[
string
]
string
,
dryRun
bool
)
(
*
extension
s
.
Deployment
,
error
)
{
func
(
r
*
RollbackREST
)
setDeploymentRollback
(
ctx
context
.
Context
,
deploymentID
string
,
config
*
apps
.
RollbackConfig
,
annotations
map
[
string
]
string
,
dryRun
bool
)
(
*
app
s
.
Deployment
,
error
)
{
dKey
,
err
:=
r
.
store
.
KeyFunc
(
ctx
,
deploymentID
)
dKey
,
err
:=
r
.
store
.
KeyFunc
(
ctx
,
deploymentID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
var
finalDeployment
*
extension
s
.
Deployment
var
finalDeployment
*
app
s
.
Deployment
err
=
r
.
store
.
Storage
.
GuaranteedUpdate
(
ctx
,
dKey
,
&
extension
s
.
Deployment
{},
false
,
nil
,
storage
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
store
.
Storage
.
GuaranteedUpdate
(
ctx
,
dKey
,
&
app
s
.
Deployment
{},
false
,
nil
,
storage
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
d
,
ok
:=
obj
.
(
*
extension
s
.
Deployment
)
d
,
ok
:=
obj
.
(
*
app
s
.
Deployment
)
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected object: %#v"
,
obj
)
return
nil
,
fmt
.
Errorf
(
"unexpected object: %#v"
,
obj
)
}
}
...
@@ -247,9 +247,9 @@ func (r *ScaleREST) New() runtime.Object {
...
@@ -247,9 +247,9 @@ func (r *ScaleREST) New() runtime.Object {
func
(
r
*
ScaleREST
)
Get
(
ctx
context
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
context
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
options
)
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
extension
s
.
Resource
(
"deployments/scale"
),
name
)
return
nil
,
errors
.
NewNotFound
(
app
s
.
Resource
(
"deployments/scale"
),
name
)
}
}
deployment
:=
obj
.
(
*
extension
s
.
Deployment
)
deployment
:=
obj
.
(
*
app
s
.
Deployment
)
scale
,
err
:=
scaleFromDeployment
(
deployment
)
scale
,
err
:=
scaleFromDeployment
(
deployment
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
...
@@ -260,9 +260,9 @@ func (r *ScaleREST) Get(ctx context.Context, name string, options *metav1.GetOpt
...
@@ -260,9 +260,9 @@ func (r *ScaleREST) Get(ctx context.Context, name string, options *metav1.GetOpt
func
(
r
*
ScaleREST
)
Update
(
ctx
context
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
,
forceAllowCreate
bool
,
options
*
metav1
.
UpdateOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
context
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
,
forceAllowCreate
bool
,
options
*
metav1
.
UpdateOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
extension
s
.
Resource
(
"deployments/scale"
),
name
)
return
nil
,
false
,
errors
.
NewNotFound
(
app
s
.
Resource
(
"deployments/scale"
),
name
)
}
}
deployment
:=
obj
.
(
*
extension
s
.
Deployment
)
deployment
:=
obj
.
(
*
app
s
.
Deployment
)
oldScale
,
err
:=
scaleFromDeployment
(
deployment
)
oldScale
,
err
:=
scaleFromDeployment
(
deployment
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -282,7 +282,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -282,7 +282,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
}
}
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
return
nil
,
false
,
errors
.
NewInvalid
(
extensions
.
Kind
(
"Scale"
),
name
,
errs
)
return
nil
,
false
,
errors
.
NewInvalid
(
autoscaling
.
Kind
(
"Scale"
),
name
,
errs
)
}
}
deployment
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
deployment
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
...
@@ -291,7 +291,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -291,7 +291,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
deployment
=
obj
.
(
*
extension
s
.
Deployment
)
deployment
=
obj
.
(
*
app
s
.
Deployment
)
newScale
,
err
:=
scaleFromDeployment
(
deployment
)
newScale
,
err
:=
scaleFromDeployment
(
deployment
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
return
nil
,
false
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
...
@@ -300,7 +300,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -300,7 +300,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
}
}
// scaleFromDeployment returns a scale subresource for a deployment.
// scaleFromDeployment returns a scale subresource for a deployment.
func
scaleFromDeployment
(
deployment
*
extension
s
.
Deployment
)
(
*
autoscaling
.
Scale
,
error
)
{
func
scaleFromDeployment
(
deployment
*
app
s
.
Deployment
)
(
*
autoscaling
.
Scale
,
error
)
{
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
deployment
.
Spec
.
Selector
)
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
deployment
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/registry/apps/deployment/storage/storage_test.go
View file @
d0577ace
...
@@ -35,16 +35,16 @@ import (
...
@@ -35,16 +35,16 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
storeerr
"k8s.io/apiserver/pkg/storage/errors"
storeerr
"k8s.io/apiserver/pkg/storage/errors"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
)
)
const
defaultReplicas
=
100
const
defaultReplicas
=
100
func
newStorage
(
t
*
testing
.
T
)
(
*
DeploymentStorage
,
*
etcdtesting
.
EtcdTestServer
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
DeploymentStorage
,
*
etcdtesting
.
EtcdTestServer
)
{
etcdStorage
,
server
:=
registrytest
.
NewEtcdStorage
(
t
,
extension
s
.
GroupName
)
etcdStorage
,
server
:=
registrytest
.
NewEtcdStorage
(
t
,
app
s
.
GroupName
)
restOptions
:=
generic
.
RESTOptions
{
StorageConfig
:
etcdStorage
,
Decorator
:
generic
.
UndecoratedStorage
,
DeleteCollectionWorkers
:
1
,
ResourcePrefix
:
"deployments"
}
restOptions
:=
generic
.
RESTOptions
{
StorageConfig
:
etcdStorage
,
Decorator
:
generic
.
UndecoratedStorage
,
DeleteCollectionWorkers
:
1
,
ResourcePrefix
:
"deployments"
}
deploymentStorage
:=
NewStorage
(
restOptions
)
deploymentStorage
:=
NewStorage
(
restOptions
)
return
&
deploymentStorage
,
server
return
&
deploymentStorage
,
server
...
@@ -53,17 +53,17 @@ func newStorage(t *testing.T) (*DeploymentStorage, *etcdtesting.EtcdTestServer)
...
@@ -53,17 +53,17 @@ func newStorage(t *testing.T) (*DeploymentStorage, *etcdtesting.EtcdTestServer)
var
namespace
=
"foo-namespace"
var
namespace
=
"foo-namespace"
var
name
=
"foo-deployment"
var
name
=
"foo-deployment"
func
validNewDeployment
()
*
extension
s
.
Deployment
{
func
validNewDeployment
()
*
app
s
.
Deployment
{
return
&
extension
s
.
Deployment
{
return
&
app
s
.
Deployment
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
Namespace
:
namespace
,
Namespace
:
namespace
,
},
},
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Strategy
:
extension
s
.
DeploymentStrategy
{
Strategy
:
app
s
.
DeploymentStrategy
{
Type
:
extension
s
.
RollingUpdateDeploymentStrategyType
,
Type
:
app
s
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
extension
s
.
RollingUpdateDeployment
{
RollingUpdate
:
&
app
s
.
RollingUpdateDeployment
{
MaxSurge
:
intstr
.
FromInt
(
1
),
MaxSurge
:
intstr
.
FromInt
(
1
),
MaxUnavailable
:
intstr
.
FromInt
(
1
),
MaxUnavailable
:
intstr
.
FromInt
(
1
),
},
},
...
@@ -87,7 +87,7 @@ func validNewDeployment() *extensions.Deployment {
...
@@ -87,7 +87,7 @@ func validNewDeployment() *extensions.Deployment {
},
},
Replicas
:
7
,
Replicas
:
7
,
},
},
Status
:
extension
s
.
DeploymentStatus
{
Status
:
app
s
.
DeploymentStatus
{
Replicas
:
5
,
Replicas
:
5
,
},
},
}
}
...
@@ -106,8 +106,8 @@ func TestCreate(t *testing.T) {
...
@@ -106,8 +106,8 @@ func TestCreate(t *testing.T) {
// valid
// valid
deployment
,
deployment
,
// invalid (invalid selector)
// invalid (invalid selector)
&
extension
s
.
Deployment
{
&
app
s
.
Deployment
{
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Template
:
validDeployment
.
Spec
.
Template
,
Template
:
validDeployment
.
Spec
.
Template
,
},
},
...
@@ -125,23 +125,23 @@ func TestUpdate(t *testing.T) {
...
@@ -125,23 +125,23 @@ func TestUpdate(t *testing.T) {
validNewDeployment
(),
validNewDeployment
(),
// updateFunc
// updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
Deployment
)
object
:=
obj
.
(
*
app
s
.
Deployment
)
object
.
Spec
.
Template
.
Spec
.
NodeSelector
=
map
[
string
]
string
{
"c"
:
"d"
}
object
.
Spec
.
Template
.
Spec
.
NodeSelector
=
map
[
string
]
string
{
"c"
:
"d"
}
return
object
return
object
},
},
// invalid updateFunc
// invalid updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
Deployment
)
object
:=
obj
.
(
*
app
s
.
Deployment
)
object
.
Name
=
""
object
.
Name
=
""
return
object
return
object
},
},
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
Deployment
)
object
:=
obj
.
(
*
app
s
.
Deployment
)
object
.
Spec
.
Template
.
Spec
.
RestartPolicy
=
api
.
RestartPolicyOnFailure
object
.
Spec
.
Template
.
Spec
.
RestartPolicy
=
api
.
RestartPolicyOnFailure
return
object
return
object
},
},
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
Deployment
)
object
:=
obj
.
(
*
app
s
.
Deployment
)
object
.
Spec
.
Selector
=
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}}
object
.
Spec
.
Selector
=
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}}
return
object
return
object
},
},
...
@@ -202,7 +202,7 @@ func TestScaleGet(t *testing.T) {
...
@@ -202,7 +202,7 @@ func TestScaleGet(t *testing.T) {
storage
,
server
:=
newStorage
(
t
)
storage
,
server
:=
newStorage
(
t
)
defer
server
.
Terminate
(
t
)
defer
server
.
Terminate
(
t
)
defer
storage
.
Deployment
.
Store
.
DestroyFunc
()
defer
storage
.
Deployment
.
Store
.
DestroyFunc
()
var
deployment
extension
s
.
Deployment
var
deployment
app
s
.
Deployment
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
key
:=
"/deployments/"
+
namespace
+
"/"
+
name
key
:=
"/deployments/"
+
namespace
+
"/"
+
name
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
&
deployment
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
&
deployment
,
0
,
false
);
err
!=
nil
{
...
@@ -243,7 +243,7 @@ func TestScaleUpdate(t *testing.T) {
...
@@ -243,7 +243,7 @@ func TestScaleUpdate(t *testing.T) {
storage
,
server
:=
newStorage
(
t
)
storage
,
server
:=
newStorage
(
t
)
defer
server
.
Terminate
(
t
)
defer
server
.
Terminate
(
t
)
defer
storage
.
Deployment
.
Store
.
DestroyFunc
()
defer
storage
.
Deployment
.
Store
.
DestroyFunc
()
var
deployment
extension
s
.
Deployment
var
deployment
app
s
.
Deployment
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
key
:=
"/deployments/"
+
namespace
+
"/"
+
name
key
:=
"/deployments/"
+
namespace
+
"/"
+
name
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
&
deployment
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
&
deployment
,
0
,
false
);
err
!=
nil
{
...
@@ -286,12 +286,12 @@ func TestStatusUpdate(t *testing.T) {
...
@@ -286,12 +286,12 @@ func TestStatusUpdate(t *testing.T) {
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
nil
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
Deployment
.
Storage
.
Create
(
ctx
,
key
,
&
validDeployment
,
nil
,
0
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
update
:=
extension
s
.
Deployment
{
update
:=
app
s
.
Deployment
{
ObjectMeta
:
validDeployment
.
ObjectMeta
,
ObjectMeta
:
validDeployment
.
ObjectMeta
,
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Replicas
:
defaultReplicas
,
Replicas
:
defaultReplicas
,
},
},
Status
:
extension
s
.
DeploymentStatus
{
Status
:
app
s
.
DeploymentStatus
{
Replicas
:
defaultReplicas
,
Replicas
:
defaultReplicas
,
},
},
}
}
...
@@ -304,7 +304,7 @@ func TestStatusUpdate(t *testing.T) {
...
@@ -304,7 +304,7 @@ func TestStatusUpdate(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
deployment
:=
obj
.
(
*
extension
s
.
Deployment
)
deployment
:=
obj
.
(
*
app
s
.
Deployment
)
if
deployment
.
Spec
.
Replicas
!=
7
{
if
deployment
.
Spec
.
Replicas
!=
7
{
t
.
Errorf
(
"we expected .spec.replicas to not be updated but it was updated to %v"
,
deployment
.
Spec
.
Replicas
)
t
.
Errorf
(
"we expected .spec.replicas to not be updated but it was updated to %v"
,
deployment
.
Spec
.
Replicas
)
}
}
...
@@ -317,28 +317,28 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) {
...
@@ -317,28 +317,28 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) {
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
testCases
:=
map
[
string
]
struct
{
testCases
:=
map
[
string
]
struct
{
rollback
extension
s
.
DeploymentRollback
rollback
app
s
.
DeploymentRollback
errOK
func
(
error
)
bool
errOK
func
(
error
)
bool
}{
}{
"normal"
:
{
"normal"
:
{
rollback
:
extension
s
.
DeploymentRollback
{
rollback
:
app
s
.
DeploymentRollback
{
Name
:
name
,
Name
:
name
,
UpdatedAnnotations
:
map
[
string
]
string
{},
UpdatedAnnotations
:
map
[
string
]
string
{},
RollbackTo
:
extension
s
.
RollbackConfig
{
Revision
:
1
},
RollbackTo
:
app
s
.
RollbackConfig
{
Revision
:
1
},
},
},
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
},
},
"noAnnotation"
:
{
"noAnnotation"
:
{
rollback
:
extension
s
.
DeploymentRollback
{
rollback
:
app
s
.
DeploymentRollback
{
Name
:
name
,
Name
:
name
,
RollbackTo
:
extension
s
.
RollbackConfig
{
Revision
:
1
},
RollbackTo
:
app
s
.
RollbackConfig
{
Revision
:
1
},
},
},
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
},
},
"noName"
:
{
"noName"
:
{
rollback
:
extension
s
.
DeploymentRollback
{
rollback
:
app
s
.
DeploymentRollback
{
UpdatedAnnotations
:
map
[
string
]
string
{},
UpdatedAnnotations
:
map
[
string
]
string
{},
RollbackTo
:
extension
s
.
RollbackConfig
{
Revision
:
1
},
RollbackTo
:
app
s
.
RollbackConfig
{
Revision
:
1
},
},
},
errOK
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
errOK
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
},
},
...
@@ -365,8 +365,8 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) {
...
@@ -365,8 +365,8 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) {
d
,
err
:=
storage
.
Deployment
.
Get
(
ctx
,
validNewDeployment
()
.
ObjectMeta
.
Name
,
&
metav1
.
GetOptions
{})
d
,
err
:=
storage
.
Deployment
.
Get
(
ctx
,
validNewDeployment
()
.
ObjectMeta
.
Name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%s: unexpected error: %v"
,
k
,
err
)
t
.
Errorf
(
"%s: unexpected error: %v"
,
k
,
err
)
}
else
if
!
reflect
.
DeepEqual
(
*
d
.
(
*
extension
s
.
Deployment
)
.
Spec
.
RollbackTo
,
test
.
rollback
.
RollbackTo
)
{
}
else
if
!
reflect
.
DeepEqual
(
*
d
.
(
*
app
s
.
Deployment
)
.
Spec
.
RollbackTo
,
test
.
rollback
.
RollbackTo
)
{
t
.
Errorf
(
"%s: expected: %v, got: %v"
,
k
,
*
d
.
(
*
extension
s
.
Deployment
)
.
Spec
.
RollbackTo
,
test
.
rollback
.
RollbackTo
)
t
.
Errorf
(
"%s: expected: %v, got: %v"
,
k
,
*
d
.
(
*
app
s
.
Deployment
)
.
Spec
.
RollbackTo
,
test
.
rollback
.
RollbackTo
)
}
}
}
}
storage
.
Deployment
.
Store
.
DestroyFunc
()
storage
.
Deployment
.
Store
.
DestroyFunc
()
...
@@ -383,15 +383,15 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) {
...
@@ -383,15 +383,15 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) {
rollbackStorage
:=
storage
.
Rollback
rollbackStorage
:=
storage
.
Rollback
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
namespace
)
_
,
err
:=
rollbackStorage
.
Create
(
ctx
,
&
extension
s
.
DeploymentRollback
{
_
,
err
:=
rollbackStorage
.
Create
(
ctx
,
&
app
s
.
DeploymentRollback
{
Name
:
name
,
Name
:
name
,
UpdatedAnnotations
:
map
[
string
]
string
{},
UpdatedAnnotations
:
map
[
string
]
string
{},
RollbackTo
:
extension
s
.
RollbackConfig
{
Revision
:
1
},
RollbackTo
:
app
s
.
RollbackConfig
{
Revision
:
1
},
},
rest
.
ValidateAllObjectFunc
,
&
metav1
.
CreateOptions
{})
},
rest
.
ValidateAllObjectFunc
,
&
metav1
.
CreateOptions
{})
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"Expected not-found-error but got nothing"
)
t
.
Fatalf
(
"Expected not-found-error but got nothing"
)
}
}
if
!
errors
.
IsNotFound
(
storeerr
.
InterpretGetError
(
err
,
extension
s
.
Resource
(
"deployments"
),
name
))
{
if
!
errors
.
IsNotFound
(
storeerr
.
InterpretGetError
(
err
,
app
s
.
Resource
(
"deployments"
),
name
))
{
t
.
Fatalf
(
"Unexpected error returned: %#v"
,
err
)
t
.
Fatalf
(
"Unexpected error returned: %#v"
,
err
)
}
}
...
@@ -399,7 +399,7 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) {
...
@@ -399,7 +399,7 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) {
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"Expected not-found-error but got nothing"
)
t
.
Fatalf
(
"Expected not-found-error but got nothing"
)
}
}
if
!
errors
.
IsNotFound
(
storeerr
.
InterpretGetError
(
err
,
extension
s
.
Resource
(
"deployments"
),
name
))
{
if
!
errors
.
IsNotFound
(
storeerr
.
InterpretGetError
(
err
,
app
s
.
Resource
(
"deployments"
),
name
))
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
}
}
...
...
pkg/registry/apps/deployment/strategy.go
View file @
d0577ace
...
@@ -32,8 +32,8 @@ import (
...
@@ -32,8 +32,8 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/apis/
extension
s"
"k8s.io/kubernetes/pkg/apis/
app
s"
"k8s.io/kubernetes/pkg/apis/
extension
s/validation"
"k8s.io/kubernetes/pkg/apis/
app
s/validation"
)
)
// deploymentStrategy implements behavior for Deployments.
// deploymentStrategy implements behavior for Deployments.
...
@@ -68,8 +68,8 @@ func (deploymentStrategy) NamespaceScoped() bool {
...
@@ -68,8 +68,8 @@ func (deploymentStrategy) NamespaceScoped() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
deploymentStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
func
(
deploymentStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
deployment
:=
obj
.
(
*
extension
s
.
Deployment
)
deployment
:=
obj
.
(
*
app
s
.
Deployment
)
deployment
.
Status
=
extension
s
.
DeploymentStatus
{}
deployment
.
Status
=
app
s
.
DeploymentStatus
{}
deployment
.
Generation
=
1
deployment
.
Generation
=
1
pod
.
DropDisabledAlphaFields
(
&
deployment
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledAlphaFields
(
&
deployment
.
Spec
.
Template
.
Spec
)
...
@@ -77,7 +77,7 @@ func (deploymentStrategy) PrepareForCreate(ctx context.Context, obj runtime.Obje
...
@@ -77,7 +77,7 @@ func (deploymentStrategy) PrepareForCreate(ctx context.Context, obj runtime.Obje
// Validate validates a new deployment.
// Validate validates a new deployment.
func
(
deploymentStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
deployment
:=
obj
.
(
*
extension
s
.
Deployment
)
deployment
:=
obj
.
(
*
app
s
.
Deployment
)
return
validation
.
ValidateDeployment
(
deployment
)
return
validation
.
ValidateDeployment
(
deployment
)
}
}
...
@@ -92,8 +92,8 @@ func (deploymentStrategy) AllowCreateOnUpdate() bool {
...
@@ -92,8 +92,8 @@ func (deploymentStrategy) AllowCreateOnUpdate() bool {
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
deploymentStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
deploymentStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDeployment
:=
obj
.
(
*
extension
s
.
Deployment
)
newDeployment
:=
obj
.
(
*
app
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
extension
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
app
s
.
Deployment
)
newDeployment
.
Status
=
oldDeployment
.
Status
newDeployment
.
Status
=
oldDeployment
.
Status
pod
.
DropDisabledAlphaFields
(
&
newDeployment
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledAlphaFields
(
&
newDeployment
.
Spec
.
Template
.
Spec
)
...
@@ -110,8 +110,8 @@ func (deploymentStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime
...
@@ -110,8 +110,8 @@ func (deploymentStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime
// ValidateUpdate is the default update validation for an end user.
// ValidateUpdate is the default update validation for an end user.
func
(
deploymentStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newDeployment
:=
obj
.
(
*
extension
s
.
Deployment
)
newDeployment
:=
obj
.
(
*
app
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
extension
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
app
s
.
Deployment
)
allErrs
:=
validation
.
ValidateDeploymentUpdate
(
newDeployment
,
oldDeployment
)
allErrs
:=
validation
.
ValidateDeploymentUpdate
(
newDeployment
,
oldDeployment
)
// Update is not allowed to set Spec.Selector for all groups/versions except extensions/v1beta1.
// Update is not allowed to set Spec.Selector for all groups/versions except extensions/v1beta1.
...
@@ -145,13 +145,13 @@ var StatusStrategy = deploymentStatusStrategy{Strategy}
...
@@ -145,13 +145,13 @@ var StatusStrategy = deploymentStatusStrategy{Strategy}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
deploymentStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
deploymentStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDeployment
:=
obj
.
(
*
extension
s
.
Deployment
)
newDeployment
:=
obj
.
(
*
app
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
extension
s
.
Deployment
)
oldDeployment
:=
old
.
(
*
app
s
.
Deployment
)
newDeployment
.
Spec
=
oldDeployment
.
Spec
newDeployment
.
Spec
=
oldDeployment
.
Spec
newDeployment
.
Labels
=
oldDeployment
.
Labels
newDeployment
.
Labels
=
oldDeployment
.
Labels
}
}
// ValidateUpdate is the default update validation for an end user updating status
// ValidateUpdate is the default update validation for an end user updating status
func
(
deploymentStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateDeploymentStatusUpdate
(
obj
.
(
*
extensions
.
Deployment
),
old
.
(
*
extension
s
.
Deployment
))
return
validation
.
ValidateDeploymentStatusUpdate
(
obj
.
(
*
apps
.
Deployment
),
old
.
(
*
app
s
.
Deployment
))
}
}
pkg/registry/apps/deployment/strategy_test.go
View file @
d0577ace
...
@@ -26,8 +26,8 @@ import (
...
@@ -26,8 +26,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/apps"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
)
)
const
(
const
(
...
@@ -63,17 +63,17 @@ func TestStatusUpdates(t *testing.T) {
...
@@ -63,17 +63,17 @@ func TestStatusUpdates(t *testing.T) {
}
}
}
}
func
newDeployment
(
labels
,
annotations
map
[
string
]
string
)
*
extension
s
.
Deployment
{
func
newDeployment
(
labels
,
annotations
map
[
string
]
string
)
*
app
s
.
Deployment
{
return
&
extension
s
.
Deployment
{
return
&
app
s
.
Deployment
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test"
,
Name
:
"test"
,
Labels
:
labels
,
Labels
:
labels
,
Annotations
:
annotations
,
Annotations
:
annotations
,
},
},
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Replicas
:
1
,
Replicas
:
1
,
Strategy
:
extension
s
.
DeploymentStrategy
{
Strategy
:
app
s
.
DeploymentStrategy
{
Type
:
extension
s
.
RecreateDeploymentStrategyType
,
Type
:
app
s
.
RecreateDeploymentStrategyType
,
},
},
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
...
@@ -152,21 +152,21 @@ func TestSelectorImmutability(t *testing.T) {
...
@@ -152,21 +152,21 @@ func TestSelectorImmutability(t *testing.T) {
}
}
}
}
func
newDeploymentWithSelectorLabels
(
selectorLabels
map
[
string
]
string
)
*
extension
s
.
Deployment
{
func
newDeploymentWithSelectorLabels
(
selectorLabels
map
[
string
]
string
)
*
app
s
.
Deployment
{
return
&
extension
s
.
Deployment
{
return
&
app
s
.
Deployment
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
deploymentName
,
Name
:
deploymentName
,
Namespace
:
namespace
,
Namespace
:
namespace
,
ResourceVersion
:
"1"
,
ResourceVersion
:
"1"
,
},
},
Spec
:
extension
s
.
DeploymentSpec
{
Spec
:
app
s
.
DeploymentSpec
{
Selector
:
&
metav1
.
LabelSelector
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
selectorLabels
,
MatchLabels
:
selectorLabels
,
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
},
},
Strategy
:
extension
s
.
DeploymentStrategy
{
Strategy
:
app
s
.
DeploymentStrategy
{
Type
:
extension
s
.
RollingUpdateDeploymentStrategyType
,
Type
:
app
s
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
extension
s
.
RollingUpdateDeployment
{
RollingUpdate
:
&
app
s
.
RollingUpdateDeployment
{
MaxSurge
:
intstr
.
FromInt
(
1
),
MaxSurge
:
intstr
.
FromInt
(
1
),
MaxUnavailable
:
intstr
.
FromInt
(
1
),
MaxUnavailable
:
intstr
.
FromInt
(
1
),
},
},
...
...
pkg/registry/apps/replicaset/storage/storage.go
View file @
d0577ace
...
@@ -29,12 +29,12 @@ import (
...
@@ -29,12 +29,12 @@ import (
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/apps"
appsv1beta1
"k8s.io/kubernetes/pkg/apis/apps/v1beta1"
appsv1beta1
"k8s.io/kubernetes/pkg/apis/apps/v1beta1"
appsv1beta2
"k8s.io/kubernetes/pkg/apis/apps/v1beta2"
appsv1beta2
"k8s.io/kubernetes/pkg/apis/apps/v1beta2"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
"k8s.io/kubernetes/pkg/apis/extensions"
extensionsv1beta1
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
extensionsv1beta1
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
...
@@ -67,10 +67,10 @@ type REST struct {
...
@@ -67,10 +67,10 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against ReplicaSet.
// NewREST returns a RESTStorage object that will work against ReplicaSet.
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
)
{
func
NewREST
(
optsGetter
generic
.
RESTOptionsGetter
)
(
*
REST
,
*
StatusREST
)
{
store
:=
&
genericregistry
.
Store
{
store
:=
&
genericregistry
.
Store
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
ReplicaSet
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
ReplicaSet
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
extension
s
.
ReplicaSetList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
app
s
.
ReplicaSetList
{}
},
PredicateFunc
:
replicaset
.
MatchReplicaSet
,
PredicateFunc
:
replicaset
.
MatchReplicaSet
,
DefaultQualifiedResource
:
extension
s
.
Resource
(
"replicasets"
),
DefaultQualifiedResource
:
app
s
.
Resource
(
"replicasets"
),
CreateStrategy
:
replicaset
.
Strategy
,
CreateStrategy
:
replicaset
.
Strategy
,
UpdateStrategy
:
replicaset
.
Strategy
,
UpdateStrategy
:
replicaset
.
Strategy
,
...
@@ -116,7 +116,7 @@ type StatusREST struct {
...
@@ -116,7 +116,7 @@ type StatusREST struct {
}
}
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
return
&
extension
s
.
ReplicaSet
{}
return
&
app
s
.
ReplicaSet
{}
}
}
// Get retrieves the object from the storage. It is required to support Patch.
// Get retrieves the object from the storage. It is required to support Patch.
...
@@ -160,9 +160,9 @@ func (r *ScaleREST) New() runtime.Object {
...
@@ -160,9 +160,9 @@ func (r *ScaleREST) New() runtime.Object {
func
(
r
*
ScaleREST
)
Get
(
ctx
context
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
context
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
options
)
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
extension
s
.
Resource
(
"replicasets/scale"
),
name
)
return
nil
,
errors
.
NewNotFound
(
app
s
.
Resource
(
"replicasets/scale"
),
name
)
}
}
rs
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
:=
obj
.
(
*
app
s
.
ReplicaSet
)
scale
,
err
:=
scaleFromReplicaSet
(
rs
)
scale
,
err
:=
scaleFromReplicaSet
(
rs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
...
@@ -173,9 +173,9 @@ func (r *ScaleREST) Get(ctx context.Context, name string, options *metav1.GetOpt
...
@@ -173,9 +173,9 @@ func (r *ScaleREST) Get(ctx context.Context, name string, options *metav1.GetOpt
func
(
r
*
ScaleREST
)
Update
(
ctx
context
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
,
forceAllowCreate
bool
,
options
*
metav1
.
UpdateOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
context
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
,
forceAllowCreate
bool
,
options
*
metav1
.
UpdateOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
extension
s
.
Resource
(
"replicasets/scale"
),
name
)
return
nil
,
false
,
errors
.
NewNotFound
(
app
s
.
Resource
(
"replicasets/scale"
),
name
)
}
}
rs
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
:=
obj
.
(
*
app
s
.
ReplicaSet
)
oldScale
,
err
:=
scaleFromReplicaSet
(
rs
)
oldScale
,
err
:=
scaleFromReplicaSet
(
rs
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -196,7 +196,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -196,7 +196,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
}
}
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
return
nil
,
false
,
errors
.
NewInvalid
(
extensions
.
Kind
(
"Scale"
),
scale
.
Name
,
errs
)
return
nil
,
false
,
errors
.
NewInvalid
(
autoscaling
.
Kind
(
"Scale"
),
scale
.
Name
,
errs
)
}
}
rs
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
rs
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
...
@@ -205,7 +205,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -205,7 +205,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
rs
=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
=
obj
.
(
*
app
s
.
ReplicaSet
)
newScale
,
err
:=
scaleFromReplicaSet
(
rs
)
newScale
,
err
:=
scaleFromReplicaSet
(
rs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
return
nil
,
false
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%v"
,
err
))
...
@@ -214,7 +214,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -214,7 +214,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
}
}
// scaleFromReplicaSet returns a scale subresource for a replica set.
// scaleFromReplicaSet returns a scale subresource for a replica set.
func
scaleFromReplicaSet
(
rs
*
extension
s
.
ReplicaSet
)
(
*
autoscaling
.
Scale
,
error
)
{
func
scaleFromReplicaSet
(
rs
*
app
s
.
ReplicaSet
)
(
*
autoscaling
.
Scale
,
error
)
{
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
rs
.
Spec
.
Selector
)
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
rs
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/registry/apps/replicaset/storage/storage_test.go
View file @
d0577ace
...
@@ -31,9 +31,9 @@ import (
...
@@ -31,9 +31,9 @@ import (
genericregistrytest
"k8s.io/apiserver/pkg/registry/generic/testing"
genericregistrytest
"k8s.io/apiserver/pkg/registry/generic/testing"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
)
)
...
@@ -47,23 +47,23 @@ func newStorage(t *testing.T) (*ReplicaSetStorage, *etcdtesting.EtcdTestServer)
...
@@ -47,23 +47,23 @@ func newStorage(t *testing.T) (*ReplicaSetStorage, *etcdtesting.EtcdTestServer)
}
}
// createReplicaSet is a helper function that returns a ReplicaSet with the updated resource version.
// createReplicaSet is a helper function that returns a ReplicaSet with the updated resource version.
func
createReplicaSet
(
storage
*
REST
,
rs
extensions
.
ReplicaSet
,
t
*
testing
.
T
)
(
extension
s
.
ReplicaSet
,
error
)
{
func
createReplicaSet
(
storage
*
REST
,
rs
apps
.
ReplicaSet
,
t
*
testing
.
T
)
(
app
s
.
ReplicaSet
,
error
)
{
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
rs
.
Namespace
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
rs
.
Namespace
)
obj
,
err
:=
storage
.
Create
(
ctx
,
&
rs
,
rest
.
ValidateAllObjectFunc
,
&
metav1
.
CreateOptions
{})
obj
,
err
:=
storage
.
Create
(
ctx
,
&
rs
,
rest
.
ValidateAllObjectFunc
,
&
metav1
.
CreateOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create ReplicaSet, %v"
,
err
)
t
.
Errorf
(
"Failed to create ReplicaSet, %v"
,
err
)
}
}
newRS
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
newRS
:=
obj
.
(
*
app
s
.
ReplicaSet
)
return
*
newRS
,
nil
return
*
newRS
,
nil
}
}
func
validNewReplicaSet
()
*
extension
s
.
ReplicaSet
{
func
validNewReplicaSet
()
*
app
s
.
ReplicaSet
{
return
&
extension
s
.
ReplicaSet
{
return
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
Namespace
:
metav1
.
NamespaceDefault
,
Namespace
:
metav1
.
NamespaceDefault
,
},
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"b"
}},
Template
:
api
.
PodTemplateSpec
{
Template
:
api
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
...
@@ -84,7 +84,7 @@ func validNewReplicaSet() *extensions.ReplicaSet {
...
@@ -84,7 +84,7 @@ func validNewReplicaSet() *extensions.ReplicaSet {
},
},
Replicas
:
7
,
Replicas
:
7
,
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
5
,
Replicas
:
5
,
},
},
}
}
...
@@ -103,8 +103,8 @@ func TestCreate(t *testing.T) {
...
@@ -103,8 +103,8 @@ func TestCreate(t *testing.T) {
// valid
// valid
rs
,
rs
,
// invalid (invalid selector)
// invalid (invalid selector)
&
extension
s
.
ReplicaSet
{
&
app
s
.
ReplicaSet
{
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Replicas
:
2
,
Replicas
:
2
,
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}},
Template
:
validReplicaSet
.
Spec
.
Template
,
Template
:
validReplicaSet
.
Spec
.
Template
,
...
@@ -123,18 +123,18 @@ func TestUpdate(t *testing.T) {
...
@@ -123,18 +123,18 @@ func TestUpdate(t *testing.T) {
validNewReplicaSet
(),
validNewReplicaSet
(),
// valid updateFunc
// valid updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
object
:=
obj
.
(
*
app
s
.
ReplicaSet
)
object
.
Spec
.
Replicas
=
object
.
Spec
.
Replicas
+
1
object
.
Spec
.
Replicas
=
object
.
Spec
.
Replicas
+
1
return
object
return
object
},
},
// invalid updateFunc
// invalid updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
object
:=
obj
.
(
*
app
s
.
ReplicaSet
)
object
.
Name
=
""
object
.
Name
=
""
return
object
return
object
},
},
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
object
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
object
:=
obj
.
(
*
app
s
.
ReplicaSet
)
object
.
Spec
.
Selector
=
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}}
object
.
Spec
.
Selector
=
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{}}
return
object
return
object
},
},
...
@@ -165,7 +165,7 @@ func TestGenerationNumber(t *testing.T) {
...
@@ -165,7 +165,7 @@ func TestGenerationNumber(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
storedRS
,
_
:=
etcdRS
.
(
*
extension
s
.
ReplicaSet
)
storedRS
,
_
:=
etcdRS
.
(
*
app
s
.
ReplicaSet
)
// Generation initialization
// Generation initialization
if
storedRS
.
Generation
!=
1
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
if
storedRS
.
Generation
!=
1
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
...
@@ -181,7 +181,7 @@ func TestGenerationNumber(t *testing.T) {
...
@@ -181,7 +181,7 @@ func TestGenerationNumber(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
storedRS
,
_
=
etcdRS
.
(
*
extension
s
.
ReplicaSet
)
storedRS
,
_
=
etcdRS
.
(
*
app
s
.
ReplicaSet
)
if
storedRS
.
Generation
!=
2
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
if
storedRS
.
Generation
!=
2
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
t
.
Fatalf
(
"Unexpected generation, spec: %v, status: %v"
,
storedRS
.
Generation
,
storedRS
.
Status
.
ObservedGeneration
)
t
.
Fatalf
(
"Unexpected generation, spec: %v, status: %v"
,
storedRS
.
Generation
,
storedRS
.
Status
.
ObservedGeneration
)
}
}
...
@@ -195,7 +195,7 @@ func TestGenerationNumber(t *testing.T) {
...
@@ -195,7 +195,7 @@ func TestGenerationNumber(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
storedRS
,
_
=
etcdRS
.
(
*
extension
s
.
ReplicaSet
)
storedRS
,
_
=
etcdRS
.
(
*
app
s
.
ReplicaSet
)
if
storedRS
.
Generation
!=
2
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
if
storedRS
.
Generation
!=
2
||
storedRS
.
Status
.
ObservedGeneration
!=
0
{
t
.
Fatalf
(
"Unexpected generation number, spec: %v, status: %v"
,
storedRS
.
Generation
,
storedRS
.
Status
.
ObservedGeneration
)
t
.
Fatalf
(
"Unexpected generation number, spec: %v, status: %v"
,
storedRS
.
Generation
,
storedRS
.
Status
.
ObservedGeneration
)
}
}
...
@@ -257,7 +257,7 @@ func TestScaleGet(t *testing.T) {
...
@@ -257,7 +257,7 @@ func TestScaleGet(t *testing.T) {
name
:=
"foo"
name
:=
"foo"
var
rs
extension
s
.
ReplicaSet
var
rs
app
s
.
ReplicaSet
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
metav1
.
NamespaceDefault
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
metav1
.
NamespaceDefault
)
key
:=
"/replicasets/"
+
metav1
.
NamespaceDefault
+
"/"
+
name
key
:=
"/replicasets/"
+
metav1
.
NamespaceDefault
+
"/"
+
name
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
&
rs
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
&
rs
,
0
,
false
);
err
!=
nil
{
...
@@ -302,7 +302,7 @@ func TestScaleUpdate(t *testing.T) {
...
@@ -302,7 +302,7 @@ func TestScaleUpdate(t *testing.T) {
name
:=
"foo"
name
:=
"foo"
var
rs
extension
s
.
ReplicaSet
var
rs
app
s
.
ReplicaSet
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
metav1
.
NamespaceDefault
)
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
metav1
.
NamespaceDefault
)
key
:=
"/replicasets/"
+
metav1
.
NamespaceDefault
+
"/"
+
name
key
:=
"/replicasets/"
+
metav1
.
NamespaceDefault
+
"/"
+
name
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
&
rs
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
&
rs
,
0
,
false
);
err
!=
nil
{
...
@@ -350,12 +350,12 @@ func TestStatusUpdate(t *testing.T) {
...
@@ -350,12 +350,12 @@ func TestStatusUpdate(t *testing.T) {
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
nil
,
0
,
false
);
err
!=
nil
{
if
err
:=
storage
.
ReplicaSet
.
Storage
.
Create
(
ctx
,
key
,
&
validReplicaSet
,
nil
,
0
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
update
:=
extension
s
.
ReplicaSet
{
update
:=
app
s
.
ReplicaSet
{
ObjectMeta
:
validReplicaSet
.
ObjectMeta
,
ObjectMeta
:
validReplicaSet
.
ObjectMeta
,
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Replicas
:
defaultReplicas
,
Replicas
:
defaultReplicas
,
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
defaultReplicas
,
Replicas
:
defaultReplicas
,
},
},
}
}
...
@@ -368,7 +368,7 @@ func TestStatusUpdate(t *testing.T) {
...
@@ -368,7 +368,7 @@ func TestStatusUpdate(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
rs
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
:=
obj
.
(
*
app
s
.
ReplicaSet
)
if
rs
.
Spec
.
Replicas
!=
7
{
if
rs
.
Spec
.
Replicas
!=
7
{
t
.
Errorf
(
"we expected .spec.replicas to not be updated but it was updated to %v"
,
rs
.
Spec
.
Replicas
)
t
.
Errorf
(
"we expected .spec.replicas to not be updated but it was updated to %v"
,
rs
.
Spec
.
Replicas
)
}
}
...
...
pkg/registry/apps/replicaset/strategy.go
View file @
d0577ace
...
@@ -39,8 +39,8 @@ import (
...
@@ -39,8 +39,8 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/apis/
extension
s"
"k8s.io/kubernetes/pkg/apis/
app
s"
"k8s.io/kubernetes/pkg/apis/
extension
s/validation"
"k8s.io/kubernetes/pkg/apis/
app
s/validation"
)
)
// rsStrategy implements verification logic for ReplicaSets.
// rsStrategy implements verification logic for ReplicaSets.
...
@@ -74,8 +74,8 @@ func (rsStrategy) NamespaceScoped() bool {
...
@@ -74,8 +74,8 @@ func (rsStrategy) NamespaceScoped() bool {
// PrepareForCreate clears the status of a ReplicaSet before creation.
// PrepareForCreate clears the status of a ReplicaSet before creation.
func
(
rsStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
func
(
rsStrategy
)
PrepareForCreate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
{
rs
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
:=
obj
.
(
*
app
s
.
ReplicaSet
)
rs
.
Status
=
extension
s
.
ReplicaSetStatus
{}
rs
.
Status
=
app
s
.
ReplicaSetStatus
{}
rs
.
Generation
=
1
rs
.
Generation
=
1
...
@@ -84,8 +84,8 @@ func (rsStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
...
@@ -84,8 +84,8 @@ func (rsStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
rsStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rsStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRS
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
newRS
:=
obj
.
(
*
app
s
.
ReplicaSet
)
oldRS
:=
old
.
(
*
extension
s
.
ReplicaSet
)
oldRS
:=
old
.
(
*
app
s
.
ReplicaSet
)
// update is not allowed to set status
// update is not allowed to set status
newRS
.
Status
=
oldRS
.
Status
newRS
.
Status
=
oldRS
.
Status
...
@@ -107,7 +107,7 @@ func (rsStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object)
...
@@ -107,7 +107,7 @@ func (rsStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object)
// Validate validates a new ReplicaSet.
// Validate validates a new ReplicaSet.
func
(
rsStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStrategy
)
Validate
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
rs
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
:=
obj
.
(
*
app
s
.
ReplicaSet
)
return
validation
.
ValidateReplicaSet
(
rs
)
return
validation
.
ValidateReplicaSet
(
rs
)
}
}
...
@@ -123,9 +123,9 @@ func (rsStrategy) AllowCreateOnUpdate() bool {
...
@@ -123,9 +123,9 @@ func (rsStrategy) AllowCreateOnUpdate() bool {
// ValidateUpdate is the default update validation for an end user.
// ValidateUpdate is the default update validation for an end user.
func
(
rsStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newReplicaSet
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
newReplicaSet
:=
obj
.
(
*
app
s
.
ReplicaSet
)
oldReplicaSet
:=
old
.
(
*
extension
s
.
ReplicaSet
)
oldReplicaSet
:=
old
.
(
*
app
s
.
ReplicaSet
)
allErrs
:=
validation
.
ValidateReplicaSet
(
obj
.
(
*
extension
s
.
ReplicaSet
))
allErrs
:=
validation
.
ValidateReplicaSet
(
obj
.
(
*
app
s
.
ReplicaSet
))
allErrs
=
append
(
allErrs
,
validation
.
ValidateReplicaSetUpdate
(
newReplicaSet
,
oldReplicaSet
)
...
)
allErrs
=
append
(
allErrs
,
validation
.
ValidateReplicaSetUpdate
(
newReplicaSet
,
oldReplicaSet
)
...
)
// Update is not allowed to set Spec.Selector for all groups/versions except extensions/v1beta1.
// Update is not allowed to set Spec.Selector for all groups/versions except extensions/v1beta1.
...
@@ -151,7 +151,7 @@ func (rsStrategy) AllowUnconditionalUpdate() bool {
...
@@ -151,7 +151,7 @@ func (rsStrategy) AllowUnconditionalUpdate() bool {
}
}
// ReplicaSetToSelectableFields returns a field set that represents the object.
// ReplicaSetToSelectableFields returns a field set that represents the object.
func
ReplicaSetToSelectableFields
(
rs
*
extension
s
.
ReplicaSet
)
fields
.
Set
{
func
ReplicaSetToSelectableFields
(
rs
*
app
s
.
ReplicaSet
)
fields
.
Set
{
objectMetaFieldsSet
:=
generic
.
ObjectMetaFieldsSet
(
&
rs
.
ObjectMeta
,
true
)
objectMetaFieldsSet
:=
generic
.
ObjectMetaFieldsSet
(
&
rs
.
ObjectMeta
,
true
)
rsSpecificFieldsSet
:=
fields
.
Set
{
rsSpecificFieldsSet
:=
fields
.
Set
{
"status.replicas"
:
strconv
.
Itoa
(
int
(
rs
.
Status
.
Replicas
)),
"status.replicas"
:
strconv
.
Itoa
(
int
(
rs
.
Status
.
Replicas
)),
...
@@ -161,7 +161,7 @@ func ReplicaSetToSelectableFields(rs *extensions.ReplicaSet) fields.Set {
...
@@ -161,7 +161,7 @@ func ReplicaSetToSelectableFields(rs *extensions.ReplicaSet) fields.Set {
// GetAttrs returns labels and fields of a given object for filtering purposes.
// GetAttrs returns labels and fields of a given object for filtering purposes.
func
GetAttrs
(
obj
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
)
{
func
GetAttrs
(
obj
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
)
{
rs
,
ok
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
rs
,
ok
:=
obj
.
(
*
app
s
.
ReplicaSet
)
if
!
ok
{
if
!
ok
{
return
nil
,
nil
,
false
,
fmt
.
Errorf
(
"given object is not a ReplicaSet."
)
return
nil
,
nil
,
false
,
fmt
.
Errorf
(
"given object is not a ReplicaSet."
)
}
}
...
@@ -186,12 +186,12 @@ type rsStatusStrategy struct {
...
@@ -186,12 +186,12 @@ type rsStatusStrategy struct {
var
StatusStrategy
=
rsStatusStrategy
{
Strategy
}
var
StatusStrategy
=
rsStatusStrategy
{
Strategy
}
func
(
rsStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rsStatusStrategy
)
PrepareForUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRS
:=
obj
.
(
*
extension
s
.
ReplicaSet
)
newRS
:=
obj
.
(
*
app
s
.
ReplicaSet
)
oldRS
:=
old
.
(
*
extension
s
.
ReplicaSet
)
oldRS
:=
old
.
(
*
app
s
.
ReplicaSet
)
// update is not allowed to set spec
// update is not allowed to set spec
newRS
.
Spec
=
oldRS
.
Spec
newRS
.
Spec
=
oldRS
.
Spec
}
}
func
(
rsStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStatusStrategy
)
ValidateUpdate
(
ctx
context
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateReplicaSetStatusUpdate
(
obj
.
(
*
extensions
.
ReplicaSet
),
old
.
(
*
extension
s
.
ReplicaSet
))
return
validation
.
ValidateReplicaSetStatusUpdate
(
obj
.
(
*
apps
.
ReplicaSet
),
old
.
(
*
app
s
.
ReplicaSet
))
}
}
pkg/registry/apps/replicaset/strategy_test.go
View file @
d0577ace
...
@@ -24,8 +24,8 @@ import (
...
@@ -24,8 +24,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/apps"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/extensions"
)
)
const
(
const
(
...
@@ -57,13 +57,13 @@ func TestReplicaSetStrategy(t *testing.T) {
...
@@ -57,13 +57,13 @@ func TestReplicaSetStrategy(t *testing.T) {
},
},
},
},
}
}
rs
:=
&
extension
s
.
ReplicaSet
{
rs
:=
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Template
:
validPodTemplate
.
Template
,
Template
:
validPodTemplate
.
Template
,
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
ObservedGeneration
:
int64
(
10
),
ObservedGeneration
:
int64
(
10
),
},
},
...
@@ -81,7 +81,7 @@ func TestReplicaSetStrategy(t *testing.T) {
...
@@ -81,7 +81,7 @@ func TestReplicaSetStrategy(t *testing.T) {
t
.
Errorf
(
"Unexpected error validating %v"
,
errs
)
t
.
Errorf
(
"Unexpected error validating %v"
,
errs
)
}
}
invalidRc
:=
&
extension
s
.
ReplicaSet
{
invalidRc
:=
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
ResourceVersion
:
"4"
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
ResourceVersion
:
"4"
},
}
}
Strategy
.
PrepareForUpdate
(
ctx
,
invalidRc
,
rs
)
Strategy
.
PrepareForUpdate
(
ctx
,
invalidRc
,
rs
)
...
@@ -115,26 +115,26 @@ func TestReplicaSetStatusStrategy(t *testing.T) {
...
@@ -115,26 +115,26 @@ func TestReplicaSetStatusStrategy(t *testing.T) {
},
},
},
},
}
}
oldRS
:=
&
extension
s
.
ReplicaSet
{
oldRS
:=
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
,
ResourceVersion
:
"10"
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
,
ResourceVersion
:
"10"
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Replicas
:
3
,
Replicas
:
3
,
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Template
:
validPodTemplate
.
Template
,
Template
:
validPodTemplate
.
Template
,
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
ObservedGeneration
:
int64
(
10
),
ObservedGeneration
:
int64
(
10
),
},
},
}
}
newRS
:=
&
extension
s
.
ReplicaSet
{
newRS
:=
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
,
ResourceVersion
:
"9"
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
metav1
.
NamespaceDefault
,
ResourceVersion
:
"9"
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Replicas
:
1
,
Replicas
:
1
,
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
validSelector
},
Template
:
validPodTemplate
.
Template
,
Template
:
validPodTemplate
.
Template
,
},
},
Status
:
extension
s
.
ReplicaSetStatus
{
Status
:
app
s
.
ReplicaSetStatus
{
Replicas
:
3
,
Replicas
:
3
,
ObservedGeneration
:
int64
(
11
),
ObservedGeneration
:
int64
(
11
),
},
},
...
@@ -203,14 +203,14 @@ func TestSelectorImmutability(t *testing.T) {
...
@@ -203,14 +203,14 @@ func TestSelectorImmutability(t *testing.T) {
}
}
}
}
func
newReplicaSetWithSelectorLabels
(
selectorLabels
map
[
string
]
string
)
*
extension
s
.
ReplicaSet
{
func
newReplicaSetWithSelectorLabels
(
selectorLabels
map
[
string
]
string
)
*
app
s
.
ReplicaSet
{
return
&
extension
s
.
ReplicaSet
{
return
&
app
s
.
ReplicaSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
replicasetName
,
Name
:
replicasetName
,
Namespace
:
namespace
,
Namespace
:
namespace
,
ResourceVersion
:
"1"
,
ResourceVersion
:
"1"
,
},
},
Spec
:
extension
s
.
ReplicaSetSpec
{
Spec
:
app
s
.
ReplicaSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
selectorLabels
,
MatchLabels
:
selectorLabels
,
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{},
...
...
pkg/registry/apps/statefulset/storage/storage.go
View file @
d0577ace
...
@@ -33,7 +33,6 @@ import (
...
@@ -33,7 +33,6 @@ import (
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingv1
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
autoscalingvalidation
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printersinternal
"k8s.io/kubernetes/pkg/printers/internalversion"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
printerstorage
"k8s.io/kubernetes/pkg/printers/storage"
...
@@ -184,7 +183,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
...
@@ -184,7 +183,7 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
}
}
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
if
errs
:=
autoscalingvalidation
.
ValidateScale
(
scale
);
len
(
errs
)
>
0
{
return
nil
,
false
,
errors
.
NewInvalid
(
extensions
.
Kind
(
"Scale"
),
scale
.
Name
,
errs
)
return
nil
,
false
,
errors
.
NewInvalid
(
autoscaling
.
Kind
(
"Scale"
),
scale
.
Name
,
errs
)
}
}
ss
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
ss
.
Spec
.
Replicas
=
scale
.
Spec
.
Replicas
...
...
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