Skip to content

Commit

Permalink
fix(operatorgroup): No targetNamespaces matched namespace selector
Browse files Browse the repository at this point in the history
If no namespaces are matched selector in operatorgroup, CSV should have a failure
status to indicate OperatorGroup NoTargetNamspaces. Also, a warning message for
no-matched namespaces is added for visibility.

Signed-off-by: Vu Dinh <[email protected]>
  • Loading branch information
dinhxuanvu committed May 9, 2019
1 parent fb76336 commit 462e73a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const (
CSVReasonInvalidInstallModes ConditionReason = "InvalidInstallModes"
CSVReasonNoTargetNamespaces ConditionReason = "NoTargetNamespaces"
CSVReasonUnsupportedOperatorGroup ConditionReason = "UnsupportedOperatorGroup"
CSVReasonNoOperatorGroup ConditionReason = "NoOperatorGroup"
CSVReasonNoOperatorGroup ConditionReason = "OperatorGroupIncorrect"
CSVReasonTooManyOperatorGroups ConditionReason = "TooManyOperatorGroups"
CSVReasonInterOperatorGroupOwnerConflict ConditionReason = "InterOperatorGroupOwnerConflict"
CSVReasonCannotModifyStaticOperatorGroupProvidedAPIs ConditionReason = "CannotModifyStaticOperatorGroupProvidedAPIs"
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ func (a *Operator) operatorGroupForCSV(csv *v1alpha1.ClusterServiceVersion, logg
logger.WithError(err).Warn("error adding operatorgroup annotations")
return nil, err
}
if targetNamespaceList, err := a.getOperatorGroupTargets(operatorGroup); err == nil && len(targetNamespaceList) == 0 {
csv.SetPhaseWithEventIfChanged(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonNoTargetNamespaces, "no targetNamespaces are matched operatorgroups namespace selection", now, a.recorder)
}
return nil, nil
}
logger.Info("csv in operatorgroup")
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/operators/olm/operatorgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ func (a *Operator) getOperatorGroupTargets(op *v1.OperatorGroup) (map[string]str
matchedNamespaces, err := a.lister.CoreV1().NamespaceLister().List(selector)
if err != nil {
return nil, err
} else if len(matchedNamespaces) == 0 {
a.Log.Debugf("No matched TargetNamespaces are found for given selector: %#v\n", selector)
}

for _, ns := range matchedNamespaces {
Expand Down

0 comments on commit 462e73a

Please sign in to comment.