Skip to content

Commit af3c7ad

Browse files
committed
Seperates errors in Common Status
1 parent 2e0be0e commit af3c7ad

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ type CommonSpec struct {
4747

4848
// CommonSpec is a set of status attributes that must be exposed on all addons.
4949
type CommonStatus struct {
50-
Healthy bool `json:"healthy"`
51-
Errors []string `json:"errors,omitempty"`
52-
Phase string `json:"phase,omitempty"`
50+
VersionCheckErrors []string
51+
StatusErrors []string
52+
Healthy bool `json:"healthy"`
53+
Errors []string `json:"errors,omitempty"`
54+
Phase string `json:"phase,omitempty"`
5355
}
5456

5557
// Patchable is a trait for addon CRDs that expose a raw set of Patches to be

pkg/patterns/addon/pkg/status/aggregate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative
7878

7979
status := currentStatus
8080
status.Healthy = statusHealthy
81-
status.Errors = statusErrors
81+
status.StatusErrors = statusErrors
8282

8383
if !reflect.DeepEqual(status, currentStatus) {
8484
err := utils.SetCommonStatus(src, status)

pkg/patterns/addon/pkg/status/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (p *versionCheck) VersionCheck(
7272

7373
status := currentStatus
7474
status.Healthy = false
75-
status.Errors = errors
75+
status.VersionCheckErrors = errors
7676

7777
if !reflect.DeepEqual(status, currentStatus) {
7878
err := utils.SetCommonStatus(src, status)

pkg/patterns/addon/pkg/utils/helpers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func SetCommonStatus(instance runtime.Object, status addonsv1alpha1.CommonStatus
3939
case addonsv1alpha1.CommonObject:
4040
v.SetCommonStatus(status)
4141
case *unstructured.Unstructured:
42-
unstructStatus, err := runtime.DefaultUnstructuredConverter.ToUnstructured(status)
42+
unstructStatus, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&status)
4343
if err != nil {
4444
return fmt.Errorf("unable to convert unstructured to addonStatus: %v", err)
4545
}
@@ -87,3 +87,12 @@ func GetCommonName(instance runtime.Object) (string, error) {
8787
return "", genError(v)
8888
}
8989
}
90+
91+
func CompileErrors(status addonsv1alpha1.CommonStatus) addonsv1alpha1.CommonStatus {
92+
fmt.Println(status.StatusErrors)
93+
status.Errors = []string{}
94+
status.Errors = append(status.Errors, status.VersionCheckErrors...)
95+
status.Errors = append(status.Errors, status.StatusErrors...)
96+
fmt.Println(status.Errors)
97+
return status
98+
}

pkg/patterns/declarative/reconciler.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"errors"
2222
"fmt"
2323
"path/filepath"
24+
"reflect"
2425
"strings"
2526

2627
"k8s.io/apimachinery/pkg/api/meta"
28+
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/utils"
2729

2830
apierrors "k8s.io/apimachinery/pkg/api/errors"
2931

@@ -189,6 +191,25 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
189191
log.Error(err, "failed to reconcile status")
190192
}
191193
}
194+
195+
status, err := utils.GetCommonStatus(instance)
196+
if err != nil {
197+
log.Error(err, "failed to get status")
198+
}
199+
compiledStatus := utils.CompileErrors(status)
200+
fmt.Println("compiling errors")
201+
if !reflect.DeepEqual(status, compiledStatus) {
202+
err := utils.SetCommonStatus(instance, compiledStatus)
203+
if err != nil {
204+
log.Error(err, "failed to update status")
205+
}
206+
207+
err = r.client.Status().Update(context.Background(), instance)
208+
if err != nil {
209+
log.Error(err, "failed to update status")
210+
}
211+
}
212+
192213
}()
193214

194215
objects, err = parseListKind(objects)

0 commit comments

Comments
 (0)