Skip to content

Commit

Permalink
Merge pull request operator-framework#552 from ecordell/e2e
Browse files Browse the repository at this point in the history
feat(make): add e2e command for running from ci-operator
  • Loading branch information
ecordell authored Dec 3, 2018
2 parents 6f6c442 + f3cc9c6 commit bd57c33
Show file tree
Hide file tree
Showing 32 changed files with 536 additions and 236 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,22 @@ run-local-shift:
. ./scripts/install_local.sh local build/resources
rm -rf build

# useful if running e2e directly with `go test -tags=bare`
setup-bare:
. ./scripts/build_bare.sh
. ./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources

e2e:
go test -v -timeout 20m ./test/e2e/... -namespace=default -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager

e2e-local:
. ./scripts/build_local.sh
. ./scripts/run_e2e_local.sh $(TEST)

e2e-bare: setup-bare
. ./scripts/run_e2e_bare.sh $(TEST)

e2e-local-shift:
. ./scripts/build_local_shift.sh
. ./scripts/run_e2e_local.sh $(TEST)
Expand Down
13 changes: 12 additions & 1 deletion cmd/catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"

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

// `namespaces` will always contain at least one entry: if `*watchedNamespaces` is
// the empty string, the resulting array will be `[]string{""}`.
namespaces := strings.Split(*watchedNamespaces, ",")
for _, ns := range namespaces {
if ns == v1.NamespaceAll {
namespaces = []string{v1.NamespaceAll}
break
}
}

// Serve a health check.
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
go http.ListenAndServe(":8080", nil)

