Skip to content

Commit

Permalink
Obtain konnectivity pod logs
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Sep 18, 2023
1 parent 51b1e4c commit 23abd96
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 89 deletions.
52 changes: 0 additions & 52 deletions inttest/Makefile.variables
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
smoketests := \
check-addons \
check-airgap \
check-ap-airgap \
check-ap-ha3x3 \
check-ap-platformselect \
check-ap-quorum \
check-ap-quorumsafety \
check-ap-removedapis \
check-ap-selector \
check-ap-single \
check-ap-updater \
check-backup \
check-basic \
check-byocri \
check-calico \
check-capitalhostnames \
check-cli \
check-clusterreboot \
check-cnichange \
check-configchange \
check-containerdimports \
check-ctr \
check-custom-cidrs \
check-customca \
check-customdomain \
check-customports \
check-customports-dynamicconfig \
check-defaultstorage \
check-disabledcomponents \
check-dualstack \
check-dualstack-dynamicconfig \
check-embedded-binaries \
check-externaletcd \
check-extraargs \
check-hacontrolplane \
check-hostnameoverride \
check-k0scloudprovider \
check-k0sctl \
check-kine \
check-kubectl \
check-kubeletcertrotate \
check-kuberouter \
check-metrics \
check-metricsscraper \
check-multicontroller \
check-network-conformance-calico \
check-network-conformance-kuberouter \
check-nllb \
check-noderole \
check-noderole-no-taints \
check-noderole-single \
check-psp \
check-singlenode \
check-statussocket \
check-upgrade \
138 changes: 101 additions & 37 deletions inttest/dualstack/dualstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ package dualstack
// have proper values for spec.PodCIDRs

