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 a bug in Generator options #5117

Conversation

yutaroyamanaka
Copy link
Contributor

As mentioned by @KnVerey in this comment, using both kustomize.config.k8s.io/behavior and kustomize.config.k8s.io/needs-hash as generator options can cause a bug where the hash is not added to the metadata.name of the generated resource.

I reproduced this issue with current master branch as follows.

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- configmap.yaml
generators:
- |-
  kind: Executable
  metadata:
    name: demo
    annotations:
      config.kubernetes.io/function: |
        exec:
          path: ./generator.sh

configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: cmap
data:
  a: b

generator.sh

#!/bin/sh
cat <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: cmap2
  annotations:
    kustomize.config.k8s.io/behavior: merge
    kustomize.config.k8s.io/needs-hash: true
data:
  c: d
EOF

result of kustomize build

$ chmod +x generator.sh
$ kustomize build --enable-alpha-plugins --enable-exec .
apiVersion: v1
data:
  a: b
  c: d
kind: ConfigMap
metadata:
  name: cmap # hash isn't added here

If we set kustomize.config.k8s.io/needs-hash as a generator option, UpdateResourceOptions is called from Generate
in api/internal/target/kusttarget.go. UpdateResourceOptions sets a build annotation internal.config.kubernetes.io/needsHashSuffix to the resource generated by a generator.

However, I found out this annotation is removed when kustomize.config.k8s.io/behavior option is set.
We can confirm this In kustomize/blob/master/api/resmap/reswrangler.go, where CopyMergeMetaDataFieldsFrom is called. I believe this method copies the metadata of the origin resource to the one of the generated resource. In merge process, all build annotations, including internal.config.kubernetes.io/needsHashSuffix are removed (see https://github.com/natasha41575/kustomize/blob/master/api/resource/resource.go#L465). My approach is to not delete internal.config.kubernetes.io/needsHashSuffix annotation here.

Here is output of this branch

$ ./kustomize build --enable-alpha-plugins --enable-exec .
apiVersion: v1
data:
  a: b
  c: d
kind: ConfigMap
metadata:
  name: cmap-fh478f99mk

Reference: https://kubectl.docs.kubernetes.io/guides/extending_kustomize/#generator-options

@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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 9, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @yutaroyamanaka. 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 9, 2023
@koba1t
Copy link
Member

koba1t commented Apr 27, 2023

/ok-to-test

/triage accepted
/prioirty important-soon
/kind bug

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/bug Categorizes issue or PR as related to a bug. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 27, 2023
@chulkilee
Copy link

What's the status of this PR? If it indeed fixes #4833, can we make it at the next release?

@yutaroyamanaka
Copy link
Contributor Author

@chulkilee
I'm waiting for feedbacks from reviewers

@chulkilee
Copy link

@koba1t could you please take a look on this PR? Or could you invite other reviewers? Thanks!

Please note that this is one of major blocker to adopt kustomize for our team since we need to specify this to static resources (e.g. sops-encrypted Secrets)

@koba1t
Copy link
Member

koba1t commented Jul 4, 2023

@yutaroyamanaka
I thought this PR should review by Katrina due to that comment was made by her.
But She is still very busy. I'll check your PR instead.

@koba1t
Copy link
Member

koba1t commented Jul 4, 2023

Hi @yutaroyamanaka
This PR almost looks good!
I add a small nit comment and please check that.

@yutaroyamanaka
Copy link
Contributor Author

Hi @yutaroyamanaka This PR almost looks good! I add a small nit comment and please check that.

Thank you for your review.

@yutaroyamanaka yutaroyamanaka requested a review from koba1t July 5, 2023 13:11
@koba1t
Copy link
Member

koba1t commented Jul 5, 2023

/lgtm
/cc @natasha41575 @annasong20

@k8s-ci-robot k8s-ci-robot requested a review from annasong20 July 5, 2023 14:58
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 5, 2023
@chulkilee
Copy link

@koba1t what's the plan on this PR? Are there any blockers?

@koba1t
Copy link
Member

koba1t commented Aug 24, 2023

@chulkilee

We need to wait for a review from the maintainer.

@natasha41575 natasha41575 self-assigned this Aug 30, 2023
@natasha41575
Copy link
Contributor

@yutaroyamanaka Can you rebase your PR to retrigger the tests? I will try to take a look in the next week or so

@yutaroyamanaka yutaroyamanaka force-pushed the fix-bug-needs-hash-with-merge/replace-behavior branch from ed4d755 to b2190ea Compare September 9, 2023 07:23
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 9, 2023
@koba1t
Copy link
Member

koba1t commented Sep 9, 2023

/label tide/merge-method-squash
/lgtm

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Sep 9, 2023
@chulkilee
Copy link

chulkilee commented Sep 23, 2023

@yutaroyamanaka could you fix the go lint error? It's just complaining not using return value in tests.

@yutaroyamanaka yutaroyamanaka force-pushed the fix-bug-needs-hash-with-merge/replace-behavior branch from b2190ea to 0b23711 Compare October 16, 2023 12:07
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 16, 2023
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yutaroyamanaka
Once this PR has been reviewed and has the lgtm label, please ask for approval from koba1t. For more information see the Kubernetes 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

@koba1t
Copy link
Member

koba1t commented Oct 19, 2023

@yutaroyamanaka
Could you fix the lint error that happened on CI?

@yutaroyamanaka
Copy link
Contributor Author

@yutaroyamanaka Could you fix the lint error that happened on CI?

@koba1t
Thank you.
I fixed this in f0f0cf3

@koba1t
Copy link
Member

koba1t commented Oct 24, 2023

Hi @yutaroyamanaka
We need to set a license notice for every source file.
Could you add it?

@yutaroyamanaka
Copy link
Contributor Author

@koba1t
Sorry for late reply, I added that one

@koba1t
Copy link
Member

koba1t commented Nov 8, 2023

@yutaroyamanaka
Looks like some error happened on CI....
So, Could you try rebase master?

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 6, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 7, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

6 participants