-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreplicas_normalizer.go
41 lines (31 loc) · 1.21 KB
/
replicas_normalizer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright 2020 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
*/
package normalizer
import "github.com/adobe/kratos/api/v1alpha1"
type normalizer interface {
normalizeReplicas(spec *v1alpha1.KratosSpec, status *v1alpha1.KratosStatus, desiredReplicas int32) int32
}
type ReplicaNormalizer struct {
standardNormalizer normalizer
behaviourNormalizer normalizer
}
func NewReplicaNormalizer() *ReplicaNormalizer {
return &ReplicaNormalizer{
standardNormalizer: newStandardNormalizer(),
behaviourNormalizer: newBehaviorNormalizer(),
}
}
func (n *ReplicaNormalizer) NormalizeReplicas(spec *v1alpha1.KratosSpec, status *v1alpha1.KratosStatus,
desiredReplicas int32) int32 {
if spec.Behavior == nil || (spec.Behavior.ScaleUp == nil && spec.Behavior.ScaleDown == nil) {
return n.standardNormalizer.normalizeReplicas(spec, status, desiredReplicas)
}
return n.behaviourNormalizer.normalizeReplicas(spec, status, desiredReplicas)
}