list-setters - support returning just the value of a setter
It would be great if list-setters had a format option to just get the value of a setter without formatting so it was easy to assign it to a variable in a shell script. e.g.
CLUSTERNAME=$(kpt cfg list-setters . cluster-name)
Right now this doesn't work because the output of list-setters is a table e.g.
kpt cfg list-setters . cluster-name
NAME DESCRIPTION VALUE TYPE COUNT SETBY
cluster-name '' kf-2020-0423-001 string 91 kpt
Getting the values out of kpt would be useful for writing "sugar" that depends on values set by the user.
As an example, here's some Makefile magic to create a rule to create a kubecontext
create-cnrm-ctxt:
# TODO(jlewi): How to use variables to store values from settings.yaml to make it cleaner?
# Create a kubeconfig context;
# TODO(jlewi): Make this a script to make it a bit cleaner
gcloud --project=$(shell yq r ./management/settings.yaml project) container clusters get-credentials \
--region=$(shell yq r ./management/settings.yaml location) $(shell yq r ./management/settings.yaml name)
# Rename the context
kubectl config rename-context $(shell kubectl config current-context) $(shell yq r ./management/settings.yaml name)-$(shell yq r $(APP_DIR)/settings.yaml project)
# Set the name of the context
kpt cfg set ./kubeflow mgmt-ctxt $(shell yq r management/settings.yaml name)-$(shell yq r $(APP_DIR)/settings.yaml project)
# Set the namespace to the host project
kubectl config set-context --current --namespace=$(shell yq r $(APP_DIR)/settings.yaml project)
The gcloud parameters are available from kpt setters used to control the CNRM cluster resource.
The work around I used was to create a settings.yaml file which sets the values from the same setters and then extract those values using yq. This is a hack it be much better if I could just get those values using kpt list-setters.
Thanks for the issue. Does json formatting of entire table help so that you can extract desired values ?
@phanimarupaka Returning a json table doesn't make it easy to write scripts without additional tooling.
In my particular case I'm trying to use Make to create some syntactic sugar for deploying Kubeflow blueprints.
Here's the Makefile
If its json or yaml you need addition tools like yq to get values out. Requiring additional tools is what I'm trying to avoid. I'd like to just be able to use kpt to get the values.
It would also be nice to support substitutions.
In the event, I find some time to create a PR for this it would be great to know what the desired syntax would be. I might suggest
kpt cfg get . <setter | substitution>
Is there existing functions/libraries that can be used to compute actual value of a substitution?
Is there any update? This is very useful to simplify installation scripts around kpt packages.
@Bobgy list-setters is now a function in kpt v1(https://kpt.dev/installation/). Is this issue still relevant ?