Comments (7)
The kcl code should be
envs = option("envs",type="dict", help="环境变量")
from kcl-go.
In KCL the option key need to be offered a positional argument instead of keyword argument. For the latter, we will support it in the next version.
from kcl-go.
In KCL the option key need to be offered a positional argument instead of keyword argument. For the latter, we will support it in the next version.
Many parameters did not use the key syntax, but this one did, which seems a bit unfortunate.
Thank you for your support.
from kcl-go.
You can use a json format like
var envs = `
{
"aa":"bb"
}
`
Note that a valid JSON string does not have a comma at the end of the line.
from kcl-go.
You can use a json format like
var envs = ` { "aa":"bb" } `
Note that a valid JSON string does not have a comma at the end of the line.
It’s still not working.
from kcl-go.
full code
main.go
package main
import (
"fmt"
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kcl-go/pkg/loader"
)
func main() {
//yaml := kcl.MustRun("kubernetes.k", kcl.WithCode(code), kcl.WithOptions("metadata.name=huangyf", "metadata.lables=111")).GetRawYamlResult()
//fmt.Println(yaml)
ops, err := loader.ListFileOptions("amd64.k")
// ops, err := loader.ListFileOptions("./myk8s/main.k")
if err != nil {
panic(err)
}
fmt.Println(ops)
for _, op := range ops {
//fmt.Println(op.Name)
//fmt.Println(op.Type)
//fmt.Println(op.Required)
//fmt.Println(op.DefaultValue)
fmt.Printf("变量名为%s类型是%v默认值为%v是否必填%v\n", op.Name, op.Type, op.DefaultValue, op.Required)
}
var envs = `
{
"aa":"bb"
}
`
fmt.Println(kcl.MustRun("amd64.k", kcl.WithOptions("app=nginx", "image=aaa", fmt.Sprintf("envs=%s", envs))).GetRawYamlResult())
}
const code = `
metadata = {
name = "nginx"
labels = "app"
}
apiVersion = "apps/v1"
kind = "Deployment"
spec = {
replicas = 3
selector.matchLabels = metadata.labels
template.metadata.labels = metadata.labels
template.spec.containers = [
{
name = metadata.name
image = "${metadata.name}:1.14.2"
ports = [{ containerPort = 80 }]
}
]
}
`
amd64.k
_image = option("image", help="镜像地址", required=True)
_app : str = option("app", help="应用名称", required=True)
_namespace : str = option("namespace", help="命名空间") or "default"
envs = option(key="envs",type="dict", help="环境变量")
MQTT_BROKER_URL = option("MQTT_BROKER_URL", help="MQTT_BROKER_URL", required=False) or "tcp://1111"
__EDGEMANAGER__CLOUDBROKERADDR = option("__EDGEMANAGER__CLOUDBROKERADDR", help="__EDGEMANAGER__CLOUDBROKERADDR", required=False) or "tcp://1111"
__EDGEMANAGER__NODEID = option("__EDGEMANAGER__NODEID", help="__EDGEMANAGER__NODEID", required=False) or "tcp://1111"
__EDGEMANAGER__CACERTHTTPSERVER = option("__EDGEMANAGER__CACERTHTTPSERVER", help="__EDGEMANAGER__CACERTHTTPSERVER", required=False) or "tcp://1111"
_static_envs = [
# {
# name = "MQTT_BROKER_URL"
# value = MQTT_BROKER_URL
# }
# {
# name = "__EDGEMANAGER__CLOUDBROKERADDR"
# value = __EDGEMANAGER__CLOUDBROKERADDR
# }
# {
# name = "__EDGEMANAGER__NODEID"
# value = __EDGEMANAGER__NODEID
# }
# {
# name = "__EDGEMANAGER__CACERTHTTPSERVER"
# value = __EDGEMANAGER__CACERTHTTPSERVER
# }
]
# print(envs)
# print(_app)
# assert envs != None , "envs is required"
if envs:
_dy_env = [{
name: k
value: v
} for k,v in envs]
else:
_dy_env = []
{
apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = _app
namespace = _namespace
}
spec = {
replicas = 1
selector = {
matchLabels = {
app = _app
}
}
template = {
metadata = {
labels = {
app = _app
}
}
spec = {
containers = [
{
name = _app
image = _image
env = _static_envs + _dy_env
ports = [
{
containerPort = 80
}
]
volumeMounts = [
{
mountPath = "/data"
name = "data"
}
]
}
]
volumes = [
{
name = "data"
persistentVolumeClaim = {
claimName = _app
}
}
]
}
}
}
}
# if envs:
# _a=[{name: k, value: envs[k]} for k in envs]
# print(_a)
from kcl-go.
What is the difference between them?
envs = option("envs",type="dict", help="环境变量")
envs = option(key="envs",type="dict", help="环境变量")
from kcl-go.
Related Issues (20)
- WithSettings should merge options instead of overwriting HOT 5
- [Enhancement] KCL File Generate API for GitClickOps
- [Enhancement] Add AllOf validations for KCL jsonschema generations HOT 4
- Import tool use wrong mode and generate schema with error
- KCL Go Plugin API and documents HOT 1
- error get depends HOT 2
- [Question] [API] How can i get all params (option function call) from the kcl code HOT 26
- Disable auto block pr option of contributor-assistant/github-action HOT 1
- Request: allow disabling shared lib download behavior at build time HOT 8
- Inconsistent native and service KCL api `ParseFile` behaviour HOT 2
- version miss match HOT 2
- ‘_’ seems to be a bit unexpected. HOT 3
- [Enhancement] kcl import muti yaml resource HOT 3
- Get locally depended .k files of a given .k file (from imports)
- [Enhancement] Gen KCL config from toml config. HOT 14
- [Enhancement] Gen KCL schema from protobuf message HOT 5
- [Enhancement] Gen KCL config from textproto and KCL type/protobuf message
- [Enhancement] Import multiple documents in single YAML file into one KCL file with the `manifests.yaml_stream` function calling.
- [Enhancement] KCL Import supports importing the entire Go package into KCL schema
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kcl-go.