Skip to content

Commit c8f7f04

Browse files
author
OpenShift Bot
authored
Merge pull request #11913 from kargakis/cleanup-strategy-code
Merged by openshift-bot
2 parents 6a6dc30 + 97b3125 commit c8f7f04

File tree

6 files changed

+140
-140
lines changed

6 files changed

+140
-140
lines changed

pkg/deploy/strategy/recreate/recreate.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type RecreateDeploymentStrategy struct {
4848
// codec is used to decode DeploymentConfigs contained in deployments.
4949
decoder runtime.Decoder
5050
// hookExecutor can execute a lifecycle hook.
51-
hookExecutor hookExecutor
51+
hookExecutor stratsupport.HookExecutor
5252
// retryTimeout is how long to wait for the replica count update to succeed
5353
// before giving up.
5454
retryTimeout time.Duration
@@ -58,9 +58,9 @@ type RecreateDeploymentStrategy struct {
5858
events record.EventSink
5959
}
6060

61-
// AcceptorInterval is how often the UpdateAcceptor should check for
61+
// acceptorInterval is how often the UpdateAcceptor should check for
6262
// readiness.
63-
const AcceptorInterval = 1 * time.Second
63+
const acceptorInterval = 1 * time.Second
6464

6565
// NewRecreateDeploymentStrategy makes a RecreateDeploymentStrategy backed by
6666
// a real HookExecutor and client.
@@ -82,7 +82,7 @@ func NewRecreateDeploymentStrategy(oldClient kclient.Interface, tagClient client
8282
rcClient: client.Core(),
8383
eventClient: client.Core(),
8484
getUpdateAcceptor: func(timeout time.Duration, minReadySeconds int32) strat.UpdateAcceptor {
85-
return stratsupport.NewAcceptNewlyObservedReadyPods(out, client.Core(), timeout, AcceptorInterval, minReadySeconds)
85+
return stratsupport.NewAcceptAvailablePods(out, client.Core(), timeout, acceptorInterval, minReadySeconds)
8686
},
8787
scaler: scaler,
8888
decoder: decoder,
@@ -221,18 +221,3 @@ func (s *RecreateDeploymentStrategy) scaleAndWait(deployment *kapi.ReplicationCo
221221

222222
return s.rcClient.ReplicationControllers(deployment.Namespace).Get(deployment.Name)
223223
}
224-
225-
// hookExecutor knows how to execute a deployment lifecycle hook.
226-
type hookExecutor interface {
227-
Execute(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
228-
}
229-
230-
// hookExecutorImpl is a pluggable hookExecutor.
231-
type hookExecutorImpl struct {
232-
executeFunc func(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
233-
}
234-
235-
// Execute executes the provided lifecycle hook
236-
func (i *hookExecutorImpl) Execute(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error {
237-
return i.executeFunc(hook, deployment, suffix, label)
238-
}

pkg/deploy/strategy/recreate/recreate_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func (c *fakeControllerClient) ReplicationControllers(ns string) kcoreclient.Rep
2929
return fake.NewSimpleClientset(c.deployment).Core().ReplicationControllers(ns)
3030
}
3131

32+
type hookExecutorImpl struct {
33+
executeFunc func(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
34+
}
35+
36+
func (h *hookExecutorImpl) Execute(hook *deployapi.LifecycleHook, rc *kapi.ReplicationController, suffix, label string) error {
37+
return h.executeFunc(hook, rc, suffix, label)
38+
}
39+
3240
func TestRecreate_initialDeployment(t *testing.T) {
3341
var deployment *kapi.ReplicationController
3442
scaler := &cmdtest.FakeScaler{}

pkg/deploy/strategy/rolling/rolling.go

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ import (
2626
deployutil "github.com/openshift/origin/pkg/deploy/util"
2727
)
2828

29-
// TODO: This should perhaps be made public upstream. See:
30-
// https://github.com/kubernetes/kubernetes/issues/7851
31-
const sourceIdAnnotation = "kubectl.kubernetes.io/update-source-id"
29+
const (
30+
// TODO: This should perhaps be made public upstream. See:
31+
// https://github.com/kubernetes/kubernetes/issues/7851
32+
sourceIdAnnotation = "kubectl.kubernetes.io/update-source-id"
3233

33-
const DefaultApiRetryPeriod = 1 * time.Second
34-
const DefaultApiRetryTimeout = 10 * time.Second
34+
defaultApiRetryPeriod = 1 * time.Second
35+
defaultApiRetryTimeout = 10 * time.Second
36+
// acceptorInterval is how often the UpdateAcceptor should check for
37+
// readiness.
38+
acceptorInterval = 1 * time.Second
39+
)
3540

3641
// RollingDeploymentStrategy is a Strategy which implements rolling
3742
// deployments using the upstream Kubernetes RollingUpdater.
@@ -65,7 +70,7 @@ type RollingDeploymentStrategy struct {
6570
// decoder is used to access the encoded config on a deployment.
6671
decoder runtime.Decoder
6772
// hookExecutor can execute a lifecycle hook.
68-
hookExecutor hookExecutor
73+
hookExecutor stratsupport.HookExecutor
6974
// getUpdateAcceptor returns an UpdateAcceptor to verify the first replica
7075
// of the deployment.
7176
getUpdateAcceptor func(time.Duration, int32) strat.UpdateAcceptor
@@ -84,10 +89,6 @@ type acceptingDeploymentStrategy interface {
8489
DeployWithAcceptor(from *kapi.ReplicationController, to *kapi.ReplicationController, desiredReplicas int, updateAcceptor strat.UpdateAcceptor) error
8590
}
8691

87-
// AcceptorInterval is how often the UpdateAcceptor should check for
88-
// readiness.
89-
const AcceptorInterval = 1 * time.Second
90-
9192
// NewRollingDeploymentStrategy makes a new RollingDeploymentStrategy.
9293
func NewRollingDeploymentStrategy(namespace string, oldClient kclient.Interface, tags client.ImageStreamTagsNamespacer, events record.EventSink, decoder runtime.Decoder, initialStrategy acceptingDeploymentStrategy, out, errOut io.Writer, until string) *RollingDeploymentStrategy {
9394
if out == nil {
@@ -107,15 +108,15 @@ func NewRollingDeploymentStrategy(namespace string, oldClient kclient.Interface,
107108
rcClient: client.Core(),
108109
eventClient: client.Core(),
109110
tags: tags,
110-
apiRetryPeriod: DefaultApiRetryPeriod,
111-
apiRetryTimeout: DefaultApiRetryTimeout,
111+
apiRetryPeriod: defaultApiRetryPeriod,
112+
apiRetryTimeout: defaultApiRetryTimeout,
112113
rollingUpdate: func(config *kubectl.RollingUpdaterConfig) error {
113114
updater := kubectl.NewRollingUpdater(namespace, oldClient)
114115
return updater.Update(config)
115116
},
116117
hookExecutor: stratsupport.NewHookExecutor(client.Core(), tags, client.Core(), os.Stdout, decoder),
117118
getUpdateAcceptor: func(timeout time.Duration, minReadySeconds int32) strat.UpdateAcceptor {
118-
return stratsupport.NewAcceptNewlyObservedReadyPods(out, client.Core(), timeout, AcceptorInterval, minReadySeconds)
119+
return stratsupport.NewAcceptAvailablePods(out, client.Core(), timeout, acceptorInterval, minReadySeconds)
119120
},
120121
}
121122
}
@@ -282,18 +283,3 @@ func (w *rollingUpdaterWriter) Write(p []byte) (n int, err error) {
282283
}
283284
return n, nil
284285
}
285-
286-
// hookExecutor knows how to execute a deployment lifecycle hook.
287-
type hookExecutor interface {
288-
Execute(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
289-
}
290-
291-
// hookExecutorImpl is a pluggable hookExecutor.
292-
type hookExecutorImpl struct {
293-
executeFunc func(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
294-
}
295-
296-
// Execute executes the provided lifecycle hook
297-
func (i *hookExecutorImpl) Execute(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error {
298-
return i.executeFunc(hook, deployment, suffix, label)
299-
}

pkg/deploy/strategy/rolling/rolling_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func TestRolling_deployRolling(t *testing.T) {
145145
}
146146
}
147147

148+
type hookExecutorImpl struct {
149+
executeFunc func(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, suffix, label string) error
150+
}
151+
152+
func (h *hookExecutorImpl) Execute(hook *deployapi.LifecycleHook, rc *kapi.ReplicationController, suffix, label string) error {
153+
return h.executeFunc(hook, rc, suffix, label)
154+
}
155+
148156
func TestRolling_deployRollingHooks(t *testing.T) {
149157
config := deploytest.OkDeploymentConfig(1)
150158
config.Spec.Strategy = deploytest.OkRollingStrategy()

0 commit comments

Comments
 (0)