-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No panic when getting a plan status for an instance with no plan #461
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,12 @@ package planexecution | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"strconv" | ||
|
||
"k8s.io/apimachinery/pkg/util/json" | ||
apijson "k8s.io/apimachinery/pkg/util/json" | ||
|
||
kudoengine "github.com/kudobuilder/kudo/pkg/engine" | ||
|
||
|
@@ -489,11 +490,11 @@ func (r *ReconcilePlanExecution) Reconcile(request reconcile.Request) (reconcile | |
key, _ := client.ObjectKeyFromObject(obj) | ||
truth := obj.DeepCopyObject() | ||
err := r.Client.Get(context.TODO(), key, truth) | ||
rawObj, _ := json.Marshal(obj) | ||
rawObj, _ := apijson.Marshal(obj) | ||
if err == nil { | ||
log.Printf("PlanExecutionController: CreateOrUpdate Object present") | ||
//update | ||
log.Printf("Going to apply patch\n%+v\n\n to object\n%+v\n", string(rawObj), truth) | ||
log.Printf("Going to apply patch\n%+v\n\n to object\n%s\n", string(rawObj), prettyPrint(truth)) | ||
if err != nil { | ||
log.Printf("Error getting patch between truth and obj: %v\n", err) | ||
} else { | ||
|
@@ -525,7 +526,7 @@ func (r *ReconcilePlanExecution) Reconcile(request reconcile.Request) (reconcile | |
} | ||
err = health.IsHealthy(r.Client, obj) | ||
if err != nil { | ||
log.Printf("PlanExecutionController: Obj is NOT healthy: %+v", obj) | ||
log.Printf("PlanExecutionController: Obj is NOT healthy: %s", prettyPrint(obj)) | ||
planExecution.Status.Phases[i].Steps[j].State = kudov1alpha1.PhaseStateInProgress | ||
planExecution.Status.Phases[i].State = kudov1alpha1.PhaseStateInProgress | ||
} | ||
|
@@ -621,3 +622,8 @@ func (r *ReconcilePlanExecution) Cleanup(obj runtime.Object) error { | |
|
||
return nil | ||
} | ||
|
||
func prettyPrint(i interface{}) string { | ||
s, _ := json.MarshalIndent(i, "", " ") | ||
return string(s) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be in a json util package? this is not planexec specific There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as I reason through this more... this function literal swallows the err. what is the output for an error? do we not want any indication there was an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I haven't put it into util package - I didn't want a general purpose prettyPrint method for everybody (though it can be). So far, I only saw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated to the bug, just making our lives easier when debugging integration tests.