From d92df04f53b56c386b1fe9cf926c4a20110028a1 Mon Sep 17 00:00:00 2001 From: Antonio Alonso Dominguez Date: Tue, 24 May 2022 09:47:26 +0200 Subject: [PATCH 1/2] Add documentation-related fields to `helm_chart` --- src/python/pants/backend/helm/target_types.py | 37 +++++++++++++++++++ .../pants/backend/helm/util_rules/sources.py | 20 +++++++++- .../backend/helm/util_rules/sources_test.py | 10 ++++- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/python/pants/backend/helm/target_types.py b/src/python/pants/backend/helm/target_types.py index ecfed34444f..c2e354b56a8 100644 --- a/src/python/pants/backend/helm/target_types.py +++ b/src/python/pants/backend/helm/target_types.py @@ -15,6 +15,7 @@ Dependencies, FieldSet, MultipleSourcesField, + OptionalSingleSourceField, SingleSourceField, StringField, StringSequenceField, @@ -121,6 +122,34 @@ class HelmChartSourcesField(MultipleSourcesField): ) +class HelmChartReadmeField(OptionalSingleSourceField): + alias = "readme" + default = "README.md" + help = "Main documentation for the Helm chart" + expected_file_extensions = (".md",) + + +class HelmChartLicenseField(OptionalSingleSourceField): + alias = "license" + default = "LICENSE" + help = "A plain text file containing the license for the chart" + expected_file_extensions = ("",) + + +class HelmChartSchemaField(OptionalSingleSourceField): + alias = "schema" + default = "values.schema.json" + help = "A JSON Schema for imposing a structure on the `values.yaml` file" + expected_file_extensions = (".json",) + + +class HelmChartNotesField(OptionalSingleSourceField): + alias = "notes" + default = "templates/NOTES.txt" + help = "A plain text file containing short usage notes" + expected_file_extensions = (".txt",) + + class HelmChartDependenciesField(Dependencies): pass @@ -176,6 +205,10 @@ class HelmChartTarget(Target): HelmChartOutputPathField, HelmChartLintStrictField, HelmChartRepositoryField, + HelmChartReadmeField, + HelmChartLicenseField, + HelmChartSchemaField, + HelmChartNotesField, HelmRegistriesField, HelmSkipPushField, HelmSkipLintField, @@ -193,6 +226,10 @@ class HelmChartFieldSet(FieldSet): chart: HelmChartMetaSourceField sources: HelmChartSourcesField dependencies: HelmChartDependenciesField + readme: HelmChartReadmeField + license: HelmChartLicenseField + schema: HelmChartSchemaField + notes: HelmChartNotesField class AllHelmChartTargets(Targets): diff --git a/src/python/pants/backend/helm/util_rules/sources.py b/src/python/pants/backend/helm/util_rules/sources.py index e8e6a4dd084..4b96607622b 100644 --- a/src/python/pants/backend/helm/util_rules/sources.py +++ b/src/python/pants/backend/helm/util_rules/sources.py @@ -7,7 +7,11 @@ from pants.backend.helm.target_types import ( HelmChartFieldSet, + HelmChartLicenseField, HelmChartMetaSourceField, + HelmChartNotesField, + HelmChartReadmeField, + HelmChartSchemaField, HelmChartSourcesField, ) from pants.core.target_types import FileSourceField, ResourceSourceField @@ -59,14 +63,26 @@ def for_field_set( @property def sources_fields(self) -> tuple[SourcesField, ...]: - fields: list[SourcesField] = [self.field_set.sources] + fields: list[SourcesField] = [ + self.field_set.sources, + self.field_set.readme, + self.field_set.license, + self.field_set.schema, + self.field_set.notes, + ] if self.include_metadata: fields.append(self.field_set.chart) return tuple(fields) @property def valid_sources_types(self) -> tuple[type[SourcesField], ...]: - types: list[type[SourcesField]] = [HelmChartSourcesField] + types: list[type[SourcesField]] = [ + HelmChartSourcesField, + HelmChartReadmeField, + HelmChartSchemaField, + HelmChartLicenseField, + HelmChartNotesField, + ] if self.include_metadata: types.append(HelmChartMetaSourceField) if self.include_resources: diff --git a/src/python/pants/backend/helm/util_rules/sources_test.py b/src/python/pants/backend/helm/util_rules/sources_test.py index 019d8785c97..f1003fc6d19 100644 --- a/src/python/pants/backend/helm/util_rules/sources_test.py +++ b/src/python/pants/backend/helm/util_rules/sources_test.py @@ -37,7 +37,7 @@ def rule_runner() -> RuleRunner: ) -def test_source_templates_are_always_included(rule_runner: RuleRunner) -> None: +def test_standard_sources_are_always_included(rule_runner: RuleRunner) -> None: rule_runner.write_files( { "BUILD": dedent( @@ -49,9 +49,13 @@ def test_source_templates_are_always_included(rule_runner: RuleRunner) -> None: ), "Chart.yaml": HELM_CHART_FILE, "values.yaml": HELM_VALUES_FILE, + "values.schema.json": "", + "README.md": "", + "LICENSE": "", "crds/foo.yml": K8S_CRD_FILE, "templates/_helpers.tpl": HELM_TEMPLATE_HELPERS_FILE, "templates/service.yaml": K8S_SERVICE_FILE, + "templates/NOTES.txt": "", "resource.xml": "", "file.txt": "", } @@ -69,9 +73,13 @@ def test_source_templates_are_always_included(rule_runner: RuleRunner) -> None: ) assert source_files.snapshot.files == ( + "LICENSE", + "README.md", "crds/foo.yml", + "templates/NOTES.txt", "templates/_helpers.tpl", "templates/service.yaml", + "values.schema.json", "values.yaml", ) From 9fbd2dfab8ec3b4b29806b6279e989b70d135307 Mon Sep 17 00:00:00 2001 From: Antonio Alonso Dominguez Date: Tue, 31 May 2022 09:29:59 +0200 Subject: [PATCH 2/2] Add doc files to the sources field --- src/python/pants/backend/helm/target_types.py | 44 +++---------------- .../pants/backend/helm/util_rules/sources.py | 20 +-------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/src/python/pants/backend/helm/target_types.py b/src/python/pants/backend/helm/target_types.py index c2e354b56a8..d7af9915516 100644 --- a/src/python/pants/backend/helm/target_types.py +++ b/src/python/pants/backend/helm/target_types.py @@ -15,7 +15,6 @@ Dependencies, FieldSet, MultipleSourcesField, - OptionalSingleSourceField, SingleSourceField, StringField, StringSequenceField, @@ -108,48 +107,25 @@ class HelmChartMetaSourceField(SingleSourceField): class HelmChartSourcesField(MultipleSourcesField): default = ( + ".helmignore", + "README.md", + "LICENSE", "values.yaml", "values.yml", + "values.schema.json", "templates/*.yaml", "templates/*.yml", "templates/*.tpl", + "templates/NOTES.txt", "crds/*.yaml", "crds/*.yml", ) - expected_file_extensions = (".yaml", ".yml", ".tpl") + expected_file_extensions = (".helmignore", ".yaml", ".yml", ".tpl", ".json", ".md", ".txt", "") help = generate_multiple_sources_field_help_message( "Example: `sources=['values.yaml', 'templates/*.yaml', '!values_ignore.yaml']`" ) -class HelmChartReadmeField(OptionalSingleSourceField): - alias = "readme" - default = "README.md" - help = "Main documentation for the Helm chart" - expected_file_extensions = (".md",) - - -class HelmChartLicenseField(OptionalSingleSourceField): - alias = "license" - default = "LICENSE" - help = "A plain text file containing the license for the chart" - expected_file_extensions = ("",) - - -class HelmChartSchemaField(OptionalSingleSourceField): - alias = "schema" - default = "values.schema.json" - help = "A JSON Schema for imposing a structure on the `values.yaml` file" - expected_file_extensions = (".json",) - - -class HelmChartNotesField(OptionalSingleSourceField): - alias = "notes" - default = "templates/NOTES.txt" - help = "A plain text file containing short usage notes" - expected_file_extensions = (".txt",) - - class HelmChartDependenciesField(Dependencies): pass @@ -205,10 +181,6 @@ class HelmChartTarget(Target): HelmChartOutputPathField, HelmChartLintStrictField, HelmChartRepositoryField, - HelmChartReadmeField, - HelmChartLicenseField, - HelmChartSchemaField, - HelmChartNotesField, HelmRegistriesField, HelmSkipPushField, HelmSkipLintField, @@ -226,10 +198,6 @@ class HelmChartFieldSet(FieldSet): chart: HelmChartMetaSourceField sources: HelmChartSourcesField dependencies: HelmChartDependenciesField - readme: HelmChartReadmeField - license: HelmChartLicenseField - schema: HelmChartSchemaField - notes: HelmChartNotesField class AllHelmChartTargets(Targets): diff --git a/src/python/pants/backend/helm/util_rules/sources.py b/src/python/pants/backend/helm/util_rules/sources.py index 4b96607622b..e8e6a4dd084 100644 --- a/src/python/pants/backend/helm/util_rules/sources.py +++ b/src/python/pants/backend/helm/util_rules/sources.py @@ -7,11 +7,7 @@ from pants.backend.helm.target_types import ( HelmChartFieldSet, - HelmChartLicenseField, HelmChartMetaSourceField, - HelmChartNotesField, - HelmChartReadmeField, - HelmChartSchemaField, HelmChartSourcesField, ) from pants.core.target_types import FileSourceField, ResourceSourceField @@ -63,26 +59,14 @@ def for_field_set( @property def sources_fields(self) -> tuple[SourcesField, ...]: - fields: list[SourcesField] = [ - self.field_set.sources, - self.field_set.readme, - self.field_set.license, - self.field_set.schema, - self.field_set.notes, - ] + fields: list[SourcesField] = [self.field_set.sources] if self.include_metadata: fields.append(self.field_set.chart) return tuple(fields) @property def valid_sources_types(self) -> tuple[type[SourcesField], ...]: - types: list[type[SourcesField]] = [ - HelmChartSourcesField, - HelmChartReadmeField, - HelmChartSchemaField, - HelmChartLicenseField, - HelmChartNotesField, - ] + types: list[type[SourcesField]] = [HelmChartSourcesField] if self.include_metadata: types.append(HelmChartMetaSourceField) if self.include_resources: