Skip to content

Commit

Permalink
Seperates errors in Common Status
Browse files Browse the repository at this point in the history
  • Loading branch information
somtochiama committed Aug 19, 2020
1 parent 2e0be0e commit af3c7ad
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/patterns/addon/pkg/apis/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/patterns/addon/pkg/status/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/patterns/addon/pkg/status/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion pkg/patterns/addon/pkg/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
21 changes: 21 additions & 0 deletions pkg/patterns/declarative/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit af3c7ad

Please sign in to comment.