forked from openshift/library-go
/
management_state.go
69 lines (60 loc) · 1.93 KB
/
management_state.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package management
import (
"github.com/openshift/api/operator/v1"
)
var (
allowOperatorUnmanagedState = true
allowOperatorRemovedState = true
)
// These are for unit testing
var (
getAllowedOperatorUnmanaged = func() bool {
return allowOperatorUnmanagedState
}
getAllowedOperatorRemovedState = func() bool {
return allowOperatorRemovedState
}
)
// SetOperatorAlwaysManaged is one time choice when an operator want to opt-out from supporting the "unmanaged" state.
// This is a case of control plane operators or operators that are required to always run otherwise the cluster will
// get into unstable state or critical components will stop working.
func SetOperatorAlwaysManaged() {
allowOperatorUnmanagedState = false
}
// SetOperatorNotRemovable is one time choice the operator author can make to indicate the operator does not support
// removing of his operand. This makes sense for operators like kube-apiserver where removing operand will lead to a
// bricked, non-automatically recoverable state.
func SetOperatorNotRemovable() {
allowOperatorRemovedState = false
}
// IsOperatorAlwaysManaged means the operator can't be set to unmanaged state.
func IsOperatorAlwaysManaged() bool {
return !getAllowedOperatorUnmanaged()
}
// IsOperatorNotRemovable means the operator can't bet set to removed state.
func IsOperatorNotRemovable() bool {
return !getAllowedOperatorRemovedState()
}
func IsOperatorUnknownState(state v1.ManagementState) bool {
switch state {
case v1.Managed, v1.Removed, v1.Unmanaged:
return false
default:
return true
}
}
// IsOperatorManaged indicates whether the operator management state allows the control loop to proceed and manage the operand.
func IsOperatorManaged(state v1.ManagementState) bool {
if IsOperatorAlwaysManaged() || IsOperatorNotRemovable() {
return true
}
switch state {
case v1.Managed:
return true
case v1.Removed:
return false
case v1.Unmanaged:
return false
}
return true
}