Skip to content
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

list-setters - support returning just the value of a setter #542

Open
jlewi opened this issue Apr 23, 2020 · 5 comments
Open

list-setters - support returning just the value of a setter #542

jlewi opened this issue Apr 23, 2020 · 5 comments
Assignees
Labels
area/fn-catalog Functions Catalog triaged Issue has been triaged by adding an `area/` label

Comments

@jlewi
Copy link

jlewi commented Apr 23, 2020

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.

@phanimarupaka
Copy link
Contributor

Thanks for the issue. Does json formatting of entire table help so that you can extract desired values ?

@phanimarupaka phanimarupaka added this to the 2020-Q2: Polish kpt + kustomize + kubectl experience milestone Apr 24, 2020
@jlewi
Copy link
Author

jlewi commented Apr 25, 2020

@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.

@frankfarzan frankfarzan added the triaged Issue has been triaged by adding an `area/` label label May 27, 2020
@phanimarupaka phanimarupaka added this to To do in Config as Data - Milestone 3 via automation Jun 2, 2020
@phanimarupaka phanimarupaka modified the milestones: Milestone 2 (Starts 2020-Q2), Milestone 3 (Starts 2020-Q3) Jun 2, 2020
@sankit2020 sankit2020 removed this from the Milestone 3 (Starts 2020-Q3) milestone Jun 24, 2020
@mortent mortent added this to Backlog in Config as Data - Milestone 4 via automation Sep 29, 2020
@mikebz mikebz added this to To do in kpt kanban board via automation Oct 23, 2020
@jlewi
Copy link
Author

jlewi commented Nov 18, 2020

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?

@Bobgy
Copy link

Bobgy commented Jan 30, 2021

Is there any update? This is very useful to simplify installation scripts around kpt packages.

@phanimarupaka
Copy link
Contributor

@Bobgy list-setters is now a function in kpt v1(https://kpt.dev/installation/). Is this issue still relevant ?

@yuwenma yuwenma self-assigned this May 17, 2022
@mortent mortent added area/fn-catalog Functions Catalog and removed area/cfg labels Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fn-catalog Functions Catalog triaged Issue has been triaged by adding an `area/` label
Projects
No open projects
Development

No branches or pull requests

7 participants