Skip to content

Commit

Permalink
feat(operatorgroups): don't process CSVs that aren't in an operatorgroup
Browse files Browse the repository at this point in the history
this commit also moves the copying / rbac logic into the CSV loop, so
that we don't have to requeue operatorgroups frequently
  • Loading branch information
ecordell committed Dec 10, 2018
1 parent af566ee commit a0c1f69
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 212 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ setup-bare:
. ./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
go test -v -timeout 30m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager

e2e-local:
. ./scripts/build_local.sh
Expand Down
1 change: 1 addition & 0 deletions deploy/chart/templates/0000_30_00-namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: {{ .Values.namespace }}
labels:
openshift.io/run-level: "1"
olm.components: "global"
---
apiVersion: v1
kind: Namespace
Expand Down
12 changes: 11 additions & 1 deletion deploy/chart/templates/0000_30_15-operatorgroup-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: global-operators
namespace: {{ .Values.operator_namespace }}
namespace: {{ .Values.operator_namespace }}
---
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: olm-operators
namespace: {{ .Values.namespace }}
spec:
selector:
matchLabels:
olm.components: "global"
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ require (
google.golang.org/grpc v1.16.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3 // indirect
k8s.io/api v0.0.0-20180904230853-4e7be11eab3f
k8s.io/apiextensions-apiserver v0.0.0-20180905004947-16750353bf97
k8s.io/apimachinery v0.0.0-20181126123124-70adfbae261e
k8s.io/api v0.0.0-20181203235848-2dd39edadc55
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc
k8s.io/apimachinery v0.0.0-20181203235515-3d8ee2261517
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170
k8s.io/client-go v8.0.0+incompatible
k8s.io/code-generator v0.0.0-20180904193909-8c97d6ab64da
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3
k8s.io/gengo v0.0.0-20181106084056-51747d6e00da // indirect
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 // indirect
k8s.io/kube-aggregator v0.0.0-20181201191901-6466d3c7f6e4
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kubernetes v1.11.6-beta.0.0.20181126160157-5933b9771b71
k8s.io/kubernetes v1.11.6-beta.0.0.20181207014600-4600add36de5
)
28 changes: 13 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,25 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20180904230853-4e7be11eab3f h1:DLRkv8Ps4Sdx8Srj+UtGisj4whV7v/HezlHx6QqiZqE=
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/apimachinery v0.0.0-20181126123124-70adfbae261e h1:aoIs4wbKOxWFPPOoMSWC9V4b5+kp7c70tAD8LLByFQY=
k8s.io/apimachinery v0.0.0-20181126123124-70adfbae261e/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/api v0.0.0-20181203235848-2dd39edadc55 h1:FmAMYGd999iHkN+swot+oART9AumJiAvH0idpIZ3Ozo=
k8s.io/api v0.0.0-20181203235848-2dd39edadc55/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc h1:IOukeE9HtTwpLslbujLDfRpfFU6tsjq28yO0fjnl/hk=
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
k8s.io/apimachinery v0.0.0-20181203235515-3d8ee2261517 h1:p6GEgV1/cc7H0AT6XfjHwHNIypirOprIB09oKp2DQ/M=
k8s.io/apimachinery v0.0.0-20181203235515-3d8ee2261517/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:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4=
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/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/code-generator v0.0.0-20181203235156-f8cba74510f3 h1:f/Aa24HPnPEDWia884BCF94E1b29KYjOTVTHcBzvT2Q=
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
k8s.io/gengo v0.0.0-20181106084056-51747d6e00da h1:ZMvcXtMVbhUCtCuiSEzBV+Eur4swzfdxx6ZyX3qT6dk=
k8s.io/gengo v0.0.0-20181106084056-51747d6e00da/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 h1:PgoMI/L1Nu5Vmvgm+vGheLuxKST8h6FMOqggyAFtHPc=
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-20181201191901-6466d3c7f6e4 h1:fPcE8vd9K1N42jDQEFOdf8phjgi6d+zeIb2Ya7qNFuM=
k8s.io/kube-aggregator v0.0.0-20181201191901-6466d3c7f6e4/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429 h1:wIDPKpRuwEfyt+ImBaP6wSEZeAR5gYJl/Mlg74L0hHI=
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
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.6-beta.0.0.20181126160157-5933b9771b71 h1:ZiDzUVY+KNDO1sbcG0hHZokQsNIhjCCCsy06Z4Ck4JA=
k8s.io/kubernetes v1.11.6-beta.0.0.20181126160157-5933b9771b71/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/kubernetes v1.11.6-beta.0.0.20181207014600-4600add36de5 h1:+oToqFCSumcTuKDfnGBfGDTufqPJK3JmI0+ItcYB2tg=
k8s.io/kubernetes v1.11.6-beta.0.0.20181207014600-4600add36de5/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
8 changes: 7 additions & 1 deletion manifests/0000_30_15-operatorgroup-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: global-operators
namespace: openshift-operators
namespace: openshift-operators
---
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: olm-operators
namespace: openshift-operator-lifecycle-manager
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ const (
CSVPhaseReplacing ClusterServiceVersionPhase = "Replacing"
// CSVPhaseDeleting means that a CSV has been replaced by a new one and will be checked for safety before being deleted
CSVPhaseDeleting ClusterServiceVersionPhase = "Deleting"
// CSVPhaseAny matches all other phases in CSV queries
CSVPhaseAny ClusterServiceVersionPhase = ""
)

// ConditionReason is a camelcased reason for the state transition
Expand Down
20 changes: 8 additions & 12 deletions pkg/controller/install/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
)

var (
Controller = false
BlockOwnerDeletion = false
)

func testDeployment(name, namespace string, mockOwner ownerutil.Owner) appsv1.Deployment {
testDeploymentLabels := map[string]string{"olm.owner": mockOwner.GetName(), "olm.owner.namespace": mockOwner.GetNamespace()}

Expand All @@ -34,8 +29,8 @@ func testDeployment(name, namespace string, mockOwner ownerutil.Owner) appsv1.De
Kind: v1alpha1.ClusterServiceVersionKind,
Name: mockOwner.GetName(),
UID: mockOwner.GetUID(),
Controller: &Controller,
BlockOwnerDeletion: &BlockOwnerDeletion,
Controller: &ownerutil.NotController,
BlockOwnerDeletion: &ownerutil.DontBlockOwnerDeletion,
},
},
Labels: testDeploymentLabels,
Expand All @@ -53,8 +48,8 @@ func testServiceAccount(name string, mockOwner ownerutil.Owner) *corev1.ServiceA
Kind: v1alpha1.ClusterServiceVersionKind,
Name: mockOwner.GetName(),
UID: mockOwner.GetUID(),
Controller: &Controller,
BlockOwnerDeletion: &BlockOwnerDeletion,
Controller: &ownerutil.NotController,
BlockOwnerDeletion: &ownerutil.DontBlockOwnerDeletion,
},
})
return serviceAccount
Expand Down Expand Up @@ -102,8 +97,8 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) {
Kind: v1alpha1.ClusterServiceVersionKind,
Name: mockOwner.GetName(),
UID: mockOwner.UID,
Controller: &Controller,
BlockOwnerDeletion: &BlockOwnerDeletion,
Controller: &ownerutil.NotController,
BlockOwnerDeletion: &ownerutil.DontBlockOwnerDeletion,
}}
)

Expand Down Expand Up @@ -236,7 +231,8 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) {
fakeClient.CreateDeploymentReturns(nil, m.returnError)
defer func(i int, expectedDeployment appsv1.Deployment) {
dep := fakeClient.CreateOrUpdateDeploymentArgsForCall(i)
assert.Equal(t, expectedDeployment, *dep)
expectedDeployment.Spec.Template.Annotations = map[string]string{}
require.Equal(t, expectedDeployment.OwnerReferences, dep.OwnerReferences)
}(i, m.expectedDeployment)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/operators/catalog/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package catalog

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

"github.com/sirupsen/logrus"

"github.com/ghodss/yaml"

"github.com/stretchr/testify/require"
Expand Down
98 changes: 89 additions & 9 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
kagg "k8s.io/kube-aggregator/pkg/client/informers/externalversions"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha2"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/certs"
Expand Down Expand Up @@ -403,7 +404,31 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
"phase": clusterServiceVersion.Status.Phase,
})

