-
Notifications
You must be signed in to change notification settings - Fork 128
/
promotion_types.go
114 lines (102 loc) · 4.13 KB
/
promotion_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
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type PromotionPhase string
const (
// PromotionPhasePending denotes a Promotion that has not been executed yet.
// i.e. It is currently waiting in a queue. Queues are stage-specific and
// prioritized by Promotion creation time.
PromotionPhasePending PromotionPhase = "Pending"
// PromotionPhaseRunning denotes a Promotion that is actively being executed.
//
// TODO: "Active" is the operative word here. We are leaving room for the
// possibility in the near future that an in-progress Promotion might be
// paused/suspended pending some user action.
PromotionPhaseRunning PromotionPhase = "Running"
// PromotionPhaseSucceeded denotes a Promotion that has been successfully
// executed.
PromotionPhaseSucceeded PromotionPhase = "Succeeded"
// PromotionPhaseFailed denotes a Promotion that has failed
PromotionPhaseFailed PromotionPhase = "Failed"
// PromotionPhaseErrored denotes a Promotion that has failed for technical
// reasons. Further information about the failure can be found in the
// Promotion's status.
PromotionPhaseErrored PromotionPhase = "Errored"
)
// IsTerminal returns true if the PromotionPhase is a terminal one.
func (p *PromotionPhase) IsTerminal() bool {
switch *p {
case PromotionPhaseSucceeded, PromotionPhaseFailed, PromotionPhaseErrored:
return true
default:
return false
}
}
//+kubebuilder:resource:shortName={promo,promos}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name=Stage,type=string,JSONPath=`.spec.stage`
//+kubebuilder:printcolumn:name=Freight,type=string,JSONPath=`.spec.freight`
//+kubebuilder:printcolumn:name=Phase,type=string,JSONPath=`.status.phase`
//+kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp`
// Promotion represents a request to transition a particular Stage into a
// particular Freight.
type Promotion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec describes the desired transition of a specific Stage into a specific
// Freight.
//
//+kubebuilder:validation:Required
Spec *PromotionSpec `json:"spec"`
// Status describes the current state of the transition represented by this
// Promotion.
Status PromotionStatus `json:"status,omitempty"`
}
func (p *Promotion) GetStatus() *PromotionStatus {
return &p.Status
}
// PromotionSpec describes the desired transition of a specific Stage into a
// specific Freight.
type PromotionSpec struct {
// Stage specifies the name of the Stage to which this Promotion
// applies. The Stage referenced by this field MUST be in the same
// namespace as the Promotion.
//
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
Stage string `json:"stage"`
// Freight specifies the piece of Freight to be promoted into the Stage
// referenced by the Stage field.
//
//+kubebuilder:validation:MinLength=1
Freight string `json:"freight"`
}
// PromotionStatus describes the current state of the transition represented by
// a Promotion.
type PromotionStatus struct {
// Phase describes where the Promotion currently is in its lifecycle.
Phase PromotionPhase `json:"phase,omitempty"`
// Message is a display message about the promotion, including any errors
// preventing the Promotion controller from executing this Promotion.
// i.e. If the Phase field has a value of Failed, this field can be expected
// to explain why.
Message string `json:"message,omitempty"`
// Metadata holds arbitrary metadata set by promotion mechanisms
// (e.g. for display purposes, or internal bookkeeping)
Metadata map[string]string `json:"metadata,omitempty"`
}
// WithPhase returns a copy of PromotionStatus with the given phase
func (p *PromotionStatus) WithPhase(phase PromotionPhase) *PromotionStatus {
status := p.DeepCopy()
status.Phase = phase
return status
}
//+kubebuilder:object:root=true
// PromotionList contains a list of Promotion
type PromotionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Promotion `json:"items"`
}