diff --git a/pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go b/pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go index de3ea0fe..ae3c0e34 100644 --- a/pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go +++ b/pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go @@ -47,9 +47,11 @@ type CommonSpec struct { // CommonSpec is a set of status attributes that must be exposed on all addons. type CommonStatus struct { - Healthy bool `json:"healthy"` - Errors []string `json:"errors,omitempty"` - Phase string `json:"phase,omitempty"` + VersionCheckErrors []string + StatusErrors []string + Healthy bool `json:"healthy"` + Errors []string `json:"errors,omitempty"` + Phase string `json:"phase,omitempty"` } // Patchable is a trait for addon CRDs that expose a raw set of Patches to be diff --git a/pkg/patterns/addon/pkg/status/aggregate.go b/pkg/patterns/addon/pkg/status/aggregate.go index 9d6e92cf..37de6e0b 100644 --- a/pkg/patterns/addon/pkg/status/aggregate.go +++ b/pkg/patterns/addon/pkg/status/aggregate.go @@ -78,7 +78,7 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative status := currentStatus status.Healthy = statusHealthy - status.Errors = statusErrors + status.StatusErrors = statusErrors if !reflect.DeepEqual(status, currentStatus) { err := utils.SetCommonStatus(src, status) diff --git a/pkg/patterns/addon/pkg/status/version.go b/pkg/patterns/addon/pkg/status/version.go index 54192439..54420cc5 100644 --- a/pkg/patterns/addon/pkg/status/version.go +++ b/pkg/patterns/addon/pkg/status/version.go @@ -72,7 +72,7 @@ func (p *versionCheck) VersionCheck( status := currentStatus status.Healthy = false - status.Errors = errors + status.VersionCheckErrors = errors if !reflect.DeepEqual(status, currentStatus) { err := utils.SetCommonStatus(src, status) diff --git a/pkg/patterns/addon/pkg/utils/helpers.go b/pkg/patterns/addon/pkg/utils/helpers.go index 04e24e94..89463a2f 100644 --- a/pkg/patterns/addon/pkg/utils/helpers.go +++ b/pkg/patterns/addon/pkg/utils/helpers.go @@ -39,7 +39,7 @@ func SetCommonStatus(instance runtime.Object, status addonsv1alpha1.CommonStatus case addonsv1alpha1.CommonObject: v.SetCommonStatus(status) case *unstructured.Unstructured: - unstructStatus, err := runtime.DefaultUnstructuredConverter.ToUnstructured(status) + unstructStatus, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&status) if err != nil { return fmt.Errorf("unable to convert unstructured to addonStatus: %v", err) } @@ -87,3 +87,12 @@ func GetCommonName(instance runtime.Object) (string, error) { return "", genError(v) } } + +func CompileErrors(status addonsv1alpha1.CommonStatus) addonsv1alpha1.CommonStatus { + fmt.Println(status.StatusErrors) + status.Errors = []string{} + status.Errors = append(status.Errors, status.VersionCheckErrors...) + status.Errors = append(status.Errors, status.StatusErrors...) + fmt.Println(status.Errors) + return status +} diff --git a/pkg/patterns/declarative/reconciler.go b/pkg/patterns/declarative/reconciler.go index 6c608c6b..4b082b74 100644 --- a/pkg/patterns/declarative/reconciler.go +++ b/pkg/patterns/declarative/reconciler.go @@ -21,9 +21,11 @@ import ( "errors" "fmt" "path/filepath" + "reflect" "strings" "k8s.io/apimachinery/pkg/api/meta" + "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/utils" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -189,6 +191,25 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN log.Error(err, "failed to reconcile status") } } + + status, err := utils.GetCommonStatus(instance) + if err != nil { + log.Error(err, "failed to get status") + } + compiledStatus := utils.CompileErrors(status) + fmt.Println("compiling errors") + if !reflect.DeepEqual(status, compiledStatus) { + err := utils.SetCommonStatus(instance, compiledStatus) + if err != nil { + log.Error(err, "failed to update status") + } + + err = r.client.Status().Update(context.Background(), instance) + if err != nil { + log.Error(err, "failed to update status") + } + } + }() objects, err = parseListKind(objects)