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

Populate container list to allow filtering #380

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dbaudracco
Copy link

@dbaudracco dbaudracco commented Nov 22, 2024

This PR fixes the exclusion of containers not working

Background

When using a spinach file like

---
popeye:
  excludes:
    linters:
      deployments:
        instances:
          - codes:
              - 106
            containers:
              - "rx:.*init.*"

I noticed that the relevant containers were not excluded:

· namespace/varnish.................................................................................😱
🐳 init-varnish
😱 [POP-106] No resources requests/limits defined.

After some debugging it appears that this is because the container list is not populated for the appropriate resources: this PR addresses the issue

· namespace/varnish.................................................................................✅

Todo

  • proper testing of the resource parsing

@dbaudracco
Copy link
Author

If I'm not wrong this supersedes #267, fixes #200 and #168

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@dbaudracco Thank you for this PR. Nice catch! You are correct about adding the containers to the rule.
I think this could use some TLC in terms of drying up the code and testing the actual fix.
Also I think rs are missing from this line up.

@@ -31,6 +32,12 @@ func NewCronJob(co *issues.Collector, db *db.DB) *CronJob {
}
}

func CjSpecFor(fqn string, cj *batchv1.CronJob) rules.Spec {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could be dry-ed up a bit i.e coSpecFor(string, metav1.ObjectMetaAccessor, v1.PodSpec).
Thus we would not need the same impl for any pod resources.

@@ -59,3 +60,54 @@ func TestCronJobLint(t *testing.T) {
assert.Equal(t, `[POP-106] No resources requests/limits defined`, ii[5].Message)
assert.Equal(t, rules.WarnLevel, ii[5].Level)
}

func TestCjSpecFor(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

These tests really test the same call. Better would be to have tests that actually show the resolved fix i.e no spinach vs with spinach and show container codes exclusions.

@derailed derailed added bug Something isn't working need-tlc labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need-tlc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants