Skip to content

Commit

Permalink
Allow to skip linting on Helm charts (pantsbuild#15640)
Browse files Browse the repository at this point in the history
Closes pantsbuild#15639

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
alonsodomin authored May 25, 2022
1 parent 08e4640 commit 54a25fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/python/pants/backend/helm/goals/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from dataclasses import dataclass

from pants.backend.helm.subsystems.helm import HelmSubsystem
from pants.backend.helm.target_types import HelmChartFieldSet, HelmChartLintStrictField
from pants.backend.helm.target_types import (
HelmChartFieldSet,
HelmChartLintStrictField,
HelmSkipLintField,
)
from pants.backend.helm.util_rules.chart import HelmChart, HelmChartRequest
from pants.backend.helm.util_rules.tool import HelmProcess
from pants.core.goals.lint import LintResult, LintResults, LintTargetsRequest
Expand All @@ -23,6 +27,7 @@
@dataclass(frozen=True)
class HelmLintFieldSet(HelmChartFieldSet):
lint_strict: HelmChartLintStrictField
skip_lint: HelmSkipLintField


class HelmLintRequest(LintTargetsRequest):
Expand All @@ -33,7 +38,9 @@ class HelmLintRequest(LintTargetsRequest):
@rule(desc="Lint Helm charts", level=LogLevel.DEBUG)
async def run_helm_lint(request: HelmLintRequest, helm_subsystem: HelmSubsystem) -> LintResults:
charts = await MultiGet(
Get(HelmChart, HelmChartRequest(field_set)) for field_set in request.field_sets
Get(HelmChart, HelmChartRequest(field_set))
for field_set in request.field_sets
if not field_set.skip_lint.value
)
logger.debug(f"Linting {pluralize(len(charts), 'chart')}...")

Expand Down
20 changes: 20 additions & 0 deletions src/python/pants/backend/helm/goals/lint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,23 @@ def test_one_lint_result_per_chart(rule_runner: RuleRunner) -> None:
assert lint_results[0].partition_description == "chart1"
assert lint_results[1].exit_code == 0
assert lint_results[1].partition_description == "chart2"


def test_skip_lint(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"src/chart/BUILD": "helm_chart(skip_lint=True)",
"src/chart/Chart.yaml": gen_chart_file("chart", version="0.1.0"),
"src/chart/values.yaml": HELM_VALUES_FILE,
"src/chart/templates/_helpers.tpl": HELM_TEMPLATE_HELPERS_FILE,
"src/chart/templates/service.yaml": K8S_SERVICE_FILE,
}
)

source_root_patterns = ("src/*",)

chart_target = rule_runner.get_target(Address("src/chart", target_name="chart"))
lint_results = run_helm_lint(
rule_runner, [chart_target], source_root_patterns=source_root_patterns
)
assert len(lint_results) == 0
14 changes: 13 additions & 1 deletion src/python/pants/backend/helm/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ class HelmRegistriesField(StringSequenceField):
)


class HelmSkipLintField(BoolField):
alias = "skip_lint"
default = False
help = softwrap(
f"""
If set to true, do not run any linting in this Helm chart when running `{bin_name()}
lint`.
"""
)


class HelmSkipPushField(BoolField):
alias = "skip_push"
default = False
help = softwrap(
f"""
If set to true, do not push this helm chart to registries when running `{bin_name()}
If set to true, do not push this Helm chart to registries when running `{bin_name()}
publish`.
"""
)
Expand Down Expand Up @@ -167,6 +178,7 @@ class HelmChartTarget(Target):
HelmChartRepositoryField,
HelmRegistriesField,
HelmSkipPushField,
HelmSkipLintField,
)
help = "A Helm chart."

Expand Down

0 comments on commit 54a25fa

Please sign in to comment.