Closed onepushmain closed 10 months ago
@onepushmain Kubeconform looks for specific file extensions & content to be activated
Activated only if sub-directory kubernetes is found. (directory name can be overridden with KUBERNETES_DIRECTORY)
File extensions: .yml, .yaml, .json
Detected file content (regex): apiVersion:, kustomize\.config\.k8s\.io, tekton
Source: https://megalinter.io/beta/descriptors/kubernetes_kubeconform/#how-are-identified-applicable-files
How is structured your repository ? do you have a kubernetes directory ?
Similar issue here, at least for the KUBERNETES_HELM linter: We have our Helm charts in its own dedicated subdirectory, i.e.
project-root/
├─ subdir/
│ ├─ our-chart/
│ │ ├─ Chart.yml
│ │ ├─ templates/
Since the descriptor sets active_only_if_file_found the linter is skipped.
There is a variable KUBERNETES_DIRECTORY, but I could not figure out how to use it properly.
At the moment my only workaround is adding a dummy Chart.yaml file at the root and then passing the actual subdirectory with KUBERNETES_HELM_ARGUMENTS: "subdir/our-chart"
. Setting this config is fine, adding a dummy Chart.yaml is not.
Are there any solutions to disable the active_only_if_file_found check? Can one override it?
Thanks!
What if you try KUBERNETES_DIRECTORY: subdir
?
The same thing happens when KUBERNETES_DIRECTORY
is set: The check for activation does not pass.
Looking at the code there are only two places that are looked at to do the check (directly in the workspace or under linter_rules_path). This linter_rules_path is global, right? So any other linters would be affected as well. I have nonetheless tried setting it and found that the workspace is in the path twice (in line 351, since in my test linter_rules_path included the absolute path). Removing the workspace from the front allows the check to go through (but using this global LINTER_RULES_PATH variable).
My config for testing was (in various variations):
ENABLE_LINTERS:
- KUBERNETES_HELM
LINTER_RULES_PATH: subdir/our-chart
KUBERNETES_DIRECTORY: subdir/our-chart
KUBERNETES_HELM_ARGUMENTS: "subdir/our-chart"
mmmm what if we always activate the linter if KUBERNETES_DIRECTORY: any
is defined ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
Yeah, that seems like a logical solution.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
A million years later, PR is on the way :)
I think this issue isn't resolved yet. With KUBERNETES_HELM and KUBERNETES_KUBESCAPE linters enabled and with the KUBERNETES_DIRECTORY environment variable set to any
, I get the following log output:
[Activation] KUBERNETES_HELM skip check of directory as value set to "any"
[Activation] KUBERNETES_HELM has been set inactive, as none of these files has been found: ['Chart.yml', 'Chart.yaml']
[Activation] KUBERNETES_KUBESCAPE skip check of directory as value set to "any"
[Activation] KUBERNETES_KUBESCAPE has been set inactive, as none of these files has been found: ['Chart.yml', 'Chart.yaml']
@lukaalba it is another problem ^^
Isn't there a Chart.yml in your repo ? Many you need us to provide a variable allowing to override it ? It's just that we can't run KUBE linters on any repo everytime there is any YML file found :/
https://megalinter.io/latest/descriptors/kubernetes_helm/#how-are-identified-applicable-files
Thanks for your reply! But I'm not sure if I fully get you here.
I have a similar project structure as @TimothyEarley with the Chart.yml
placed not in the root-path of the project, but in a subfolder chart
.
Reading the previous comments I would have expected that setting the KUBERNETES_DIRECTORY
to any
the whole project will be scanned even if a Chart.yaml is not placed at root-level. Am I mistaken here?
Setting KUBERNETES_DIRECTORY
to chart
doesn't work neither.
I'm not sure but to me it looks like self.files_sub_directory
which is filled with the KUBERNETES_DIRECTORY value is not respected in the actual file existence check.
@lukaalba MegaLinter will look in KUBERNETES_DIRECTORY + "/Chart.yml"
If KUBERNETES_DIRECTORY is any
, it will look for Chart.yml at the root
Do you have one or multiple Chart.yml files ? ( I'm not a K8 expert ^^ ) IF you have one, you could define KUBERNETES_DIRECTORY=path/to/folder/ where Chart.yml can be found
If you have multiple, we'll have to make some enhancements ^^
I have only one Chart.yml, so this shouldn't be an issue :D
Just for clarification. With this project structure:
project-root/
├─ chart/
│ ├─ Chart.yml
│ ├─ templates/
Setting KUBERNETES_DIRECTORY
to chart
should work, right?
Hi, first of all thank for this tool @nvuillam.
I am encountering the same issue as @lukaalba . Even if I set KUBERNETES_DIRECTORY to "chart" or "chart/" it will be ignored and i get the following message:
[Activation] KUBERNETES_HELM has been set inactive, as none of these files has been found: ['Chart.yml', 'Chart.yaml']
The directory structure is equal to the one provided by @lukaalba.
I "discovered" that setting KUBERNETES_DIRECTORY doesn't affect the "helm" and "kubescape" linter, but only kubeconform. Starting megalinter inside the chart-directory is working as expected.
Megalinter recognizes that this directory indeed exists, but it's maybe checking the wrong directory for the Chart.yaml ? If I set KUBERNETES_DIRECTORY to something "random" you'll receive the following output for KUBERNETES_HELM:
[Activation] KUBERNETES_HELM has been set inactive, as subdirectory has not been found: someotherfolder (set value "any" to always activate)
[Activation] KUBERNETES_HELM has been set inactive, as none of these files has been found: ['Chart.yml', 'Chart.yaml']
Megalinter recognizes that this directory indeed exists, but it's maybe checking the wrong directory for the Chart.yaml ? If I set KUBERNETES_DIRECTORY to something "random" you'll receive the following output for KUBERNETES_HELM:
I think you're right... let's provide a variable that will force KUBE linters if set to true ?
Thanks for reopening this issue!
From the user point of perspective it would be clearer how to use those linters if the helm and kubescape one respect the KUBERNETES_DIRECTORY, too. Any idea if this is possible?
The helm lint
command has a path argument by default
Megalinter recognizes that this directory indeed exists, but it's maybe checking the wrong directory for the Chart.yaml ? If I set KUBERNETES_DIRECTORY to something "random" you'll receive the following output for KUBERNETES_HELM:
I think you're right... let's provide a variable that will force KUBE linters if set to true ?
Sry for the late reply, i've been sick. I'm not sure if a force-variable is really needed here. Why not just always check "force" megalinter, to look inside this directory ? Are there any known side-effects ?
@dennishoffmann-edu because the detection rules would make MegaLinter read the content of all YML files everytime... that's not fair for other MegaLinter usages performances ;)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
@lukaalba MegaLinter will look in
KUBERNETES_DIRECTORY + "/Chart.yml"
If KUBERNETES_DIRECTORY is
any
, it will look for Chart.yml at the rootDo you have one or multiple Chart.yml files ? ( I'm not a K8 expert ^^ ) IF you have one, you could define KUBERNETES_DIRECTORY=path/to/folder/ where Chart.yml can be found
If you have multiple, we'll have to make some enhancements ^^
Hi - I just ran into this issue as well (having a Chart.yaml file located in <workspace>/charts
and Megalinter not detecting the Chart.yaml file). I tried setting KUBERNETES_DIRECTORY
, similarly without success as the other reports
Assuming I'm looking in the correct location in the source code: https://github.com/oxsecurity/megalinter/blob/main/megalinter/Linter.py#L346-L379, would it be correct to say that MegaLinter isn't incorporating self.files_sub_directory
to extend the checked path(s) with the KUBERNETES_DIRECTORY
value?
From cursory testing (adding additional logging to Linter.py
), it appears only ./Chart.yml
and ././.github/linters/Chart.yml
(and the .yaml equivalents) are being checked, even while KUBERNETES_DIRECTORY
is being properly identified
Is there a general timeline for when the next release will be? Ran into this same issue today and realized the fix isn't present in v7.8.0
@Kryan90 there is no pre-written timeline for new releases as it depends from content and maintainers availability, but there is almost never more than one month between 2 minor releases :)
Meanwhile, you can use beta version if you are in a hurry to benefit from a features/fix :)
Hello!
I'm having some problems while using megalinter into my kubernetes manifest repository. Seem like the megalinter don't have the option to run some kubernetes linteres/checkers
my
.mega-linter.yml
:logs that I get while running with this config:
Am I doing something wrong?
thanks in advance for the support and, I apologize if this is too trivial, it's my first time using this tool