// Create a new instance of the operator.
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, *wakeupInterval, *catalogNamespace, strings.Split(*watchedNamespaces, ",")...)
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, log.New(), *wakeupInterval, *catalogNamespace, namespaces...)
if err != nil {
log.Panicf("error configuring operator: %s", err.Error())
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"

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

// helper function for required env vars
func envOrDie(varname, description string) string {
val := os.Getenv(varname)
if len(val) == 0 {
log.Fatalf("must set env %s - %s", varname, description)
}
return val
}

// config flags defined globally so that they appear on the test binary as well
var (
kubeConfigPath = flag.String(
Expand All @@ -44,7 +36,7 @@ var (
watchedNamespaces = flag.String(
"watchedNamespaces", "", "comma separated list of namespaces for alm operator to watch. "+
"If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+
"alm operator will watch all namespaces in the cluster.")
"olm operator will watch all namespaces in the cluster.")

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

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

opClient := operatorclient.NewClientFromConfig(*kubeConfigPath)
logger := log.New()

opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)

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

if err != nil {
log.Fatalf("error configuring operator: %s", err.Error())
Expand Down
1 change: 1 addition & 0 deletions manifests/0000_30_11-catalog-operator.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spec:
- /bin/catalog
- '-namespace'
- openshift-operator-lifecycle-manager
- -debug
image: quay.io/coreos/olm@sha256:1639d570809c5827810a1870763016e8c046283632d47e0b47183c82f8e515f2
imagePullPolicy: IfNotPresent
ports:
Expand Down
42 changes: 19 additions & 23 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
v1beta1ext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
Expand Down Expand Up @@ -55,7 +55,7 @@ type Operator struct {
}

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

// Create a new queueinformer-based operator.
queueOperator, err := queueinformer.NewOperator(kubeconfigPath)
queueOperator, err := queueinformer.NewOperator(kubeconfigPath, logger)
if err != nil {
return nil, err
}
Expand All @@ -107,6 +107,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
nil,
"catsrc",
metrics.NewMetricsCatalogSource(op.client),
logger,
)
for _, informer := range catsrcQueueInformer {
op.RegisterQueueInformer(informer)
Expand All @@ -121,6 +122,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
nil,
"installplan",
metrics.NewMetricsInstallPlan(op.client),
logger,
)
for _, informer := range ipQueueInformers {
op.RegisterQueueInformer(informer)
Expand All @@ -135,6 +137,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
nil,
"subscription",
metrics.NewMetricsSubscription(op.client),
logger,
)
op.subQueue = subscriptionQueue
for _, informer := range subscriptionQueueInformers {
Expand All @@ -147,7 +150,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
catsrc, ok := obj.(*v1alpha1.CatalogSource)
if !ok {
log.Debugf("wrong type: %#v", obj)
o.Log.Debugf("wrong type: %#v", obj)
return fmt.Errorf("casting CatalogSource failed")
}

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

logger := log.WithFields(log.Fields{
logger := o.Log.WithFields(logrus.Fields{
"sub": sub.GetName(),
"namespace": sub.GetNamespace(),
"source": sub.Spec.CatalogSource,
Expand Down Expand Up @@ -248,18 +251,18 @@ func (o *Operator) requeueInstallPlan(name, namespace string) {
func (o *Operator) syncInstallPlans(obj interface{}) (syncError error) {
plan, ok := obj.(*v1alpha1.InstallPlan)
if !ok {
log.Debugf("wrong type: %#v", obj)
o.Log.Debugf("wrong type: %#v", obj)
return fmt.Errorf("casting InstallPlan failed")
}

logger := log.WithFields(log.Fields{
logger := o.Log.WithFields(logrus.Fields{
"ip": plan.GetName(),
"namespace": plan.GetNamespace(),
"phase": plan.Status.Phase,
})

logger.Info("syncing")
outInstallPlan, syncError := transitionInstallPlanState(o, *plan)
outInstallPlan, syncError := transitionInstallPlanState(logger.Logger, o, *plan)

if syncError != nil {
logger = logger.WithField("syncError", syncError)
Expand Down Expand Up @@ -297,23 +300,17 @@ type installPlanTransitioner interface {

var _ installPlanTransitioner = &Operator{}

func transitionInstallPlanState(transitioner installPlanTransitioner, in v1alpha1.InstallPlan) (*v1alpha1.InstallPlan, error) {
logger := log.WithFields(log.Fields{
"ip": in.GetName(),
"namespace": in.GetNamespace(),
"phase": in.Status.Phase,
})

func transitionInstallPlanState(log *logrus.Logger, transitioner installPlanTransitioner, in v1alpha1.InstallPlan) (*v1alpha1.InstallPlan, error) {
out := in.DeepCopy()

switch in.Status.Phase {
case v1alpha1.InstallPlanPhaseNone:
logger.Debugf("setting phase to %s", v1alpha1.InstallPlanPhasePlanning)
log.Debugf("setting phase to %s", v1alpha1.InstallPlanPhasePlanning)
out.Status.Phase = v1alpha1.InstallPlanPhasePlanning
return out, nil

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

case v1alpha1.InstallPlanPhaseRequiresApproval:
if out.Spec.Approved {
logger.Debugf("approved, setting to %s", v1alpha1.InstallPlanPhasePlanning)
log.Debugf("approved, setting to %s", v1alpha1.InstallPlanPhasePlanning)
out.Status.Phase = v1alpha1.InstallPlanPhaseInstalling
} else {
logger.Debug("not approved, skipping sync")
log.Debug("not approved, skipping sync")
}
return out, nil

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

case v1alpha1.StepStatusUnknown, v1alpha1.StepStatusNotPresent:
log.Debugf("resource kind: %s", step.Resource.Kind)
log.Debugf("resource name: %s", step.Resource.Name)
o.Log.WithFields(logrus.Fields{"kind": step.Resource.Kind, "name": step.Resource.Name}).Debug("execute resource")
switch step.Resource.Kind {
case crdKind:
// Marshal the manifest into a CRD instance.
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/operators/catalog/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package catalog

import (
"errors"
"github.com/sirupsen/logrus"
"testing"

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

// Attempt to transition phases.
out, _ := transitionInstallPlanState(transitioner, *plan)
out, _ := transitionInstallPlanState(logrus.New(), transitioner, *plan)

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

// Create the new operator
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake)
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake, logrus.New())
op := &Operator{
Operator: queueOperator,
client: clientFake,
Expand Down
Loading

0 comments on commit bd57c33

Please sign in to comment.