Skip to content

Commit

Permalink
Remove custom Docker networks from integration tests
Browse files Browse the repository at this point in the history
Using custom networks makes CoreDNS's loop plugin detect a loop and
fail. Fix this by simply ripping out all custom network functionality
from the inttests. An alternative would have been to apply the
workarounds in k0s's Docker entrypoint also inside the inttests, but,
since the custom networks apparently didn't serve any special purpose,
deleting code is better than adding code.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Oct 18, 2023
1 parent 089dc71 commit 57b5560
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 165 deletions.
20 changes: 2 additions & 18 deletions inttest/airgap/airgap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ type AirgapSuite struct {
common.FootlooseSuite
}

const network = "airgap"

// SetupSuite creates the required network before starting footloose.
func (s *AirgapSuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *AirgapSuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

func (s *AirgapSuite) TestK0sGetsUp() {
err := (&common.Airgap{
SSH: s.SSH,
Expand Down Expand Up @@ -122,10 +108,8 @@ func (s *AirgapSuite) TestK0sGetsUp() {
func TestAirgapSuite(t *testing.T) {
s := AirgapSuite{
common.FootlooseSuite{
ControllerCount: 1,
WorkerCount: 1,
ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
ControllerCount: 1,
WorkerCount: 1,

AirgapImageBundleMountPoints: []string{"/var/lib/k0s/images/bundle.tar"},
},
Expand Down
17 changes: 0 additions & 17 deletions inttest/ap-airgap/airgap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ type airgapSuite struct {
common.FootlooseSuite
}

const network = "ap-airgap"

// SetupSuite creates the required network before starting footloose.
func (s *airgapSuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *airgapSuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

// SetupTest prepares the controller and filesystem, getting it into a consistent
// state which we can run tests against.
func (s *airgapSuite) SetupTest() {
Expand Down Expand Up @@ -157,9 +143,6 @@ func TestAirgapSuite(t *testing.T) {
LaunchMode: common.LaunchModeOpenRC,

AirgapImageBundleMountPoints: []string{"/dist/bundle.tar"},

ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
},
})
}
17 changes: 0 additions & 17 deletions inttest/ap-ha3x3/ha3x3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ spec:
externalAddress: %s
`

const network = "ha3x3net"

// SetupSuite creates the required network before starting footloose.
func (s *ha3x3Suite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *ha3x3Suite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

// SetupTest prepares the controller and filesystem, getting it into a consistent
// state which we can run tests against.
func (s *ha3x3Suite) SetupTest() {
Expand Down Expand Up @@ -195,9 +181,6 @@ func TestHA3x3Suite(t *testing.T) {
WorkerCount: 3,
WithLB: true,
LaunchMode: common.LaunchModeOpenRC,

ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
},
})
}
17 changes: 0 additions & 17 deletions inttest/ap-quorum/quorum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ spec:
externalAddress: %s
`

const network = "quorumnet"

// SetupSuite creates the required network before starting footloose.
func (s *quorumSuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *quorumSuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

// SetupTest prepares the controller and filesystem, getting it into a consistent
// state which we can run tests against.
func (s *quorumSuite) SetupTest() {
Expand Down Expand Up @@ -152,9 +138,6 @@ func TestQuorumSuite(t *testing.T) {
ControllerCount: 3,
WorkerCount: 0,
LaunchMode: common.LaunchModeOpenRC,

ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
},
})
}
17 changes: 0 additions & 17 deletions inttest/ap-quorumsafety/quorumsafety_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ spec:
externalAddress: %s
`

const network = "quorumsafetynet"

// SetupSuite creates the required network before starting footloose.
func (s *quorumSafetySuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *quorumSafetySuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

// SetupTest prepares the controller and filesystem, getting it into a consistent
// state which we can run tests against.
func (s *quorumSafetySuite) SetupTest() {
Expand Down Expand Up @@ -163,9 +149,6 @@ func TestQuorumSafetySuite(t *testing.T) {
ControllerCount: 2,
WorkerCount: 0,
LaunchMode: common.LaunchModeOpenRC,

ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
},
})
}
14 changes: 0 additions & 14 deletions inttest/ap-selector/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ spec:
externalAddress: %s
`

const network = "selectornet"

// SetupSuite creates the required network before starting footloose.
func (s *selectorSuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *selectorSuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

// SetupTest prepares the controller and filesystem, getting it into a consistent
// state which we can run tests against.
func (s *selectorSuite) SetupTest() {
Expand Down
49 changes: 1 addition & 48 deletions inttest/common/footloosesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ type FootlooseSuite struct {
K0smotronWorkerCount int
WithUpdateServer bool
K0sUpdateVersion string
ControllerNetworks []string
WorkerNetworks []string
K0smotronNetworks []string
FootLooseImage string

ctx context.Context
Expand Down Expand Up @@ -608,13 +605,7 @@ func (s *FootlooseSuite) getControllersIPAddresses() []string {
s.Require().NoError(err)

for i := 0; i < s.ControllerCount; i++ {
// If a network is supplied, the address will need to be obtained from there.
// Note that this currently uses the first network found.
if machines[i].Status().IP != "" {
addresses[i] = machines[i].Status().IP
} else if len(machines[i].Status().RuntimeNetworks) > 0 {
addresses[i] = machines[i].Status().RuntimeNetworks[0].IP
}
addresses[i] = machines[i].Status().IP
}
return addresses
}
Expand Down Expand Up @@ -1196,7 +1187,6 @@ func (s *FootlooseSuite) initializeFootlooseClusterInDir(dir string) error {
Privileged: true,
Volumes: volumes,
PortMappings: portMaps,
Networks: s.ControllerNetworks,
},
},
{
Expand All @@ -1207,7 +1197,6 @@ func (s *FootlooseSuite) initializeFootlooseClusterInDir(dir string) error {
Privileged: true,
Volumes: volumes,
PortMappings: portMaps,
Networks: s.WorkerNetworks,
},
},
{
Expand All @@ -1218,7 +1207,6 @@ func (s *FootlooseSuite) initializeFootlooseClusterInDir(dir string) error {
Privileged: true,
Volumes: volumes,
PortMappings: portMaps,
Networks: s.K0smotronNetworks,
},
},
},
Expand All @@ -1233,7 +1221,6 @@ func (s *FootlooseSuite) initializeFootlooseClusterInDir(dir string) error {
Volumes: volumes,
PortMappings: portMaps,
Ignite: nil,
Networks: s.ControllerNetworks,
},
Count: 1,
})
Expand Down Expand Up @@ -1265,7 +1252,6 @@ func (s *FootlooseSuite) initializeFootlooseClusterInDir(dir string) error {
ContainerPort: 80,
},
},
Networks: s.ControllerNetworks,
},
Count: 1,
})
Expand Down Expand Up @@ -1351,39 +1337,6 @@ func (s *FootlooseSuite) getIPAddress(nodeName string) string {
return ipAddress
}