import (
"bufio"
"fmt"
"io"
"net"
"os"
"strings"
"sync"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"golang.org/x/sync/errgroup"
v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"

"testing"
Expand Down Expand Up @@ -86,15 +91,18 @@ func (s *DualstackSuite) cmdlineForExecutable(node, binary string) []string {
}

func (s *DualstackSuite) SetupSuite() {

isDockerIPv6Enabled, err := s.IsDockerIPv6Enabled()
s.NoError(err)
s.Require().True(isDockerIPv6Enabled, "Please enable IPv6 in docker before running this test")
s.FootlooseSuite.SetupSuite()

ctx := s.Context()

s.PutFile(s.ControllerNode(0), "/tmp/k0s.yaml", k0sConfigWithDualStack)
controllerArgs := []string{
"--config=/tmp/k0s.yaml",
"--disable-components=konnectivity-server,metrics-server",
//"--disable-components=konnectivity-server,metrics-server",
}
if os.Getenv("K0S_ENABLE_DYNAMIC_CONFIG") == "true" {
s.T().Log("Enabling dynamic config for controller")
Expand All @@ -115,7 +123,7 @@ func (s *DualstackSuite) SetupSuite() {
restConfig, err := s.GetKubeConfig("controller0", "")
s.Require().NoError(err)

createdTargetPod, err := kc.CoreV1().Pods("default").Create(s.Context(), &corev1.Pod{
createdTargetPod, err := kc.CoreV1().Pods("default").Create(ctx, &corev1.Pod{
TypeMeta: metav1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{Name: "nginx-worker0"},
Spec: corev1.PodSpec{
Expand All @@ -126,12 +134,12 @@ func (s *DualstackSuite) SetupSuite() {
},
}, metav1.CreateOptions{})
s.Require().NoError(err)
s.Require().NoError(common.WaitForPod(s.Context(), kc, "nginx-worker0", "default"), "nginx-worker0 pod did not start")
s.Require().NoError(common.WaitForPod(ctx, kc, "nginx-worker0", "default"), "nginx-worker0 pod did not start")

targetPod, err := kc.CoreV1().Pods(createdTargetPod.Namespace).Get(s.Context(), createdTargetPod.Name, metav1.GetOptions{})
targetPod, err := kc.CoreV1().Pods(createdTargetPod.Namespace).Get(ctx, createdTargetPod.Name, metav1.GetOptions{})
s.Require().NoError(err)

sourcePod, err := kc.CoreV1().Pods("default").Create(s.Context(), &corev1.Pod{
sourcePod, err := kc.CoreV1().Pods("default").Create(ctx, &corev1.Pod{
TypeMeta: metav1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{Name: "nginx-worker1"},
Spec: corev1.PodSpec{
Expand All @@ -142,41 +150,97 @@ func (s *DualstackSuite) SetupSuite() {
},
}, metav1.CreateOptions{})
s.Require().NoError(err)
s.NoError(common.WaitForPod(s.Context(), kc, "nginx-worker1", "default"), "nginx-worker1 pod did not start")

// test ipv6 address
err = wait.PollImmediateWithContext(s.Context(), 100*time.Millisecond, time.Minute, func(ctx context.Context) (done bool, err error) {
s.Require().Equal(len(targetPod.Status.PodIPs), 2)
podIP := targetPod.Status.PodIPs[1].IP
targetIP := net.ParseIP(podIP)
s.Require().NotNil(targetIP)
out, err := common.PodExecCmdOutput(kc, restConfig, sourcePod.Name, sourcePod.Namespace, fmt.Sprintf("/usr/bin/wget -qO- %s", targetIP))
s.T().Log(out, err)
if err != nil {
s.T().Log("error calling ipv6 address: ", err)
return false, nil
}
s.T().Log("server response", out)
return strings.Contains(out, "Welcome to nginx"), nil
s.NoError(common.WaitForPod(ctx, kc, "nginx-worker1", "default"), "nginx-worker1 pod did not start")

eg, ctx := errgroup.WithContext(ctx)
s.T().Run("IPv6", func(t *testing.T) {
eg.Go(func() error {
return wait.PollImmediateWithContext(ctx, 100*time.Millisecond, time.Minute, func(ctx context.Context) (done bool, err error) {
if !assert.Equal(t, len(targetPod.Status.PodIPs), 2) {
return true, nil
}
podIP := targetPod.Status.PodIPs[0].IP
targetIP := net.ParseIP(podIP)
if !assert.NotEmpty(t, targetIP) {
return true, nil
}
out, err := common.PodExecCmdOutput(kc, restConfig, sourcePod.Name, sourcePod.Namespace, fmt.Sprintf("/usr/bin/wget -qO- %s", targetIP))
if err != nil {
t.Log(out, err)
t.Log("error calling ipv6 address: ", err)
return false, nil
}
assert.Contains(t, out, "Welcome to nginx")
return true, nil
})
})
})
s.Require().NoError(err)

// test ipv4 address
err = wait.PollImmediateWithContext(s.Context(), 100*time.Millisecond, time.Minute, func(ctx context.Context) (done bool, err error) {
s.Require().Equal(len(targetPod.Status.PodIPs), 2)
podIP := targetPod.Status.PodIPs[0].IP
targetIP := net.ParseIP(podIP)
s.Require().NotNil(targetIP)
out, err := common.PodExecCmdOutput(kc, restConfig, sourcePod.Name, sourcePod.Namespace, fmt.Sprintf("/usr/bin/wget -qO- %s", targetIP))
s.T().Log(out, err)
if err != nil {
s.T().Log("error calling ipv4 address: ", err)
return false, nil
}
s.T().Log("server response", out)
return strings.Contains(out, "Welcome to nginx"), nil
s.T().Run("IPv4", func(t *testing.T) {
eg.Go(func() error {
return wait.PollImmediateWithContext(ctx, 100*time.Millisecond, time.Minute, func(ctx context.Context) (done bool, err error) {
if !assert.Equal(t, len(targetPod.Status.PodIPs), 2) {
return true, nil
}
podIP := targetPod.Status.PodIPs[0].IP
targetIP := net.ParseIP(podIP)
if !assert.NotEmpty(t, targetIP) {
return true, nil
}
out, err := common.PodExecCmdOutput(kc, restConfig, sourcePod.Name, sourcePod.Namespace, fmt.Sprintf("/usr/bin/wget -qO- %s", targetIP))
if err != nil {
t.Log(out, err)
t.Log("error calling ipv4 address: ", err)
return false, nil
}
assert.Contains(t, out, "Welcome to nginx")
return true, nil
})
})
})
s.Require().NoError(err)

s.NoError(eg.Wait())
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

var wg sync.WaitGroup

for i := 0; i < s.WorkerCount; i++ {
nodeName := s.WorkerNode(i)
ssh, err := s.SSH(ctx, nodeName)
if !s.NoError(err) {
continue
}
defer ssh.Disconnect()

reader, writer := io.Pipe()

wg.Add(1)
go func() {
defer wg.Done()
defer reader.Close()
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
s.T().Logf("konnectivity-agent on %s: %s\n", nodeName, line)
}
s.NoError(scanner.Err())
}()

wg.Add(1)
go func() {
defer wg.Done()
defer writer.Close()
s.NoError(ssh.Exec(ctx,
"cat /var/log/containers/konnectivity-agent-*_kube-system_konnectivity-agent-*.log",
common.SSHStreams{Out: writer},
), "While retrieving konnectivity logs from %s", nodeName)
}()

}

wg.Wait()

s.client = client
}

Expand Down

0 comments on commit 23abd96

Please sign in to comment.