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

[Helm] Implement values.schema.json #5535

Merged

Conversation

pkoutsovasilis
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis commented Sep 12, 2024

What does this PR do?

This PR does the following:

  • introduces a value.schema.json inside the chart which is used by Helm to validate the input values.yaml
  • splits ESPlainAuth output type into ESPlainAuthBasic and ESPlainAuthAPI types, favouring explicitness, for better validation and
  • introduces hostNetwork as an option in an Agent preset

Why is it important?

By having a value.schema.json we can reduce validation checks inside the templates of the Helm chart (less ifs inside templates). Furthermore, many text editors/IDEs offer the capability to import the schema and hence get hints and proposal write writing a values.yaml for the Helm chart

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

N/A

How to test this PR locally

Checking validation

run the following which is actually missing required values

helm template test ./deploy/helm/elastic-agent --set kubernetes.enabled=true  --set outputs.default.type=ESSecretAuthBasic  --set agent.fleet.enabled=true --set agent.fleet.token=""

you should see the following errors

Error: values don't meet the specifications of the schema(s) in the following chart(s):
elastic-agent:
- agent.fleet: Must validate "then" as "if" was valid
- agent.fleet: Must validate at least one schema (anyOf)
- agent.fleet.url: Does not match format 'uri'
- agent.fleet.kibanaHost: Does not match format 'uri'
- agent.fleet.kibanaUser: String length must be greater than or equal to 1
- agent.fleet.kibanaPassword: String length must be greater than or equal to 1
- outputs.default: Must validate "then" as "if" was valid
- outputs.default.secretName: String length must be greater than or equal to 1
- outputs.default: Must validate all the schemas (allOf)

Checking hints

  1. Create a new values.yaml file with your text editor/IDE (tested with vscode)
  2. Add on top this comment
    # yaml-language-server: $schema=elastic-agent/deploy/helm/elastic-agent/values.schema.json
  3. For any fields you add below the above line you should get hints

Related issues

N/A

Copy link
Contributor

mergify bot commented Sep 12, 2024

This pull request does not have a backport label. Could you fix it @pkoutsovasilis? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Sep 12, 2024

backport-v8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Sep 12, 2024
@pkoutsovasilis pkoutsovasilis force-pushed the pkoutsovasilis/helm_values_schema branch from e8f34e4 to 4f9ae86 Compare September 13, 2024 10:31
@pkoutsovasilis pkoutsovasilis added the enhancement New feature or request label Sep 16, 2024
@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review September 16, 2024 09:45
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner September 16, 2024 09:45
@pkoutsovasilis pkoutsovasilis changed the title [wip] implement values.schema.json for elastic-agent helm chart [Helm] Implement values.schema.json Sep 16, 2024
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Sep 16, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

I had a quick glance at the values.schema.json for a couple of validations that were moved from the helm template itself and it looks consistent.

LGTM

@cmacknz cmacknz requested a review from swiatekm September 17, 2024 21:02
Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

Nice!

@ycombinator ycombinator force-pushed the pkoutsovasilis/helm_values_schema branch from 553613f to e4f3207 Compare September 20, 2024 00:35
Copy link

@pkoutsovasilis pkoutsovasilis merged commit 5c24129 into elastic:main Sep 20, 2024
13 checks passed
mergify bot pushed a commit that referenced this pull request Sep 20, 2024
* feat: implement values.schema.json for elastic-agent helm chart

* fix: update rendered examples to latest elastic-agent version

* feat: split ESPlainAuth into ESPlainAuthBasic and ESPlainAuthAPI for better validation

* fix: omit redundant keys for ESSecretAuthBasic and ESSecretAuthAPI

* fix: update output type in TestKubernetesAgentHelm according to new values.schema.json

(cherry picked from commit 5c24129)
ycombinator pushed a commit that referenced this pull request Sep 23, 2024
* feat: implement values.schema.json for elastic-agent helm chart

* fix: update rendered examples to latest elastic-agent version

* feat: split ESPlainAuth into ESPlainAuthBasic and ESPlainAuthAPI for better validation

* fix: omit redundant keys for ESSecretAuthBasic and ESSecretAuthAPI

* fix: update output type in TestKubernetesAgentHelm according to new values.schema.json

(cherry picked from commit 5c24129)
pierrehilbert pushed a commit that referenced this pull request Sep 26, 2024
* feat: implement values.schema.json for elastic-agent helm chart

* fix: update rendered examples to latest elastic-agent version

* feat: split ESPlainAuth into ESPlainAuthBasic and ESPlainAuthAPI for better validation

* fix: omit redundant keys for ESSecretAuthBasic and ESSecretAuthAPI

* fix: update output type in TestKubernetesAgentHelm according to new values.schema.json

(cherry picked from commit 5c24129)

Co-authored-by: Panos Koutsovasilis <[email protected]>
belimawr pushed a commit to belimawr/elastic-agent that referenced this pull request Sep 27, 2024
* feat: implement values.schema.json for elastic-agent helm chart

* fix: update rendered examples to latest elastic-agent version

* feat: split ESPlainAuth into ESPlainAuthBasic and ESPlainAuthAPI for better validation

* fix: omit redundant keys for ESSecretAuthBasic and ESSecretAuthAPI

* fix: update output type in TestKubernetesAgentHelm according to new values.schema.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify enhancement New feature or request skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants