Added advertise address integration test

Signed-off-by: Vitor Savian <vitor.savian@suse.com>
pull/8578/head
Vitor Savian 2023-10-05 17:11:14 -03:00 committed by GitHub
parent ba169d91eb
commit 8bfd2389fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 4 deletions

View File

@ -354,6 +354,27 @@ func K3sSaveLog(server *K3sServer, dump bool) error {
return nil return nil
} }
func GetEndpointsAddresses() (string, error) {
client, err := k8sClient()
if err != nil {
return "", err
}
endpoints, err := client.CoreV1().Endpoints("default").Get(context.Background(), "kubernetes", metav1.GetOptions{})
if err != nil {
return "", err
}
var addresses []string
for _, subset := range endpoints.Subsets {
for _, address := range subset.Addresses {
addresses = append(addresses, address.IP)
}
}
return strings.Join(addresses, ","), nil
}
// RunCommand Runs command on the host // RunCommand Runs command on the host
func RunCommand(cmd string) (string, error) { func RunCommand(cmd string) (string, error) {
c := exec.Command("bash", "-c", cmd) c := exec.Command("bash", "-c", cmd)

View File

@ -5,12 +5,12 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
v1 "k8s.io/api/core/v1"
testutil "github.com/k3s-io/k3s/tests/integration" testutil "github.com/k3s-io/k3s/tests/integration"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct" . "github.com/onsi/gomega/gstruct"
v1 "k8s.io/api/core/v1"
) )
var startupServer *testutil.K3sServer var startupServer *testutil.K3sServer
@ -85,12 +85,18 @@ var _ = Describe("startup tests", Ordered, func() {
It("creates dummy interfaces", func() { It("creates dummy interfaces", func() {
Expect(testutil.RunCommand("ip link add dummy2 type dummy")).To(Equal("")) Expect(testutil.RunCommand("ip link add dummy2 type dummy")).To(Equal(""))
Expect(testutil.RunCommand("ip link add dummy3 type dummy")).To(Equal("")) Expect(testutil.RunCommand("ip link add dummy3 type dummy")).To(Equal(""))
Expect(testutil.RunCommand("ip link add dummy4 type dummy")).To(Equal(""))
Expect(testutil.RunCommand("ip addr add 11.22.33.44/24 dev dummy2")).To(Equal("")) Expect(testutil.RunCommand("ip addr add 11.22.33.44/24 dev dummy2")).To(Equal(""))
Expect(testutil.RunCommand("ip addr add 55.66.77.88/24 dev dummy3")).To(Equal("")) Expect(testutil.RunCommand("ip addr add 55.66.77.88/24 dev dummy3")).To(Equal(""))
Expect(testutil.RunCommand("ip addr add 11.11.22.22/24 dev dummy4")).To(Equal(""))
}) })
It("is created with node-ip arguments", func() { It("is created with node-ip arguments", func() {
var err error var err error
startupServerArgs = []string{"--node-ip", "11.22.33.44", "--node-external-ip", "55.66.77.88"} startupServerArgs = []string{
"--node-ip", "11.22.33.44",
"--node-external-ip", "55.66.77.88",
"--advertise-address", "11.11.22.22",
}
startupServer, err = testutil.K3sStartServer(startupServerArgs...) startupServer, err = testutil.K3sStartServer(startupServerArgs...)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })
@ -110,13 +116,20 @@ var _ = Describe("startup tests", Ordered, func() {
{ {
Type: "ExternalIP", Type: "ExternalIP",
Address: "55.66.77.88", Address: "55.66.77.88",
}})) },
}))
})
It("get the kubectl and see if has the right advertise ip", func() {
apiInfo, err := testutil.GetEndpointsAddresses()
Expect(err).ToNot(HaveOccurred())
Expect(apiInfo).To(ContainSubstring("11.11.22.22"))
}) })
It("dies cleanly", func() { It("dies cleanly", func() {
Expect(testutil.K3sKillServer(startupServer)).To(Succeed()) Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
Expect(testutil.K3sCleanup(-1, "")).To(Succeed()) Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
Expect(testutil.RunCommand("ip link del dummy2")).To(Equal("")) Expect(testutil.RunCommand("ip link del dummy2")).To(Equal(""))
Expect(testutil.RunCommand("ip link del dummy3")).To(Equal("")) Expect(testutil.RunCommand("ip link del dummy3")).To(Equal(""))
Expect(testutil.RunCommand("ip link del dummy4")).To(Equal(""))
}) })
}) })
When("a server with different data-dir is created", func() { When("a server with different data-dir is created", func() {
@ -250,6 +263,7 @@ var _ = Describe("startup tests", Ordered, func() {
Expect(testutil.K3sCleanup(-1, "")).To(Succeed()) Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
}) })
}) })
}) })
var failed bool var failed bool