-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1723818: CSV name change should not cause upgrade to fail #925
Merged
openshift-merge-robot
merged 1 commit into
operator-framework:master
from
tkashem:bz-1723818
Jun 28, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package olm | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
@@ -65,18 +66,6 @@ func (a *Operator) checkAPIServiceResources(csv *v1alpha1.ClusterServiceVersion, | |
}) | ||
|
||
errs := []error{} | ||
owners := []ownerutil.Owner{csv} | ||
|
||
// Get replacing CSV if exists | ||
replacing, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(csv.GetNamespace()).Get(csv.Spec.Replaces) | ||
if err != nil && !k8serrors.IsNotFound(err) { | ||
logger.WithError(err).Warn("could not get replacement csv") | ||
return err | ||
} | ||
if replacing != nil { | ||
owners = append(owners, replacing) | ||
} | ||
|
||
ruleChecker := install.NewCSVRuleChecker(a.lister.RbacV1().RoleLister(), a.lister.RbacV1().RoleBindingLister(), a.lister.RbacV1().ClusterRoleLister(), a.lister.RbacV1().ClusterRoleBindingLister(), csv) | ||
for _, desc := range csv.GetOwnedAPIServiceDescriptions() { | ||
apiServiceName := desc.GetName() | ||
|
@@ -92,8 +81,15 @@ func (a *Operator) checkAPIServiceResources(csv *v1alpha1.ClusterServiceVersion, | |
} | ||
|
||
// Check if the APIService is adoptable | ||
if !ownerutil.AdoptableLabels(apiService.GetLabels(), true, owners...) { | ||
logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Debug("adoption failed") | ||
adoptable, err := a.isAPIServiceAdoptable(csv, apiService) | ||
if err != nil { | ||
logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Errorf("adoption check failed - %v", err) | ||
errs = append(errs, err) | ||
return utilerrors.NewAggregate(errs) | ||
} | ||
|
||
if !adoptable { | ||
logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Errorf("adoption failed") | ||
err := olmerrors.NewUnadoptableError("", apiServiceName) | ||
logger.WithError(err).Warn("found unadoptable apiservice") | ||
errs = append(errs, err) | ||
|
@@ -707,17 +703,12 @@ func (a *Operator) installAPIServiceRequirements(desc v1alpha1.APIServiceDescrip | |
} | ||
apiService.SetName(apiServiceName) | ||
} else { | ||
owners := []ownerutil.Owner{csv} | ||
|
||
// Get replacing CSV | ||
replaces, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(csv.GetNamespace()).Get(csv.Spec.Replaces) | ||
if err == nil { | ||
owners = append(owners, replaces) | ||
adoptable, err := a.isAPIServiceAdoptable(csv, apiService) | ||
if err != nil { | ||
logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Errorf("adoption check failed - %v", err) | ||
} | ||
|
||
// check if the APIService is adoptable | ||
if !ownerutil.AdoptableLabels(apiService.GetLabels(), true, owners...) { | ||
logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Debug("adoption failed") | ||
if !adoptable{ | ||
return nil, fmt.Errorf("pre-existing APIService %s is not adoptable", apiServiceName) | ||
} | ||
} | ||
|
@@ -759,3 +750,54 @@ func APIServiceNameToServiceName(apiServiceName string) string { | |
// Replace all '.'s with "-"s to convert to a DNS-1035 label | ||
return strings.Replace(apiServiceName, ".", "-", -1) | ||
} | ||
|
||
func (a *Operator) isAPIServiceAdoptable(target *v1alpha1.ClusterServiceVersion, apiService *apiregistrationv1.APIService) (adoptable bool, err error) { | ||
if apiService == nil || target == nil { | ||
err = errors.New("invalid input") | ||
return | ||
} | ||
|
||
labels := apiService.GetLabels() | ||
ownerKind := labels[ownerutil.OwnerKind] | ||
ownerName := labels[ownerutil.OwnerKey] | ||
ownerNamespace := labels[ownerutil.OwnerNamespaceKey] | ||
|
||
if ownerKind == "" || ownerNamespace == "" || ownerName == "" { | ||
return | ||
} | ||
|
||
if err := ownerutil.InferGroupVersionKind(target); err != nil { | ||
a.logger.Warn(err.Error()) | ||
} | ||
|
||
targetKind := target.GetObjectKind().GroupVersionKind().Kind | ||
if ownerKind != targetKind { | ||
return | ||
} | ||
|
||
// Get the CSV that target replaces | ||
replacing, replaceGetErr := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(target.GetNamespace()).Get(target.Spec.Replaces) | ||
if replaceGetErr != nil && !k8serrors.IsNotFound(replaceGetErr) && !k8serrors.IsGone(replaceGetErr) { | ||
err = replaceGetErr | ||
return | ||
} | ||
|
||
// Get the current owner CSV of the APIService | ||
currentOwnerCSV, ownerGetErr := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(ownerNamespace).Get(ownerName) | ||
if ownerGetErr != nil && !k8serrors.IsNotFound(ownerGetErr) && !k8serrors.IsGone(ownerGetErr) { | ||
err = ownerGetErr | ||
return | ||
} | ||
|
||
owners := []ownerutil.Owner{target} | ||
if replacing != nil { | ||
owners = append(owners, replacing) | ||
} | ||
if currentOwnerCSV != nil && ( | ||
currentOwnerCSV.Status.Phase == v1alpha1.CSVPhaseReplacing || currentOwnerCSV.Status.Phase == v1alpha1.CSVPhaseDeleting) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe there's a set of phases that include these that you can check for membership |
||
owners = append(owners, currentOwnerCSV) | ||
} | ||
|
||
adoptable = ownerutil.AdoptableLabels(apiService.GetLabels(), true, owners...) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know the type coming in and don't need the rest of the meta (just the kind string) - I would just import the
ClusterServiceVersionKind
string from the api package and compare