operatorNamespace, ok := clusterServiceVersion.GetAnnotations()["olm.operatorNamespace"]
operatorGroup := a.operatorGroupForActiveCSV(logger, clusterServiceVersion)

// don't process CSVs that are not active in an OperatorGroup
if operatorGroup == nil {
opgroups, err := a.lister.OperatorsV1alpha2().OperatorGroupLister().OperatorGroups(clusterServiceVersion.GetNamespace()).List(labels.Everything())
if err != nil {
// TODO: write out error status
logger.Warn("csv created in namespace without operator group, will not be processed")
}
if len(opgroups) == 1 {
a.addOperatorGroupAnnotations(&clusterServiceVersion.ObjectMeta, opgroups[0])
_, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(clusterServiceVersion.GetNamespace()).Update(clusterServiceVersion)
if err != nil {
logger.WithField("opgroup", opgroups[0].GetName()).Error("error adding operatorgroup annotation")
}
return
}
if len(opgroups) > 1 {
logger.Warn("csv created in namespace with multiple operatorgroups, can't pick one automatically")
}
return
}

operatorNamespace, ok := clusterServiceVersion.GetAnnotations()[operatorGroupNamespaceAnnotationKey]

if clusterServiceVersion.Status.Reason == v1alpha1.CSVReasonCopied ||
ok && clusterServiceVersion.GetNamespace() != operatorNamespace {
logger.Info("skip sync of dummy CSV")
Expand All @@ -420,7 +445,7 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
}

// Update CSV with status of transition. Log errors if we can't write them to the status.
_, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(clusterServiceVersion.GetNamespace()).UpdateStatus(outCSV)
updatedCSV, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(clusterServiceVersion.GetNamespace()).UpdateStatus(outCSV)
if err != nil {
updateErr := errors.New("error updating ClusterServiceVersion status: " + err.Error())
if syncError == nil {
Expand All @@ -429,9 +454,61 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
}
syncError = fmt.Errorf("error transitioning ClusterServiceVersion: %s and error updating CSV status: %s", syncError, updateErr)
}

// Check if we need to do any copying / annotation for the operatorgroup
if err := a.copyCsvToTargetNamespace(updatedCSV, operatorGroup); err != nil {
logger.WithError(err).Info("couldn't copy CSV to target namespaces")
}

if err := a.ensureRBACInTargetNamespace(updatedCSV, operatorGroup); err != nil {
logger.WithError(err).Info("couldn't ensure RBAC in target namespaces")
}

return
}

// operatorGroupForCSV returns the operatorgroup for the CSV only if the CSV is active one in the group
func (a *Operator) operatorGroupForActiveCSV(logger *logrus.Entry, csv *v1alpha1.ClusterServiceVersion) *v1alpha2.OperatorGroup {
annotations := csv.GetAnnotations()

// not part of a group yet
if annotations == nil {
logger.Info("not part of any operatorgroup, no annotations")
return nil
}

// not in the operatorgroup namespace
if annotations[operatorGroupNamespaceAnnotationKey] != csv.GetNamespace() {
logger.Info("not in operatorgroup namespace, skipping")
return nil
}

operatorGroupName, ok := annotations[operatorGroupAnnotationKey]

// no operatorgroup annotation
if !ok {
logger.Info("no operatorgroup annotation")
return nil
}

logger = logger.WithField("operatorgroup", operatorGroupName)

operatorGroup, err := a.lister.OperatorsV1alpha2().OperatorGroupLister().OperatorGroups(csv.GetNamespace()).Get(operatorGroupName)
// operatorgroup not found
if err != nil {
logger.Info("operatorgroup not found")
return nil
}

// target namespaces don't match
if annotations[operatorGroupTargetsAnnotationKey] != strings.Join(operatorGroup.Status.Namespaces, ",") {
logger.Info("target namespace annotation doesn't match operatorgroup namespace list")
return nil
}

return operatorGroup
}

// transitionCSVState moves the CSV status state machine along based on the current value and the current cluster state.
func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v1alpha1.ClusterServiceVersion, syncError error) {
logger := a.Log.WithFields(logrus.Fields{
Expand All @@ -441,18 +518,17 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
})

out = in.DeepCopy()
now := timeNow()

// check if the current CSV is being replaced, return with replacing status if so
if err := a.checkReplacementsAndUpdateStatus(out); err != nil {
logger.WithField("err", err).Info("replacement check")
return
}

now := timeNow()

switch out.Status.Phase {
case v1alpha1.CSVPhaseNone:
logger.Infof("scheduling ClusterServiceVersion for requirement verification")
logger.Info("scheduling ClusterServiceVersion for requirement verification")
out.SetPhaseWithEvent(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonRequirementsUnknown, "requirements not yet checked", now, a.recorder)
case v1alpha1.CSVPhasePending:
met, statuses, err := a.requirementAndPermissionStatus(out)
Expand All @@ -472,7 +548,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
}

// Check for CRD ownership conflicts
csvSet := a.csvSet(out.GetNamespace())
csvSet := a.csvSet(out.GetNamespace(), v1alpha1.CSVPhaseAny)
if syncError = a.crdOwnerConflicts(out, csvSet); syncError != nil {
out.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonOwnerConflict, fmt.Sprintf("crd owner conflict: %s", syncError), now, a.recorder)
return
Expand Down Expand Up @@ -554,6 +630,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonNeedsCertRotation, "owned APIServices need cert refresh", now)
return
}

case v1alpha1.CSVPhaseFailed:
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
if strategy == nil {
Expand Down Expand Up @@ -626,7 +703,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v

// findIntermediatesForDeletion starts at csv and follows the replacement chain until one is running and active
func (a *Operator) findIntermediatesForDeletion(csv *v1alpha1.ClusterServiceVersion) (csvs []*v1alpha1.ClusterServiceVersion) {
csvsInNamespace := a.csvSet(csv.GetNamespace())
csvsInNamespace := a.csvSet(csv.GetNamespace(), v1alpha1.CSVPhaseAny)
current := csv

// isBeingReplaced returns a copy
Expand Down Expand Up @@ -654,7 +731,7 @@ func (a *Operator) findIntermediatesForDeletion(csv *v1alpha1.ClusterServiceVers
}

// csvSet gathers all CSVs in the given namespace into a map keyed by CSV name; if metav1.NamespaceAll gets the set across all namespaces
func (a *Operator) csvSet(namespace string) map[string]*v1alpha1.ClusterServiceVersion {
func (a *Operator) csvSet(namespace string, phase v1alpha1.ClusterServiceVersionPhase) map[string]*v1alpha1.ClusterServiceVersion {
csvsInNamespace, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(namespace).List(labels.Everything())

if err != nil {
Expand All @@ -664,6 +741,9 @@ func (a *Operator) csvSet(namespace string) map[string]*v1alpha1.ClusterServiceV

csvs := make(map[string]*v1alpha1.ClusterServiceVersion, len(csvsInNamespace))
for _, csv := range csvsInNamespace {
if phase != v1alpha1.CSVPhaseAny && csv.Status.Phase != phase {
continue
}
csvs[csv.Name] = csv.DeepCopy()
}
return csvs
Expand All @@ -674,7 +754,7 @@ func (a *Operator) checkReplacementsAndUpdateStatus(csv *v1alpha1.ClusterService
if csv.Status.Phase == v1alpha1.CSVPhaseReplacing || csv.Status.Phase == v1alpha1.CSVPhaseDeleting {
return nil
}
if replacement := a.isBeingReplaced(csv, a.csvSet(csv.GetNamespace())); replacement != nil {
if replacement := a.isBeingReplaced(csv, a.csvSet(csv.GetNamespace(), v1alpha1.CSVPhaseAny)); replacement != nil {
a.Log.Infof("newer ClusterServiceVersion replacing %s, no-op", csv.SelfLink)
msg := fmt.Sprintf("being replaced by csv: %s", replacement.SelfLink)
csv.SetPhase(v1alpha1.CSVPhaseReplacing, v1alpha1.CSVReasonBeingReplaced, msg, timeNow())
Expand Down
Loading

0 comments on commit a0c1f69

Please sign in to comment.