Skip to content

Commit c272a60

Browse files
committed
Address reviewer comments
1 parent 84813a3 commit c272a60

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

test/e2e/features/install.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Install ClusterExtension
88
And "test" catalog serves bundles
99
And Service account "olm-sa" with needed permissions is available in test namespace
1010

11-
Scenario Outline: Install latest available version from the default channel
11+
Scenario Outline: Install latest available version
1212
When ClusterExtension is applied
1313
"""
1414
apiVersion: olm.operatorframework.io/v1

test/e2e/features_test.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package e2e
22

33
import (
4-
//"context"
54
"fmt"
65
"log"
76
"os"
@@ -10,9 +9,6 @@ import (
109
"github.com/cucumber/godog"
1110
"github.com/cucumber/godog/colors"
1211
"github.com/spf13/pflag"
13-
ctrl "sigs.k8s.io/controller-runtime"
14-
//ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
15-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1612

1713
utils "github.com/operator-framework/operator-controller/internal/shared/util/testutils"
1814
"github.com/operator-framework/operator-controller/test/e2e/steps"
@@ -25,11 +21,7 @@ var opts = godog.Options{
2521
Concurrency: 1,
2622
}
2723

28-
var logOpts = zap.Options{}
29-
3024
func init() {
31-
flagSet := pflag.CommandLine
32-
flagSet.BoolVar(&logOpts.Development, "log.debug", false, "print debug log level")
3325
godog.BindCommandLineFlags("godog.", &opts)
3426
}
3527

@@ -38,9 +30,6 @@ func TestMain(m *testing.M) {
3830
pflag.Parse()
3931
opts.Paths = pflag.Args()
4032

41-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&logOpts)))
42-
43-
//opts.DefaultContext = ctrl.LoggerInto(context.Background(), ctrllog.Log)
4433
// run tests
4534
sc := godog.TestSuite{
4635
TestSuiteInitializer: InitializeSuite,
@@ -53,7 +42,7 @@ func TestMain(m *testing.M) {
5342

5443
path := os.Getenv("E2E_SUMMARY_OUTPUT")
5544
if path == "" {
56-
fmt.Printf("Note: E2E_SUMMARY_OUTPUT is unset; skipping summary generation\n")
45+
fmt.Println("Note: E2E_SUMMARY_OUTPUT is unset; skipping summary generation")
5746
} else {
5847
if err := utils.PrintSummary(path); err != nil {
5948
// Fail the run if alerts are found
@@ -72,7 +61,7 @@ func TestMain(m *testing.M) {
7261
}
7362

7463
func InitializeSuite(tc *godog.TestSuiteContext) {
75-
tc.BeforeSuite(steps.DetectEnabledFeatureGates)
64+
tc.BeforeSuite(steps.BeforeSuite)
7665
}
7766

7867
func InitializeScenario(sc *godog.ScenarioContext) {

test/e2e/steps/hooks.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
"strconv"
1111

1212
"github.com/cucumber/godog"
13+
"github.com/go-logr/logr"
14+
"github.com/spf13/pflag"
1315
"k8s.io/api/apps/v1"
1416
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
17+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1518
)
1619

1720
type resource struct {
@@ -35,8 +38,17 @@ const (
3538
scenarioContextKey contextKey = "scenario-context"
3639
)
3740

38-
var featureGates = map[string]bool{
39-
"WebhookProviderCertManager": true,
41+
var (
42+
logOpts = zap.Options{}
43+
featureGates = map[string]bool{
44+
"WebhookProviderCertManager": true,
45+
}
46+
logger logr.Logger
47+
)
48+
49+
func init() {
50+
flagSet := pflag.CommandLine
51+
flagSet.BoolVar(&logOpts.Development, "log.debug", false, "print debug log level")
4052
}
4153

4254
func RegisterHooks(sc *godog.ScenarioContext) {
@@ -46,7 +58,9 @@ func RegisterHooks(sc *godog.ScenarioContext) {
4658
sc.After(ScenarioCleanup)
4759
}
4860

49-
func DetectEnabledFeatureGates() {
61+
func BeforeSuite() {
62+
logger = zap.New(zap.UseFlagOptions(&logOpts))
63+
5064
raw, err := kubectl("get", "deployment", "-n", olmNamespace, olmDeploymentName, "-o", "json")
5165
if err != nil {
5266
return
@@ -95,9 +109,10 @@ func scenarioCtx(ctx context.Context) *scenarioContext {
95109

96110
func ScenarioCleanup(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
97111
sc := scenarioCtx(ctx)
98-
for _, p := range sc.backGroundCmds {
99-
p.Process.Kill() // nolint: errcheck // we don't care about the error here, we just want to kill the process
100-
p.Process.Wait() // nolint: errcheck // same as above, we just want to wait for the process to exit, and do not want to fail the test if it does not
112+
for _, bgCmd := range sc.backGroundCmds {
113+
if p := bgCmd.Process; p != nil {
114+
_ = p.Kill()
115+
}
101116
}
102117
if err != nil {
103118
return ctx, err

test/e2e/steps/steps.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
"github.com/google/go-containerregistry/pkg/crane"
2323
"github.com/prometheus/common/expfmt"
2424
"github.com/prometheus/common/model"
25+
"github.com/spf13/pflag"
2526
"github.com/stretchr/testify/require"
2627
appsv1 "k8s.io/api/apps/v1"
2728
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2829
"k8s.io/utils/ptr"
29-
"sigs.k8s.io/controller-runtime/pkg/log"
3030
"sigs.k8s.io/yaml"
3131
)
3232

@@ -37,7 +37,10 @@ const (
3737
tick = 1 * time.Second
3838
)
3939

40-
var kubeconfigPath string
40+
var (
41+
kubeconfigPath string
42+
k8sCli string
43+
)
4144

4245
func RegisterSteps(sc *godog.ScenarioContext) {
4346
sc.Step(`^OLM is available$`, OLMisAvailable)
@@ -68,23 +71,29 @@ func RegisterSteps(sc *godog.ScenarioContext) {
6871
}
6972

7073
func init() {
71-
kubeconfigPath = os.Getenv("HOME") + "/.kube/config"
74+
flagSet := pflag.CommandLine
75+
flagSet.StringVar(&k8sCli, "k8s.cli", "kubectl", "Path to k8s cli")
76+
if v, found := os.LookupEnv("KUBECONFIG"); found {
77+
kubeconfigPath = v
78+
} else {
79+
home, err := os.UserHomeDir()
80+
if err != nil {
81+
panic(fmt.Sprintf("cannot determine user home directory: %v", err))
82+
}
83+
flagSet.StringVar(&kubeconfigPath, "kubeconfig", filepath.Join(home, ".kube", "config"), "Paths to a kubeconfig. Only required if out-of-cluster.")
84+
}
7285
}
7386

74-
var (
75-
logger = log.Log
76-
)
77-
7887
func kubectl(args ...string) (string, error) {
79-
cmd := exec.Command("kubectl", args...)
80-
logger.V(1).Info(strings.Join(cmd.Args, " "))
88+
cmd := exec.Command(k8sCli, args...)
89+
logger.V(1).Info("Running", "command", strings.Join(cmd.Args, " "))
8190
cmd.Env = append(os.Environ(), fmt.Sprintf("KUBECONFIG=%s", kubeconfigPath))
8291
b, err := cmd.Output()
8392
return string(b), err
8493
}
8594

8695
func kubectlWithInput(yaml string, args ...string) (string, error) {
87-
cmd := exec.Command("kubectl", args...)
96+
cmd := exec.Command(k8sCli, args...)
8897
cmd.Stdin = bytes.NewBufferString(yaml)
8998
cmd.Env = append(os.Environ(), fmt.Sprintf("KUBECONFIG=%s", kubeconfigPath))
9099
b, err := cmd.Output()
@@ -143,15 +152,13 @@ func ResourceApplyFails(ctx context.Context, errMsg string, yamlTemplate *godog.
143152
_, err := kubectlWithInput(yamlContent, "apply", "-f", "-")
144153
if err == nil {
145154
return false
146-
//return fmt.Errorf("expected apply to fail, got: %s", out)
147155
}
148156
if stdErr := string(func() *exec.ExitError {
149157
target := &exec.ExitError{}
150158
_ = errors.As(err, &target)
151159
return target
152160
}().Stderr); !strings.Contains(stdErr, errMsg) {
153161
return false
154-
//return fmt.Errorf("expected error message %s to be in stderr, got: %s", errMsg, stdErr)
155162
}
156163
return true
157164
})
@@ -436,6 +443,7 @@ func SendMetricsRequest(ctx context.Context, serviceAccount string, endpoint str
436443
return false
437444
}
438445
defer resp.Body.Close()
446+
439447
if resp.StatusCode == http.StatusOK {
440448
b, err := io.ReadAll(resp.Body)
441449
if err != nil {

0 commit comments

Comments
 (0)