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

Fix nil pointer dereferencing when converting vars to replacements #5211

Merged
merged 7 commits into from
Nov 17, 2023

Conversation

Aceralon
Copy link
Contributor

@Aceralon Aceralon commented Jun 17, 2023

Fix patch.Target is nil in writePatchTargets

func writePatchTargets(patch types.Patch, node *kyaml.RNode, fieldPaths []string,
options []*types.FieldOptions) ([]*types.TargetSelector, error) {
var result []*types.TargetSelector
selector := patch.Target.Copy()

When converting a kustomization file that contains Patch with only Path field, using --vars might cause kustomize to panic for dereferencing nil pointer.

Example for the bug:

#kustomization.yaml
patchesStrategicMerge:
  - patch.yaml

vars:
  - name: CERTIFICATE_NAMESPACE
    objref:
      name: system
    fieldref:
      fieldpath: metadata.namespace
#patch.yaml
apiVersion: apps/v1
kapiVersion: apps/v1
kind: Deployment
metadata:
  name: controller-manager
  namespace: system
spec:
  template:
    spec:
      containers:
        - name: $(CERTIFICATE_NAMESPACE)

Then run kustomise edit fix --vars under this folder.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 17, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @Aceralon!

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. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 17, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @Aceralon. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 17, 2023
@Aceralon Aceralon changed the title Fix nil pointer when converting vars to replacements Fix nil pointer dereferencing when converting vars to replacements Jun 17, 2023
Copy link

@Aisuko Aisuko left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, we do not have any test cases covering this function ConvertVarsToReplacements, nor writePatchTargets. To make us more confident to merge this PR, would you mind add a test case for this PR into convert_test.go?

kustomize/commands/edit/fix/convert.go Outdated Show resolved Hide resolved
@Aisuko
Copy link

Aisuko commented Jun 30, 2023

/assign

@k8s-ci-robot
Copy link
Contributor

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 30, 2023
@Aceralon
Copy link
Contributor Author

Thanks for your contribution, we do not have any test cases covering this function ConvertVarsToReplacements, nor writePatchTargets. To make us more confident to merge this PR, would you mind add a test case for this PR into convert_test.go?

Added the test case.

@Aceralon Aceralon force-pushed the feat/bug branch 2 times, most recently from 5c8587f to 1d49a72 Compare June 30, 2023 06:39
@Aisuko
Copy link

Aisuko commented Jul 2, 2023

Thanks for your contribution, we do not have any test cases covering this function ConvertVarsToReplacements, nor writePatchTargets. To make us more confident to merge this PR, would you mind add a test case for this PR into convert_test.go?

Added the test case.

Thank you.

@Aisuko
Copy link

Aisuko commented Jul 2, 2023

cc @koba1t may you please look at this one? And we need to trigger the CI process.

@koba1t
Copy link
Member

koba1t commented Jul 2, 2023

@Aisuko
Sorry, I don't have that permission to run Github Actions...
Please wait for a check from the maintainer.

/cc @annasong20 @natasha41575

@Aisuko
Copy link

Aisuko commented Jul 3, 2023

@Aisuko Sorry, I don't have that permission to run Github Actions... Please wait for a check from the maintainer.

/cc @annasong20 @natasha41575

Got it, thank you.

@Aceralon
Copy link
Contributor Author

Rebased to the latest master.

@Aceralon
Copy link
Contributor Author

Aceralon commented Sep 11, 2023

I see that there are some new issues raised relate to this bug:
#5299 #5323

cc @annasong20 @natasha41575 can you kindly look at this pr. Thank you.

@natasha41575
Copy link
Contributor

/ok-to-test

@Aceralon Apologies, could you rebase again to trigger the test suite?

Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

Couple of very small comments. Overall LGTM

kustomize/commands/edit/fix/convert.go Outdated Show resolved Hide resolved
kustomize/commands/edit/fix/convert_test.go Outdated Show resolved Hide resolved
kustomize/commands/edit/fix/convert.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 3, 2023
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

accidentally approved instead of requesting changes, whoops

@natasha41575 natasha41575 removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 3, 2023
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 4, 2023
@natasha41575 natasha41575 added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 4, 2023
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but the tests seem to have a small typo.

kustomize/commands/edit/fix/convert_test.go Outdated Show resolved Hide resolved
kustomize/commands/edit/fix/convert_test.go Show resolved Hide resolved
@Aceralon
Copy link
Contributor Author

Aceralon commented Nov 7, 2023

Couple of very small comments. Overall LGTM

@natasha41575 Finished all the changes.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Aceralon, natasha41575

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

The pull request process is described 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 k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 10, 2023
@natasha41575
Copy link
Contributor

Thanks for the contribution! Please feel free to take a look at our project boards if you are looking for more issues to contribute to.

@natasha41575
Copy link
Contributor

/lgtm

Sorry, missed adding the lgtm tag with my approval

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit fdf8f44 into kubernetes-sigs:master Nov 17, 2023
9 checks passed
@ncapps ncapps mentioned this pull request Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Development

Successfully merging this pull request may close these issues.

7 participants