From fbfe95ae45fb3f63a80b90d9aef91654d64a162e Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Mon, 11 Jul 2022 15:50:42 +0800 Subject: [PATCH 1/2] add openyurt example Signed-off-by: Jianbo Sun --- openyurt/definition/helm-edge.cue | 212 ++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 openyurt/definition/helm-edge.cue diff --git a/openyurt/definition/helm-edge.cue b/openyurt/definition/helm-edge.cue new file mode 100644 index 0000000..99e0ee1 --- /dev/null +++ b/openyurt/definition/helm-edge.cue @@ -0,0 +1,212 @@ +"yurt-helm": { + attributes: { + workload: type: "autodetects.core.oam.dev" + status: { + healthPolicy: #""" + isHealth: len(context.outputs.release.status.conditions) != 0 && context.outputs.release.status.conditions[0]["status"]=="True + """# + customStatus: #""" + repoMessage: *"" | string + releaseMessage: *"" | string + if context.output.status == _|_ { + repoMessage: "Fetching repository" + releaseMessage: "Wating repository ready" + } + if context.output.status != _|_ { + repoStatus: context.output.status + if len(repoStatus.conditions) == 0 || repoStatus.conditions[0]["type"] != "Ready" { + repoMessage: "Fetch repository fail" + } + if len(repoStatus.conditions) != 0 && repoStatus.conditions[0]["type"] == "Ready" { + repoMessage: "Fetch repository successfully" + } + if context.outputs.release.status == _|_ { + releaseMessage: "Creating helm release" + } + if context.outputs.release.status != _|_ { + if context.outputs.release.status.conditions[0]["message"] == "Release reconciliation succeeded" { + releaseMessage: "Create helm release successfully" + } + if context.outputs.release.status.conditions[0]["message"] != "Release reconciliation succeeded" { + releaseBasicMessage: "Delivery helm release in progress, message: " + context.outputs.release.status.conditions[0]["message"] + if len(context.outputs.release.status.conditions) == 1 { + releaseMessage: releaseBasicMessage + } + if len(context.outputs.release.status.conditions) > 1 { + releaseMessage: releaseBasicMessage + ", " + context.outputs.release.status.conditions[1]["message"] + } + } + } + } + message: repoMessage + ", " + releaseMessage + """# + } + } + description: "helm release is a group of K8s resources from either git repository or helm repo" + type: "component" +} + +template: { + output: { + apiVersion: "source.toolkit.fluxcd.io/v1beta2" + metadata: { + name: context.name + parameter.subnet + } + if parameter.repoType == "git" { + kind: "GitRepository" + spec: { + url: parameter.url + if parameter.git.branch != _|_ { + ref: branch: parameter.git.branch + } + _secret + _sourceCommonArgs + } + } + if parameter.repoType == "oss" { + kind: "Bucket" + spec: { + endpoint: parameter.url + bucketName: parameter.oss.bucketName + provider: parameter.oss.provider + if parameter.oss.region != _|_ { + region: parameter.oss.region + } + _secret + _sourceCommonArgs + } + } + if parameter.repoType == "helm" || parameter.repoType == "oci" { + kind: "HelmRepository" + spec: { + url: parameter.url + if parameter.repoType == "oci" { + type: "oci" + } + _secret + _sourceCommonArgs + } + } + } + + outputs: release: { + apiVersion: "helm.toolkit.fluxcd.io/v2beta1" + kind: "HelmRelease" + metadata: { + name: context.name + parameter.subnet + } + spec: { + timeout: parameter.installTimeout + interval: parameter.pullInterval + chart: { + spec: { + chart: parameter.chart + version: parameter.version + sourceRef: { + if parameter.repoType == "git" { + kind: "GitRepository" + } + if parameter.repoType == "helm" || parameter.repoType == "oci" { + kind: "HelmRepository" + } + if parameter.repoType == "oss" { + kind: "Bucket" + } + name: context.name + parameter.subnet + } + interval: parameter.interval + if parameter["valuesFiles"] != _|_ { + valuesFiles: parameter["valuesFiles"] + } + } + } + if parameter.targetNamespace != _|_ { + targetNamespace: parameter.targetNamespace + } + if parameter.releaseName != _|_ { + releaseName: parameter.releaseName + } + if parameter.values != _|_ { + values: parameter.values + } + install: { + remediation: { + retries: parameter.retries + } + } + upgrade: { + remediation: { + retries: parameter.retries + } + } + } + } + + _secret: { + if parameter.secretRef != _|_ { + if parameter.secretRef != "" { + secretRef: { + name: parameter.secretRef + } + } + } + } + + _sourceCommonArgs: { + interval: parameter.pullInterval + if parameter.timeout != _|_ { + timeout: parameter.timeout + } + } + + parameter: { + + subnet: *"" | string + + repoType: *"helm" | "git" | "oss" | "oci" + // +usage=The interval at which to check for repository/bucket and release updates, default to 5m + pullInterval: *"5m" | string + // +usage=The Interval at which to reconcile the Helm release, default to 30s + interval: *"30s" | string + // +usage=The Git or Helm repository URL, OSS endpoint, accept HTTP/S or SSH address as git url, + url: string + // +usage=The name of the secret containing authentication credentials + secretRef?: string + // +usage=The timeout for operations like download index/clone repository, optional + timeout?: string + // +usage=The timeout for operation `helm install`, optional + installTimeout: *"10m" | string + + git?: { + // +usage=The Git reference to checkout and monitor for changes, defaults to master branch + branch: string + } + oss?: { + // +usage=The bucket's name, required if repoType is oss + bucketName: string + // +usage="generic" for Minio, Amazon S3, Google Cloud Storage, Alibaba Cloud OSS, "aws" for retrieve credentials from the EC2 service when credentials not specified, default "generic" + provider: *"generic" | "aws" + // +usage=The bucket region, optional + region?: string + } + // +usage=Alternative list of values files to use as the chart values (values.yaml is not included by default), expected to be a relative path in the SourceRef.Values files are merged in the order of this list with the last file overriding the first. + valuesFiles?: [...string] + + // +usage=1.The relative path to helm chart for git/oss source. 2. chart name for helm resource 3. relative path for chart package(e.g. ./charts/podinfo-1.2.3.tgz) + chart: string + // +usage=Chart version + version: *"*" | string + // +usage=The namespace for helm chart, optional + targetNamespace?: string + // +usage=The release name + releaseName?: string + // +usage=Retry times when install/upgrade fail. + retries: *3 | int + // +usage=Chart values + values?: #nestedmap + } + + #nestedmap: { + ... + } +} From 062232b1db4836e2ba2c43ce1e65654eb3391212 Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Mon, 11 Jul 2022 16:10:44 +0800 Subject: [PATCH 2/2] Add yurt app example Signed-off-by: Jianbo Sun --- openyurt/app.yaml | 44 +++++++++++++++++++++++++++++++ openyurt/definition/helm-edge.cue | 10 +++---- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 openyurt/app.yaml diff --git a/openyurt/app.yaml b/openyurt/app.yaml new file mode 100644 index 0000000..8838fb8 --- /dev/null +++ b/openyurt/app.yaml @@ -0,0 +1,44 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: yurt-app +spec: + components: + - name: redis + type: yurt-helm + properties: + repoType: "helm" + url: "https://charts.bitnami.com/bitnami" + chart: "redis" + version: "16.8.5" + values: + customNodeSelectorLabel: "apps.openyurt.io/nodepool" + policies: + - name: override-beijing + type: override + properties: + components: + - name: redis + properties: + subset: beijing + values: + customodeSelectorValues: ["beijing"] + - name: override-hangzhou + type: override + properties: + components: + - name: redis + properties: + subset: hangzhou + values: + customodeSelectorValues: ["hangzhou"] + workflow: + steps: + - name: deploy2beijing + type: deploy + properties: + policies: ["override-beijing"] + - name: deploy2hangzhou + type: deploy + properties: + policies: ["override-hangzhou"] diff --git a/openyurt/definition/helm-edge.cue b/openyurt/definition/helm-edge.cue index 99e0ee1..f4a4fc0 100644 --- a/openyurt/definition/helm-edge.cue +++ b/openyurt/definition/helm-edge.cue @@ -3,7 +3,7 @@ workload: type: "autodetects.core.oam.dev" status: { healthPolicy: #""" - isHealth: len(context.outputs.release.status.conditions) != 0 && context.outputs.release.status.conditions[0]["status"]=="True + isHealth: len(context.outputs.release.status.conditions) != 0 && context.outputs.release.status.conditions[0]["status"]=="True" """# customStatus: #""" repoMessage: *"" | string @@ -50,7 +50,7 @@ template: { output: { apiVersion: "source.toolkit.fluxcd.io/v1beta2" metadata: { - name: context.name + parameter.subnet + name: context.name + parameter.subset } if parameter.repoType == "git" { kind: "GitRepository" @@ -93,7 +93,7 @@ template: { apiVersion: "helm.toolkit.fluxcd.io/v2beta1" kind: "HelmRelease" metadata: { - name: context.name + parameter.subnet + name: context.name + parameter.subset } spec: { timeout: parameter.installTimeout @@ -112,7 +112,7 @@ template: { if parameter.repoType == "oss" { kind: "Bucket" } - name: context.name + parameter.subnet + name: context.name + parameter.subset } interval: parameter.interval if parameter["valuesFiles"] != _|_ { @@ -161,7 +161,7 @@ template: { parameter: { - subnet: *"" | string + subset: *"" | string repoType: *"helm" | "git" | "oss" | "oci" // +usage=The interval at which to check for repository/bucket and release updates, default to 5m