Skip to content

Commit

Permalink
Merge pull request #736 from ecordell/opgroup-expand-contract
Browse files Browse the repository at this point in the history
OperatorGroup expansion/contraction
  • Loading branch information
openshift-merge-robot authored Mar 11, 2019
2 parents a196e4e + 121243a commit 25a917e
Show file tree
Hide file tree
Showing 26 changed files with 1,697 additions and 513 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ container:
clean-e2e:
kubectl delete crds --all
kubectl delete apiservices.apiregistration.k8s.io v1alpha1.packages.apps.redhat.com
kubectl delete -f test/e2e/resources/0000_50_00-namespace.yaml
kubectl delete -f test/e2e/resources/0000_50_olm_00-namespace.yaml

clean:
@rm -rf cover.out
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.2.2
go.etcd.io/bbolt v1.3.2 // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
google.golang.org/grpc v1.16.0
k8s.io/api v0.0.0-20190118113203-912cbe2bfef3
k8s.io/apiextensions-apiserver v0.0.0-20190223021643-57c81b676ab1
Expand All @@ -41,5 +41,5 @@ require (
k8s.io/klog v0.2.0 // indirect
k8s.io/kube-aggregator v0.0.0-20190223015803-f706565beac0
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kubernetes v1.11.8-beta.0.0.20190223014307-4e209c9383fa
k8s.io/kubernetes v1.11.9-beta.0.0.20190305054513-b2539d50ae56
)
51 changes: 3 additions & 48 deletions go.sum

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions pkg/api/apis/operators/v1alpha1/clusterserviceversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ import (
"k8s.io/client-go/tools/record"
)

const (
CopiedLabelKey = "olm.copiedFrom"
)

// obsoleteReasons are the set of reasons that mean a CSV should no longer be processed as active
var obsoleteReasons = map[ConditionReason]struct{}{
CSVReasonReplaced: {},
CSVReasonBeingReplaced: {},
}

// uncopiableReasons are the set of reasons that should prevent a CSV from being copied to target namespaces
var uncopiableReasons = map[ConditionReason]struct{}{
CSVReasonCopied: {},
CSVReasonInvalidInstallModes: {},
CSVReasonNoTargetNamespaces: {},
CSVReasonUnsupportedOperatorGroup: {},
CSVReasonNoOperatorGroup: {},
CSVReasonTooManyOperatorGroups: {},
CSVReasonInterOperatorGroupOwnerConflict: {},
CSVReasonCannotModifyStaticOperatorGroupProvidedAPIs: {},
}

func (c *ClusterServiceVersion) SetPhaseWithEvent(phase ClusterServiceVersionPhase, reason ConditionReason, message string, now metav1.Time, recorder record.EventRecorder) {
var eventtype string
if phase == CSVPhaseFailed {
Expand Down Expand Up @@ -77,9 +93,23 @@ func (c *ClusterServiceVersion) IsCopied() bool {
if c.Status.Reason == CSVReasonCopied || ok && c.GetNamespace() != operatorNamespace {
return true
}

if labels := c.GetLabels(); labels != nil {
if _, ok := labels[CopiedLabelKey]; ok {
return true
}
}
return false
}

func (c *ClusterServiceVersion) IsUncopiable() bool {
if c.Status.Phase == CSVPhaseNone {
return true
}
_, ok := uncopiableReasons[c.Status.Reason]
return ok
}

// NewInstallModeSet returns an InstallModeSet instantiated from the given list of InstallModes.
// If the given list is not a set, an error is returned.
func NewInstallModeSet(modes []InstallMode) (InstallModeSet, error) {
Expand Down
20 changes: 14 additions & 6 deletions pkg/api/apis/operators/v1alpha2/operatorgroup_types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package v1alpha2

import (
"sort"
"strings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
OperatorGroupAnnotationKey = "olm.operatorGroup"
OperatorGroupNamespaceAnnotationKey = "olm.operatorNamespace"
OperatorGroupTargetsAnnotationKey = "olm.targetNamespaces"
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
)

type OperatorGroupSpec struct {
// Selector selects the OperatorGroup's target namespaces.
// +optional
Expand Down Expand Up @@ -52,9 +62,7 @@ type OperatorGroupList struct {
Items []OperatorGroup `json:"items"`
}

const (
OperatorGroupAnnotationKey = "olm.operatorGroup"
OperatorGroupNamespaceAnnotationKey = "olm.operatorNamespace"
OperatorGroupTargetsAnnotationKey = "olm.targetNamespaces"
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
)
func (o *OperatorGroup) BuildTargetNamespaces() string {
sort.Strings(o.Status.Namespaces)
return strings.Join(o.Status.Namespaces, ",")
}
20 changes: 13 additions & 7 deletions pkg/controller/operators/catalog/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ghodss/yaml"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"golang.org/x/time/rate"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -516,13 +517,18 @@ func NewFakeOperator(clientObjs []runtime.Object, k8sObjs []runtime.Object, extO
// Create the new operator
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake, logrus.New())
op := &Operator{
Operator: queueOperator,
client: clientFake,
lister: lister,
namespace: namespace,
namespaceResolveQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "resolver"),
sources: make(map[resolver.CatalogKey]resolver.SourceRef),
resolver: &fakes.FakeResolver{},
Operator: queueOperator,
client: clientFake,
lister: lister,
namespace: namespace,
namespaceResolveQueue: workqueue.NewNamedRateLimitingQueue(
workqueue.NewMaxOfRateLimiter(
workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 1000*time.Second),
// 1 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(1), 100)},
), "resolver"),
sources: make(map[resolver.CatalogKey]resolver.SourceRef),
resolver: &fakes.FakeResolver{},
}

op.reconciler = &reconciler.RegistryReconcilerFactory{
Expand Down
Loading

0 comments on commit 25a917e

Please sign in to comment.