Skip to content

Commit

Permalink
Removes patches and uses the raw template object as the patch instead (
Browse files Browse the repository at this point in the history
  • Loading branch information
gerred and jbarrick-mesosphere authored Jun 28, 2019
1 parent 40f8a46 commit 4e41c0f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 99 deletions.
36 changes: 5 additions & 31 deletions pkg/controller/planexecution/planexecution_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"log"
"strconv"

"k8s.io/apimachinery/pkg/util/json"

kudoengine "github.com/kudobuilder/kudo/pkg/engine"

"gopkg.in/yaml.v2"
Expand All @@ -38,7 +40,6 @@ import (
kudov1alpha1 "github.com/kudobuilder/kudo/pkg/apis/kudo/v1alpha1"
"github.com/kudobuilder/kudo/pkg/util/health"
"github.com/kudobuilder/kudo/pkg/util/template"
"github.com/tidwall/gjson"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -488,15 +489,15 @@ 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)
if err == nil {
log.Printf("PlanExecutionController: CreateOrUpdate Object present")
//update
patchString, err := patchObject(obj, truth)
log.Printf("Going to apply patch\n%+v\n\n to object\n%+v\n", patchString, truth)
log.Printf("Going to apply patch\n%+v\n\n to object\n%+v\n", string(rawObj), truth)
if err != nil {
log.Printf("Error getting patch between truth and obj: %v\n", err)
} else {
err = r.Client.Patch(context.TODO(), truth, client.ConstantPatch(types.MergePatchType, []byte(patchString)))
err = r.Client.Patch(context.TODO(), truth, client.ConstantPatch(types.StrategicMergePatchType, rawObj))
log.Printf("PlanExecutionController: CreateOrUpdate Patch: %v", err)
}
} else {
Expand Down Expand Up @@ -620,30 +621,3 @@ func (r *ReconcilePlanExecution) Cleanup(obj runtime.Object) error {

return nil
}

func patchObject(expected runtime.Object, actual runtime.Object) (string, error) {
p := client.MergeFrom(actual)

mergePatch, err := p.Data(expected)
if err != nil {
return "", err
}

specPatch := gjson.Get(string(mergePatch), "spec")
annotationPatch := gjson.Get(string(mergePatch), "metadata.annotations")

annotationPatchStr := annotationPatch.String()
if annotationPatchStr == "" {
annotationPatchStr = "{}"
}

specPatchStr := specPatch.String()
if specPatchStr == "" {
specPatchStr = "{}"
}

return fmt.Sprintf("{\"metadata\": {\"annotations\": %v}, \"spec\": %v}",
annotationPatchStr,
specPatchStr,
), nil
}
68 changes: 0 additions & 68 deletions pkg/controller/planexecution/planexecution_controller_test.go

This file was deleted.

0 comments on commit 4e41c0f

Please sign in to comment.