Skip to content

Commit 092c795

Browse files
authored
enhance status checks for crds and apiservices (#234)
1 parent d066ec5 commit 092c795

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/reconciler/reconciler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ func (r *Reconciler) Apply(ctx context.Context, inventory *[]*InventoryItem, obj
612612
// that means, only if all objects of a wave are ready or completed, the next wave
613613
// will be procesed; within each wave, objects which are instances of managed types
614614
// will be applied after all other objects
615+
// TODO: it would be good to have a special handling of APIService objects; probably, APIService objects
616+
// should be applied after all regular (aka unmanaged until now) and before all managed objects
615617
numNotManagedToBeApplied := 0
616618
numUnready := 0
617619
for k, object := range objects {

pkg/status/analyzer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func NewStatusAnalyzer(reconcilerName string) StatusAnalyzer {
4545
func (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

Comments
 (0)