Skip to content

Commit

Permalink
Added advertise address integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Savian <vitor.savian@suse.com>
  • Loading branch information
vitorsavian committed Oct 5, 2023
1 parent e7e7615 commit c928fb0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 21 additions & 0 deletions tests/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,27 @@ func K3sSaveLog(server *K3sServer, dump bool) error {
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
func RunCommand(cmd string) (string, error) {
c := exec.Command("bash", "-c", cmd)
Expand Down
22 changes: 18 additions & 4 deletions tests/integration/startup/startup_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"path/filepath"
"testing"

v1 "k8s.io/api/core/v1"

testutil "github.com/k3s-io/k3s/tests/integration"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/onsi/gomega/gstruct"
v1 "k8s.io/api/core/v1"
)

var startupServer *testutil.K3sServer
Expand Down Expand Up @@ -85,12 +85,18 @@ var _ = Describe("startup tests", Ordered, func() {
It("creates dummy interfaces", func() {
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 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 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() {
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...)
Expect(err).ToNot(HaveOccurred())
})
Expand All @@ -110,13 +116,20 @@ var _ = Describe("startup tests", Ordered, func() {
{
Type: "ExternalIP",
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() {
Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
Expect(testutil.RunCommand("ip link del dummy2")).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() {
Expand Down Expand Up @@ -250,6 +263,7 @@ var _ = Describe("startup tests", Ordered, func() {
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
})
})

})

var failed bool
Expand Down

0 comments on commit c928fb0

Please sign in to comment.