Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Jun 12, 2024
1 parent 8dd832b commit c5415a4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ help:
@echo ' EXTRA_GO_BUILD_FLAGS - extra flags to pass to the Go builder'
@echo ' EXTRA_GO_BUILD_FLAGS - extra flags to pass to the Go builder'


# Generate compile-commands.json using bear
.PHONY: compile-commands
compile-commands:
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/install/cilium/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (c *ciliumCLI) uninstall() error {
if c.opts.ChartDirectory != "" {
args = append(args, fmt.Sprintf("--chart-directory=%s", c.opts.ChartDirectory))
}
args = append(args, "--wait")

uninstallCmd := exec.Command(c.cmd, args...)
klog.Infof("Running cilium uninstall command %s", uninstallCmd)
Expand Down
45 changes: 45 additions & 0 deletions tests/e2e/install/tetragon/tetragon.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,49 @@ func processOpts(opts ...Option) *flags.HelmOptions {
return &defaultOpts
}

func Uninstall(opts ...Option) env.Func {
return func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
o := processOpts(opts...)
klog.InfoS("Uninstalling Tetragon...", "opts", o)

manager := helm.New(cfg.KubeconfigFile())

klog.InfoS("Uninstalling Tetragon...", "namespace", o.Namespace, "daemonset", o.DaemonSetName)

helmOpts := []helm.Option{
helm.WithName(o.DaemonSetName),
helm.WithNamespace(o.Namespace),
helm.WithWait(),
}

if err := manager.RunUninstall(helmOpts...); err != nil {
return ctx, fmt.Errorf("failed to uninstall via helm chart: %w", err)
}

if o.Wait {
client, err := cfg.NewClient()
if err != nil {
return ctx, err
}
r := client.Resources(o.Namespace)

ds := v1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: o.DaemonSetName,
Namespace: o.Namespace,
},
}

// Wait for Tetragon daemon set to be ready
klog.Info("Waiting for Tetragon DaemonSet to be removed...")
wait.For(conditions.New(r).ResourceDeleted(&ds))
klog.Info("Tetragon DaemonSet is removed!")
}

return context.WithValue(ctx, state.InstallOpts, o), nil
}
}

func Install(opts ...Option) env.Func {
return func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
o := processOpts(opts...)
Expand Down Expand Up @@ -170,6 +213,8 @@ func Install(opts ...Option) env.Func {

helmArgs.WriteString(" --install")

klog.InfoS("Installing Tetragon...", "namespace", o.Namespace, "daemonset", o.DaemonSetName)

helmOpts := []helm.Option{
helm.WithName(o.DaemonSetName),
helm.WithNamespace(o.Namespace),
Expand Down
27 changes: 25 additions & 2 deletions tests/e2e/runners/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ type PortForwardFunc func(env.Environment) env.Func
type Runner struct {
setupCluster SetupClusterFunc
installCilium env.Func
uninstallCilium env.Func
installTetragon env.Func
uninstallTetragon env.Func
tetragonPortForward PortForwardFunc
hasCalledInit bool
keepExportFiles bool
Expand All @@ -61,10 +63,23 @@ var DefaultRunner = Runner{
}
return ctx, nil
},
uninstallCilium: func(ctx context.Context, c *envconf.Config) (context.Context, error) {
client, err := c.NewClient()
if err != nil {
return ctx, err
}
// Only uninstall Cilium if it already exist
ciliumDs := &appsv1.DaemonSet{}
if err := client.Resources("kube-system").Get(ctx, "cilium", "kube-system", ciliumDs); err == nil {
return cilium.Finish(cilium.WithNamespace("kube-system"), cilium.WithVersion(flags.Opts.CiliumVersion))(ctx, c)
}
return ctx, nil
},
installTetragon: tetragon.Install(tetragon.WithHelmOptions(map[string]string{
"tetragon.exportAllowList": "",
"tetragon.enablePolicyFilter": "true",
})),
uninstallTetragon: tetragon.Uninstall(tetragon.WithHelmOptions(map[string]string{})),
tetragonPortForward: func(testenv env.Environment) env.Func {
return helpers.PortForwardTetragonPods(testenv)
},
Expand Down Expand Up @@ -173,6 +188,10 @@ func (r *Runner) Init() *Runner {
}
r.Setup(r.installTetragon)

if r.tetragonPortForward != nil {
r.Setup(r.tetragonPortForward(r.Environment))
}

// Store test success or failure
r.AfterEachTest(func(ctx context.Context, _ *envconf.Config, t *testing.T) (context.Context, error) {
if t.Failed() {
Expand Down Expand Up @@ -201,8 +220,12 @@ func (r *Runner) Init() *Runner {
return helpers.DumpInfo(ctx, c)
})

if r.tetragonPortForward != nil {
r.Setup(r.tetragonPortForward(r.Environment))
if r.uninstallTetragon != nil {
r.Finish(r.uninstallTetragon)
}

if r.uninstallCilium != nil && flags.Opts.InstallCilium {
r.Finish(r.uninstallCilium)
}

return r
Expand Down

0 comments on commit c5415a4

Please sign in to comment.