VSCode Datree: Datree's power now in your code editor 💪
Tags: kubernetes, vscode, datree
Published: 2022-01-06 14:48:22

# What’s in this article?

VSCode Datree  —  a VSCode Extension that brings [Datree’s](https://www.datree.io/?utm_source=suyash+sonawane&utm_medium=Medium+com&utm_campaign=VSCode+Datree%3A+Datree%E2%80%99s+power+now+in+your+code+editor&utm_id=Datree) features right inside your code editor 🚀

![Devs after installing VSCode Datree](https://cdn-images-1.medium.com/max/2000/1*Yap8sVqvwQbrH3WXStqD3g.gif)

## 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/](https://hub.datree.io/?utm_source=suyash+sonawane&utm_medium=Medium+com&utm_campaign=VSCode+Datree%3A+Datree%E2%80%99s+power+now+in+your+code+editor&utm_id=Datree)

The extension can be installed directly through the extensions tab available in VSCode or through VSCode’s marketplace.

[**VSCode Datree - Visual Studio Marketplace**](https://marketplace.visualstudio.com/items?itemName=suyashsonawane.vscode-datree)
![Installing VSCode Datree](https://cdn-images-1.medium.com/max/2000/1*UPkkPN6VFb6zi9QHhVzpog.gif)


## 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

![YAML Errors](https://cdn-images-1.medium.com/max/2000/1*CfsOjJ5aKkeaNoUur3v5ng.gif)

## 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

![K8s Schema Error](https://cdn-images-1.medium.com/max/2000/1*hx6RA_kCMfFX8ViDKei7sw.gif)

![Policy Errors](https://cdn-images-1.medium.com/max/2000/1*Aa7m36SIbQMi3uLFlKAMcQ.gif)

## 3. Support for Helm Workflows
>  Helm and Datree’s Helm Plugin is required, get it here 👇
[https://hub.datree.io/helm-plugin](https://hub.datree.io/helm-plugin?utm_source=suyash+sonawane&utm_medium=Medium+com&utm_campaign=VSCode+Datree%3A+Datree%E2%80%99s+power+now+in+your+code+editor&utm_id=Datree)

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]

![Helm Charts](https://cdn-images-1.medium.com/max/2000/1*JeXsvnJ639y1ANfs_S_lcQ.gif)

## 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

![Custom Parameters](https://cdn-images-1.medium.com/max/2000/1*AQZDzPK4aWVfLd3BpCKihA.gif)

## 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.

![Suggesting Solutions](https://cdn-images-1.medium.com/max/2000/1*YjLYl2isSEA7SWAf0uAZcA.gif)

## 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…**](https://github.com/SuyashSonawane/vscode-datree)

## 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](https://cloudnativehack21.devpost.com/).
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](https://github.com/eyarz) 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](https://github.com/shimont) suggested adding Helm support and [Dima Brusilovsky](https://github.com/dimabru) 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 🚀
[**Portfolio | Suyash Sonawane**](https://suyashsonawane.me/)

# That’s All Folks

You can follow me on:
Twitter: [Suyash Sonawane (@SuyashYSonawane) / Twitter](https://twitter.com/SuyashYSonawane)
LinkedIn: [Suyash Sonawane | LinkedIn](https://www.linkedin.com/in/suyash-sonawane-44661417b/)
Github: [SuyashSonawane (Suyash Sonawane)](https://github.com/SuyashSonawane)