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
f40c793b
Commit
f40c793b
authored
Apr 24, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address a couple of TODO's in the recent rolling update change.
parent
d0288f71
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
+46
-6
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+24
-6
rollingupdate_test.go
pkg/kubectl/cmd/rollingupdate_test.go
+22
-0
No files found.
pkg/kubectl/cmd/rollingupdate.go
View file @
f40c793b
...
@@ -251,6 +251,15 @@ func addDeploymentKeyToReplicationController(oldRc *api.ReplicationController, c
...
@@ -251,6 +251,15 @@ func addDeploymentKeyToReplicationController(oldRc *api.ReplicationController, c
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// First, update the template label. This ensures that any newly created pods will have the new label
if
oldRc
.
Spec
.
Template
.
Labels
==
nil
{
oldRc
.
Spec
.
Template
.
Labels
=
map
[
string
]
string
{}
}
oldRc
.
Spec
.
Template
.
Labels
[
deploymentKey
]
=
oldHash
if
_
,
err
:=
client
.
ReplicationControllers
(
namespace
)
.
Update
(
oldRc
);
err
!=
nil
{
return
err
}
// Update all labels to include the new hash, so they are correctly adopted
// Update all labels to include the new hash, so they are correctly adopted
// TODO: extract the code from the label command and re-use it here.
// TODO: extract the code from the label command and re-use it here.
podList
,
err
:=
client
.
Pods
(
namespace
)
.
List
(
labels
.
SelectorFromSet
(
oldRc
.
Spec
.
Selector
),
fields
.
Everything
())
podList
,
err
:=
client
.
Pods
(
namespace
)
.
List
(
labels
.
SelectorFromSet
(
oldRc
.
Spec
.
Selector
),
fields
.
Everything
())
...
@@ -282,21 +291,30 @@ func addDeploymentKeyToReplicationController(oldRc *api.ReplicationController, c
...
@@ -282,21 +291,30 @@ func addDeploymentKeyToReplicationController(oldRc *api.ReplicationController, c
return
err
return
err
}
}
}
}
if
oldRc
.
Spec
.
Selector
==
nil
{
if
oldRc
.
Spec
.
Selector
==
nil
{
oldRc
.
Spec
.
Selector
=
map
[
string
]
string
{}
oldRc
.
Spec
.
Selector
=
map
[
string
]
string
{}
}
}
if
oldRc
.
Spec
.
Template
.
Labels
==
nil
{
// Copy the old selector, so that we can scrub out any orphaned pods
oldRc
.
Spec
.
Template
.
Labels
=
map
[
string
]
string
{}
selectorCopy
:=
map
[
string
]
string
{}
for
k
,
v
:=
range
oldRc
.
Spec
.
Selector
{
selectorCopy
[
k
]
=
v
}
}
oldRc
.
Spec
.
Selector
[
deploymentKey
]
=
oldHash
oldRc
.
Spec
.
Selector
[
deploymentKey
]
=
oldHash
oldRc
.
Spec
.
Template
.
Labels
[
deploymentKey
]
=
oldHash
if
_
,
err
:=
client
.
ReplicationControllers
(
namespace
)
.
Update
(
oldRc
);
err
!=
nil
{
if
_
,
err
:=
client
.
ReplicationControllers
(
namespace
)
.
Update
(
oldRc
);
err
!=
nil
{
return
err
return
err
}
}
// Note there is still a race here, if a pod was created during the update phase.
// It's unlikely, but it could happen, and if it does, we'll create extra pods.
podList
,
err
=
client
.
Pods
(
namespace
)
.
List
(
labels
.
SelectorFromSet
(
selectorCopy
),
fields
.
Everything
())
// TODO: Clean up orphaned pods here.
for
ix
:=
range
podList
.
Items
{
pod
:=
&
podList
.
Items
[
ix
]
if
value
,
found
:=
pod
.
Labels
[
deploymentKey
];
!
found
||
value
!=
oldHash
{
if
err
:=
client
.
Pods
(
namespace
)
.
Delete
(
pod
.
Name
);
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
}
}
pkg/kubectl/cmd/rollingupdate_test.go
View file @
f40c793b
...
@@ -18,12 +18,14 @@ package cmd
...
@@ -18,12 +18,14 @@ package cmd
import
(
import
(
"bytes"
"bytes"
"io/ioutil"
"net/http"
"net/http"
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
)
...
@@ -137,12 +139,18 @@ func TestAddDeploymentHash(t *testing.T) {
...
@@ -137,12 +139,18 @@ func TestAddDeploymentHash(t *testing.T) {
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
podList
)},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
podList
)},
nil
case
p
==
"/api/v1beta3/namespaces/default/pods/foo"
&&
m
==
"PUT"
:
case
p
==
"/api/v1beta3/namespaces/default/pods/foo"
&&
m
==
"PUT"
:
seen
.
Insert
(
"foo"
)
seen
.
Insert
(
"foo"
)
obj
:=
readOrDie
(
t
,
req
,
codec
)
podList
.
Items
[
0
]
=
*
(
obj
.
(
*
api
.
Pod
))
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
0
])},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
0
])},
nil
case
p
==
"/api/v1beta3/namespaces/default/pods/bar"
&&
m
==
"PUT"
:
case
p
==
"/api/v1beta3/namespaces/default/pods/bar"
&&
m
==
"PUT"
:
seen
.
Insert
(
"bar"
)
seen
.
Insert
(
"bar"
)
obj
:=
readOrDie
(
t
,
req
,
codec
)
podList
.
Items
[
1
]
=
*
(
obj
.
(
*
api
.
Pod
))
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
1
])},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
1
])},
nil
case
p
==
"/api/v1beta3/namespaces/default/pods/baz"
&&
m
==
"PUT"
:
case
p
==
"/api/v1beta3/namespaces/default/pods/baz"
&&
m
==
"PUT"
:
seen
.
Insert
(
"baz"
)
seen
.
Insert
(
"baz"
)
obj
:=
readOrDie
(
t
,
req
,
codec
)
podList
.
Items
[
2
]
=
*
(
obj
.
(
*
api
.
Pod
))
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
2
])},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
podList
.
Items
[
2
])},
nil
case
p
==
"/api/v1beta3/namespaces/default/replicationcontrollers/rc"
&&
m
==
"PUT"
:
case
p
==
"/api/v1beta3/namespaces/default/replicationcontrollers/rc"
&&
m
==
"PUT"
:
updatedRc
=
true
updatedRc
=
true
...
@@ -175,3 +183,17 @@ func TestAddDeploymentHash(t *testing.T) {
...
@@ -175,3 +183,17 @@ func TestAddDeploymentHash(t *testing.T) {
t
.
Errorf
(
"Failed to update replication controller with new labels"
)
t
.
Errorf
(
"Failed to update replication controller with new labels"
)
}
}
}
}
func
readOrDie
(
t
*
testing
.
T
,
req
*
http
.
Request
,
codec
runtime
.
Codec
)
runtime
.
Object
{
data
,
err
:=
ioutil
.
ReadAll
(
req
.
Body
)
if
err
!=
nil
{
t
.
Errorf
(
"Error reading: %v"
,
err
)
t
.
FailNow
()
}
obj
,
err
:=
codec
.
Decode
(
data
)
if
err
!=
nil
{
t
.
Errorf
(
"error decoding: %v"
,
err
)
t
.
FailNow
()
}
return
obj
}
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