Skip to content

Commit 825cb24

Browse files
committed
change strategy type to string with order map
1 parent 312485a commit 825cb24

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

operator/api/v1alpha1/deployment_policy_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ type DeploymentBudget struct {
109109
Count *int `json:"count,omitempty"`
110110
}
111111

112+
// StrategyType represents the type of deployment strategy
113+
type StrategyType string
114+
115+
const (
116+
StrategyTypeFixed StrategyType = "fixed"
117+
StrategyTypeLinear StrategyType = "linear"
118+
StrategyTypeExponential StrategyType = "exponential"
119+
StrategyTypeUnknown StrategyType = "unknown"
120+
)
121+
112122
const (
113123
DefaultCompartmentName = "__default__"
114124
)

operator/internal/wrapper/compartment.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,37 @@ func (c *Compartment) AddNode(node SkyhookNode) {
6060
c.Nodes = append(c.Nodes, node)
6161
}
6262

63-
// strategyType represents the type of deployment strategy
64-
type strategyType int
65-
66-
const (
67-
strategyFixed strategyType = iota
68-
strategyLinear
69-
strategyExponential
70-
strategyUnknown
71-
)
63+
// strategySafetyOrder defines the safety ordering of strategies
64+
// Lower values indicate safer strategies (less aggressive rollout)
65+
// Strategy safety order: Fixed (0) > Linear (1) > Exponential (2)
66+
var strategySafetyOrder = map[v1alpha1.StrategyType]int{
67+
v1alpha1.StrategyTypeFixed: 0,
68+
v1alpha1.StrategyTypeLinear: 1,
69+
v1alpha1.StrategyTypeExponential: 2,
70+
v1alpha1.StrategyTypeUnknown: 999, // Unknown is least safe
71+
}
7272

7373
// getStrategyType returns the strategy type for a compartment
74-
func getStrategyType(strategy *v1alpha1.DeploymentStrategy) strategyType {
74+
func getStrategyType(strategy *v1alpha1.DeploymentStrategy) v1alpha1.StrategyType {
7575
if strategy == nil {
76-
return strategyUnknown
76+
return v1alpha1.StrategyTypeUnknown
7777
}
7878
if strategy.Fixed != nil {
79-
return strategyFixed
79+
return v1alpha1.StrategyTypeFixed
8080
}
8181
if strategy.Linear != nil {
82-
return strategyLinear
82+
return v1alpha1.StrategyTypeLinear
8383
}
8484
if strategy.Exponential != nil {
85-
return strategyExponential
85+
return v1alpha1.StrategyTypeExponential
8686
}
87-
return strategyUnknown
87+
return v1alpha1.StrategyTypeUnknown
8888
}
8989

9090
// strategyIsSafer returns true if strategy a is safer than strategy b
9191
// Strategy safety order: Fixed > Linear > Exponential
92-
func strategyIsSafer(a, b strategyType) bool {
93-
return a < b
92+
func strategyIsSafer(a, b v1alpha1.StrategyType) bool {
93+
return strategySafetyOrder[a] < strategySafetyOrder[b]
9494
}
9595

9696
// computeEffectiveCapacity calculates the effective ceiling for a compartment's budget
@@ -111,7 +111,7 @@ func computeEffectiveCapacity(budget v1alpha1.DeploymentBudget, matchedNodes int
111111
// compartmentMatch represents a compartment that matches a node
112112
type compartmentMatch struct {
113113
name string
114-
strategyType strategyType
114+
strategyType v1alpha1.StrategyType
115115
capacity int
116116
}
117117

0 commit comments

Comments
 (0)