// CreateNetwork creates a docker network with the provided name, destroying
// any network that has the same name first.
func (s *FootlooseSuite) CreateNetwork(name string) error {
// Don't create the network if it already exists as it might be in use from previous tests
// ran with K0S_KEEP_AFTER_TEST variable set.
if s.NetworkExists(name) {
return nil
}

cmd := exec.Command("docker", "network", "create", name)
return cmd.Run()
}

// MaybeDestroyNetwork removes a docker network with the provided name.
// The network might not get removed if there's still containers attached to it.
// This is the case for example when running the tests with K0S_KEEP_AFTER_TEST=always.
func (s *FootlooseSuite) MaybeDestroyNetwork(name string) error {
// If we're supposed to leave the footloose containers running, don't try to destroy the network
if keepEnvironment(s.T()) {
return nil
}
cmd := exec.Command("docker", "network", "rm", name)
return cmd.Run()
}

// NetworkExists returns true if a docker network with the provided name exists.
func (s *FootlooseSuite) NetworkExists(name string) bool {
cmd := exec.Command("docker", "network", "inspect", name)
err := cmd.Run()

return err == nil
}

// RunCommandController runs a command via SSH on a specified controller node
func (s *FootlooseSuite) RunCommandController(idx int, command string) (string, error) {
ssh, err := s.SSH(s.Context(), s.ControllerNode(idx))
Expand Down
17 changes: 0 additions & 17 deletions inttest/kubeletcertrotate/kubeletcertrotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ type kubeletCertRotateSuite struct {
common.FootlooseSuite
}

const network = "kubeletcertrotatenet"

// SetupSuite creates the required network before starting footloose.
func (s *kubeletCertRotateSuite) SetupSuite() {
s.Require().NoError(s.CreateNetwork(network))
s.FootlooseSuite.SetupSuite()
}

// TearDownSuite tears down the network created after footloose has finished.
func (s *kubeletCertRotateSuite) TearDownSuite() {
s.FootlooseSuite.TearDownSuite()
s.Require().NoError(s.MaybeDestroyNetwork(network))
}

type statusJSON struct {
WorkerToAPIConnectionStatus status.ProbeStatus
}
Expand Down Expand Up @@ -189,9 +175,6 @@ func TestKubeletCertRotateSuite(t *testing.T) {
ControllerCount: 1,
WorkerCount: 1,
LaunchMode: common.LaunchModeOpenRC,

ControllerNetworks: []string{network},
WorkerNetworks: []string{network},
},
})
}

0 comments on commit 57b5560

Please sign in to comment.