diff --git a/templates/argo-cd/createapp-wftpl.yaml b/templates/argo-cd/createapp-wftpl.yaml index 67a47cb..fd09826 100644 --- a/templates/argo-cd/createapp-wftpl.yaml +++ b/templates/argo-cd/createapp-wftpl.yaml @@ -10,10 +10,10 @@ spec: value: "hanu-deploy-apps" - name: app_name value: "lma" - - name: repository_url + - name: manifest_repo_url value: "https://github.com/openinfradev/decapod-manifests" - name: revision - value: main + value: "main" templates: - name: createApp inputs: @@ -56,7 +56,7 @@ spec: - name: NAMESPACE value: "{{inputs.parameters.namespace}}" - name: REPO - value: "{{workflow.parameters.repository_url}}" + value: "{{workflow.parameters.manifest_repo_url}}" - name: REVISION value: "{{workflow.parameters.revision}}" diff --git a/templates/decapod-apps/lma-uniformed-wftpl.yaml b/templates/decapod-apps/lma-uniformed-wftpl.yaml index 4dce67d..5fd27f8 100644 --- a/templates/decapod-apps/lma-uniformed-wftpl.yaml +++ b/templates/decapod-apps/lma-uniformed-wftpl.yaml @@ -11,7 +11,9 @@ spec: value: "hanu-reference" - name: app_name value: "lma" - - name: repository_url + - name: site_repo_url + value: "https://github.com/openinfradev/decapod-site" + - name: manifest_repo_url value: "https://github.com/openinfradev/decapod-manifests" - name: revision value: main diff --git a/templates/decapod-apps/openstack-components-wf.yaml b/templates/decapod-apps/openstack-components-wf.yaml index b8d2a1e..1157bba 100644 --- a/templates/decapod-apps/openstack-components-wf.yaml +++ b/templates/decapod-apps/openstack-components-wf.yaml @@ -11,7 +11,7 @@ spec: value: "hanu-reference" - name: app_name value: "openstack" - - name: repository_url + - name: manifest_repo_url value: "https://github.com/openinfradev/decapod-manifests" - name: revision value: main diff --git a/templates/decapod-apps/openstack-infra-wftpl.yaml b/templates/decapod-apps/openstack-infra-wftpl.yaml index 9cdd3ba..78f98c2 100644 --- a/templates/decapod-apps/openstack-infra-wftpl.yaml +++ b/templates/decapod-apps/openstack-infra-wftpl.yaml @@ -11,7 +11,7 @@ spec: value: "hanu-reference" - name: app_name value: "openstack" - - name: repository_url + - name: manifest_repo_url value: "https://github.com/openinfradev/decapod-manifests" - name: revision value: main diff --git a/templates/decapod-apps/service-mesh-wf.yaml b/templates/decapod-apps/service-mesh-wf.yaml index c6c0cdc..a7d77e7 100644 --- a/templates/decapod-apps/service-mesh-wf.yaml +++ b/templates/decapod-apps/service-mesh-wf.yaml @@ -11,7 +11,7 @@ spec: value: hanu-reference - name: app_name value: service-mesh - - name: repository_url + - name: manifest_repo_url value: 'https://github.com/openinfradev/decapod-manifests' - name: revision value: main diff --git a/templates/decapod-apps/tks-lma-federation-wftpl.yaml b/templates/decapod-apps/tks-lma-federation-wftpl.yaml deleted file mode 100644 index 6cd7976..0000000 --- a/templates/decapod-apps/tks-lma-federation-wftpl.yaml +++ /dev/null @@ -1,153 +0,0 @@ -apiVersion: argoproj.io/v1alpha1 -kind: WorkflowTemplate -metadata: - name: tks-lma-federation - namespace: argo -spec: - entrypoint: deploy - arguments: - parameters: - - name: site_name - value: "hanu-reference" - - name: app_name - value: "lma" - - name: label - value: "hanu-app1" - - name: repository_url - value: "https://github.com/openinfradev/decapod-manifests" - templates: - - name: deploy - steps: - - - name: process - template: argocd - - - name: postprocess - template: tks-client-epregister - arguments: - parameters: - - name: tks - value: "127.0.0.1" - - name: clusterid - value: "6abead61-ff2a-4af4-8f41-d2c44c745de7" - - name: appgroupid - value: "abbead61-ff2a-4af4-8f41-d2c44c745de7" - - name: clusterep - value: "" - # 3-ways for transfer information (about applications) - # 1. eplist 변수에 json 형태로 어플리케이션별 모든 url 제공 "{"1":"127.0.0.1","2":"127.0.0.1:10232"}" - # 2. clusterep에 클러스터에 대한 ip혹은 dns를 명시하고 epportlist변수에 어플리케이션별 포트를 제공 "{"1":"30000","2":"30005"}" - # 3. clusterep에 클러스터에 대한 ip 혹은 dns를 적용하여 미리 정해진 내용을 등록하도록 유도 - 현재는 30007 포트만 prometheus sidecar 서비스로 등재 - # (For Example) - # (case 1) - # - name: eplist - # value: "{\"1\":\"127.0.0.1\",\"2\":\"127.0.0.1:10232\"}" - # (case 2) - # - name: clusterep - # value: "taco.mycluster.com" - # - name: epportlist - # value: "{"1":"30000","2":"30005"}" - # (case 3) - # - name: clusterep - # value: "192.168.0.1" - - - name: argocd - dag: - tasks: - - name: operator - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "prometheus-operator", "namespace": "lma" }, - { "path": "eck-operator", "namespace": "elastic-system" }, - { "path": "fluentbit-operator", "namespace": "lma" } - ] - dependencies: [] - - name: logging - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "eck-resource", "namespace": "lma" }, - { "path": "fluentbit", "namespace": "lma" }, - { "path": "kubernetes-event-exporter", "namespace": "lma" } - ] - dependencies: [operator] - - name: prepare-lma - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "thanos-config", "namespace": "lma" } - ] - dependencies: [operator] - - - name: prometheus - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "prometheus", "namespace": "lma" }, - { "path": "kube-state-metrics", "namespace": "lma" }, - { "path": "prometheus-process-exporter", "namespace": "lma" }, - { "path": "prometheus-pushgateway", "namespace": "lma" }, - { "path": "prometheus-node-exporter", "namespace": "lma" }, - { "path": "prometheus-adapter", "namespace": "lma" }, - { "path": "addons", "namespace": "lma" } - ] - dependencies: [prepare-lma] - - - name: federation - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "thanos", "namespace": "lma" } - ] - dependencies: [prometheus,logging] - - - name: grafana - templateRef: - name: create-application - template: installApps - arguments: - parameters: - - name: list - value: | - [ - { "path": "grafana", "namespace": "lma" } - ] - dependencies: [federation] - - - name: tks-client-epregister - inputs: - parameters: - - name: tks - - name: clusterid - - name: appgroupid - - name: clusterep - container: - # run cowsay with that message input parameter as args - image: ghcr.io/openinfradev/ep2tks:v0.1.0 - command: ["/app/ep2tks"] - args: ["-tks","{{inputs.parameters.tks}}","-clusterep","{{inputs.parameters.clusterep}}", - "-appgroupid","{{inputs.parameters.appgroupid}}","-clusterid","{{inputs.parameters.clusterid}}"] diff --git a/templates/decapod-manifests/update-decapod-manifest-wftpl.yaml b/templates/decapod-manifests/update-decapod-manifest-wftpl.yaml new file mode 100644 index 0000000..2ee3d87 --- /dev/null +++ b/templates/decapod-manifests/update-decapod-manifest-wftpl.yaml @@ -0,0 +1,136 @@ +apiVersion: argoproj.io/v1alpha1 +kind: WorkflowTemplate +metadata: + name: update-decapod-manifest + namespace: argo +spec: + templates: + - name: updateManifest + synchronization: + mutex: + name: default + inputs: + parameters: + - name: action + value: "update" + - name: cluster_name + value: "hanu-reference" + - name: app_group + value: "lma" + - name: chart + value: "thanos" + # kv_map_str usage # + # - 'update' action: {"k1": "v1", "k2": "v2"} + # - 'insert' action: above format or value as list type. For eg, {"key": [v1, v2]} + - name: kv_map_str + value: "" + script: + image: sktdev/python-centos-wf-worker:v1.0 + command: ["python"] + env: + source: | + import sys + import argparse + import git + import ruamel.yaml + import os + import json + + action = "{{inputs.parameters.action}}" + clusterName = "{{inputs.parameters.cluster_name}}" + appGroup = "{{inputs.parameters.app_group}}" + chartName = "{{inputs.parameters.chart}}" + kvMapStr = "{{inputs.parameters.kv_map_str}}" + kvMapStr2 = kvMapStr.replace("'", "\"") + kvMap = json.loads(kvMapStr2) + + repo = None + config = {} + commit_msg = '' + numChanged = 0 + sitePath = './decapod-site' + siteFileName = "{}/{}/site-values.yaml".format(clusterName,appGroup) + siteFileNameFull = "{}/{}".format(sitePath, siteFileName) + + # Clone or re-use decapod-site repository # + if not os.path.isdir(sitePath): + print("Cloning repository...") + + repo = git.Repo.clone_from("{{workflow.parameters.site_repo_url}}", 'decapod-site') + with repo.config_writer() as git_config: + git_config.set_value('user', 'email', 'tks-argo@tks.com') + git_config.set_value('user', 'name', 'TKS Argo') + else: + print("The repo already exists. Pulling latest updates..") + + repo = git.Repo(sitePath) + repo.remotes.origin.pull() + + with open(siteFileNameFull, 'r') as f: + config = ruamel.yaml.round_trip_load(f, preserve_quotes=True) + + charts = config["charts"] + chartFound = [chart for chart in charts if chart['name'] == chartName][0] + + if action == 'update': + for k,v in kvMap.items(): + if (chartFound['override'][k] == v): + print("The value {} isn't changed. Skipping update...".format(v)) + else: + chartFound['override'][k] = v + numChanged += 1 + commit_msg = "update items for {} chart in '{}' cluster".format(chartName, clusterName) + elif action == 'insert': + for k,v in kvMap.items(): + # If the value is list type, then append one by one iterating over the list. + if isinstance(v, list): + for item in v: + if item in chartFound['override'][k]: + print("The value {} already exists.".format(item)) + else: + chartFound['override'][k].append(item) + numChanged += 1 + elif (v in chartFound['override'][k]): + print("The value {} already exists.".format(v)) + else: + chartFound['override'][k].append(v) + numChanged += 1 + commit_msg = "insert items for {} chart in '{}' cluster".format(chartName, clusterName) + elif action == 'delete': + for k,v in kvMap.items(): + if (v in chartFound['override'][k]): + print("Found value '{}'. Deleting it...".format(v)) + chartFound['override'][k].remove(v) + numChanged += 1 + else: + print("The value {} doesn't exist.".format(v)) + commit_msg = "delete items for {} chart in '{}' cluster".format(chartName, clusterName) + else: + sys.exit("Wrong action type") + + if numChanged == 0: + print("Nothing updated. Exiting task..") + sys.exit(0) + + ############################### + # Commit and push the changed # + ############################### + + with open(siteFileNameFull, 'w') as f: + ruamel.yaml.round_trip_dump(config, f) + + diff = repo.git.diff(repo.head.commit.tree) + print(diff) + + # Provide a list of the files to stage + repo.index.add([siteFileName]) + + # Provide a commit message + repo.index.commit(commit_msg) + res = repo.remotes.origin.push()[0] + + # flag '256' means successful fast-forward + if res.flags != 256: + print(res.summary) + sys.exit("Push failed!") +