Skip to content

Commit d636997

Browse files
committed
feat(e2e-bare): add utilities for running olm and e2e locally against a
remote cluster
1 parent ff6cee2 commit d636997

25 files changed

+414
-156
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,23 @@ run-local-shift:
6969
. ./scripts/install_local.sh local build/resources
7070
rm -rf build
7171

72+
setup-bare:
73+
. ./scripts/build_bare.sh
74+
. ./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml
75+
. ./scripts/install_bare.sh e2e test/e2e/resources
76+
7277
e2e:
73-
export NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
78+
export NAMESPACE=default
7479
go test ./test/e2e/...
7580

7681
e2e-local:
7782
. ./scripts/build_local.sh
7883
. ./scripts/run_e2e_local.sh $(TEST)
7984

85+
e2e-bare:
86+
. ./scripts/build_bare.sh
87+
. ./scripts/run_e2e_bare.sh $(TEST)
88+
8089
e2e-local-shift:
8190
. ./scripts/build_local_shift.sh
8291
. ./scripts/run_e2e_local.sh $(TEST)

cmd/catalog/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
log "github.com/sirupsen/logrus"
12+
"k8s.io/api/core/v1"
1213

1314
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
1415
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
@@ -58,14 +59,24 @@ func main() {
5859
log.SetLevel(log.DebugLevel)
5960
}
6061

62+
// `namespaces` will always contain at least one entry: if `*watchedNamespaces` is
63+
// the empty string, the resulting array will be `[]string{""}`.
64+
namespaces := strings.Split(*watchedNamespaces, ",")
65+
for _, ns := range namespaces {
66+
if ns == v1.NamespaceAll {
67+
namespaces = []string{v1.NamespaceAll}
68+
break
69+
}
70+
}
71+
6172
// Serve a health check.
6273
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
6374
w.WriteHeader(http.StatusOK)
6475
})
6576
go http.ListenAndServe(":8080", nil)
6677

6778
// Create a new instance of the operator.
68-
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, *wakeupInterval, *catalogNamespace, strings.Split(*watchedNamespaces, ",")...)
79+
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, log.New(), *wakeupInterval, *catalogNamespace, namespaces...)
6980
if err != nil {
7081
log.Panicf("error configuring operator: %s", err.Error())
7182
}

cmd/olm/main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/prometheus/client_golang/prometheus"
1212
log "github.com/sirupsen/logrus"
13+
"k8s.io/api/core/v1"
1314

1415
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
1516
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
@@ -24,15 +25,6 @@ const (
2425
defaultWakeupInterval = 5 * time.Minute
2526
)
2627

