@@ -26,37 +26,63 @@ type KnativeStatus struct {
2626 SelfLink string
2727 }
2828 Status struct {
29- Conditions []Condition
29+ Conditions []Condition
30+ ObservedGeneration float64
3031 }
3132}
3233
33- func PollCheckKnativeStatus (resp map [string ]interface {}, respErr error ) PollResult {
34- if respErr != nil {
35- return ErrorPollResult (respErr )
34+ func getGeneration (res map [string ]interface {}) (int , error ) {
35+ metadata , ok := res ["metadata" ]
36+ if ! ok {
37+ return 0 , fmt .Errorf ("Unable to find knative metadata" )
3638 }
37- s := KnativeStatus {}
38- if err := Convert ( resp , & s ); err != nil {
39- return ErrorPollResult ( errwrap . Wrapf ( "unable to get KnativeStatus: {{err}}" , err ) )
39+ m , ok := metadata .( map [ string ] interface {})
40+ if ! ok {
41+ return 0 , fmt . Errorf ( "Unable to find generation in knative metadata" )
4042 }
43+ gen , ok := m ["generation" ]
44+ if ! ok {
45+ return 0 , fmt .Errorf ("Unable to find generation in knative metadata" )
46+ }
47+ return int (gen .(float64 )), nil
48+ }
4149
42- for _ , condition := range s .Status .Conditions {
43- if condition .Type == readyStatusType {
44- log .Printf ("[DEBUG] checking KnativeStatus Ready condition %s: %s" , condition .Status , condition .Message )
45- switch condition .Status {
46- case "True" :
47- // Resource is ready
48- return SuccessPollResult ()
49- case "Unknown" :
50- // DomainMapping can enter a 'terminal' state where "Ready" status is "Unknown"
51- // but the resource is waiting for external verification of DNS records.
52- if condition .Reason == pendingCertificateReason {
50+ func PollCheckKnativeStatusFunc (knativeRestResponse map [string ]interface {}) func (resp map [string ]interface {}, respErr error ) PollResult {
51+ return func (resp map [string ]interface {}, respErr error ) PollResult {
52+ if respErr != nil {
53+ return ErrorPollResult (respErr )
54+ }
55+ s := KnativeStatus {}
56+ if err := Convert (resp , & s ); err != nil {
57+ return ErrorPollResult (errwrap .Wrapf ("unable to get KnativeStatus: {{err}}" , err ))
58+ }
59+
60+ gen , err := getGeneration (knativeRestResponse )
61+ if err != nil {
62+ return ErrorPollResult (errwrap .Wrapf ("unable to find Knative generation: {{err}}" , err ))
63+ }
64+ if int (s .Status .ObservedGeneration ) != gen {
65+ return PendingStatusPollResult ("waiting for observed generation to match" )
66+ }
67+ for _ , condition := range s .Status .Conditions {
68+ if condition .Type == readyStatusType {
69+ log .Printf ("[DEBUG] checking KnativeStatus Ready condition %s: %s" , condition .Status , condition .Message )
70+ switch condition .Status {
71+ case "True" :
72+ // Resource is ready
5373 return SuccessPollResult ()
74+ case "Unknown" :
75+ // DomainMapping can enter a 'terminal' state where "Ready" status is "Unknown"
76+ // but the resource is waiting for external verification of DNS records.
77+ if condition .Reason == pendingCertificateReason {
78+ return SuccessPollResult ()
79+ }
80+ return PendingStatusPollResult (fmt .Sprintf ("%s:%s" , condition .Status , condition .Message ))
81+ case "False" :
82+ return ErrorPollResult (fmt .Errorf (`resource is in failed state "Ready:False", message: %s` , condition .Message ))
5483 }
55- return PendingStatusPollResult (fmt .Sprintf ("%s:%s" , condition .Status , condition .Message ))
56- case "False" :
57- return ErrorPollResult (fmt .Errorf (`resource is in failed state "Ready:False", message: %s` , condition .Message ))
5884 }
5985 }
86+ return PendingStatusPollResult ("no status yet" )
6087 }
61- return PendingStatusPollResult ("no status yet" )
6288}
0 commit comments