Skip to content
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

Bugfix ignore and copy from obj #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ishankhare07
Copy link
Contributor

Also add knative-serving plugin example

also rename few variables to communicate better context

Signed-off-by: Ishan Khare <[email protected]>
@ishankhare07 ishankhare07 added the enhancement New feature or request label Nov 16, 2022
also add README for deploying plugin

Signed-off-by: Ishan Khare <[email protected]>
@@ -46,7 +46,7 @@ func ApplyPatches(obj1, obj2 client.Object, patchesConf []*config.Patch, reverse

// remove ignore paths from patched object
for _, p := range reversePatchesConf {
if p.Path == "" || (p.Ignore != nil && !*p.Ignore) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that is correct, the logic currently is that its true by default, this would make it false by default, so only in the case of ignore: false we want to skip applying the delete patch

// apply patches on from object
err = patches.ApplyPatches(toObjCopied, toObj, patchesConfig, reversePatchesConfig, nameResolver)
// apply patches on toObjCopied
err = patches.ApplyPatches(toObjCopied, fromObj, patchesConfig, reversePatchesConfig, nameResolver)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we want to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed in cases where we want to populated controller applied default back into the virtual obj. i.e.
vObj.field1 = pObj.field1.

Currently the behavior of copyFromObject is like vObj.field1 = vObj.field2

But consider the scenario where

vobj
=====
spec.template.timeoutSeconds: nil (unset)
|
|
v
-------------------------------------------
pobj
spec.template.timeoutSeconds: 300 ----------> set by controller to default

I would want to (expect that) copyFromObject in reversePatches as defined

                  - op: copyFromObject
                    fromPath: spec.template.spec.timeoutSeconds
                    path: spec.template.spec.timeoutSeconds
                    conditions:
                      - empty: true
                        path: spec.template.spec.timeoutSeconds

would copy across physical <-> virtual boundary, but since both the args to ApplyPatches originated from same source obj, it was not happening

@@ -78,15 +79,15 @@ func (s *patcher) ApplyPatches(ctx context.Context, fromObj, toObj client.Object
return outObject, nil
}

func (s *patcher) ApplyReversePatches(ctx context.Context, fromObj, otherObj client.Object, reversePatchConfig []*config.Patch, nameResolver patches.NameResolver) (controllerutil.OperationResult, error) {
originalUnstructured, err := toUnstructured(fromObj)
func (s *patcher) ApplyReversePatches(ctx context.Context, destObj, sourceObj client.Object, reversePatchConfig []*config.Patch, nameResolver patches.NameResolver) (controllerutil.OperationResult, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rename the parameters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO original name was confusing. So unless I understand the function incorrectly, the new name is much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants