-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable ip_forward, disable arp_ignore arp_filter (#1484)
* feat: enable ip_forward, disable arp_ignore arp_filter we are now enabling ip_forward on the node, this is required for the embedded-cluster to work properly. we are also disabling arp_ignore and arp_filter to make sure the system is prepared for calico. * chore: do not fail if unable to config sysctl * feat: does not fail if unable to write sysctl config we only fail if the sysctl binary is not present on the system as we know that preflights depend on it. if we fail to configure sysctl we just move on as the preflights are expected to fail later on. * feat: config sysctl on 'run-prelights' command we need to configure sysctl before running the preflights. * chore: add unit tests for the new functions added unit tests around the sysctl configuation functions.
- Loading branch information
1 parent
3f4d8bd
commit d44af2b
Showing
11 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package configutils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/replicatedhq/embedded-cluster/pkg/defaults" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigureSysctl(t *testing.T) { | ||
basedir, err := os.MkdirTemp("", "embedded-cluster-test-base-dir") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(basedir) | ||
|
||
orig := sysctlConfigPath | ||
defer func() { | ||
sysctlConfigPath = orig | ||
}() | ||
|
||
provider := defaults.NewProvider(basedir) | ||
|
||
// happy path. | ||
dstdir, err := os.MkdirTemp("", "embedded-cluster-test") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dstdir) | ||
|
||
sysctlConfigPath = filepath.Join(dstdir, "sysctl.conf") | ||
err = ConfigureSysctl(provider) | ||
assert.NoError(t, err) | ||
|
||
// check that the file exists. | ||
_, err = os.Stat(sysctlConfigPath) | ||
assert.NoError(t, err) | ||
|
||
// now use a non-existing directory. | ||
sysctlConfigPath = filepath.Join(dstdir, "non-existing-dir", "sysctl.conf") | ||
// we do not expect an error here. | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package goods | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMaterializer_SysctlConfig(t *testing.T) { | ||
m := NewMaterializer(nil) | ||
|
||
// happy path. | ||
dstdir, err := os.MkdirTemp("", "embedded-cluster-test") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dstdir) | ||
|
||
dstpath := filepath.Join(dstdir, "sysctl.conf") | ||
err = m.SysctlConfig(dstpath) | ||
assert.NoError(t, err) | ||
|
||
expected, err := os.ReadFile(dstpath) | ||
assert.NoError(t, err) | ||
|
||
content, err := staticfs.ReadFile("static/99-embedded-cluster.conf") | ||
assert.NoError(t, err) | ||
assert.Equal(t, string(expected), string(content)) | ||
|
||
// write to a non-existent directory. | ||
dstpath = filepath.Join(dstdir, "dir-does-not-exist", "sysctl.conf") | ||
err = m.SysctlConfig(dstpath) | ||
assert.Contains(t, err.Error(), "no such file or directory") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# this entry enables ip forwarding. this feature is necessary as embedded | ||
# cluster creates virtual network interfaces and need the traffic among them to | ||
# be forwarded. | ||
net.ipv4.ip_forward = 1 | ||
|
||
# arp filter and ignore need to be disabled otherwise we can't have arp | ||
# resolving across the calico network interfaces. | ||
net.ipv4.conf.default.arp_filter = 0 | ||
net.ipv4.conf.default.arp_ignore = 0 | ||
net.ipv4.conf.all.arp_filter = 0 | ||
net.ipv4.conf.all.arp_ignore = 0 |