Add VM host aliases to jumphost
This allows these host aliases to be used with any tool available in the jumphost, rather than needing to build wrapper scripts around each of them just to do VM IP lookup. Change-Id: I58a9ba457f9057c391694994fbedc722de2cc7d8
This commit is contained in:
parent
116bddc80d
commit
6fa7c3f141
@ -114,12 +114,32 @@ func (jh jumpHost) generateDeployment(instance string, labels map[string]string)
|
||||
},
|
||||
},
|
||||
},
|
||||
HostAliases: jh.generateHostAliases(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (jh jumpHost) generateHostAliases() []corev1.HostAlias {
|
||||
hostAliases := []corev1.HostAlias{}
|
||||
for _, machine := range jh.machines.Machines {
|
||||
namespace := machine.BMH.Namespace
|
||||
name := machine.BMH.Name
|
||||
ip, exists := machine.Data.IPOnInterface[jh.config.NodeInterface]
|
||||
if !exists {
|
||||
jh.logger.Info("Machine does not have ip to be aliased",
|
||||
"interface", jh.config.NodeInterface,
|
||||
"machine", namespace+"/"+name,
|
||||
)
|
||||
continue
|
||||
}
|
||||
hostname := machine.BMH.Name
|
||||
hostAliases = append(hostAliases, corev1.HostAlias{IP: ip, Hostnames: []string{hostname}})
|
||||
}
|
||||
return hostAliases
|
||||
}
|
||||
|
||||
func (jh jumpHost) generateService(instance string, labels map[string]string) *corev1.Service {
|
||||
return &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
airshipv1 "sipcluster/pkg/api/v1"
|
||||
|
||||
metal3 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
@ -16,18 +17,26 @@ import (
|
||||
"sipcluster/testutil"
|
||||
)
|
||||
|
||||
const (
|
||||
ip1 = "192.168.0.1"
|
||||
ip2 = "192.168.0.2"
|
||||
)
|
||||
|
||||
var bmh1 *metal3.BareMetalHost
|
||||
var bmh2 *metal3.BareMetalHost
|
||||
|
||||
var _ = Describe("Service Set", func() {
|
||||
Context("When new SIP cluster is created", func() {
|
||||
It("Deploys services", func() {
|
||||
By("Getting machine IPs and creating secrets, pods, and nodeport service")
|
||||
|
||||
bmh1, _ := testutil.CreateBMH(1, "default", "control-plane", 1)
|
||||
bmh2, _ := testutil.CreateBMH(2, "default", "control-plane", 2)
|
||||
bmh1, _ = testutil.CreateBMH(1, "default", "control-plane", 1)
|
||||
bmh2, _ = testutil.CreateBMH(2, "default", "control-plane", 2)
|
||||
m1 := &vbmh.Machine{
|
||||
BMH: *bmh1,
|
||||
Data: &vbmh.MachineData{
|
||||
IPOnInterface: map[string]string{
|
||||
"eno3": "192.168.0.1",
|
||||
"eno3": ip1,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -35,7 +44,7 @@ var _ = Describe("Service Set", func() {
|
||||
BMH: *bmh2,
|
||||
Data: &vbmh.MachineData{
|
||||
IPOnInterface: map[string]string{
|
||||
"eno3": "192.168.0.2",
|
||||
"eno3": ip2,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -101,6 +110,17 @@ func testDeployment(sip *airshipv1.SIPCluster) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jumpHostHostAliases := jumpHostDeployment.Spec.Template.Spec.HostAliases
|
||||
Expect(jumpHostHostAliases).To(ConsistOf(
|
||||
corev1.HostAlias{
|
||||
IP: ip1,
|
||||
Hostnames: []string{bmh1.GetName()},
|
||||
},
|
||||
corev1.HostAlias{
|
||||
IP: ip2,
|
||||
Hostnames: []string{bmh2.GetName()},
|
||||
},
|
||||
))
|
||||
|
||||
jumpHostService := &corev1.Service{}
|
||||
err = k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
|
Loading…
x
Reference in New Issue
Block a user