Skip to content

Commit

Permalink
WIP: CRD replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Dec 4, 2021
1 parent 9dcade6 commit 5ddca96
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func Update(c UpdateConfig) (*unstructured.Unstructured, error) {
// - [ ] Support server-side apply, when it comes out.
//

client, err := c.ClientSet.ResourceClient(c.Inputs.GroupVersionKind(), c.Inputs.GetNamespace())
client, err := c.ClientSet.ResourceClientForObject(c.Inputs)
if err != nil {
return nil, err
}
Expand All @@ -366,21 +366,28 @@ func Update(c UpdateConfig) (*unstructured.Unstructured, error) {
return nil, err
}

// Create merge patch (prefer strategic merge patch, fall back to JSON merge patch).
patch, patchType, _, err := openapi.PatchForResourceUpdate(c.Resources, c.Previous, c.Inputs, liveOldObj)
if err != nil {
return nil, err
}
// TODO: May just need to GET, set resourceVersion, and then immediately Update
var currentOutputs *unstructured.Unstructured
if clients.IsCRD(c.Inputs) {
c.Inputs.SetResourceVersion(liveOldObj.GetResourceVersion())
currentOutputs, err = client.Update(context.TODO(), c.Inputs, metav1.UpdateOptions{})
} else {
// Create merge patch (prefer strategic merge patch, fall back to JSON merge patch).
patch, patchType, _, err := openapi.PatchForResourceUpdate(c.Resources, c.Previous, c.Inputs, liveOldObj)
if err != nil {
return nil, err
}

var options metav1.PatchOptions
if c.DryRun {
options.DryRun = []string{metav1.DryRunAll}
}
var options metav1.PatchOptions
if c.DryRun {
options.DryRun = []string{metav1.DryRunAll}
}

// Issue patch request.
// NOTE: We can use the same client because if the `kind` changes, this will cause
// a replace (i.e., destroy and create).
currentOutputs, err := client.Patch(context.TODO(), c.Inputs.GetName(), patchType, patch, options)
// Issue patch request.
// NOTE: We can use the same client because if the `kind` changes, this will cause
// a replace (i.e., destroy and create).
currentOutputs, err = client.Patch(context.TODO(), c.Inputs.GetName(), patchType, patch, options)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5ddca96

Please sign in to comment.