-
Notifications
You must be signed in to change notification settings - Fork 19
/
porter_resource.go
50 lines (42 loc) · 1.61 KB
/
porter_resource.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
package v1
import (
"crypto/md5"
"encoding/hex"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type PorterResourceStatus struct {
// The last generation observed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// The most recent action executed for the resource
Action *corev1.LocalObjectReference `json:"action,omitempty"`
// The current status of the agent.
// Possible values are: Unknown, Pending, Running, Succeeded, and Failed.
// +kubebuilder:validation:Type=string
Phase AgentPhase `json:"phase,omitempty"`
// Conditions store a list of states that have been reached.
// Each condition refers to the status of the ActiveJob
// Possible conditions are: Scheduled, Started, Completed, and Failed
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
// Initialize resets the resource status before Porter is run.
// This wipes out the status from any previous runs.
func (s *PorterResourceStatus) Initialize() {
s.Conditions = []metav1.Condition{}
s.Phase = PhaseUnknown
s.Action = nil
}
// GetRetryLabelValue returns a value that is safe to use
// as a label value and represents the retry annotation used
// to trigger reconciliation. Annotations don't have limits on
// the value, but labels are restricted to alphanumeric and .-_
// I am just hashing the annotation value here to avoid problems
// using it directly as a label value.
func getRetryLabelValue(annotations map[string]string) string {
retry := annotations[AnnotationRetry]
if retry == "" {
return ""
}
sum := md5.Sum([]byte(retry))
return hex.EncodeToString(sum[:])
}