Skip to content

Commit fcbdbc8

Browse files
author
Mikalai Radchuk
committed
WIP: e2e tests
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent bfe4cbf commit fcbdbc8

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

pkg/controller/bundle/bundle_unpacker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const (
3838
BundleLookupFailed operatorsv1alpha1.BundleLookupConditionType = "BundleLookupFailed"
3939

4040
// TODO: This can be a spec field
41-
// BundleUnpackTimeoutAnnotationKey allows setting a bundle unpack timeout per InstallPlan
41+
// BundleUnpackTimeoutAnnotationKey allows setting a bundle unpack timeout per OperatorGroup
4242
// and overrides the default specified by the --bundle-unpack-timeout flag
4343
// The time duration should be in the same format as accepted by time.ParseDuration()
4444
// e.g 1m30s

pkg/controller/operators/catalog/operator.go

+39-17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/operator-framework/api/pkg/operators/v1alpha1"
4747
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
4848
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
49+
v1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1"
4950
operatorsv1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
5051
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
5152
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
@@ -934,7 +935,42 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
934935
return err
935936
}
936937

937-
failForwardEnabled, err := resolver.IsFailForwardEnabled(o.lister.OperatorsV1().OperatorGroupLister().OperatorGroups(namespace))
938+
ogLister := o.lister.OperatorsV1().OperatorGroupLister().OperatorGroups(namespace)
939+
failForwardEnabled, err := resolver.IsFailForwardEnabled(ogLister)
940+
if err != nil {
941+
return err
942+
}
943+
944+
// TODO: Move into a separate func (probably into the github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle package)
945+
// operatorGroupBundleUnpackTimeout returns bundle timeout from annotation if specified.
946+
// This is to overrides the --bundle-unpack-timeout flag value on per-OperatorGroup basis.
947+
// If the timeout cannot be parsed it's set to < 0 and subsequently ignored.
948+
operatorGroupBundleUnpackTimeout := func(logger *logrus.Logger, ogLister v1listers.OperatorGroupNamespaceLister) (time.Duration, error) {
949+
ignoreTimeout := -1 * time.Minute
950+
951+
ogs, err := ogLister.List(labels.Everything())
952+
if err != nil || len(ogs) == 0 {
953+
return ignoreTimeout, nil
954+
}
955+
if len(ogs) != 1 {
956+
return ignoreTimeout, fmt.Errorf("found %d operatorGroups, expected 1", len(ogs))
957+
}
958+
959+
timeoutStr, ok := ogs[0].GetAnnotations()[bundle.BundleUnpackTimeoutAnnotationKey]
960+
if !ok {
961+
return ignoreTimeout, nil
962+
}
963+
964+
d, err := time.ParseDuration(timeoutStr)
965+
if err != nil {
966+
logger.Errorf("failed to parse unpack timeout annotation(%s: %s): %v", bundle.BundleUnpackTimeoutAnnotationKey, timeoutStr, err)
967+
return ignoreTimeout, nil
968+
}
969+
970+
return d, nil
971+
}
972+
973+
unpackTimeout, err := operatorGroupBundleUnpackTimeout(o.logger, ogLister)
938974
if err != nil {
939975
return err
940976
}
@@ -1034,7 +1070,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
10341070
logger.Debug("unpacking bundles")
10351071

10361072
var unpacked bool
1037-
unpacked, steps, bundleLookups, err = o.unpackBundles(namespace, bundleLookups)
1073+
unpacked, steps, bundleLookups, err = o.unpackBundles(namespace, bundleLookups, unpackTimeout)
10381074
if err != nil {
10391075
return fmt.Errorf("bundle unpacking failed with an error: %v", err)
10401076
}
@@ -1456,28 +1492,14 @@ type UnpackedBundleReference struct {
14561492
Properties string `json:"properties"`
14571493
}
14581494

1459-
func (o *Operator) unpackBundles(namespace string, bundleLookups []v1alpha1.BundleLookup) (bool, []*v1alpha1.Step, []v1alpha1.BundleLookup, error) {
1495+
func (o *Operator) unpackBundles(namespace string, bundleLookups []v1alpha1.BundleLookup, unpackTimeout time.Duration) (bool, []*v1alpha1.Step, []v1alpha1.BundleLookup, error) {
14601496
unpacked := true
14611497

14621498
outBundleLookups := make([]v1alpha1.BundleLookup, len(bundleLookups))
14631499
for i := range bundleLookups {
14641500
bundleLookups[i].DeepCopyInto(&outBundleLookups[i])
14651501
}
14661502

1467-
// The bundle timeout annotation if specified overrides the --bundle-unpack-timeout flag value
1468-
// If the timeout cannot be parsed it's set to < 0 and subsequently ignored
1469-
unpackTimeout := -1 * time.Minute
1470-
// TODO: Update. This is internal stuff for testing. Maybe move to a sub?
1471-
// timeoutStr, ok := plan.GetAnnotations()[bundle.BundleUnpackTimeoutAnnotationKey]
1472-
// if ok {
1473-
// d, err := time.ParseDuration(timeoutStr)
1474-
// if err != nil {
1475-
// o.logger.Errorf("failed to parse unpack timeout annotation(%s: %s): %v", bundle.BundleUnpackTimeoutAnnotationKey, timeoutStr, err)
1476-
// } else {
1477-
// unpackTimeout = d
1478-
// }
1479-
// }
1480-
14811503
installPlanSteps := []*v1alpha1.Step{}
14821504
var errs []error
14831505
for i := 0; i < len(outBundleLookups); i++ {

0 commit comments

Comments
 (0)