Skip to content

Commit

Permalink
feat(e2e-bare): add utilities for running olm and e2e locally against a
Browse files Browse the repository at this point in the history
remote cluster
  • Loading branch information
ecordell committed Nov 27, 2018
1 parent 9155118 commit a2ab3e0
Show file tree
Hide file tree
Showing 26 changed files with 414 additions and 159 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,23 @@ run-local-shift:
. ./scripts/install_local.sh local build/resources
rm -rf build

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 e2e test/e2e/resources

e2e:
export NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
export NAMESPACE=default
go test ./test/e2e/...

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

e2e-bare:
. ./scripts/build_bare.sh
. ./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
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,12 @@ k8s.io/api v0.0.0-20180904230853-4e7be11eab3f h1:DLRkv8Ps4Sdx8Srj+UtGisj4whV7v/H
k8s.io/api v0.0.0-20180904230853-4e7be11eab3f/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apiextensions-apiserver v0.0.0-20180905004947-16750353bf97 h1:s4lWWs6JN5kWVzk5bztddkr5kgO/cGIbqTDP+QttUeQ=
k8s.io/apiextensions-apiserver v0.0.0-20180905004947-16750353bf97/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
k8s.io/apiextensions-apiserver v0.0.0-20181110192823-2c43ee60e25b h1:O3KqnOdhludLAAHs7bvV7UpPYow3gqLqF5Junc5hbw8=
k8s.io/apimachinery v0.0.0-20181026144827-8ee1a638bafa h1:i0EOpPFWExNx7efINILpw8LJeah7gakRl1zjvwVfjiI=
k8s.io/apimachinery v0.0.0-20181026144827-8ee1a638bafa/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170 h1:CqI85nZvPaV+7JFono0nAOGOx2brocqefcOhDPVhHKI=
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w=
k8s.io/client-go v8.0.0+incompatible h1:2pUaSg2x6iEHr8cia6zmWhoCXG1EDG9TCx9s//Aq7HY=
k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/client-go v9.0.0+incompatible h1:2kqW3X2xQ9SbFvWZjGEHBLlWc1LG9JIJNXWkuqwdZ3A=
k8s.io/code-generator v0.0.0-20180904193909-8c97d6ab64da h1:L6YB6ObZIbZlYikTQcCjzZGilwS3OVyQBA2esULs8VM=
k8s.io/code-generator v0.0.0-20180904193909-8c97d6ab64da/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
k8s.io/gengo v0.0.0-20181106084056-51747d6e00da h1:ZMvcXtMVbhUCtCuiSEzBV+Eur4swzfdxx6ZyX3qT6dk=
Expand All @@ -230,7 +228,6 @@ k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 h1:PgoMI/L1Nu5Vmvgm+vGheLuxKST8h6
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/kube-aggregator v0.0.0-20180905000155-efa32eb095fe h1:LM48rywzVEPRg+Os2oUL9/vsztPQGoxmiD3m5VySchw=
k8s.io/kube-aggregator v0.0.0-20180905000155-efa32eb095fe/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
k8s.io/kube-aggregator v0.0.0-20181110192014-6f96af33cb59 h1:8VFjmCurXo3sMW0ASrUvoE4aT8FCzsIz55uic1EyUIc=
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd h1:ggv/Vfza0i5xuhUZyYyxcc25AmQvHY8Zi1C2m8WgBvA=
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kubernetes v1.11.5-beta.0.0.20181108064615-3290824d1c7b h1:Ej2VgtycDFPfQunFFfAsWvdjT+dhte1CcwnPNId+V1k=
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 a2ab3e0

Please sign in to comment.