devfile / devworkspace-operator

Apache License 2.0
67 stars 55 forks source link

extension management in declarative way #1262

Closed yaroslavkasatikov closed 5 months ago

yaroslavkasatikov commented 6 months ago

Hi team, Could you please tell me or share the link with the way how to add extension declarative in devoperator managed dev workspace?

Thanks a lot!

AObuchow commented 6 months ago

Sorry, can you provide some more detail on what you're looking for? What kind of extensions are you referring to? What are you trying to accomplish? Thanks.

yaroslavkasatikov commented 6 months ago

Hey @AObuchow, Thank you for the reply.

For example I want to add .vscode/extension like:

  attributes:
    .vscode/extensions.json: |
      {
        "recommendations": [
          "redhat.java"
        ]
      }

I want to do it declarative in DevWorkspace resource, but can't find the way :(

AObuchow commented 5 months ago

@yaroslavkasatikov This is not currently possible from my knowledge, though maybe some hacky workaround exists that I haven't thought of yet.

From my understanding, the supported way to add a .vscode/extension is to include it in your devfile's repository, like this for example. Could you let me know if that solution fit your needs?

yaroslavkasatikov commented 5 months ago

Okay, got it! Do you know if the devworkspace-operator has the ability to mount configMap inside the container? This way the extensions may be mounted into project dir..

AObuchow commented 5 months ago

@yaroslavkasatikov yes, you can configure configmaps with data that is automatically mounted to all your devworkspaces, see here.

You'll likely need to use controller.devfile.io/mount-as: subpath since the/projects/ directory already exists. Here's an example of how this configmap would look like. Note that you'll have to set the appropriate namespace and project directory name:

kind: ConfigMap
apiVersion: v1
metadata:
  name: code-extensions
  namespace: <your-devspaces-user-namespace>
  labels:
    controller.devfile.io/mount-to-devworkspace: 'true'
    controller.devfile.io/watch-configmap: 'true'
  annotations:
    controller.devfile.io/mount-as: subpath
    controller.devfile.io/mount-path: /projects/<your-project-name>/.vscode/
data:
  extensions.json: |
      {
        "recommendations": [
          "redhat.java"
        ]
      }

The disadvantage of this approach is that the same configmap will be mounted in all of your devworkspaces, and each devworkspace will probably have a different name for your project (thus, the mount-path will only be valid for a single devworkspace).

I guess theoretically, you could mount your extensions.json somewhere other than your project location, and then have a preStart command that does a mkdir $PROJECT_SOURCE/.vscode/ and cp <path-to-extensions.json> $PROJECT_SOURCE/.vscode/extensions.json.

It'd be nice if we could set controller.devfile.io/mount-path: /projects/$PROJECT_SOURCE/.vscode/ but unfortunately the $PROJECT_SOURCE environment variable (which points to your active devfile project) won't be expanded properly. This could be a useful feature to request?

AObuchow commented 5 months ago

@yaroslavkasatikov is there a reason why you don't want to just define the .vscode/extensions.json in your project's git repository?

yaroslavkasatikov commented 5 months ago

Hi Andrew, thank you very much for the reply! Yes, the idea was having installed extensions independently from git repo. Btw, do you have anywhere the list of all annotation which can be used with controller?

AObuchow commented 5 months ago

Hi Andrew, thank you very much for the reply! Yes, the idea was having installed extensions independently from git repo.

Sounds good.

Btw, do you have anywhere the list of all annotation which can be used with controller?

There isn't an exhaustive, officially documented list, unfortunately. Your best bet for finding supported annotations is to visit the additional documentation. You can find more of the annotations used by the controller in this source file, but some annotations are for internal use by the controller and not "officially" supported.

yaroslavkasatikov commented 5 months ago

Andrew, thank you very much for your assist.