Skip to content

Commit 00c6858

Browse files
committed
Unify SSH key mount path format across all dataplane services
Previously, the SSH key mount path differed between global services (DeployOnAllNodeSets=true) and non-global services: - Global services: /runner/env/ssh_key/ssh_key_<nodesetname> - Non-global services: /runner/env/ssh_key The non-global services path happened to work because ansible-runner has a built-in mechanism that looks for an SSH key at /runner/env/ssh_key and automatically loads it into ssh-agent. However, this relied on ansible-runner's implicit behavior rather than the explicit ansible_ssh_private_key_file variable set in the inventory. The inventory always sets ansible_ssh_private_key_file to /runner/env/ssh_key/ssh_key_<nodesetname> regardless of service type (see inventory.go line 178). This inconsistency meant non-global services were mounting the SSH key at a different path than what Ansible expected from the inventory variable, relying on ansible-runner's fallback behavior. However, there were errors in ansible logs as there were no files in /runner/env/ssh_key/ssh_key_<nodesetname> which was confusing to users. This change unifies the SSH key mount path to always use the format: /runner/env/ssh_key/ssh_key_<nodesetname> This ensures: 1. The mount path matches the ansible_ssh_private_key_file variable set in the inventory for all service types 2. Explicit and consistent SSH key configuration rather than relying on ansible-runner's implicit ssh-agent loading 3. Simplified code by removing the conditional branching 4. Consistent behavior between global and non-global services For global services, multiple SSH keys are mounted (one per nodeset) in the ssh_key folder. For non-global services, only the matching nodeset's key is mounted, but at the same path format. Assisted-by: Claude-4.5-opus Signed-off-by: rabi <[email protected]>
1 parent c2b767a commit 00c6858

File tree

16 files changed

+225
-228
lines changed

16 files changed

+225
-228
lines changed

internal/dataplane/util/ansible_execution.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,14 @@ func SetAeeSSHMounts(
316316

317317
for _, sshKeyNodeName := range sshKeys {
318318
sshKeySecret := sshKeySecrets[sshKeyNodeName]
319-
if service.Spec.DeployOnAllNodeSets {
320-
sshKeyName = fmt.Sprintf("ssh-key-%s", sshKeyNodeName)
321-
sshKeyMountSubPath = fmt.Sprintf("ssh_key_%s", sshKeyNodeName)
322-
sshKeyMountPath = fmt.Sprintf("/runner/env/ssh_key/%s", sshKeyMountSubPath)
323-
} else {
324-
if sshKeyNodeName != nodeSet.GetName() {
325-
continue
326-
}
327-
sshKeyName = "ssh-key"
328-
sshKeyMountSubPath = "ssh_key"
329-
sshKeyMountPath = "/runner/env/ssh_key"
319+
if !service.Spec.DeployOnAllNodeSets && sshKeyNodeName != nodeSet.GetName() {
320+
continue
330321
}
331322

323+
sshKeyName = fmt.Sprintf("ssh-key-%s", sshKeyNodeName)
324+
sshKeyMountSubPath = fmt.Sprintf("ssh_key_%s", sshKeyNodeName)
325+
sshKeyMountPath = fmt.Sprintf("/runner/env/ssh_key/%s", sshKeyMountSubPath)
326+
332327
CreateVolume(ansibleEEMounts, sshKeyName, sshKeyMountSubPath, sshKeySecret, "ssh-privatekey")
333328
CreateVolumeMount(ansibleEEMounts, sshKeyName, sshKeyMountPath, sshKeyMountSubPath)
334329
}

test/functional/dataplane/openstackdataplanenodeset_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,11 @@ var _ = Describe("Dataplane NodeSet Test", func() {
13871387
ansibleEE := GetAnsibleee(ansibleeeName)
13881388
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).To(HaveLen(3))
13891389
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[0].Name).To(Equal("bootstrap-combined-ca-bundle"))
1390-
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].Name).To(Equal("ssh-key"))
1390+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].Name).To(Equal("ssh-key-edpm-compute-nodeset"))
13911391
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].Name).To(Equal("inventory"))
13921392
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[0].VolumeSource.Secret.SecretName).To(Equal("combined-ca-bundle"))
13931393
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.SecretName).To(Equal("dataplane-ansible-ssh-private-key-secret"))
1394-
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.Items[0].Path).To(Equal("ssh_key"))
1394+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.Items[0].Path).To(Equal("ssh_key_edpm-compute-nodeset"))
13951395
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.Items[0].Key).To(Equal("ssh-privatekey"))
13961396

13971397
}, th.Timeout, th.Interval).Should(Succeed())
@@ -1455,12 +1455,12 @@ var _ = Describe("Dataplane NodeSet Test", func() {
14551455
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).To(HaveLen(4))
14561456
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[0].Name).To(Equal("edpm-ansible"))
14571457
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].Name).To(Equal("bootstrap-combined-ca-bundle"))
1458-
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].Name).To(Equal("ssh-key"))
1458+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].Name).To(Equal("ssh-key-edpm-compute-nodeset"))
14591459
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[3].Name).To(Equal("inventory"))
14601460
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName).To(Equal("edpm-ansible"))
14611461
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.SecretName).To(Equal("combined-ca-bundle"))
14621462
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].VolumeSource.Secret.SecretName).To(Equal("dataplane-ansible-ssh-private-key-secret"))
1463-
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].VolumeSource.Secret.Items[0].Path).To(Equal("ssh_key"))
1463+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].VolumeSource.Secret.Items[0].Path).To(Equal("ssh_key_edpm-compute-nodeset"))
14641464
g.Expect(ansibleEE.Spec.Template.Spec.Volumes[2].VolumeSource.Secret.Items[0].Key).To(Equal("ssh-privatekey"))
14651465

14661466
}, th.Timeout, th.Interval).Should(Succeed())

0 commit comments

Comments
 (0)