-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1740332: OLM should resume operator install
OLM should automatically resume operator install when a user grants proper permission(s). Currently, a user has to manually delete the subscription and recreate it in order to trigger a reinstall of the operator. Do the following to trigger reinstall: - Add a new field 'AttenuatedServiceAccountRef' to status of InstallPlan. We use this to refer to the ServiceAccount that will be used to do attenuated scoped install of the operator. - Watch on Role(Binding), ServiceAccount resources. When these RBAC resources are added/updated find the target InstallPlan object. - Update the status.phase of the InstallPlan object to Installing. This will trigger a sync of the InstallPlan. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1740332 Jira: https://jira.coreos.com/browse/OLM-1244
- Loading branch information
Showing
9 changed files
with
228 additions
and
28 deletions.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package catalog | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
utilerrors "k8s.io/apimachinery/pkg/util/errors" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil" | ||
) | ||
|
||
// When a user adds permission to a ServiceAccount by creating or updating | ||
// Role/RoleBinding then we expect the InstallPlan that refers to the | ||
// ServiceAccount to be retried if it has failed to install before due to | ||
// permission issue(s). | ||
func (o *Operator) triggerInstallPlanRetry(obj interface{}) (syncError error) { | ||
metaObj, ok := obj.(metav1.Object) | ||
if !ok { | ||
syncError = errors.New("casting to metav1 object failed") | ||
o.logger.Warn(syncError.Error()) | ||
return | ||
} | ||
|
||
related, _ := isObjectRBACRelated(obj) | ||
if !related { | ||
return | ||
} | ||
|
||
ips, err := o.lister.OperatorsV1alpha1().InstallPlanLister().InstallPlans(metaObj.GetNamespace()).List(labels.Everything()) | ||
if err != nil { | ||
syncError = err | ||
return | ||
} | ||
|
||
isTarget := func(ip *v1alpha1.InstallPlan) bool { | ||
// Only an InstallPlan that has failed to install before and only if it | ||
// has a reference to a ServiceAccount then | ||
return ip.Status.Phase == v1alpha1.InstallPlanPhaseFailed && ip.Status.AttenuatedServiceAccountRef != nil | ||
} | ||
|
||
update := func(ip *v1alpha1.InstallPlan) error { | ||
out := ip.DeepCopy() | ||
out.Status.Phase = v1alpha1.InstallPlanPhaseInstalling | ||
_, err := o.client.OperatorsV1alpha1().InstallPlans(ip.GetNamespace()).UpdateStatus(out) | ||
|
||
return err | ||
} | ||
|
||
var errs []error | ||
for _, ip := range ips { | ||
if !isTarget(ip) { | ||
continue | ||
} | ||
|
||
logger := o.logger.WithFields(logrus.Fields{ | ||
"ip": ip.GetName(), | ||
"namespace": ip.GetNamespace(), | ||
"phase": ip.Status.Phase, | ||
}) | ||
|
||
if updateErr := update(ip); updateErr != nil { | ||
errs = append(errs, updateErr) | ||
logger.WithError(updateErr).Warn("failed to kick off InstallPlan retry") | ||
continue | ||
} | ||
|
||
logger.Info("InstallPlan status set to 'Installing' for retry") | ||
} | ||
|
||
syncError = utilerrors.NewAggregate(errs) | ||
return | ||
} | ||
|
||
func isObjectRBACRelated(obj interface{}) (related bool, object runtime.Object) { | ||
object, ok := obj.(runtime.Object) | ||
if !ok { | ||
return | ||
} | ||
|
||
if err := ownerutil.InferGroupVersionKind(object); err != nil { | ||
return | ||
} | ||
|
||
kind := object.GetObjectKind().GroupVersionKind().Kind | ||
switch kind { | ||
case roleKind: | ||
fallthrough | ||
case roleBindingKind: | ||
fallthrough | ||
case serviceAccountKind: | ||
related = true | ||
} | ||
|
||
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
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
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