@@ -45,6 +45,7 @@ func NewStatusAnalyzer(reconcilerName string) StatusAnalyzer {
4545func (s * statusAnalyzer ) ComputeStatus (object * unstructured.Unstructured ) (Status , error ) {
4646 var extraConditions []string
4747
48+ // parse hints from annotations
4849 if hint , ok := object .GetAnnotations ()[s .reconcilerName + "/" + types .AnnotationKeySuffixStatusHint ]; ok {
4950 object = object .DeepCopy ()
5051 for _ , hint := range strings .Split (hint , "," ) {
@@ -59,6 +60,7 @@ func (s *statusAnalyzer) ComputeStatus(object *unstructured.Unstructured) (Statu
5960 }
6061 switch strcase .ToKebab (key ) {
6162 case types .StatusHintHasObservedGeneration :
63+ // add an impossible status.observedGeneration if there is none, but the hint says there will be one
6264 if hasValue {
6365 return UnknownStatus , fmt .Errorf ("status hint %s does not take a value" , types .StatusHintHasObservedGeneration )
6466 }
@@ -72,6 +74,7 @@ func (s *statusAnalyzer) ComputeStatus(object *unstructured.Unstructured) (Statu
7274 }
7375 }
7476 case types .StatusHintHasReadyCondition :
77+ // add an Unknown Ready condition if there is none, but the hint says there will be one
7578 if hasValue {
7679 return UnknownStatus , fmt .Errorf ("status hint %s does not take a value" , types .StatusHintHasReadyCondition )
7780 }
@@ -115,12 +118,22 @@ func (s *statusAnalyzer) ComputeStatus(object *unstructured.Unstructured) (Statu
115118 }
116119 }
117120
121+ // add some well known extra conditions; note this might lead to duplicate checks, but that's ok
122+ switch object .GroupVersionKind () {
123+ case schema.GroupVersionKind {Group : "apiextensions.k8s.io" , Version : "v1" , Kind : "CustomResourceDefinition" }:
124+ extraConditions = append (extraConditions , "Established" , "NamesAccepted" )
125+ case schema.GroupVersionKind {Group : "apiregistration.k8s.io" , Version : "v1" , Kind : "APIService" }:
126+ extraConditions = append (extraConditions , "Available" )
127+ }
128+
129+ // retrieve status from upstream kstatus
118130 res , err := kstatus .Compute (object )
119131 if err != nil {
120132 return UnknownStatus , err
121133 }
122134 status := Status (res .Status )
123135
136+ // check extra conditions
124137 if status == CurrentStatus && len (extraConditions ) > 0 {
125138 objc , err := kstatus .GetObjectWithConditions (object .UnstructuredContent ())
126139 if err != nil {
@@ -142,6 +155,7 @@ func (s *statusAnalyzer) ComputeStatus(object *unstructured.Unstructured) (Statu
142155 }
143156 }
144157
158+ // special processing for some types
145159 switch object .GroupVersionKind () {
146160 case schema.GroupVersionKind {Group : "batch" , Version : "v1" , Kind : "Job" }:
147161 // other than kstatus we want to consider jobs as InProgress if its pods are still running, resp. did not (yet) finish successfully
0 commit comments