27-
// helper function for required env vars
28-
func envOrDie(varname, description string) string {
29-
val := os.Getenv(varname)
30-
if len(val) == 0 {
31-
log.Fatalf("must set env %s - %s", varname, description)
32-
}
33-
return val
34-
}
35-
3628
// config flags defined globally so that they appear on the test binary as well
3729
var (
3830
kubeConfigPath = flag.String(
@@ -44,7 +36,7 @@ var (
4436
watchedNamespaces = flag.String(
4537
"watchedNamespaces", "", "comma separated list of namespaces for alm operator to watch. "+
4638
"If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+
47-
"alm operator will watch all namespaces in the cluster.")
39+
"olm operator will watch all namespaces in the cluster.")
4840

4941
debug = flag.Bool(
5042
"debug", false, "use debug log level")
@@ -79,17 +71,25 @@ func main() {
7971
// `namespaces` will always contain at least one entry: if `*watchedNamespaces` is
8072
// the empty string, the resulting array will be `[]string{""}`.
8173
namespaces := strings.Split(*watchedNamespaces, ",")
74+
for _, ns := range namespaces {
75+
if ns == v1.NamespaceAll {
76+
namespaces = []string{v1.NamespaceAll}
77+
break
78+
}
79+
}
8280

8381
// Create a client for OLM
8482
crClient, err := client.NewClient(*kubeConfigPath)
8583
if err != nil {
8684
log.Fatalf("error configuring client: %s", err.Error())
8785
}
8886

89-
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath)
87+
logger := log.New()
88+
89+
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
9090

9191
// Create a new instance of the operator.
92-
operator, err := olm.NewOperator(crClient, opClient, &install.StrategyResolver{}, *wakeupInterval, namespaces)
92+
operator, err := olm.NewOperator(logger, crClient, opClient, &install.StrategyResolver{}, *wakeupInterval, namespaces)
9393

9494
if err != nil {
9595
log.Fatalf("error configuring operator: %s", err.Error())

pkg/controller/operators/catalog/operator.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync"
88
"time"
99

10-
log "github.com/sirupsen/logrus"
10+
"github.com/sirupsen/logrus"
1111
corev1 "k8s.io/api/core/v1"
1212
rbacv1 "k8s.io/api/rbac/v1"
1313
v1beta1ext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
@@ -55,7 +55,7 @@ type Operator struct {
5555
}
5656

5757
// NewOperator creates a new Catalog Operator.
58-
func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNamespace string, watchedNamespaces ...string) (*Operator, error) {
58+
func NewOperator(kubeconfigPath string, logger *logrus.Logger, wakeupInterval time.Duration, operatorNamespace string, watchedNamespaces ...string) (*Operator, error) {
5959
// Default to watching all namespaces.
6060
if watchedNamespaces == nil {
6161
watchedNamespaces = []string{metav1.NamespaceAll}
@@ -84,7 +84,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
8484
}
8585

8686
// Create a new queueinformer-based operator.
87-
queueOperator, err := queueinformer.NewOperator(kubeconfigPath)
87+
queueOperator, err := queueinformer.NewOperator(kubeconfigPath, logger)
8888
if err != nil {
8989
return nil, err
9090
}
@@ -107,6 +107,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
107107
nil,
108108
"catsrc",
109109
metrics.NewMetricsCatalogSource(op.client),
110+
logger,
110111
)
111112
for _, informer := range catsrcQueueInformer {
112113
op.RegisterQueueInformer(informer)
@@ -121,6 +122,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
121122
nil,
122123
"installplan",
123124
metrics.NewMetricsInstallPlan(op.client),
125+
logger,
124126
)
125127
for _, informer := range ipQueueInformers {
126128
op.RegisterQueueInformer(informer)
@@ -135,6 +137,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
135137
nil,
136138
"subscription",
137139
metrics.NewMetricsSubscription(op.client),
140+
logger,
138141
)
139142
op.subQueue = subscriptionQueue
140143
for _, informer := range subscriptionQueueInformers {
@@ -147,7 +150,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
147150
func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
148151
catsrc, ok := obj.(*v1alpha1.CatalogSource)
149152
if !ok {
150-
log.Debugf("wrong type: %#v", obj)
153+
o.Log.Debugf("wrong type: %#v", obj)
151154
return fmt.Errorf("casting CatalogSource failed")
152155
}
153156

@@ -198,11 +201,11 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
198201
func (o *Operator) syncSubscriptions(obj interface{}) (syncError error) {
199202
sub, ok := obj.(*v1alpha1.Subscription)
200203
if !ok {
201-
log.Debugf("wrong type: %#v", obj)
204+
o.Log.Debugf("wrong type: %#v", obj)
202205
return fmt.Errorf("casting Subscription failed")
203206
}
204207

205-
logger := log.WithFields(log.Fields{
208+
logger := o.Log.WithFields(logrus.Fields{
206209
"sub": sub.GetName(),
207210
"namespace": sub.GetNamespace(),
208211
"source": sub.Spec.CatalogSource,
@@ -248,18 +251,18 @@ func (o *Operator) requeueInstallPlan(name, namespace string) {
248251
func (o *Operator) syncInstallPlans(obj interface{}) (syncError error) {
249252
plan, ok := obj.(*v1alpha1.InstallPlan)
250253
if !ok {
251-
log.Debugf("wrong type: %#v", obj)
254+
o.Log.Debugf("wrong type: %#v", obj)
252255
return fmt.Errorf("casting InstallPlan failed")
253256
}
254257

255-
logger := log.WithFields(log.Fields{
258+
logger := o.Log.WithFields(logrus.Fields{
256259
"ip": plan.GetName(),
257260
"namespace": plan.GetNamespace(),
258261
"phase": plan.Status.Phase,
259262
})
260263

261264
logger.Info("syncing")
262-
outInstallPlan, syncError := transitionInstallPlanState(o, *plan)
265+
outInstallPlan, syncError := transitionInstallPlanState(logger.Logger, o, *plan)
263266

264267
if syncError != nil {
265268
logger = logger.WithField("syncError", syncError)
@@ -297,23 +300,17 @@ type installPlanTransitioner interface {
297300

298301
var _ installPlanTransitioner = &Operator{}
299302

300-
func transitionInstallPlanState(transitioner installPlanTransitioner, in v1alpha1.InstallPlan) (*v1alpha1.InstallPlan, error) {
301-
logger := log.WithFields(log.Fields{
302-
"ip": in.GetName(),
303-
"namespace": in.GetNamespace(),
304-
"phase": in.Status.Phase,
305-
})
306-
303+
func transitionInstallPlanState(log *logrus.Logger, transitioner installPlanTransitioner, in v1alpha1.InstallPlan) (*v1alpha1.InstallPlan, error) {
307304
out := in.DeepCopy()
308305

309306
switch in.Status.Phase {
310307
case v1alpha1.InstallPlanPhaseNone:
311-
logger.Debugf("setting phase to %s", v1alpha1.InstallPlanPhasePlanning)
308+
log.Debugf("setting phase to %s", v1alpha1.InstallPlanPhasePlanning)
312309
out.Status.Phase = v1alpha1.InstallPlanPhasePlanning
313310
return out, nil
314311

315312
case v1alpha1.InstallPlanPhasePlanning:
316-
logger.Debug("attempting to resolve")
313+
log.Debug("attempting to resolve")
317314
if err := transitioner.ResolvePlan(out); err != nil {
318315
out.Status.SetCondition(v1alpha1.ConditionFailed(v1alpha1.InstallPlanResolved,
319316
v1alpha1.InstallPlanReasonInstallCheckFailed, err))
@@ -331,15 +328,15 @@ func transitionInstallPlanState(transitioner installPlanTransitioner, in v1alpha
331328

332329
case v1alpha1.InstallPlanPhaseRequiresApproval:
333330
if out.Spec.Approved {
334-
logger.Debugf("approved, setting to %s", v1alpha1.InstallPlanPhasePlanning)
331+
log.Debugf("approved, setting to %s", v1alpha1.InstallPlanPhasePlanning)
335332
out.Status.Phase = v1alpha1.InstallPlanPhaseInstalling
336333
} else {
337-
logger.Debug("not approved, skipping sync")
334+
log.Debug("not approved, skipping sync")
338335
}
339336
return out, nil
340337

341338
case v1alpha1.InstallPlanPhaseInstalling:
342-
logger.Debug("attempting to install")
339+
log.Debug("attempting to install")
343340
if err := transitioner.ExecutePlan(out); err != nil {
344341
out.Status.SetCondition(v1alpha1.ConditionFailed(v1alpha1.InstallPlanInstalled,
345342
v1alpha1.InstallPlanReasonComponentFailed, err))
@@ -447,8 +444,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
447444
continue
448445

449446
case v1alpha1.StepStatusUnknown, v1alpha1.StepStatusNotPresent:
450-
log.Debugf("resource kind: %s", step.Resource.Kind)
451-
log.Debugf("resource name: %s", step.Resource.Name)
447+
o.Log.WithFields(logrus.Fields{"kind": step.Resource.Kind, "name": step.Resource.Name}).Debug("execute resource")
452448
switch step.Resource.Kind {
453449
case crdKind:
454450
// Marshal the manifest into a CRD instance.

pkg/controller/operators/catalog/operator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package catalog
22

33
import (
44
"errors"
5+
"github.com/sirupsen/logrus"
56
"testing"
67

78
"github.com/ghodss/yaml"
@@ -110,7 +111,7 @@ func TestTransitionInstallPlan(t *testing.T) {
110111
transitioner := &mockTransitioner{tt.transError}
111112

112113
// Attempt to transition phases.
113-
out, _ := transitionInstallPlanState(transitioner, *plan)
114+
out, _ := transitionInstallPlanState(logrus.New(), transitioner, *plan)
114115

115116
// Assert that the final phase is as expected.
116117
require.Equal(t, tt.expected, out.Status.Phase)
@@ -386,7 +387,7 @@ func NewFakeOperator(clientObjs []runtime.Object, k8sObjs []runtime.Object, extO
386387
}
387388

388389
// Create the new operator
389-
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake)
390+
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake, logrus.New())
390391
op := &Operator{
391392
Operator: queueOperator,
392393
client: clientFake,

0 commit comments

Comments
 (0)