Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit da5e4d7

Browse files
committed
Rolling updater availability enhancements
Enhance the rolling updater to support maintaining minimum pod availability for the duration of the update process.
1 parent cb2252b commit da5e4d7

File tree

6 files changed

+1239
-878
lines changed

6 files changed

+1239
-878
lines changed

hack/test-cmd.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,6 @@ __EOF__
680680
kubectl delete pod valid-pod "${kube_flags[@]}"
681681
kubectl delete service frontend{,-2,-3,-4,-5} "${kube_flags[@]}"
682682

683-
### Perform a rolling update with --image
684-
# Command
685-
kubectl rolling-update frontend --image=kubernetes/pause --update-period=10ns --poll-interval=10ms "${kube_flags[@]}"
686-
# Post-condition: current image IS kubernetes/pause
687-
kube::test::get_object_assert 'rc frontend' '{{range \$c:=$rc_container_image_field}} {{\$c.image}} {{end}}' ' +kubernetes/pause +'
688-
689683
### Delete replication controller with id
690684
# Pre-condition: frontend replication controller is running
691685
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'

pkg/client/unversioned/testclient/fake_pods.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ func (c *FakePods) List(label labels.Selector, field fields.Selector) (*api.PodL
4444
if obj == nil {
4545
return nil, err
4646
}
47-
48-
return obj.(*api.PodList), err
47+
list := &api.PodList{}
48+
for _, pod := range obj.(*api.PodList).Items {
49+
if label.Matches(labels.Set(pod.Labels)) {
50+
list.Items = append(list.Items, pod)
51+
}
52+
}
53+
return list, err
4954
}
5055

5156
func (c *FakePods) Create(pod *api.Pod) (*api.Pod, error) {

pkg/kubectl/cmd/rollingupdate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/kubernetes/pkg/kubectl"
3333
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
3434
"k8s.io/kubernetes/pkg/kubectl/resource"
35+
"k8s.io/kubernetes/pkg/util"
3536
)
3637

3738
const (
@@ -141,8 +142,6 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
141142
return err
142143
}
143144

144-
updaterClient := kubectl.NewRollingUpdaterClient(client)
145-
146145
var newRc *api.ReplicationController
147146
// fetch rc
148147
oldRc, err := client.ReplicationControllers(cmdNamespace).Get(oldName)
@@ -151,11 +150,11 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
151150
return err
152151
}
153152
// We're in the middle of a rename, look for an RC with a source annotation of oldName
154-
newRc, err := kubectl.FindSourceController(updaterClient, cmdNamespace, oldName)
153+
newRc, err := kubectl.FindSourceController(client, cmdNamespace, oldName)
155154
if err != nil {
156155
return err
157156
}
158-
return kubectl.Rename(kubectl.NewRollingUpdaterClient(client), newRc, oldName)
157+
return kubectl.Rename(client, newRc, oldName)
159158
}
160159

161160
var keepOldName bool
@@ -235,7 +234,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
235234
filename, oldName)
236235
}
237236

238-
updater := kubectl.NewRollingUpdater(newRc.Namespace, updaterClient)
237+
updater := kubectl.NewRollingUpdater(newRc.Namespace, client)
239238

240239
// To successfully pull off a rolling update the new and old rc have to differ
241240
// by at least one selector. Every new pod should have the selector and every
@@ -279,7 +278,8 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
279278
Interval: interval,
280279
Timeout: timeout,
281280
CleanupPolicy: updateCleanupPolicy,
282-
UpdateAcceptor: kubectl.DefaultUpdateAcceptor,
281+
MaxUnavailable: util.NewIntOrStringFromInt(0),
282+
MaxSurge: util.NewIntOrStringFromInt(1),
283283
}
284284
if cmdutil.GetFlagBool(cmd, "rollback") {
285285
kubectl.AbortRollingUpdate(config)

0 commit comments

Comments
 (0)