Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove fatals and panics + fix loggings in init container #666

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions init/retina/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func run(args ...string) error {
// Get config
cfg, err := config.GetConfig(*configPath)
if err != nil {
l.Fatal("failed to get config", zap.Error(err))
return errors.Wrap(err, "failed to get config")
}

// Enable telemetry if applicationInsightsID is provided and telemetry is enabled in config.
Expand All @@ -59,10 +59,16 @@ func run(args ...string) error {
}

// Setup BPF
bpf.Setup(l)
err = bpf.Setup(l)
if err != nil {
return errors.Wrap(err, "failed to setup Retina bpf filesystem")
}

// Setup CiliumFS.
ciliumfs.Setup(l)
err = ciliumfs.Setup(l)
if err != nil {
return errors.Wrap(err, "failed to setup CiliumFS")
}

return nil
}
10 changes: 6 additions & 4 deletions pkg/bpf/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cilium/cilium/pkg/mountinfo"
plugincommon "github.com/microsoft/retina/pkg/plugin/common"
"github.com/microsoft/retina/pkg/plugin/filter"
"github.com/pkg/errors"
"go.uber.org/zap"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -53,25 +54,26 @@ func mountBpfFs() error {
return nil
}

func Setup(l *zap.Logger) {
func Setup(l *zap.Logger) error {
err := mountBpfFs()
if err != nil {
l.Panic("Failed to mount bpf filesystem", zap.Error(err))
return errors.Wrap(err, "failed to mount BPF filesystem")
}
l.Info("BPF filesystem mounted successfully", zap.String("path", plugincommon.FilterMapPath))

// Delete existing filter map file.
err = os.Remove(plugincommon.FilterMapPath + "/" + plugincommon.FilterMapName)
if err != nil && !os.IsNotExist(err) {
l.Panic("Failed to delete existing filter map file", zap.Error(err))
return errors.Wrap(err, "failed to delete existing filter map file")
}
l.Info("Deleted existing filter map file", zap.String("path", plugincommon.FilterMapPath), zap.String("Map name", plugincommon.FilterMapName))

// Initialize the filter map.
// This will create the filter map in kernel and pin it to /sys/fs/bpf.
_, err = filter.Init()
if err != nil {
l.Panic("Failed to initialize filter map", zap.Error(err))
return errors.Wrap(err, "failed to initialize filter map")
}
l.Info("Filter map initialized successfully", zap.String("path", plugincommon.FilterMapPath), zap.String("Map name", plugincommon.FilterMapName))
return nil
}
9 changes: 5 additions & 4 deletions pkg/ciliumfs/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package ciliumfs
import (
"os"

"github.com/pkg/errors"
"go.uber.org/zap"
)

const ciliumDir = "/var/run/cilium"

func Setup(l *zap.Logger) {
func Setup(l *zap.Logger) error {
// Create /var/run/cilium directory.
fp, err := os.Stat(ciliumDir)
if err != nil {
Expand All @@ -18,13 +19,13 @@ func Setup(l *zap.Logger) {
// Path does not exist. Create it.
err = os.MkdirAll("/var/run/cilium", 0o755) //nolint:gomnd // 0o755 is the permission mode.
if err != nil {
l.Error("Failed to create directory", zap.String("dir path", ciliumDir), zap.Error(err))
l.Panic("Failed to create directory", zap.String("dir path", ciliumDir), zap.Error(err))
return errors.Wrap(err, "failed to create Cilium directory")
}
} else {
// Some other error. Return.
l.Panic("Failed to stat directory", zap.String("dir path", ciliumDir), zap.Error(err))
return errors.Wrap(err, "failed to stat Cilium directory")
}
}
l.Info("Created directory", zap.String("dir path", ciliumDir), zap.Any("file", fp))
return nil
}
Loading