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

Solve yaml warnings in the scaffolds #3599

Closed
camilamacedo86 opened this issue Sep 6, 2023 · 3 comments · Fixed by #3634
Closed

Solve yaml warnings in the scaffolds #3599

camilamacedo86 opened this issue Sep 6, 2023 · 3 comments · Fixed by #3634
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@camilamacedo86
Copy link
Member

What do you want to happen?

Check in the makefile that we have the target:

.PHONY: yamllint
yamllint:
	@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest testdata -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings

Then, remove the flag --no-warnings and run make yamllint.
See that the following warnings will be raised

 $ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
camiladeomacedo@camilas-MacBook-Air ~/go/src/sigs.k8s.io/kubebuilder (master) $ make yamllint
testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/rbac/role.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/webhook/manifests.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v2/config/webhook/service.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v3/config/default/kustomization.yaml
  34:1      warning  too many blank lines (3 > 2)  (empty-lines)

testdata/project-v3/config/default/manager_auth_proxy_patch.yaml
  17:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v3/config/manager/manager.yaml
  79:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v3/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v3/config/webhook/service.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4/config/default/kustomization.yaml
  36:1      warning  too many blank lines (3 > 2)  (empty-lines)

testdata/project-v4/config/default/manager_auth_proxy_patch.yaml
  17:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4/config/manager/manager.yaml
  79:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4/config/webhook/service.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-multigroup/config/default/kustomization.yaml
  36:1      warning  too many blank lines (3 > 2)  (empty-lines)

testdata/project-v4-multigroup/config/default/manager_auth_proxy_patch.yaml
  17:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-multigroup/config/manager/manager.yaml
  84:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-multigroup/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-multigroup/config/samples/example.com_v1alpha1_busybox.yaml
  9:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-multigroup/config/webhook/service.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-with-deploy-image/config/default/kustomization.yaml
  36:1      warning  too many blank lines (3 > 2)  (empty-lines)

testdata/project-v4-with-deploy-image/config/default/manager_auth_proxy_patch.yaml
  17:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-with-deploy-image/config/manager/manager.yaml
  84:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-with-deploy-image/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-with-deploy-image/config/samples/example.com_v1alpha1_busybox.yaml
  9:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-with-deploy-image/config/webhook/service.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

testdata/project-v4-with-grafana/config/default/kustomization.yaml
  36:1      warning  too many blank lines (3 > 2)  (empty-lines)

testdata/project-v4-with-grafana/config/default/manager_auth_proxy_patch.yaml
  17:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-with-grafana/config/manager/manager.yaml
  79:15     warning  wrong indentation: expected 12 but found 14  (indentation)

testdata/project-v4-with-grafana/config/prometheus/monitor.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

To solve them out you will need to:

Extra Labels

No response

@camilamacedo86 camilamacedo86 added kind/feature Categorizes issue or PR as related to a new feature. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Sep 6, 2023
@ashutosh887
Copy link
Contributor

I can do this one @camilamacedo86

/assign

@varshaprasad96
Copy link
Member

@ashutosh887 Adding some pointers to what needs to be done here:

So yamllint as mentioned in the target, is similar to any other linter (Linter is a tool that performs many checks in the static code (the code that we write) in the project. In this case, you can refer to the yamllint documentation here: https://yamllint.readthedocs.io.

Now if you follow the steps in the issue and run it, you can see errors like this:

testdata/project-v4-with-grafana/config/default/kustomization.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)

Now let's see what this means. It says that the kustomization.yaml in the particular project has too many blank lines in this yaml file. kustomization files are scaffolded by the kustomize plugin in Kubebuilder which is located here: https://github.com/kubernetes-sigs/kubebuilder/tree/master/pkg/plugins/common/kustomize. Within there, you can see that there are templates defined for kustomization files, for example, in case of config/default/kustomization.yaml the template is defined here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v2/scaffolds/internal/templates/config/kdefault/kustomization.go#L57.

You can find the version of kustomize plugin being used (which is usually v2 for go/v3 projects and above). Then check for filename along with its path here:

f.Path = filepath.Join("config", "default", "kustomization.yaml")
, followed by which you can fix the template. If the linter says too many blank lines, you can accordingly remove the extra blank lines from the defined yaml template.

Things to consider:

  1. Based on the path, you would have to first identify which plugin is scaffolding that particular file.
  2. The plugin code is present in plg/plugins folder.
  3. You would have to check the path defined in there, and fix the template.

Ignore the errors in the crd and rbac generation files, as they are scaffolded by controller-gen. We would have to fix in that project instead of KB.

Hope this helps, let us know if you need any help.

@ashutosh887
Copy link
Contributor

Thank you so much @varshaprasad96 for the explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
3 participants