-
Notifications
You must be signed in to change notification settings - Fork 163
/
source_resolver.go
58 lines (44 loc) · 1.41 KB
/
source_resolver.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
package v1alpha2
import (
corev1 "k8s.io/api/core/v1"
corev1alpha1 "github.com/pivotal/kpack/pkg/apis/core/v1alpha1"
)
const ActivePolling = "ActivePolling"
func (sr *SourceResolver) ResolvedSource(config corev1alpha1.ResolvedSourceConfig) {
resolvedSource := config.ResolvedSource()
if resolvedSource.IsUnknown() && sr.Status.ObservedGeneration == sr.ObjectMeta.Generation {
return
}
sr.Status.Source = config
sr.Status.Conditions = []corev1alpha1.Condition{{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
}}
pollingStatus := corev1.ConditionFalse
if resolvedSource.IsPollable() {
pollingStatus = corev1.ConditionTrue
}
sr.Status.Conditions = append(sr.Status.Conditions, corev1alpha1.Condition{
Type: ActivePolling,
Status: pollingStatus,
})
}
func (sr *SourceResolver) PollingReady() bool {
return sr.Status.GetCondition(ActivePolling).IsTrue()
}
func (sr *SourceResolver) Ready() bool {
return sr.Status.GetCondition(corev1alpha1.ConditionReady).IsTrue() &&
(sr.Generation == sr.Status.ObservedGeneration)
}
func (sr SourceResolver) IsGit() bool {
return sr.Spec.Source.Git != nil
}
func (sr SourceResolver) IsBlob() bool {
return sr.Spec.Source.Blob != nil
}
func (sr SourceResolver) IsRegistry() bool {
return sr.Spec.Source.Registry != nil
}
func (st *SourceResolver) SourceConfig() corev1alpha1.SourceConfig {
return st.Status.Source.ResolvedSource().SourceConfig()
}