Skip to content

Commit

Permalink
Terminal reconciliation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Dec 29, 2023
1 parent 49beafa commit d60dea8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 10 additions & 5 deletions internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

apiv1 "github.com/Azure/eno/api/v1"
"github.com/Azure/eno/internal/reconstitution"
Expand All @@ -25,8 +26,6 @@ import (
// TODO: Block ResourceSlice deletion until resources have been cleaned up
// TODO: Clean up unused resource slices older than a duration

// TODO: Handle 400s better

type Controller struct {
client client.Client
resourceClient reconstitution.Client
Expand Down Expand Up @@ -168,7 +167,7 @@ func (c *Controller) buildPatch(ctx context.Context, prev, resource *reconstitut

currentJS, err := current.MarshalJSON()
if err != nil {
return nil, "", fmt.Errorf("building json representation of desired state: %w", err)
return nil, "", reconcile.TerminalError(fmt.Errorf("building json representation of desired state: %w", err))
}

model, err := c.discovery.Get(ctx, resource.Object.GroupVersionKind())
Expand All @@ -177,24 +176,30 @@ func (c *Controller) buildPatch(ctx context.Context, prev, resource *reconstitut
}
if model == nil {
patch, err := jsonmergepatch.CreateThreeWayJSONMergePatch(prevManifest, []byte(resource.Manifest), currentJS)
if err != nil {
return nil, "", reconcile.TerminalError(err)
}
return patch, types.MergePatchType, err
}

patchmeta := strategicpatch.NewPatchMetaFromOpenAPI(model)
patch, err := strategicpatch.CreateThreeWayMergePatch(prevManifest, []byte(resource.Manifest), currentJS, patchmeta, true)
if err != nil {
return nil, "", reconcile.TerminalError(err)
}
return patch, types.StrategicMergePatchType, err
}

func mungePatch(patch []byte, rv string) ([]byte, error) {
var patchMap map[string]interface{}
err := json.Unmarshal(patch, &patchMap)
if err != nil {
return nil, err
return nil, reconcile.TerminalError(err)
}
u := unstructured.Unstructured{Object: patchMap}
a, err := meta.Accessor(&u)
if err != nil {
return nil, err
return nil, reconcile.TerminalError(err)
}
a.SetResourceVersion(rv)
a.SetCreationTimestamp(metav1.Time{})
Expand Down
1 change: 0 additions & 1 deletion internal/controllers/synthesis/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (c *rolloutController) Reconcile(ctx context.Context, req ctrl.Request) (ct
}

// randomize list to avoid always rolling out changes in the same order
// TODO: Consider a more efficient approach here
rand.Shuffle(len(compList.Items), func(i, j int) { compList.Items[i] = compList.Items[j] })

for _, comp := range compList.Items {
Expand Down

0 comments on commit d60dea8

Please sign in to comment.