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

[Feature] Add vela ql create <view.cue> to create velaql view #4268

Closed
wonderflow opened this issue Jun 27, 2022 · 1 comment · Fixed by #4324
Closed

[Feature] Add vela ql create <view.cue> to create velaql view #4268

wonderflow opened this issue Jun 27, 2022 · 1 comment · Fixed by #4324
Assignees
Labels
Milestone

Comments

@wonderflow
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

We have a great velaql to help query K8s resources from CUE: https://kubevela.io/docs/platform-engineers/system-operation/velaql

We have supported using vela ql command to query in #4196

vela ql --query "<query>"
vela ql --file my-view.cue

But we can't share the view in cue format to others.

Describe the solution you'd like

we need a way to create the view into K8s system, such as:

vela ql create <view.cue>

It will generate view from CUE to YAML, the render logic is aligned with:

0c190ef#diff-dfc3f6e3b7231b7b41cf82b8e561f3cbf8191d214886e21d798f287f693806dbR997

Generally follow the format:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-component-pod-view
  namespace: vela-system
data:
  template: |
    <CUE template>

As a result, the working process would be:

  1. prepare a general purpose cue view as below:
import (
	"vela/ql"
)

parameter: {
	name:      string
	namespace: *"default" | string
	key:       string
}

// You can use configmap.value.data after this action.
configmap: ql.#Read & {
	value: {
		kind:       "Secret"
		apiVersion: "v1"
		metadata: {
			name:      parameter.name
			namespace: parameter.namespace
		}
	}
}
status: configmap.value.data["\(parameter.key)"]

This view can help load value from K8s secret.

  1. Share the view with others:
vela ql create -f secret-view.cue

If no name, we can use the file as name "secret-view", the command line can also specify the name:

vela ql create -f secret-view.cue --name my-secret-view
  1. Other people can use it by:
vela ql --query "my-secret-view{name=my-secret,key=password}"

Describe alternatives you've considered

Additional context

@charlie0129
Copy link
Member

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants