redhat-developer / odo

odo - Developer-focused CLI for fast & iterative container-based application development on Podman and Kubernetes. Implementation of the open Devfile standard.
https://odo.dev
Apache License 2.0
797 stars 243 forks source link

use swagger.json to get available parameters for `odo service create` #4850

Closed kadel closed 3 years ago

kadel commented 3 years ago

Acceptance criteria:

girishramnani commented 3 years ago

link to the proposal https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md

dharmit commented 3 years ago

/triage needs-information

As a part of research, please also break this "Epic" down into "User Stories".

dharmit commented 3 years ago

We need to consider how this will help odo catalog describe service <operator>/<cr>. For example, currently, odo can't print anything helpful for Redis Operator:

$ odo catalog list services
Services available through Operators
NAME                                CRDs
etcdoperator.v0.9.4-clusterwide     EtcdCluster, EtcdBackup, EtcdRestore
redis-operator.v0.6.0               RedisCluster, Redis

$ odo catalog describe service redis-operator.v0.6.0/RedisCluster 
Kind: RedisCluster
Version: v1beta1
Description: Redis Cluster
Parameters:

 PATH  DISPLAYNAME  DESCRIPTION 

$ odo catalog describe service redis-operator.v0.6.0/Redis       
Kind: Redis
Version: v1beta1
Description: Redis
Parameters:

 PATH  DISPLAYNAME  DESCRIPTION 
dharmit commented 3 years ago

Currently, there are three places where we know we can get the parameters' info from:

Based on the discussion between @kadel and Adapters team, ODC is mainly using swagger.json and relies on X descriptors only for additional data it provides on top of what's available via swagger.json.

In odo, so far, we have relied on X descriptors as primary source of info, and only now we're trying to use what swagger.json has to offer. odo should try and change its approach to how ODC is doing it, because swagger seems to have much more information than X Descriptors.

mik-dass commented 3 years ago

Three cases (arranged by ascending priority):

Case 1: User has access to the CRD's api path, cluster provides an api to get metadata for any CRD needed. URL - <cluster-url>/api/kubernetes/apis/apiextensions.k8s.io/v1/customresourcedefinitions

Case 2: Get the swagger.json from the openapi endpoint provided by kubernetes, <cluster-url>/api/kubernetes/openapi/v2. We fetch the file during odo catalog list services. Steps: https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md#kuberenetes-cluster-swagger-has-the-schema

Case 3: Admin-only approach of using CRD api from the cluster: https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md#fetch-clusterserviceversion-to-generate-the-information

Parsing the data

Case 1:

Case 2: Fetch the same openAPIV3Schema from the cluster's swagger.json from the endpoint /api/kubernetes/openapi/v2 and parse it as mentioned in https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md#user-has-access-to-openapiv3schema

Case 3: Use the spec.customresourcedefinitions present in the ClusterServiceVersion. This CRD def is different from what is provided by the CustomResourceDefinition as it has less information. Example output: https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md#fetch-clusterserviceversion-to-generate-the-information

Commands

odo catalog describe service

Human readable output:

- FieldPath: zookeeper.resources.limit.min
  DisplayName: Limit Min
  Description: <description>
  Type: string
- FieldPath: zookeeper.storage.type
  Type: string
- FieldPath: zookeeper.env[*].key
  Type: string

odo service create

Parse the user inputs provided via -p and validate it as mentioned in https://github.com/openshift/odo/blob/main/docs/proposals/improved-schema-for-services.md#allowing-user-to-set-the-parameters

dharmit commented 3 years ago

Scope:

dharmit commented 3 years ago

Scope