What’s in this article?
VSCode Datree — a VSCode Extension that brings Datree’s features right inside your code editor 🚀
Abstract
Improper Kubernetes configurations can lead to ineffective and hard-to-maintain resource allocations, in worst cases it can break the whole CI/CD if not detected in earlier stages of deployment. The VSCode Datree extension uses Datree under the hood to gather information about the YAML and Helm configurations and generate errors and suggestions that can be displayed right inside the code editor for the developer to act upon, as the Datree CLI currently doesn’t show the line number where the error is occurring this can help developers to find errors easily in large configurations. This open-source extension extends Datree’s functionality by allowing users to use custom policies made with Datree and use them directly through VSCode.
The extension also simplifies it for the developer to correct the errors during the development phase rather than waiting for warnings later during the CI/CD pipelines.
What’s Datree?
Prevent Kubernetes misconfigurations from reaching production (again 😤 )!
Datree helps us tackle misconfigurations easily with the command-line tool that can be easily integrated into existing CI/CD pipelines and warns us before any misconfigured resources get deployed to production. It can also assist during the development phase by warning about possible incorrect values much earlier in the first place to increase the overall efficiency.
Installing VSCode Datree
Datree needs to be installed for the extension to work, get it here 👇https://hub.datree.io/
The extension can be installed directly through the extensions tab available in VSCode or through VSCode’s marketplace.
VSCode Datree - Visual Studio Marketplace
Exploring the features
Highlighting YAML Errors
Highlighting K8s Schema Errors
Helm Workflow Support
Custom Test Configurations
Solution Suggestions
The extension incorporates different Datree features and provides added functionalities to the user. Let us discuss each of these features in detail and the datree commands they run under the hood.
1. Highlighting YAML Errors
This feature shows the issue in the YAML structure of the configuration file, this helps to ensure that a properly structured configuration file is fed during production to avoid silly delays.
By default, Datree checks the YAML structure of the config file even before running the actual configuration checks.
$ datree test config.yaml
2. Highlighting K8s Schema Errors
This is the feature where Datree and the extension shines. The configuration file is analysed for any misconfiguration and incorrect values, then problems are highlighted along with helpful suggestions.
$ datree test config.yaml
3. Support for Helm Workflows
Helm and Datree’s Helm Plugin is required, get it here 👇
https://hub.datree.io/helm-plugin
When it comes to defining Kubernetes configuration for large applications, Helm Charts play an important role by reducing duplication & complexity and boosting productivity. Datree’s Helm Plugin allows you to run policy checks on Helm Charts with ease, the extension can also detect the Helm workflow and automatically run the required helm plugin.
$ helm datree test [CHART_DIRECTORY]
4. Custom Test Configurations
Datree CLI provides a couple of options such as mentioning K8s schema version, policies, etc. The extension enables you to harness these options through an options panel.
$ datree test config.yaml --schema-version 1.18.0 --policy staging
5. Solution Suggestions
Datree has 30 built-in battle-tested policy checks, if your configuration has these errors, a link to the solution article will be linked along with the error highlight.
Future Scope
Linking Execution history
Improved Error Highlighting
As this extension is actively maintained, new features that are added to Datree CLI will be made available in the extension as well!
Being an Opensource project, if you find any issues, bugs, or have any suggestions feel free to contribute 🙌
GitHub - SuyashSonawane/vscode-datree: Simple VSCode Extension that allows you to run Datree tests…
Pretext
Here I share the idea behind the extension and how it was created!
This extension is built for Datree as a part of the Cloud Native Hackathon.
Datree is a CLI tool that allows the rectification of K8s configuration files with ease and zero dependencies. While researching the possible use case for the hackathon I came across an idea about a VSCode extension that can show errors directly in the editor and to my surprise there was no existing solution to this!! , I always wanted to make a VSCode extension and now it was the perfect opportunity.
First, I started with parsing the CLI’s output with its JSON output format, faced some issues with the structure, and contacted datree support for assistance, I came to know that there was already an issue that addressed this and Eyar Zilberman provided me with some ideas and a video that link that suggests such VSCode extension. I was very much pumped at this point and worked with full force to make it into a reality.
VSCode has a very extensive API when it comes to developing extensions. I got the opportunity to learn and understand the logic that goes behind building such extensions. I worked with reviews, child processes, providers, and typescript while building this extension and React.js for building the webviews.
I periodically updated the datree team with my progress and they were kind enough to solve my doubts and suggest improvements and features. Shimon Tolts suggested adding Helm support and Dima Brusilovsky suggested having an interface where the user can provide custom configuration for the tests, thanks to them I was able to complete the first stable release of the extension.
While working on this project I interacted with many hackers, solved their doubts, got some of the mine cleared, thanks to Community Classroom for making this happen
Interested to know more about me, here’s my portfolio 🚀
That’s All Folks
You can follow me on:
Twitter: Suyash Sonawane (@SuyashYSonawane) / Twitter
LinkedIn: Suyash Sonawane | LinkedIn
Github: SuyashSonawane (Suyash Sonawane)
Top comments (0)