-
Notifications
You must be signed in to change notification settings - Fork 141
/
project_types.go
91 lines (79 loc) · 3.2 KB
/
project_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
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ProjectPhase string
const (
// ProjectPhaseInitializing denotes a Project that is not yet fully
// initialized.
ProjectPhaseInitializing ProjectPhase = "Initializing"
// ProjectPhaseInitializationFailed denotes a Project while failed to
// initialize properly.
ProjectPhaseInitializationFailed ProjectPhase = "InitializationFailed"
// ProjectPhaseReady denotes a Project that is fully initialized.
ProjectPhaseReady ProjectPhase = "Ready"
)
// IsTerminal returns true if the ProjectPhase is a terminal one.
func (p *ProjectPhase) IsTerminal() bool {
switch *p {
case ProjectPhaseInitializationFailed, ProjectPhaseReady:
return true
default:
return false
}
}
//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name=Phase,type=string,JSONPath=`.status.phase`
//+kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp`
// Project is a resource type that reconciles to a specially labeled namespace
// and other TODO: TBD project-level resources.
type Project struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec describes a Project.
Spec *ProjectSpec `json:"spec,omitempty"`
// Status describes the Project's current status.
Status ProjectStatus `json:"status,omitempty"`
}
func (p *Project) GetStatus() *ProjectStatus {
return &p.Status
}
// ProjectSpec describes a Project.
type ProjectSpec struct {
// PromotionPolicies defines policies governing the promotion of Freight to
// specific Stages within this Project.
PromotionPolicies []PromotionPolicy `json:"promotionPolicies,omitempty"`
}
// PromotionPolicy defines policies governing the promotion of Freight to a
// specific Stage.
type PromotionPolicy struct {
//+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"`
// AutoPromotionEnabled indicates whether new Freight can automatically be
// promoted into the Stage referenced by the Stage field. Note: There are may
// be other conditions also required for an auto-promotion to occur. This
// field defaults to false, but is commonly set to true for Stages that
// subscribe to Warehouses instead of other, upstream Stages. This allows
// users to define Stages that are automatically updated as soon as new
// artifacts are detected.
AutoPromotionEnabled bool `json:"autoPromotionEnabled,omitempty"`
}
// ProjectStatus describes a Project's current status.
type ProjectStatus struct {
// Phase describes the Project's current phase.
Phase ProjectPhase `json:"phase,omitempty"`
// Message is a display message about the Project, including any errors
// preventing the Project from being reconciled. i.e. If the Phase field has a
// value of CreationFailed, this field can be expected to explain why.
Message string `json:"message,omitempty"`
}
//+kubebuilder:object:root=true
// ProjectList is a list of Project resources.
type ProjectList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Project `json:"items"`
}