-
Notifications
You must be signed in to change notification settings - Fork 0
/
handover_types.go
152 lines (128 loc) · 4.88 KB
/
handover_types.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package v1alpha1
import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// HandoverSpec defines the desired state of a Handover.
type HandoverSpec struct {
// Strategy to use when handing over objects between operators.
Strategy HandoverStrategy `json:"strategy"`
// TargetAPI to use for handover.
TargetAPI TargetAPI `json:"targetAPI"`
// Probes to check selected objects for availability.
Probes []Probe `json:"probes"`
}
// HandoverStrategy defines the strategy to handover objects.
type HandoverStrategy struct {
// Type of handover strategy. Can be "Relabel".
// +kubebuilder:default=Relabel
// +kubebuilder:validation:Enum={"Relabel"}
Type HandoverStrategyType `json:"type"`
// Relabel handover strategy configuration.
// Only present when type=Relabel.
Relabel *HandoverStrategyRelabelSpec `json:"relabel,omitempty"`
}
type HandoverStrategyType string
const (
// Relabel will change a specified label object after object.
HandoverStrategyRelabel HandoverStrategyType = "Relabel"
)
// Relabel handover strategy definition.
type HandoverStrategyRelabelSpec struct {
// LabelKey defines the labelKey to change the value of.
// +kubebuilder:validation:MinLength=1
LabelKey string `json:"labelKey"`
// FromValue defines the initial value of the label.
// +kubebuilder:validation:MinLength=1
FromValue string `json:"fromValue"`
// ToValue defines the desired value of the label after handover.
// +kubebuilder:validation:MinLength=1
ToValue string `json:"toValue"`
// Status path to validate that the new operator is posting status information now.
StatusPath string `json:"statusPath"`
// MaxUnavailable defines how many objects may become unavailable due to the handover at the same time.
// Cannot be below 1, because we cannot surge while relabling to create more instances.
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=1
MaxUnavailable int `json:"maxUnavailable"`
}
// HandoverStatus defines the observed state of a Handover
type HandoverStatus struct {
// Processing set of objects during handover.
Processing []HandoverRef `json:"processing,omitempty"`
// Statistics of the handover process.
Stats HandoverStatusStats `json:"stats,omitempty"`
// The most recent generation observed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Conditions is a list of status conditions ths object is in.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// DEPRECATED: This field is not part of any API contract
// it will go away as soon as kubectl can print conditions!
// Human readable status - please use .Conditions from code
Phase HandoverPhase `json:"phase,omitempty"`
}
// Updates .Status.Phase based on reported conditions.
func (s *HandoverStatus) UpdatePhase() {
completedCond := meta.FindStatusCondition(s.Conditions, HandoverCompleted)
if completedCond != nil {
switch completedCond.Status {
case metav1.ConditionTrue:
s.Phase = HandoverPhaseCompleted
return
case metav1.ConditionFalse:
s.Phase = HandoverPhaseProgressing
return
}
}
s.Phase = HandoverPhasePending
}
type HandoverStatusStats struct {
// +optional
Found int32 `json:"found"`
// +optional
Available int32 `json:"available"`
// +optional
Updated int32 `json:"updated"`
}
type HandoverRef struct {
UID types.UID `json:"uid"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}
const (
HandoverCompleted = "Completed"
)
type HandoverPhase string
// Well-known Handover Phases for printing a Status in kubectl,
// see deprecation notice in HandoverStatus for details.
const (
HandoverPhasePending HandoverPhase = "Pending"
HandoverPhaseProgressing HandoverPhase = "Progressing"
HandoverPhaseCompleted HandoverPhase = "Completed"
)
// Handover controls the handover process between two operators.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Found",type="integer",JSONPath=".status.stats.found"
// +kubebuilder:printcolumn:name="Available",type="integer",JSONPath=".status.stats.available"
// +kubebuilder:printcolumn:name="Updated",type="integer",JSONPath=".status.stats.updated"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type Handover struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec HandoverSpec `json:"spec,omitempty"`
// +kubebuilder:default={phase:Pending}
Status HandoverStatus `json:"status,omitempty"`
}
// HandoverList contains a list of Handovers
// +kubebuilder:object:root=true
type HandoverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Handover `json:"items"`
}
func init() {
SchemeBuilder.Register(&Handover{}, &HandoverList{})
}