From 044cde3bfd0b211b3690a7138d4f0620c956f4ef Mon Sep 17 00:00:00 2001 From: Oscar Romeu Date: Sun, 27 Aug 2023 12:04:06 +0200 Subject: [PATCH] feat: add branch reference as variable in gitrepository --- bootstrap/tasks/validation/github.yaml | 14 ++++++++++++++ bootstrap/tasks/validation/vars.yaml | 1 + .../kubernetes/flux/config/cluster.yaml.j2 | 2 +- bootstrap/vars/config.sample.yaml | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bootstrap/tasks/validation/github.yaml b/bootstrap/tasks/validation/github.yaml index e90b468eb41..af514962e8b 100644 --- a/bootstrap/tasks/validation/github.yaml +++ b/bootstrap/tasks/validation/github.yaml @@ -26,3 +26,17 @@ that: result.json.full_name == bootstrap_github_username + '/' + bootstrap_github_repository_name success_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} exists fail_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} does not exist + +- name: Query Github repo branch + ansible.builtin.uri: + url: https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}/branches/{{ bootstrap_github_repository_branch }} + timeout: 5 + return_content: true + body_format: json + register: result + +- name: Check if repo branch exists + ansible.builtin.assert: + that: result.json.name == bootstrap_github_repository_branch + success_msg: Github repo branch {{ bootstrap_github_repository_branch }} exists + fail_msg: Github repo branch {{ bootstrap_github_repository_branch }} does not exist diff --git a/bootstrap/tasks/validation/vars.yaml b/bootstrap/tasks/validation/vars.yaml index 5edc195f55e..9e81b7ee77f 100644 --- a/bootstrap/tasks/validation/vars.yaml +++ b/bootstrap/tasks/validation/vars.yaml @@ -16,6 +16,7 @@ - bootstrap_cluster_cidr - bootstrap_flux_github_webhook_token - bootstrap_github_repository_name + - bootstrap_github_repository_branch - bootstrap_github_username - bootstrap_external_ingress_addr - bootstrap_internal_ingress_addr diff --git a/bootstrap/templates/kubernetes/flux/config/cluster.yaml.j2 b/bootstrap/templates/kubernetes/flux/config/cluster.yaml.j2 index 6b6cb15f4a6..cbabaddb3af 100644 --- a/bootstrap/templates/kubernetes/flux/config/cluster.yaml.j2 +++ b/bootstrap/templates/kubernetes/flux/config/cluster.yaml.j2 @@ -7,7 +7,7 @@ metadata: spec: interval: 30m ref: - branch: main + branch: {{ bootstrap_github_repository_branch }} url: "https://github.com/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}.git" ignore: | # exclude all diff --git a/bootstrap/vars/config.sample.yaml b/bootstrap/vars/config.sample.yaml index 5c1d0102135..0e71c64ae3a 100644 --- a/bootstrap/vars/config.sample.yaml +++ b/bootstrap/vars/config.sample.yaml @@ -7,6 +7,8 @@ bootstrap_github_username: # Github repository (e.g. flux-cluster-template) bootstrap_github_repository_name: +# Github repository branch (e.g. main) +bootstrap_github_repository_branch: # Age Public Key (e.g. age15uzrw396e67z9wdzsxzdk7ka0g2gr3l460e0slaea563zll3hdfqwqxdta) bootstrap_age_public_key: # Choose your timezone (e.g. America/New_York)