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

🐛 (kustomize/v2-alpha): use marker to track samples and do not create tracks for core types #3102

Merged
merged 1 commit into from
Nov 28, 2022

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Nov 26, 2022

Description

Instead of overwriting the file, we can use a marker so we will just append new values instead.

Motivations

  • allow manual changes
  • fix: does not track values for core types (such as deployment)
  • fix layout of the scaffold

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 26, 2022
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 26, 2022
@camilamacedo86 camilamacedo86 changed the title ✨ (kustomize/v2-alpha): use marker to track samples 🐛 (kustomize/v2-alpha): use marker to track samples and do not create tracks for core types Nov 26, 2022
@dims
Copy link
Member

dims commented Nov 27, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 27, 2022
Copy link
Contributor

@Kavinjsir Kavinjsir left a comment

Choose a reason for hiding this comment

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

Generally looks good! Just some small nits and questions.

It feels more safe and efficient to use marker with insert than the previous approach! 👍🏼

@@ -95,6 +82,13 @@ func (s *apiScaffolder) Scaffold() error {
); err != nil {
return fmt.Errorf("error scaffolding kustomize API manifests: %v", err)
}

// If the gvk is non-empty
if s.resource.Group != "" || s.resource.Version != "" || s.resource.Kind != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

nits: Just wondering in which case this gvk might be empty so that this sample kustomization should be prevented?

Copy link
Member Author

@camilamacedo86 camilamacedo86 Nov 28, 2022

Choose a reason for hiding this comment

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

It is only to prevent somewhere the validation was not made before.
I believe that when we call create API and say that we want only the controller if we do not add the check here it will create a duplication.

if err := scaffold.Execute(&samples.Kustomization{}); err != nil {
return fmt.Errorf("error scaffolding manifests: %v", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nits: we may remove the method generateManifestsPath as it is unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catcher :-)

func (f *Kustomization) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "samples", "kustomization.yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)
Copy link
Contributor

@Kavinjsir Kavinjsir Nov 27, 2022

Choose a reason for hiding this comment

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

I'm wondering why we'd like to update f.Path here? Will it be values other than config/samples/kustomization.yaml by calling replacer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catcher, we do not need this here.

// GetCodeFragments implements file.Inserter
func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
return machinery.CodeFragmentsMap{
machinery.NewMarkerFor(f.Path, samplesMarker): []string{fmt.Sprintf(samplesCodeFragment, f.makeCRFileName())},
Copy link
Contributor

@Kavinjsir Kavinjsir Nov 27, 2022

Choose a reason for hiding this comment

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

nits: will it be good/necessary if we declare a new method like:

func (f *Kustomization) sampleMarker() machinery.Marker {
	return machinery.NewMarkerFor(f.Path, samplesMarker)
}

So that we may keep consistency to use sample marker in various places in the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

I this case I think we only use here. right? But we could improve.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 28, 2022
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Changes look good to me!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 28, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, everettraven

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

@camilamacedo86 camilamacedo86 merged commit ce42706 into kubernetes-sigs:master Nov 28, 2022
@camilamacedo86 camilamacedo86 deleted the fix-kust branch November 28, 2022 15:16
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. release-blocker size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants