-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design Kyma CLI flow for basic kyma use case #2221
Comments
CommandsI collected all current commands and located them in three categories. This may help with designing new commands. Current (grouped) commandsThese commands should be still in the CLI but maybe we should refactor/redesign them # utils/scripts
kyma alpha access # <- produce kubeconfig for given cluster
# module management
kyma alpha modules # <- list available modules based on PB JSON
kyma alpha add # <- add deploy community-module based on PB JSON
kyma alpha add managed # <- add kyma-module to the Kyma CR
kyma alpha remove # <- remove deployed community-module based on PB JSON
kyma alpha remove managed # <- remove kyma-module from the Kyma CR
# module resources
kyma alpha image-import # <- import image from local docker daemon to the cluster using port-forward (kyma docker-registry image-import / import)
kyma alpha reference-instance # <- add instance ref to shared svc instance (btp) (kyma btp-operator reference-instance) Comands to removeAs in the title # utils??
kyma alpha provision # <- provision kyma on btp Commands to redefineWe don't decided what to do with these commands # utils/scripts
kyma alpha oidc # <- create kubeconfig with oidc token
# these commands are related with btp-operator but for example map looks like util/script
kyma alpha hana
kyma alpha hana check
kyma alpha hana credentials
kyma alpha hana delete
kyma alpha hana map
kyma alpha hana provision |
CommandsDetailsTogether with Andrzej Pankowski (@Cortey), we've decided to design a new commands pallet based on three requirements, domain the cli will be focused on:
Module managementInstalling, uninstalling, describing, checking status, updating. The goal was to prototype API based on high-level words that do not remind Kubectl operations. Input parameters for create/update operations and output values for get/list commands may be defined in the ConfigMap maintained by the module owners (like it's right now with busola extensions). kyma list <--installed/--available/--managed>
kyma describe <MODULE_NAME> <--crds/--description/...>
kyma deploy <MODULE_NAME> <--overwrite> <FLAGS_FROM_CONFIGMAP> #<--namespace>
kyma undeploy <MODULE_NAME> #<--namespace>
kyma enable <MODULE_NAME> <--unmanaged> <--overwrite> <FLAGS_FROM_CONFIGMAP> #<--namespace>
kyma disable <MODULE_NAME> #<--namespace>
kyma configure <MODULE_NAME> <FLAGS_FROM_CONFIGMAP> #<--namespace>
kyma inspect <MODULE_NAME> <FLAGS_FROM_CONFIGMAP> <--output=text/json/yaml> #<--namespace>
Module resourcesThe goal is to create a generic API as close as possible to the Kubectl API (possibly the same words responsible for actions). Like in the kyma create <RESOURCE_TYPE> <RESOURCE_NAME> <--overwrite/--namespace> <FLAGS_FROM_CONFIGMAP>
kyma patch <RESOURCE_TYPE> <RESOURCE_NAME> <--overwrite/--namespace> <FLAGS_FROM_CONFIGMAP>
kyma delete <RESOURCE_TYPE> <RESOURCE_NAME> <--namespace>
kyma explain <RESOURCE_TYPE>
kyma status <RESOURCE_TYPE> <RESOURCE_NAME/--all> <--namespace> <--output=text/json/yaml>
kyma get <RESOURCE_TYPE/--all> <--all> <--namespace> <--output=text/json/yaml> Scripts/UtilsThese commands should be fully maintained by our team. The goal is to keep more advanced actions in one place to, for example, import a docker image to the in-cluster docker registry or create a BTP object store instance on the cluster. These operations do require more chained actions than creating/updating a single object. Question: Maybe we should get rid of the kyma run
kyma run image-import
kyma run registry-config
kyma run reference-instance
kyma run hana-map
kyma run expose
kyma run access ConfigmapEvery team responsible for the module (and its resources) should prepare configmap with command details. This configmap requires specific labels to be fetched by the cli. For modules: labels:
kyma-cli/extension: module
kyma-cli/extension-version: 0.1 and for resources: labels:
kyma-cli/extension: resource
kyma-cli/extension-version: 0.1 output configmap should looks like this: apiVersion: v1
kind: ConfigMap
metadata:
labels:
kyma-cli/extension: resource/module
kyma-cli/extension-version: 0.1
name: function.serverless.kyma-cli
namespace: kyma-system
data:
... Configmap dataIn the following example, every team can define custom arguments and list of outputs for every module/resource: info: |
description: ...
repoUrl: ...
...: ...
meta: |
# singular: function
# plural: functions
# scope: namespaced
kind: Function
group: serverless.kyma-project.io
version: v1alpha2
input: |
runtime:
shorthand: "r"
path: ".spec.runtime"
type: string
description: "function runtime"
default: "nodejs20"
required: true
replicas:
path: ".spec.replicas"
type: int
description: "function replicas"
default: 1
required: false
source:
shorthand: "s"
path: ".spec.source.inline.source"
type: path
description: "function source code"
required: true
dependencies:
shorthand: "d"
path: ".spec.source.inline.dependencies"
type: path
description: "function dependencies"
required: false
output: |
# maybe we can support languages like JSONata? :)
runtime:
path: ".status.runtime"
type: string
runtime-image:
displayName: "Runtime Image"
path: ".status.runtimeImage"
type: string
configured:
path: ".status.conditions[0].status"
type: string
built:
path: ".status.conditions[1].status"
type: string
running:
path: ".status.conditions[2].status"
type: string In this example, a Function may have four flags used by the > kyma create function my-function --runtime=nodejs20 --replicas=12 --source=/tmp/handler.js
Function my-function created.
> kyma patch function my-function --source=/tmp/handler-2.js
Function my-function patched.
> kyma patch function my-function --replicas=1
Function my-function patched. The output section may define values that will be printed after running > kyma get function my-function --output json
{
"runtime": "nodejs20",
"runtimeImage": "some-image:0.1",
"configured": "True",
"built": "True",
"running": "True"
} or > kyma get function my-function --runtime
nodejs20 Example
|
ConclusionsSteps for the
|
V2Version No. 2 proposes the same functionality but with different commands API. The idea is to use same commands for module and resource management. CommandsIn this variant, modules and resources are managed by the same action words but depending on the context they offere different flags and functionality Moduleskyma create/add <MODULE_NAME> <--no-wait> <--unmanage> <--default-cr> <--overwrite> <FLAGS_FROM_CONFIGMAP>
kyma patch <MODULE_NAME> <--no-wait> <--unmanage> <--default-cr> <--overwrite> <FLAGS_FROM_CONFIGMAP>
kyma delete/remove <MODULE_NAME> <--remove-resources>
kyma explain <MODULE_NAME> <--crds/--description/...>
kyma status <MODULE_NAME> <--all> <--output=text/json/yaml>
kyma get modules <--installed/--available/--managed> <--output=text/json/yaml> Commands:
Flags:
Resourceskyma create/add <RESOURCE_TYPE> <RESOURCE_NAME> <--namespace> <--overwrite> <FLAGS_FROM_CONFIGMAP>
kyma patch <RESOURCE_TYPE> <RESOURCE_NAME> <--namespace> <--overwrite> <FLAGS_FROM_CONFIGMAP>
kyma delete/remove <RESOURCE_TYPE> <RESOURCE_NAME> <--namespace>
kyma explain <RESOURCE_TYPE>
kyma status <RESOURCE_TYPE> <RESOURCE_NAME/--all> <--namespace> <--output=text/json/yaml>
kyma get <RESOURCE_TYPE/--all> <--all> <--namespace> <--output=text/json/yaml> Scriptkyma get modules
kyma explain api-gateway
kyma add api-gateway
kyma status api-gateway
kyma explain btp-operator
kyma add btp-operator
kyma status btp-operator
kyma explain docker-registry
kyma add docker-registry
kyma explain cloud-manager
kyma add cloud-manager
kyma status cloud-manager
kyma add gcpnfsvolume \
my-vol --namespace default --location us-west1-a --capacity-gb 1024
export PVC_NAME=$(kyma status gcpnfsvolume \
my-vol --namespace default \
--output json | jq ".pvcName")
kyma patch docker-registry \
--external-access=true --storage-type=pvc --storage-pvc-name=$PVC_NAME
kyma run reference-instance \
--name my-instance --namespace default ...
kyma add servicebinding \
my-binding --namespace default --instance-name my-instance ...
kyma status servicebinding \
my-binding --namespace default
# create apps Dockerfile
kyma run registry-config --output config.json
export REGISTRY_URL=$(kyma run registry-config --external-url)
# or: export REGISTRY_URL=$(kyma status docker-registry --output json | jq '.externalUrl')
docker build "$REGISTRY_URL/my-app:0.1" .
docker --config=. push "$REGISTRY_URL/my-app:0.1"
export REGISTRY_SECRET_NAME=$(kyma inspect docker-registry --external-access-secret)
kubectl run my-pod --image="$REGISTRY_URL/my-app:0.1" --overrides="{ \"spec\": { \"imagePullSecrets\": [ { \"name\": \"${REGISTRY_SECRET_NAME}\" } ] } }"
kubectl expose pod my-pod --port=80 --target=8080 --name=my-svc
kyma add apirule \
my-apirule --namespace default \
--svc-name my-svc --svc-namespace default \
--svc-port 8000 --path "/.*" --methods "GET,POST"
# or: kyma run expose my-svc --namespace --path="/.*" --methods="GET,POST"... |
I tend to like the most the explicit
And other actions also should have subject in front. Example:
This way we can introduce more verbs that describe actions (not only CRUD). Using a limited number of verbs makes kyma CLI similar to kubectl (and somehow not needed as we can do everything with kubectl). Kyma CLI should help in the cases where you need multiple kubectl commands or complex configuration files. |
V3This comment describes the new idea of extendable cli API. The main idea is to keep [ACTION] from the first proposition but make them less generic and close in specific a noun representing resource/module. The second idea is to improve API extensions described in the configmap. Module managementWe should offer a generic API allowing to manage core/community modules without the possibility of extending its functionality. List of commands: kyma module list <--installed/--available/--managed>
kyma module describe <MODULE_NAME> <--crds/--description/...>
kyma module deploy <MODULE_NAME> #<--namespace>
kyma module undeploy <MODULE_NAME> #<--namespace>
kyma module enable <MODULE_NAME> <--unmanaged> #<--namespace>
kyma module disable <MODULE_NAME> #<--namespace>
kyma module configure <MODULE_NAME> <FLAGS_FROM_CONFIGMAP> #<--namespace>
kyma module inspect <MODULE_NAME> <FLAGS_FROM_CONFIGMAP> <--output=text/json/yaml> #<--namespace> ConfigmapFlags for configuration/inspection should be the only way to extensible module command responsible for specific modules: apiVersion: v1
kind: ConfigMap
metadata:
labels:
kyma-cli/extension: module
kyma-cli/extension-version: 0.1
name: serverless.kyma-cli
namespace: kyma-system
data:
additionalConfiguration: |
configure:
flags:
- name: resourcePreset
shorthand: "r"
path: ".spec.resourcePreset"
type: string
description: "resource preset used by default to all functions"
default: "L"
- name: enableInternal
shorthand: "i"
path: ".spec.dockerRegistry.enableInternal"
type: bool
description: "enable in-cluster docker-regsitry"
default: true
inspect:
parameters:
- name: state
path: ".status.state"
type: string
- name: internalRegistry
path: ".status.intenralRegistry.enabled"
type: bool
- name: resourcePreset
path: ".status.resourcePreset"
type: string This will cause cli users to configure configure and inspect commands like this: > kyma module configure serverless --resourcePreset XL --enableInternal false
Module Serverless configured.
> kyma module inspect serverless
state: Ready
internalRegistry: false
resourcePreset: XL
> kyma module inspect serverless --state
state: Ready
> kyma module inspect serverless --json
{
"state": "Ready",
"internalRegistry": false,
"resourcePreset": "XL"
} Module specific actionsThe idea is to get rid of resource-specific commands (kubectl-like) to not support generic CRUD operations. We can offer teams supporting generic operations (like create, delete, edit, view) but the team responsible for a module should specify which commands and with which flags should be added to the CLI dynamically. It should look like this:
For example, after adding module example flow: > kyma --help
<DESCRIPTION>
Commands:
module - module management
completion - generate autocompletion script
alpha - group of non-production ready and alpha commands
help - helm about commands
> kyma module enable serverless --wait --default-cr
Module serverless enabled.
Waiting for module to be ready.
Applying default CR.
> kyma --help
<DESCRIPTION>
Commands:
module - manage modules
function - manage functions <-- new command group
completion - generate autocompletion script
alpha - group of non-production ready and alpha commands
help - helm about commands
> kyma function --help
<DESCRIPTION>
Commands:
create - create function
list - list functions
delete - delete functions
expose - expose function with ApiRule
subscribe - subscribe function to events ConfigurationIt's not a good idea to support all generic use cases (CRUD operations) for all resources by default. Additionally, some resources/groups may have their own custom scripts. It's not possible to support writing scripts in configmaps without huge consequences, so we can perform three types of resource/group commands extensibility:
ConfigMapThis is the proposition of the new version of the CM: apiVersion: v1
kind: ConfigMap
metadata:
labels:
kyma-cli/extension: resource
kyma-cli/extension-version: 0.1
name: function.serverless.kyma-cli
namespace: kyma-system
data:
metadata: |
name: function # name of new commands group
description: manage functions # description of new commands group
resource: |
singular: function
plural: functions
scope: namespaced
kind: Function
group: serverless.kyma-project.io
version: v1alpha2
templateCommands: |
create:
description: create function
customFlags:
- name: runtime
shorthand: "r"
path: ".spec.runtime"
type: string
description: "function runtime"
default: "nodejs20"
required: true
- name: replicas
path: ".spec.replicas"
type: int
description: "function replicas"
default: 1
required: false
- name: source
shorthand: "s"
path: ".spec.source.inline.source"
type: path
description: "function source code"
- name: dependencies
shorthand: "d"
path: ".spec.source.inline.dependencies"
type: path
description: "function dependencies"
required: false
patch:
description: patch function
customFlags:
- name: runtime
shorthand: "r"
path: ".spec.runtime"
type: string
description: "function runtime"
default: "nodejs20"
- name: replicas
path: ".spec.replicas"
type: int
description: "function replicas"
default: 1
required: false
- name: source
shorthand: "s"
path: ".spec.source.inline.source"
type: path
description: "path to file with functions code"
- name: dependencies
shorthand: "d"
path: ".spec.source.inline.dependencies"
type: path
description: "path to file with functions dependencies"
required: false
delete:
description: delete function
explain:
description: explain function resource
info: |-
this resource allows you to deploy code as a service without taking care of architecture and Kubernetes resources
...
get:
description: get function/s
parameters:
- name: runtime
path: ".status.runtime"
type: string
- name: runtime-image
displayName: "Runtime Image"
path: ".status.runtimeImage"
type: string
- name: configured
path: ".status.conditions[0].status"
type: string
- name: built
path: ".status.conditions[1].status"
type: string
- name: running
path: ".status.conditions[2].status"
type: string
coreCommands: |
- name: expose
coreFuncID: expose-function # enables functionality defined for this resource in the cli under name defined in the `name` field
description: expose function using ApiRule
- name: migrate # example only
coreFuncID: migrate-function
description: migrate something to something...
- ...
customCommands: |
- name: demo
description: deploy demo Function subscribed for Events and exposed by ApiRule
target:
svcName: serverless-controller
port: 8080
endpoint: "/cli/demo"
token:
fromSecret:
name: serverless-controller-cli
item: token # `.data` field name
parameters:
- name: functionName
flag:
name: name
shorthand: "n"
type: string
description: "function name"
required: true
- name: functionRuntime
flag:
name: runtime
shorthand: "r"
type: string
description: "function runtime"
default: "nodejs20"
- name: gateway
flag:
name: gateway
shorthand: "g"
type: string
description: "istio gateway"
default: "kyma-system/kyma-gateway"
- name: eventType
flag:
name: event-type
shorthand: "e"
type: string
description: "event type"
default: "demo-function-type"
This configuration should cause the following commands structure: > kyma --help
<DESCRIPTION>
Commands:
module - manage modules
function - manage functions <-- new command group
completion - generate autocompletion script
alpha - group of non-production ready and alpha commands
help - help about commands > kyma function --help
Description:
manage functions # description of new commands group
Commands:
create - create function
patch - patch function
get - get function/s
delete - delete function
explain - explain function resource
expose - expose function using ApiRule
demo - deploy demo Function subscribed for Events and exposed by ApiRule > kyma function create --help
Description:
create function
Flags:
--namespace - resource namespace (default: default)
--runtime, -r - function runtime (default: Nodejs20)
--replicas - function replicas (default: 1)
--source - path to file with functions code (required)
--dependencies - path to file with functions dependencies
--overrides - an inline JSON override for the generated object |
V3 scriptkyma module list
kyma module describe api-gateway
kyma module enable api-gateway
kyma module inspect api-gateway
kyma module describe btp-operator
kyma module enable btp-operator
kyma module inspect btp-operator
kyma module describe docker-registry
kyma module enable docker-registry
kyma module describe cloud-manager
kyma module enable cloud-manager
kyma module inspect cloud-manager
kyma gcpnfsvolume create \
my-vol --namespace default --location us-west1-a --capacity-gb 1024
export PVC_NAME=$(kyma gcpnfsvolume status \
my-vol --namespace default \
--output json | jq ".pvcName")
kyma module configure docker-registry \
--external-access=true --storage-type=pvc --storage-pvc-name=$PVC_NAME
kyma btp reference-instance \
--name my-instance --namespace default ...
kyma servicebinding create \
my-binding --namespace default --instance-name my-instance ...
kyma servicebinding status \
my-binding --namespace default
# create apps Dockerfile
kyma registry config --output config.json
export REGISTRY_URL=$(kyma registry config --external-url)
# or: export REGISTRY_URL=$(kyma module inspect docker-registry --output json | jq '.externalUrl')
docker build "$REGISTRY_URL/my-app:0.1" .
docker --config=. push "$REGISTRY_URL/my-app:0.1"
export REGISTRY_SECRET_NAME=$(kyma module inspect docker-registry --external-access-secret)
kubectl run my-pod --image="$REGISTRY_URL/my-app:0.1" --overrides="{ \"spec\": { \"imagePullSecrets\": [ { \"name\": \"${REGISTRY_SECRET_NAME}\" } ] } }"
kubectl expose pod my-pod --port=80 --target=8080 --name=my-svc
kyma apirule create \
--name my-apirule --namespace default \
--svc-name my-svc --svc-namespace default \
--svc-port 8000 --path "/.*" --methods "GET,POST"
# or: kyma workload/deployment/pod/api-gateway expose my-svc --namespace --path="/.*" --methods="GET,POST"... |
Description
Propose how to combine kyma CLI into the following scenario (not every step must necessarily mean a new kyma cli command).
I have empty cluster (SKR)
Reason
The goal of this excercise is to design what could be the kyma CLI commands based on a real life scenario
Kyma cli should allow to interact with resources that kyma brings on top of kubernetes.
The text was updated successfully, but these errors were encountered: