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

kusion init provides a new way to collect template params value with specified CLI flag #72

Closed
howieyuen opened this issue Jun 13, 2022 · 3 comments · Fixed by #74
Closed
Assignees
Labels
proposal Categorizes an issue or PR as relevant to enhancement proposal
Milestone

Comments

@howieyuen
Copy link
Collaborator

howieyuen commented Jun 13, 2022

Enhancement

Summary

kusion init is a helpful tool to create a new project of KCL. Consider that we have two different roles, one is template developer, who is responsible for design and develop template, as well as a set of default values; another is to use template. For quick start of template rendering, developer provides a YAML file, named kusion.yaml, which contains type and default value of all params that is used by go template engine.

However, if I want to override template default value, there is only one solution: type new default when each Prompt asks, which is strongly Inefficient.

Proposal

Add a new flag(CustomParams) to override template defaults. Kusion must to provide a struct with filed name and type. User can prepare a new set of defaults in advance, based on file kusion.yaml.

Design Details

Field Types

Although we encourage all to use primitive type for template params:

  • string
  • int
  • float
  • bool

But we must admit there is always an exception, aka complicated data type, For example:

  • array
  • map
  • struct
  • any

and mixed complicated with primitives. So we need to explain every field type in kusion.yaml.

Flag Definition in Struct

kusion.yaml provide a struct as below:

kusion.yaml
projectName: my-app
description: A minimal kusion project of single stack
quickstart: kusion compile main.k -Y ci-test/settings.yaml
common:
  # base/base.k
  - name: ServiceName
    description: service name
    type: string
    default: frontend-svc
  - name: NodePort
    description: node port
    type: int
    default: 30000
  # project.yaml
  - name: ProjectName
    description: project name
    type: string
    default: my-app
stacks:
  - name: dev
    fields:
      # stack/ci-test/settings.yaml
      - name: Stack
        description: stack env. One of dev,test,stable,pre,sim,gray,prod.
        type: string
        default: dev
      # stack/main.k
      - name: Image
        description: The Image Address. Default to 'gcr.io/google-samples/gb-frontend:v4'
        type: string
        default: gcr.io/google-samples/gb-frontend:v4
      # stack/stack.yaml
      - name: ClusterName
        description: The Cluster Name. Default to 'kubernetes-dev'
        type: string
        default: kubernetes-dev

Implicit struct of CustomParams flag:

struct definition
{
	"projectConfig": {
		"ServiceName": "frontend-svc",
		"NodePort": 30000,
		"ProjectName": "my-app"
	},
	"stacksConfig": {
		"dev": {
			"Stack": "dev",
			"Image": "gcr.io/google-samples/gb-frontend:v4",
			"ClusterName": "kubernetes-dev"
		}
	}
}
@howieyuen howieyuen added cli proposal Categorizes an issue or PR as relevant to enhancement proposal labels Jun 13, 2022
@howieyuen howieyuen added this to the v0.5.0 milestone Jun 13, 2022
@howieyuen howieyuen self-assigned this Jun 13, 2022
@howieyuen howieyuen changed the title kusion init support a new way to collect template params with specified CLI flag kusion init support a new way to collect value of template params with specified CLI flag Jun 13, 2022
@howieyuen howieyuen changed the title kusion init support a new way to collect value of template params with specified CLI flag kusion init provides a new way to collect value of template params with specified CLI flag Jun 13, 2022
@howieyuen howieyuen changed the title kusion init provides a new way to collect value of template params with specified CLI flag kusion init provides a new way to collect template params value with specified CLI flag Jun 13, 2022
@elliotxx
Copy link
Contributor

Can you provide more example of custom parameter for CLI and 3rd-party system integration?

@howieyuen
Copy link
Collaborator Author

Can you provide more example of custom parameter for CLI and 3rd-party system integration?

CLI Example
image

Integration
please refer kusion doc here:
https://pkg.go.dev/kusionstack.io/kusion@v0.4.1/pkg/scaffold#CopyTemplateFiles
and here:
https://pkg.go.dev/kusionstack.io/kusion@v0.4.1/pkg/scaffold#LoadTemplate

Step1: call func LoadTemplate to parse kusion.yaml, and get default value of configs

alternative: use custom params

Step2: use default values as input params for func CopyTemplateFiles

@howieyuen
Copy link
Collaborator Author

Can you provide more example of custom parameter for CLI and 3rd-party system integration?

CLI Example image

Integration please refer kusion doc here: https://pkg.go.dev/kusionstack.io/kusion@v0.4.1/pkg/scaffold#CopyTemplateFiles and here: https://pkg.go.dev/kusionstack.io/kusion@v0.4.1/pkg/scaffold#LoadTemplate

Step1: call func LoadTemplate to parse kusion.yaml, and get default value of configs

alternative: use custom params

Step2: use default values as input params for func CopyTemplateFiles

CopyTemplateFiles use local file system as default, which needs to optimize params to be feasible to integrate with http service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Categorizes an issue or PR as relevant to enhancement proposal
Projects
None yet
2 participants