Skip to content

Commit 2601795

Browse files
committed
[ansibletest] Add ansibleGitBranch option
Allow selecting which branch checkout and run the ansible playbook This allows the playbook to be be run from different branches, which adds some flexibility: * The playbook can live on different branches, allowing for versioning of the playbook/tests. * The playbook can be tested in CI prior to merging Depends-On: openstack-k8s-operators/tcib#329
1 parent 574547d commit 2601795

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

api/bases/test.openstack.org_ansibletests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ spec:
6363
default: ""
6464
description: AnsibleExtraVars - string to pass parameters to ansible
6565
type: string
66+
ansibleGitBranch:
67+
description: AnsibleGitBranch - git branch to check out in the cloned
68+
repo
69+
format: string
70+
type: string
6671
ansibleGitRepo:
6772
description: AnsibleGitRepo - git repo to clone into container
6873
format: uri
@@ -1345,6 +1350,11 @@ spec:
13451350
description: AnsibleExtraVars - interface to pass parameters
13461351
to ansible using -e
13471352
type: string
1353+
ansibleGitBranch:
1354+
description: AnsibleGitBranch - git branch to check out in the
1355+
cloned repo
1356+
format: string
1357+
type: string
13481358
ansibleGitRepo:
13491359
description: AnsibleGitRepo - git repo to clone into container
13501360
format: uri

api/v1beta1/ansibletest_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ type AnsibleTestSpec struct {
5454
// AnsibleGitRepo - git repo to clone into container
5555
AnsibleGitRepo string `json:"ansibleGitRepo"`
5656

57+
// +kubebuilder:validation:Optional
58+
// +kubebuilder:validation:Format=string
59+
// +operator-sdk:csv:customresourcedefinitions:type=spec
60+
// AnsibleGitBranch - git branch to check out in the cloned repo
61+
AnsibleGitBranch string `json:"ansibleGitBranch,omitEmpty"`
62+
5763
// +kubebuilder:validation:Required
5864
// +operator-sdk:csv:customresourcedefinitions:type=spec
5965
// +kubebuilder:default:=""
@@ -134,6 +140,12 @@ type AnsibleTestWorkflowSpec struct {
134140
// AnsibleGitRepo - git repo to clone into container
135141
AnsibleGitRepo string `json:"ansibleGitRepo,omitempty"`
136142

143+
// +kubebuilder:validation:Optional
144+
// +kubebuilder:validation:Format=string
145+
// +operator-sdk:csv:customresourcedefinitions:type=spec
146+
// AnsibleGitBranch - git branch to check out in the cloned repo
147+
AnsibleGitBranch string `json:"ansibleGitBranch,omitEmpty"`
148+
137149
// +kubebuilder:validation:Optional
138150
// +operator-sdk:csv:customresourcedefinitions:type=spec
139151
// AnsiblePlaybookPath - path to ansible playbook

config/crd/bases/test.openstack.org_ansibletests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ spec:
6363
default: ""
6464
description: AnsibleExtraVars - string to pass parameters to ansible
6565
type: string
66+
ansibleGitBranch:
67+
description: AnsibleGitBranch - git branch to check out in the cloned
68+
repo
69+
format: string
70+
type: string
6671
ansibleGitRepo:
6772
description: AnsibleGitRepo - git repo to clone into container
6873
format: uri
@@ -1345,6 +1350,11 @@ spec:
13451350
description: AnsibleExtraVars - interface to pass parameters
13461351
to ansible using -e
13471352
type: string
1353+
ansibleGitBranch:
1354+
description: AnsibleGitBranch - git branch to check out in the
1355+
cloned repo
1356+
format: string
1357+
type: string
13481358
ansibleGitRepo:
13491359
description: AnsibleGitRepo - git repo to clone into container
13501360
format: uri

config/manifests/bases/test-operator.clusterserviceversion.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ spec:
3333
- description: AnsibleExtraVars - string to pass parameters to ansible
3434
displayName: Ansible Extra Vars
3535
path: ansibleExtraVars
36+
- description: AnsibleGitBranch - git branch to check out in the cloned repo
37+
displayName: Ansible Git Branch
38+
path: ansibleGitBranch
3639
- description: AnsibleGitRepo - git repo to clone into container
3740
displayName: Ansible Git Repo
3841
path: ansibleGitRepo
@@ -56,7 +59,7 @@ spec:
5659
- description: ComputeSSHKeySecretName is the name of the k8s secret that contains
5760
an ssh key for computes. The key is mounted to ~/.ssh/id_ecdsa in the ansible
5861
pod
59-
displayName: Computes SSHKey Secret Name
62+
displayName: Compute SSHKey Secret Name
6063
path: computeSSHKeySecretName
6164
- description: A URL of a container image that should be used by the test-operator
6265
for tests execution.
@@ -131,6 +134,9 @@ spec:
131134
-e
132135
displayName: Ansible Extra Vars
133136
path: workflow[0].ansibleExtraVars
137+
- description: AnsibleGitBranch - git branch to check out in the cloned repo
138+
displayName: Ansible Git Branch
139+
path: workflow[0].ansibleGitBranch
134140
- description: AnsibleGitRepo - git repo to clone into container
135141
displayName: Ansible Git Repo
136142
path: workflow[0].ansibleGitRepo
@@ -154,7 +160,7 @@ spec:
154160
- description: ComputeSSHKeySecretName is the name of the k8s secret that contains
155161
an ssh key for computes. The key is mounted to ~/.ssh/id_ecdsa in the ansible
156162
pod
157-
displayName: Computes SSHKey Secret Name
163+
displayName: Compute SSHKey Secret Name
158164
path: workflow[0].computeSSHKeySecretName
159165
- description: A URL of a container image that should be used by the test-operator
160166
for tests execution.

controllers/ansibletest_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ func (r *AnsibleTestReconciler) PrepareAnsibleEnv(
290290
envVars["POD_ANSIBLE_FILE_EXTRA_VARS"] = env.SetValue(instance.Spec.AnsibleVarFiles)
291291
envVars["POD_ANSIBLE_INVENTORY"] = env.SetValue(instance.Spec.AnsibleInventory)
292292
envVars["POD_ANSIBLE_GIT_REPO"] = env.SetValue(instance.Spec.AnsibleGitRepo)
293+
envVars["POD_ANSIBLE_GIT_BRANCH"] = env.SetValue(instance.Spec.AnsibleGitBranch)
293294
envVars["POD_ANSIBLE_PLAYBOOK"] = env.SetValue(instance.Spec.AnsiblePlaybookPath)
294295
envVars["POD_INSTALL_COLLECTIONS"] = env.SetValue(instance.Spec.AnsibleCollections)
295296

0 commit comments

Comments
 (0)