diff --git a/Makefile b/Makefile index 56e9b7b..261c487 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ render: traits-render components-render ## renders all templates apply: traits-apply components-apply ## applies all templates deploy: traits-deploy components-deploy ## deploys all templates -test: ## test example, e.g. `make test dev/manifests/applications/some-app.yaml` +test: ## test example, e.g. `make test examples/pure.yaml` @vela dry-run -f $(filter-out $@,$(MAKECMDGOALS)) traits-render: ## renders all traits @@ -37,4 +37,4 @@ install-vela: ## install kubevela help: ## show help message @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make [target]\033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m\t %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -.PHONY: all render apply deploy traits-render traits-apply traits-deploy components-render components-apply components-deploy install-vela help +.PHONY: all render apply deploy traits-render traits-apply traits-deploy components-render components-apply components-deploy install-vela help test diff --git a/cue/components/edgefarm-applications.cue b/cue/components/edgefarm-applications.cue index e70f68e..e65854d 100644 --- a/cue/components/edgefarm-applications.cue +++ b/cue/components/edgefarm-applications.cue @@ -1,3 +1,5 @@ +import "list" + "edgefarm-applications": { type: "component" annotations: {} @@ -11,6 +13,33 @@ } } template: { + predefinedTolerations: [ + { + key: "edgefarm.io", + operator: "Exists", + effect: "NoSchedule" + } + ] + + parameterTolerations: [ + if parameter.tolerations != _|_ { + for k in parameter.tolerations { + if k.key != _|_ { + key: k.key + } + if k.effect != _|_ { + effect: k.effect + } + if k.value != _|_ { + value: k.value + } + operator: k.operator + if k.tolerationSeconds != _|_ { + tolerationSeconds: k.tolerationSeconds + } + } + }] + output: { apiVersion: "apps.openyurt.io/v1alpha1" kind: "YurtAppDaemon" @@ -48,24 +77,7 @@ template: { } } spec: { - if parameter.tolerations != _|_ { - tolerations: [ - for k in parameter.tolerations { - if k.key != _|_ { - key: k.key - } - if k.effect != _|_ { - effect: k.effect - } - if k.value != _|_ { - value: k.value - } - operator: k.operator - if k.tolerationSeconds != _|_ { - tolerationSeconds: k.tolerationSeconds - } - }] - } + tolerations: predefinedTolerations + parameterTolerations containers: [{ name: context.name image: parameter.image diff --git a/examples/stress.yaml b/examples/stress.yaml new file mode 100644 index 0000000..1a54aed --- /dev/null +++ b/examples/stress.yaml @@ -0,0 +1,24 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: stress +spec: + components: + - name: stress + type: edgefarm-applications + properties: + image: alexeiled/stress-ng + nodepoolSelector: + matchLabels: + app/stress: "" + name: stress + command: + - "/stress-ng" + - "--cpu" + - "4" + - "--io" + - "2" + - "--vm-bytes" + - "1G" + - "timeout" + - "600s" diff --git a/examples/with-network-and-storage.yaml b/examples/with-network-and-storage.yaml index fcbc67e..0677f4d 100644 --- a/examples/with-network-and-storage.yaml +++ b/examples/with-network-and-storage.yaml @@ -16,10 +16,6 @@ spec: - sh - "-c" - "sleep infinity" - tolerations: - - key: "edgefarm.io" - operator: "Exists" - effect: "NoSchedule" traits: - type: edgefarm-network properties: diff --git a/examples/with-network-only.yaml b/examples/with-network-only.yaml index 2a91a05..714e2ea 100644 --- a/examples/with-network-only.yaml +++ b/examples/with-network-only.yaml @@ -16,10 +16,6 @@ spec: - sh - "-c" - "sleep infinity" - tolerations: - - key: "edgefarm.io" - operator: "Exists" - effect: "NoSchedule" traits: - type: edgefarm-network properties: diff --git a/manifests/vela-caps/components/edgefarm-applications.yaml b/manifests/vela-caps/components/edgefarm-applications.yaml index d040ee3..ffd5c54 100644 --- a/manifests/vela-caps/components/edgefarm-applications.yaml +++ b/manifests/vela-caps/components/edgefarm-applications.yaml @@ -8,7 +8,7 @@ metadata: spec: schematic: cue: - template: "output: {\n\tapiVersion: \"apps.openyurt.io/v1alpha1\"\n\tkind: \"YurtAppDaemon\"\n\tspec: {\n\t\tif parameter[\"nodepoolSelector\"] != _|_ {\n\t\t\tnodepoolSelector: parameter.nodepoolSelector\n\t\t}\n\n\t\tselector: matchLabels: {\n\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t}\n\t\tworkloadTemplate: deploymentTemplate: {\n\t\t\tmetadata: labels: {\n\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t}\n\n\t\t\tspec: {\n\t\t\t\treplicas: 1\n\t\t\t\tselector: matchLabels: {\n\t\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t\t}\n\t\t\t\ttemplate: {\n\t\t\t\t\tmetadata: labels: {\n\t\t\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t\t\t}\n\t\t\t\t\tspec: {\n\t\t\t\t\t\tif parameter.tolerations != _|_ {\n\t\t\t\t\t\t\ttolerations: [\n\t\t\t\t\t\t\t\tfor k in parameter.tolerations {\n\t\t\t\t\t\t\t\t\tif k.key != _|_ {\n\t\t\t\t\t\t\t\t\t\tkey: k.key\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif k.effect != _|_ {\n\t\t\t\t\t\t\t\t\t\teffect: k.effect\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif k.value != _|_ {\n\t\t\t\t\t\t\t\t\t\tvalue: k.value\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\toperator: k.operator\n\t\t\t\t\t\t\t\t\tif k.tolerationSeconds != _|_ {\n\t\t\t\t\t\t\t\t\t\ttolerationSeconds: k.tolerationSeconds\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontainers: [{\n\t\t\t\t\t\t\tname: context.name\n\t\t\t\t\t\t\timage: parameter.image\n\n\t\t\t\t\t\t\tif parameter[\"imagePullPolicy\"] != _|_ {\n\t\t\t\t\t\t\t\timagePullPolicy: parameter.imagePullPolicy\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"command\"] != _|_ {\n\t\t\t\t\t\t\t\tcommand: parameter.command\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"args\"] != _|_ {\n\t\t\t\t\t\t\t\targs: parameter.args\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"env\"] != _|_ {\n\t\t\t\t\t\t\t\tenv: parameter.env\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"ports\"] != _|_ {\n\t\t\t\t\t\t\t\tports: parameter.ports\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tresources: {\n\t\t\t\t\t\t\t\tif parameter.cpu != _|_ if parameter.memory != _|_ if parameter.requests == _|_ if parameter.limits == _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\trequests: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\tlimits: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif parameter.requests != _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\trequests: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.requests.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.requests.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif parameter.limits != _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\tlimits: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.limits.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.limits.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"livenessProbe\"] != _|_ {\n\t\t\t\t\t\t\t\tlivenessProbe: parameter.livenessProbe\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"readinessProbe\"] != _|_ {\n\t\t\t\t\t\t\t\treadinessProbe: parameter.readinessProbe\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"securityContext\"] != _|_ {\n\t\t\t\t\t\t\t\tsecurityContext: parameter.securityContext\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}]\n\n\t\t\t\t\t\tif parameter[\"imagePullSecrets\"] != _|_ {\n\t\t\t\t\t\t\timagePullSecrets: [ for v in parameter.imagePullSecrets {\n\t\t\t\t\t\t\t\tname: v\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n#nodepoolSelector: {\n\tmatchLabels?: [string]: string\n\tmatchExpressions?: [...{\n\t\tkey: string\n\t\toperator: *\"In\" | \"NotIn\" | \"Exists\" | \"DoesNotExist\"\n\t\tvalues?: [...string]\n\t}]\n}\n\n#tolerations: [...{\n\tkey?: string\n\toperator: *\"Equal\" | \"Exists\"\n\tvalue?: string\n\teffect?: \"NoSchedule\" | \"PreferNoSchedule\" | \"NoExecute\"\n\t// +usage=Specify the period of time the toleration\n\ttolerationSeconds?: int\n}]\n\nparameter: {\n\t// +usage=Which image would you like to use for your application\n\timage: string\n\n\t// +usage=Specify a list of nodepool selectors\n\tnodepoolSelector: #nodepoolSelector\n\n\t// +usage=Specify tolerant taint\n\ttolerations?: #tolerations\n\n\t// +usage=Specify image pull policy for your application\n\timagePullPolicy?: string\n\n\t// +usage=Specify image pull secrets for your application\n\timagePullSecrets?: [...string]\n\n\t// +usage=Commands to run in the container\n\tcommand?: [...string]\n\n\t// +usage=Args to run for the command\n\targs?: [...string]\n\n\t// +usage=Specifies the SecurityContext of the container\n\tsecurityContext?: {\n\t\t// +usage=AllowPrivilegeEscalation controls whether a process can gain more privileges than its parent process.\n\t\tallowPrivilegeEscalation?: bool\n\t\t// +uasge=The capabilities to add/drop when running containers. \n\t\tcapabilities?: {\n\t\t\t// +usage=Added capabilities\n\t\t\tadd?: [...string]\n\t\t\t// +usage=Dropped capabilities\n\t\t\tdrop?: [...string]\n\t\t}\n\t\t// +usage=Run container in privileged mode. \n\t\tprivileged?: bool\n\t\t// +usage=Whether this container has a read-only root filesystem.\n\t\treadOnlyRootFilesystem?: bool\n\t\t// +usage=The GID to run the entrypoint of the container process.\n\t\trunAsGroup?: int\n\t\t// +usage=Indicates that the container must run as a non-root user.\n\t\trunAsNonRoot?: bool\n\t\t// +usage=The UID to run the entrypoint of the container process. \n\t\trunAsUser?: int\n\t\t// procMount currently ununsed\n\t\t// procMount?: string\n\t\t// seLinuxOptions currently ununsed\n\t\t// seLinuxOptions?: {...}\n\t\t// seccompProfile currently ununsed\n\t\t// seccompProfile?: {}\n\t\t// windowsOptions never used\n\t}\n\n\t// +usage=Define arguments by using environment variables\n\tenv?: [...{\n\t\t// +usage=Environment variable name\n\t\tname: string\n\t\t// +usage=The value of the environment variable\n\t\tvalue?: string\n\t\t// +usage=Specifies a source the value of this var should come from\n\t\tvalueFrom?: {\n\t\t\t// +usage=Selects a key of a secret in the pod's namespace\n\t\t\tsecretKeyRef?: {\n\t\t\t\t// +usage=The name of the secret in the pod's namespace to select from\n\t\t\t\tname: string\n\t\t\t\t// +usage=The key of the secret to select from. Must be a valid secret key\n\t\t\t\tkey: string\n\t\t\t}\n\t\t\t// +usage=Selects a key of a config map in the pod's namespace\n\t\t\tconfigMapKeyRef?: {\n\t\t\t\t// +usage=The name of the config map in the pod's namespace to select from\n\t\t\t\tname: string\n\t\t\t\t// +usage=The key of the config map to select from. Must be a valid secret key\n\t\t\t\tkey: string\n\t\t\t}\n\t\t}\n\t}]\n\n\t// +usage=Specify port mappings\n\tports?: [...{\n\t\t// +usage=Name of the port mapping\n\t\tname?: string\n\t\t// +usage=The container port to expose\n\t\tcontainerPort: int\n\t\t// +usage=The host port the container port is mapped to\n\t\thostPort: int\n\t\t// +usage=The protocol of the port mapping\n\t\tprotocol?: string\n\t}]\n\n\t// +usage=Specify the amount of cpu for requests and limits\n\tcpu?: *\"0.25\" | number | string\n\t// +usage=Specify the amount of memory for requests and limits\n\tmemory?: *\"256Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t// +usage=Specify the resources in requests\n\trequests?: {\n\t\t// +usage=Specify the amount of cpu for requests\n\t\tcpu: *\"0.25\" | number | string\n\t\t// +usage=Specify the amount of memory for requests\n\t\tmemory: *\"256Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t}\n\t// +usage=Specify the resources in limits\n\tlimits?: {\n\t\t// +usage=Specify the amount of cpu for limits\n\t\tcpu: *\"0.5\" | number | string\n\t\t// +usage=Specify the amount of memory for limits\n\t\tmemory: *\"512Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t}\n\n\t// +usage=Instructions for assessing whether the container is alive.\n\tlivenessProbe?: #HealthProbe\n\t// +usage=Instructions for assessing whether the container is in a suitable state to serve traffic.\n\treadinessProbe?: #HealthProbe\n}\n\n#HealthProbe: {\n\t// +usage=Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute.\n\texec?: {\n\t\t// +usage=A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures.\n\t\tcommand: [...string]\n\t}\n\t// +usage=Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute.\n\thttpGet?: {\n\t\t// +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed.\n\t\tpath: string\n\t\t// +usage=The TCP socket within the container to which the HTTP GET request should be directed.\n\t\tport: int\n\t\thttpHeaders?: [...{\n\t\t\tname: string\n\t\t\tvalue: string\n\t\t}]\n\t}\n\t// +usage=Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute.\n\ttcpSocket?: {\n\t\t// +usage=The TCP socket within the container that should be probed to assess container health.\n\t\tport: int\n\t}\n\t// +usage=Number of seconds after the container is started before the first probe is initiated.\n\tinitialDelaySeconds: *0 | int\n\t// +usage=How often, in seconds, to execute the probe.\n\tperiodSeconds: *10 | int\n\t// +usage=Number of seconds after which the probe times out.\n\ttimeoutSeconds: *1 | int\n\t// +usage=Minimum consecutive successes for the probe to be considered successful after having failed.\n\tsuccessThreshold: *1 | int\n\t// +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe).\n\tfailureThreshold: *3 | int\n}\n" + template: "import \"list\"\n\npredefinedTolerations: [\n\t{\n\t\tkey: \"edgefarm.io\"\n\t\toperator: \"Exists\"\n\t\teffect: \"NoSchedule\"\n\t},\n]\n\nparameterTolerations: [\n\tif parameter.tolerations != _|_ {\n\t\tfor k in parameter.tolerations {\n\t\t\tif k.key != _|_ {\n\t\t\t\tkey: k.key\n\t\t\t}\n\t\t\tif k.effect != _|_ {\n\t\t\t\teffect: k.effect\n\t\t\t}\n\t\t\tif k.value != _|_ {\n\t\t\t\tvalue: k.value\n\t\t\t}\n\t\t\toperator: k.operator\n\t\t\tif k.tolerationSeconds != _|_ {\n\t\t\t\ttolerationSeconds: k.tolerationSeconds\n\t\t\t}\n\t\t}\n\t}]\n\noutput: {\n\tapiVersion: \"apps.openyurt.io/v1alpha1\"\n\tkind: \"YurtAppDaemon\"\n\tspec: {\n\t\tif parameter[\"nodepoolSelector\"] != _|_ {\n\t\t\tnodepoolSelector: parameter.nodepoolSelector\n\t\t}\n\n\t\tselector: matchLabels: {\n\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t}\n\t\tworkloadTemplate: deploymentTemplate: {\n\t\t\tmetadata: labels: {\n\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t}\n\n\t\t\tspec: {\n\t\t\t\treplicas: 1\n\t\t\t\tselector: matchLabels: {\n\t\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t\t}\n\t\t\t\ttemplate: {\n\t\t\t\t\tmetadata: labels: {\n\t\t\t\t\t\t\"app.kubernetes.io/component\": context.name\n\t\t\t\t\t\t\"app.kubernetes.io/app\": context.appName\n\t\t\t\t\t}\n\t\t\t\t\tspec: {\n\t\t\t\t\t\ttolerations: predefinedTolerations + parameterTolerations\n\t\t\t\t\t\tcontainers: [{\n\t\t\t\t\t\t\tname: context.name\n\t\t\t\t\t\t\timage: parameter.image\n\n\t\t\t\t\t\t\tif parameter[\"imagePullPolicy\"] != _|_ {\n\t\t\t\t\t\t\t\timagePullPolicy: parameter.imagePullPolicy\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"command\"] != _|_ {\n\t\t\t\t\t\t\t\tcommand: parameter.command\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"args\"] != _|_ {\n\t\t\t\t\t\t\t\targs: parameter.args\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"env\"] != _|_ {\n\t\t\t\t\t\t\t\tenv: parameter.env\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"ports\"] != _|_ {\n\t\t\t\t\t\t\t\tports: parameter.ports\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tresources: {\n\t\t\t\t\t\t\t\tif parameter.cpu != _|_ if parameter.memory != _|_ if parameter.requests == _|_ if parameter.limits == _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\trequests: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\tlimits: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif parameter.requests != _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\trequests: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.requests.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.requests.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif parameter.limits != _|_ {\n\t\t\t\t\t\t\t\t\t// +patchStrategy=retainKeys\n\t\t\t\t\t\t\t\t\tlimits: {\n\t\t\t\t\t\t\t\t\t\tcpu: parameter.limits.cpu\n\t\t\t\t\t\t\t\t\t\tmemory: parameter.limits.memory\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"livenessProbe\"] != _|_ {\n\t\t\t\t\t\t\t\tlivenessProbe: parameter.livenessProbe\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"readinessProbe\"] != _|_ {\n\t\t\t\t\t\t\t\treadinessProbe: parameter.readinessProbe\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif parameter[\"securityContext\"] != _|_ {\n\t\t\t\t\t\t\t\tsecurityContext: parameter.securityContext\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}]\n\n\t\t\t\t\t\tif parameter[\"imagePullSecrets\"] != _|_ {\n\t\t\t\t\t\t\timagePullSecrets: [ for v in parameter.imagePullSecrets {\n\t\t\t\t\t\t\t\tname: v\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n#nodepoolSelector: {\n\tmatchLabels?: [string]: string\n\tmatchExpressions?: [...{\n\t\tkey: string\n\t\toperator: *\"In\" | \"NotIn\" | \"Exists\" | \"DoesNotExist\"\n\t\tvalues?: [...string]\n\t}]\n}\n\n#tolerations: [...{\n\tkey?: string\n\toperator: *\"Equal\" | \"Exists\"\n\tvalue?: string\n\teffect?: \"NoSchedule\" | \"PreferNoSchedule\" | \"NoExecute\"\n\t// +usage=Specify the period of time the toleration\n\ttolerationSeconds?: int\n}]\n\nparameter: {\n\t// +usage=Which image would you like to use for your application\n\timage: string\n\n\t// +usage=Specify a list of nodepool selectors\n\tnodepoolSelector: #nodepoolSelector\n\n\t// +usage=Specify tolerant taint\n\ttolerations?: #tolerations\n\n\t// +usage=Specify image pull policy for your application\n\timagePullPolicy?: string\n\n\t// +usage=Specify image pull secrets for your application\n\timagePullSecrets?: [...string]\n\n\t// +usage=Commands to run in the container\n\tcommand?: [...string]\n\n\t// +usage=Args to run for the command\n\targs?: [...string]\n\n\t// +usage=Specifies the SecurityContext of the container\n\tsecurityContext?: {\n\t\t// +usage=AllowPrivilegeEscalation controls whether a process can gain more privileges than its parent process.\n\t\tallowPrivilegeEscalation?: bool\n\t\t// +uasge=The capabilities to add/drop when running containers. \n\t\tcapabilities?: {\n\t\t\t// +usage=Added capabilities\n\t\t\tadd?: [...string]\n\t\t\t// +usage=Dropped capabilities\n\t\t\tdrop?: [...string]\n\t\t}\n\t\t// +usage=Run container in privileged mode. \n\t\tprivileged?: bool\n\t\t// +usage=Whether this container has a read-only root filesystem.\n\t\treadOnlyRootFilesystem?: bool\n\t\t// +usage=The GID to run the entrypoint of the container process.\n\t\trunAsGroup?: int\n\t\t// +usage=Indicates that the container must run as a non-root user.\n\t\trunAsNonRoot?: bool\n\t\t// +usage=The UID to run the entrypoint of the container process. \n\t\trunAsUser?: int\n\t\t// procMount currently ununsed\n\t\t// procMount?: string\n\t\t// seLinuxOptions currently ununsed\n\t\t// seLinuxOptions?: {...}\n\t\t// seccompProfile currently ununsed\n\t\t// seccompProfile?: {}\n\t\t// windowsOptions never used\n\t}\n\n\t// +usage=Define arguments by using environment variables\n\tenv?: [...{\n\t\t// +usage=Environment variable name\n\t\tname: string\n\t\t// +usage=The value of the environment variable\n\t\tvalue?: string\n\t\t// +usage=Specifies a source the value of this var should come from\n\t\tvalueFrom?: {\n\t\t\t// +usage=Selects a key of a secret in the pod's namespace\n\t\t\tsecretKeyRef?: {\n\t\t\t\t// +usage=The name of the secret in the pod's namespace to select from\n\t\t\t\tname: string\n\t\t\t\t// +usage=The key of the secret to select from. Must be a valid secret key\n\t\t\t\tkey: string\n\t\t\t}\n\t\t\t// +usage=Selects a key of a config map in the pod's namespace\n\t\t\tconfigMapKeyRef?: {\n\t\t\t\t// +usage=The name of the config map in the pod's namespace to select from\n\t\t\t\tname: string\n\t\t\t\t// +usage=The key of the config map to select from. Must be a valid secret key\n\t\t\t\tkey: string\n\t\t\t}\n\t\t}\n\t}]\n\n\t// +usage=Specify port mappings\n\tports?: [...{\n\t\t// +usage=Name of the port mapping\n\t\tname?: string\n\t\t// +usage=The container port to expose\n\t\tcontainerPort: int\n\t\t// +usage=The host port the container port is mapped to\n\t\thostPort: int\n\t\t// +usage=The protocol of the port mapping\n\t\tprotocol?: string\n\t}]\n\n\t// +usage=Specify the amount of cpu for requests and limits\n\tcpu?: *\"0.25\" | number | string\n\t// +usage=Specify the amount of memory for requests and limits\n\tmemory?: *\"256Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t// +usage=Specify the resources in requests\n\trequests?: {\n\t\t// +usage=Specify the amount of cpu for requests\n\t\tcpu: *\"0.25\" | number | string\n\t\t// +usage=Specify the amount of memory for requests\n\t\tmemory: *\"256Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t}\n\t// +usage=Specify the resources in limits\n\tlimits?: {\n\t\t// +usage=Specify the amount of cpu for limits\n\t\tcpu: *\"0.5\" | number | string\n\t\t// +usage=Specify the amount of memory for limits\n\t\tmemory: *\"512Mi\" | =~\"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$\"\n\t}\n\n\t// +usage=Instructions for assessing whether the container is alive.\n\tlivenessProbe?: #HealthProbe\n\t// +usage=Instructions for assessing whether the container is in a suitable state to serve traffic.\n\treadinessProbe?: #HealthProbe\n}\n\n#HealthProbe: {\n\t// +usage=Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute.\n\texec?: {\n\t\t// +usage=A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures.\n\t\tcommand: [...string]\n\t}\n\t// +usage=Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute.\n\thttpGet?: {\n\t\t// +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed.\n\t\tpath: string\n\t\t// +usage=The TCP socket within the container to which the HTTP GET request should be directed.\n\t\tport: int\n\t\thttpHeaders?: [...{\n\t\t\tname: string\n\t\t\tvalue: string\n\t\t}]\n\t}\n\t// +usage=Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute.\n\ttcpSocket?: {\n\t\t// +usage=The TCP socket within the container that should be probed to assess container health.\n\t\tport: int\n\t}\n\t// +usage=Number of seconds after the container is started before the first probe is initiated.\n\tinitialDelaySeconds: *0 | int\n\t// +usage=How often, in seconds, to execute the probe.\n\tperiodSeconds: *10 | int\n\t// +usage=Number of seconds after which the probe times out.\n\ttimeoutSeconds: *1 | int\n\t// +usage=Minimum consecutive successes for the probe to be considered successful after having failed.\n\tsuccessThreshold: *1 | int\n\t// +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe).\n\tfailureThreshold: *3 | int\n}\n" workload: definition: apiVersion: apps.openyurt.io/v1alpha1 diff --git a/test/expected1.yaml b/test/expected1.yaml new file mode 100644 index 0000000..fe4dcc5 --- /dev/null +++ b/test/expected1.yaml @@ -0,0 +1,60 @@ +--- +# Application(pure) -- Component(pure) +--- + +apiVersion: apps.openyurt.io/v1alpha1 +kind: YurtAppDaemon +metadata: + annotations: {} + labels: + app.oam.dev/appRevision: "" + app.oam.dev/component: pure + app.oam.dev/name: pure + app.oam.dev/namespace: default + app.oam.dev/resourceType: WORKLOAD + workload.oam.dev/type: edgefarm-applications + name: pure + namespace: default +spec: + nodepoolSelector: + matchLabels: + app/pure: "" + selector: + matchLabels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + workloadTemplate: + deploymentTemplate: + metadata: + labels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + template: + metadata: + labels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + spec: + containers: + - command: + - sh + - -c + - sleep infinity + image: bash:5.1-alpine3.17 + name: pure + resources: {} + tolerations: + - effect: NoSchedule + key: edgefarm.io + operator: Exists + +--- + + +make: Nothing to be done for 'examples/pure.yaml'. \ No newline at end of file diff --git a/test/expected2.yaml b/test/expected2.yaml new file mode 100644 index 0000000..bb83c0d --- /dev/null +++ b/test/expected2.yaml @@ -0,0 +1,63 @@ +--- +# Application(pure) -- Component(pure) +--- + +apiVersion: apps.openyurt.io/v1alpha1 +kind: YurtAppDaemon +metadata: + annotations: {} + labels: + app.oam.dev/appRevision: "" + app.oam.dev/component: pure + app.oam.dev/name: pure + app.oam.dev/namespace: default + app.oam.dev/resourceType: WORKLOAD + workload.oam.dev/type: edgefarm-applications + name: pure + namespace: default +spec: + nodepoolSelector: + matchLabels: + app/pure: "" + selector: + matchLabels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + workloadTemplate: + deploymentTemplate: + metadata: + labels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + template: + metadata: + labels: + app.kubernetes.io/app: pure + app.kubernetes.io/component: pure + spec: + containers: + - command: + - sh + - -c + - sleep infinity + image: bash:5.1-alpine3.17 + name: pure + resources: {} + tolerations: + - effect: NoSchedule + key: edgefarm.io + operator: Exists + - effect: NoSchedule + key: foo + operator: Exists + +--- + + +make: Nothing to be done for 'test/test2.yaml'. \ No newline at end of file diff --git a/test/test1.yaml b/test/test1.yaml new file mode 100644 index 0000000..6576fe3 --- /dev/null +++ b/test/test1.yaml @@ -0,0 +1,18 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: pure +spec: + components: + - name: pure + type: edgefarm-applications + properties: + image: bash:5.1-alpine3.17 + nodepoolSelector: + matchLabels: + app/pure: "" + name: pure + command: + - sh + - "-c" + - "sleep infinity" diff --git a/test/test2.yaml b/test/test2.yaml new file mode 100644 index 0000000..7dedacd --- /dev/null +++ b/test/test2.yaml @@ -0,0 +1,22 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: pure +spec: + components: + - name: pure + type: edgefarm-applications + properties: + image: bash:5.1-alpine3.17 + nodepoolSelector: + matchLabels: + app/pure: "" + name: pure + tolerations: + - effect: NoSchedule + key: foo + operator: Exists + command: + - sh + - "-c" + - "sleep infinity"