kustomize icon indicating copy to clipboard operation
kustomize copied to clipboard

feat: use strict unmarshalling for LoadFunctionConfig

Open lorenzofelletti opened this issue 6 months ago • 15 comments

Motivation

When using SimpleProcessor (or the other processors) one generally wants to have strict unmarshalling for the function config and throw an error if any unknown field is supplied in the configuration.

The current behaviour does not fail and just ignores unexpected/unknown field defined in the function config.

This might cause users being surprised some fields they defined are not causing any effect (as they are just silently ignored).

Changes

  • Updated the LoadFunctionConfig function to use strict unmarshalling
  • Added unit tests for LoadFunctionConfig to cover scenarios for strict mode.

lorenzofelletti avatar Jun 10 '25 09:06 lorenzofelletti

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: lorenzofelletti / name: Lorenzo Felletti (e963d629fc4397d6424783377d3187fe49898d03, fcf54f5cf13a098ca6549a49fc725ee7a3938a01)

Welcome @lorenzofelletti!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

k8s-ci-robot avatar Jun 10 '25 09:06 k8s-ci-robot

Hi @lorenzofelletti. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Jun 10 '25 09:06 k8s-ci-robot

This PR has multiple commits, and the default merge method is: merge. You can request commits to be squashed using the label: tide/merge-method-squash

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Jul 01 '25 13:07 k8s-ci-robot

/test all

stormqueen1990 avatar Aug 23 '25 18:08 stormqueen1990

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lorenzofelletti Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Aug 24 '25 16:08 k8s-ci-robot

Hi @stormqueen1990!

I'm developing a KRM function in which I'd like the configuration not to allow extra fields, e.g. I want to avoid users inadvertently doing X instead of Y:

# X
spec:
  fieldA:
    fieldB: true
    fieldC: 4
# Y
spec:
  fieldA:
    fieldC: 4
  fieldB: true

If that happens, fieldB would be defaulted in Golang to false, and no indication that the nesting is actually incorrect will be given to the user. This might lead to a function generating a configuration which is not what the user intended, and the user has to dig to understand the reason of this behaviour, until they'll find the indentation error is causing this.

It'd be much faster if an incorrect configuration just fails because of serialisation error.

To achieve this behaviour, one currently has to filter the ResourceList items, find the config manifest, serialise it, deserialise it again with the strict option, fail if the deserialisation errors.

By adding this option as a function configuration parameter, it is much easier for the function's developers to achieve this behaviour out-of-the-box.

I've set the feature to default to false for backwards compatibility, but I actually think this behaviour should be the default one, but I might be wrong in that.

lorenzofelletti avatar Aug 25 '25 08:08 lorenzofelletti

Hi @lorenzofelletti I agree as to why this is needed.

The SimpleProcessor is provided as a library for krm functions, and considering how easy it makes users notice updates and changes, I believe it's better to always unmarshal the config using UnmarshalStrict() rather than introducing new parameters or making structural/interface changes.

koba1t avatar Sep 29 '25 17:09 koba1t

Hi @koba1t ! Thanks for taking a look at it. I can update the PR to always unmarshal in strict mode

lorenzofelletti avatar Sep 29 '25 17:09 lorenzofelletti

Thank you! Please update this PR and PR title!

koba1t avatar Sep 29 '25 18:09 koba1t

Hey @koba1t, quick question: do you think VersionedAPIProcessor and TemplateProcessor would benefit from the strict unmarshalling as well or just the SimpleProcessor? I'm asking because I've originally implemented this as an extra parameter (strict) passed to LoadFunctionConfig, so I might keep it and use strict for SimpleProcessor only, or remove it and use strict unmarshalling for the three processors.

lorenzofelletti avatar Oct 02 '25 21:10 lorenzofelletti