skip to Main Content

I’m sure many have come across this problem because I can’t be the only one.

In Visual Studio code I work with Kubernetes and Azure Devops YAML. Both have complete different formatting. To work with each I find I have to uninstall the others extension.

Has anyone worked out, how to have both together where VSCode can work out when your coding an Azure DevOps pipeline or a Kubernetes cluster?

2

Answers


  1. Chosen as BEST ANSWER

    I did do what @flyx recommended but late yesterday evening and did not post my answer but I am going to do that now.

    I worked out the following things.

    1. VSCode can't seem to resolve the schema that are in http://www.schemastore.org/json/composer if you try to reference them by JSON glob words
    2. You can get different schemas to work across different technologies. For Example Kubernetes, Azure DevOps and Ansible are what I have set up now.
    3. You have to be okay with having an end syntax on your YAML files for this to work. For example, my Ansible YAML files all now end with _a.yml, my Kubernetes YAML files all end with _kube.yaml, and my Azure DevOps YAML files all end with the default syntax .yml

    Having figured out those three things I was able to set up my env, to allow the inteli sense and JSON syntax checker to pull the different needed schemas. I have also found the Google Cloud Code extension for Kubernetes is actually better than the Microsoft one and it picks up a lot quicker that your building a Kubernetes YAML file.

    Also for this to work you need to save the file first, with the right extension for VSCode to know you are working on a certain technology and pull down the right Schema. Also, watch out for the .vscode file this sometimes gets a bit silly and does not put the right schema in, so just keep an eye on it. If it fails delete it close VSCode and reopen and you should be good to go.

    Here are my JSON settings for anyone that wants to do this:

    {
        "redhat.telemetry.enabled": true,
        "yaml.schemas": {
            "https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json": "*.yml",
           // "http://www.schemastore.org/json/composer": ["/*"],
          // "https://raw.githubusercontent.com/apache/camel/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json" : "/_kube*.yaml", 
           "kubernetes": ["/*.yaml"],
           "https://json.schemastore.org/ansible-playbook" : "/_a*.yaml",
           "https://json.schemastore.org/ansible-role-2.9" : ["^/roles/*/tasks/_a*.yaml", "^/tasks/_a*.yaml"]
        },
        "vs-kubernetes": {
            "vscode-kubernetes.helm-path.windows": "C:\Users\Jason\.vs-kubernetes\tools\helm\windows-amd64\helm.exe",
            "vscode-kubernetes.minikube-path.windows": "C:\Users\Jason\.vs-kubernetes\tools\minikube\windows-amd64\minikube.exe"
        },
        "files.associations": {
                "**/ci/*.yml": "azure-pipelines"
            },
        "[azure-pipelines]": {
                "editor.defaultFormatter": "esbenp.prettier-vscode"
            },
            "yaml.schemaStore.url": "http://www.schemastore.org/api/json/catalog.json",
            "cloudcode.yaml.crdSchemaLocations": [
            
            ],
            "cloudcode.yaml.schemas": {
            
            },
            "cloudcode.yaml.yamlFileMatcher": "/_kube*.yaml",
    }

    Extensions used for this:

    1. redhat yaml
    2. googles cloud code
    3. Azure Pipelines
    4. Kubernetes Microsoft Default (Some reason this is needed to make the redhat yml extension behave)
    5. The Ansible Yaml Schema (This is not an extension these just come down from the json schema store but make sure you have the right url otherwise VSCode does not resolve it. See Point 1. )

  2. The extension for Azure Pipelines describes how you can set it up to be used on specific files by setting "files.associations".

    You can do a similar thing with the extension that supports Kubernetes.

    Alternatively, you can exclusively us the latter as it supports custom schemas.
    You can find a schema for Azure Pipelines here; register it as schema and set up a glob pattern that matches your Azure files.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search