Skip to content

Commit 25a917e

Browse files
Merge pull request #736 from ecordell/opgroup-expand-contract
OperatorGroup expansion/contraction
2 parents a196e4e + 121243a commit 25a917e

File tree

26 files changed

+1697
-513
lines changed

26 files changed

+1697
-513
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ container:
9999
clean-e2e:
100100
kubectl delete crds --all
101101
kubectl delete apiservices.apiregistration.k8s.io v1alpha1.packages.apps.redhat.com
102-
kubectl delete -f test/e2e/resources/0000_50_00-namespace.yaml
102+
kubectl delete -f test/e2e/resources/0000_50_olm_00-namespace.yaml
103103

104104
clean:
105105
@rm -rf cover.out

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/spf13/cobra v0.0.3
3030
github.com/stretchr/testify v1.2.2
3131
go.etcd.io/bbolt v1.3.2 // indirect
32-
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
32+
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
3333
google.golang.org/grpc v1.16.0
3434
k8s.io/api v0.0.0-20190118113203-912cbe2bfef3
3535
k8s.io/apiextensions-apiserver v0.0.0-20190223021643-57c81b676ab1
@@ -41,5 +41,5 @@ require (
4141
k8s.io/klog v0.2.0 // indirect
4242
k8s.io/kube-aggregator v0.0.0-20190223015803-f706565beac0
4343
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
44-
k8s.io/kubernetes v1.11.8-beta.0.0.20190223014307-4e209c9383fa
44+
k8s.io/kubernetes v1.11.9-beta.0.0.20190305054513-b2539d50ae56
4545
)

go.sum

Lines changed: 3 additions & 48 deletions
Large diffs are not rendered by default.

pkg/api/apis/operators/v1alpha1/clusterserviceversion.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,28 @@ import (
88
"k8s.io/client-go/tools/record"
99
)
1010

11+
const (
12+
CopiedLabelKey = "olm.copiedFrom"
13+
)
14+
1115
// obsoleteReasons are the set of reasons that mean a CSV should no longer be processed as active
1216
var obsoleteReasons = map[ConditionReason]struct{}{
1317
CSVReasonReplaced: {},
1418
CSVReasonBeingReplaced: {},
1519
}
1620

21+
// uncopiableReasons are the set of reasons that should prevent a CSV from being copied to target namespaces
22+
var uncopiableReasons = map[ConditionReason]struct{}{
23+
CSVReasonCopied: {},
24+
CSVReasonInvalidInstallModes: {},
25+
CSVReasonNoTargetNamespaces: {},
26+
CSVReasonUnsupportedOperatorGroup: {},
27+
CSVReasonNoOperatorGroup: {},
28+
CSVReasonTooManyOperatorGroups: {},
29+
CSVReasonInterOperatorGroupOwnerConflict: {},
30+
CSVReasonCannotModifyStaticOperatorGroupProvidedAPIs: {},
31+
}
32+
1733
func (c *ClusterServiceVersion) SetPhaseWithEvent(phase ClusterServiceVersionPhase, reason ConditionReason, message string, now metav1.Time, recorder record.EventRecorder) {
1834
var eventtype string
1935
if phase == CSVPhaseFailed {
@@ -77,9 +93,23 @@ func (c *ClusterServiceVersion) IsCopied() bool {
7793
if c.Status.Reason == CSVReasonCopied || ok && c.GetNamespace() != operatorNamespace {
7894
return true
7995
}
96+
97+
if labels := c.GetLabels(); labels != nil {
98+
if _, ok := labels[CopiedLabelKey]; ok {
99+
return true
100+
}
101+
}
80102
return false
81103
}
82104

105+
func (c *ClusterServiceVersion) IsUncopiable() bool {
106+
if c.Status.Phase == CSVPhaseNone {
107+
return true
108+
}
109+
_, ok := uncopiableReasons[c.Status.Reason]
110+
return ok
111+
}
112+
83113
// NewInstallModeSet returns an InstallModeSet instantiated from the given list of InstallModes.
84114
// If the given list is not a set, an error is returned.
85115
func NewInstallModeSet(modes []InstallMode) (InstallModeSet, error) {

pkg/api/apis/operators/v1alpha2/operatorgroup_types.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package v1alpha2
22

33
import (
4+
"sort"
5+
"strings"
6+
47
corev1 "k8s.io/api/core/v1"
58
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
69
)
710

11+
const (
12+
OperatorGroupAnnotationKey = "olm.operatorGroup"
13+
OperatorGroupNamespaceAnnotationKey = "olm.operatorNamespace"
14+
OperatorGroupTargetsAnnotationKey = "olm.targetNamespaces"
15+
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
16+
)
17+
818
type OperatorGroupSpec struct {
919
// Selector selects the OperatorGroup's target namespaces.
1020
// +optional
@@ -52,9 +62,7 @@ type OperatorGroupList struct {
5262
Items []OperatorGroup `json:"items"`
5363
}
5464

55-
const (
56-
OperatorGroupAnnotationKey = "olm.operatorGroup"
57-
OperatorGroupNamespaceAnnotationKey = "olm.operatorNamespace"
58-
OperatorGroupTargetsAnnotationKey = "olm.targetNamespaces"
59-
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
60-
)
65+
func (o *OperatorGroup) BuildTargetNamespaces() string {
66+
sort.Strings(o.Status.Namespaces)
67+
return strings.Join(o.Status.Namespaces, ",")
68+
}

pkg/controller/operators/catalog/operator_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ghodss/yaml"
1111
"github.com/sirupsen/logrus"
1212
"github.com/stretchr/testify/require"
13+
"golang.org/x/time/rate"
1314
appsv1 "k8s.io/api/apps/v1"
1415
corev1 "k8s.io/api/core/v1"
1516
rbacv1 "k8s.io/api/rbac/v1"
@@ -516,13 +517,18 @@ func NewFakeOperator(clientObjs []runtime.Object, k8sObjs []runtime.Object, extO
516517
// Create the new operator
517518
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake, logrus.New())
518519
op := &Operator{
519-
Operator: queueOperator,
520-
client: clientFake,
521-
lister: lister,
522-
namespace: namespace,
523-
namespaceResolveQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "resolver"),
524-
sources: make(map[resolver.CatalogKey]resolver.SourceRef),
525-
resolver: &fakes.FakeResolver{},
520+
Operator: queueOperator,
521+
client: clientFake,
522+
lister: lister,
523+
namespace: namespace,
524+
namespaceResolveQueue: workqueue.NewNamedRateLimitingQueue(
525+
workqueue.NewMaxOfRateLimiter(
526+
workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 1000*time.Second),
527+
// 1 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
528+
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(1), 100)},
529+
), "resolver"),
530+
sources: make(map[resolver.CatalogKey]resolver.SourceRef),
531+
resolver: &fakes.FakeResolver{},
526532
}
527533

528534
op.reconciler = &reconciler.RegistryReconcilerFactory{

0 commit comments

Comments
 (0)