Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move server side apply patch code to library, use ssa to update catal…
…og source pods
- Loading branch information
Ankita Thomas
authored and
Ankita Thomas
committed
Aug 21, 2020
1 parent
63b96f4
commit cfe2bd9
Showing
15 changed files
with
1,430 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
k8scontrollerclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
fakecontrollerclient "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
) | ||
|
||
// FakeApplier provides a wrapper around the fake k8s controller client to convert the unsupported apply-type patches to merge patches. | ||
func NewFakeApplier(scheme *runtime.Scheme, owner string, objs ...runtime.Object) *ServerSideApplier { | ||
return &ServerSideApplier{ | ||
client: &fakeApplier{fakecontrollerclient.NewFakeClientWithScheme(scheme, objs...)}, | ||
Scheme: scheme, | ||
Owner: k8scontrollerclient.FieldOwner(owner), | ||
} | ||
} | ||
|
||
type fakeApplier struct { | ||
k8scontrollerclient.Client | ||
} | ||
|
||
func (c *fakeApplier) Patch(ctx context.Context, obj runtime.Object, patch k8scontrollerclient.Patch, opts ...k8scontrollerclient.PatchOption) error { | ||
patch, opts = convertApplyToMergePatch(patch, opts...) | ||
return c.Client.Patch(ctx, obj, patch, opts...) | ||
} | ||
|
||
func (c *fakeApplier) Status() k8scontrollerclient.StatusWriter { | ||
return fakeStatusWriter{c.Client.Status()} | ||
} | ||
|
||
type fakeStatusWriter struct { | ||
k8scontrollerclient.StatusWriter | ||
} | ||
|
||
func (c fakeStatusWriter) Patch(ctx context.Context, obj runtime.Object, patch k8scontrollerclient.Patch, opts ...k8scontrollerclient.PatchOption) error { | ||
patch, opts = convertApplyToMergePatch(patch, opts...) | ||
return c.StatusWriter.Patch(ctx, obj, patch, opts...) | ||
} | ||
|
||
func convertApplyToMergePatch(patch k8scontrollerclient.Patch, opts ...k8scontrollerclient.PatchOption) (k8scontrollerclient.Patch, []k8scontrollerclient.PatchOption) { | ||
// Apply patch type is not supported on the fake controller | ||
if patch.Type() == types.ApplyPatchType { | ||
patch = k8scontrollerclient.Merge | ||
patchOptions := make([]k8scontrollerclient.PatchOption, 0, len(opts)) | ||
for _, opt := range opts { | ||
if opt == k8scontrollerclient.ForceOwnership { | ||
continue | ||
} | ||
patchOptions = append(patchOptions, opt) | ||
} | ||
opts = patchOptions | ||
} | ||
return patch, opts | ||
} |
Oops, something went wrong.