Skip to content

Commit bc353f0

Browse files
Merge pull request #453 from pepedocs/handle-ip-approval
MTSRE-1447: Handled manual install plan approval
2 parents 820afed + cf20e19 commit bc353f0

File tree

7 files changed

+293
-29
lines changed

7 files changed

+293
-29
lines changed

apis/addons/v1alpha1/addons_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package v1alpha1
22

33
import (
4+
"errors"
5+
46
monv1 "github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring/v1"
57
corev1 "k8s.io/api/core/v1"
68
"k8s.io/apimachinery/pkg/api/meta"
@@ -324,6 +326,9 @@ const (
324326

325327
// Addon instance has been successfully installed.
326328
AddonReasonInstanceInstalled = "AddonInstanceInstalled"
329+
330+
// Addon's Install Plan is pending due to some condition such as a manual approval.
331+
AddonReasonInstallPlanPending = "AddonInstallPlanPending"
327332
)
328333

329334
type AddonNamespace struct {
@@ -486,6 +491,21 @@ func (a *Addon) UpgradeCompleteForCurrentVersion() bool {
486491
a.Status.UpgradePolicy.Value == AddonUpgradePolicyValueCompleted
487492
}
488493

494+
// Gets the AddonInstallOLMCommon by Install Type
495+
func (a *Addon) GetInstallOLMCommon() (AddonInstallOLMCommon, error) {
496+
switch a.Spec.Install.Type {
497+
case OLMAllNamespaces:
498+
if a.Spec.Install.OLMAllNamespaces != nil {
499+
return a.Spec.Install.OLMAllNamespaces.AddonInstallOLMCommon, nil
500+
}
501+
case OLMOwnNamespace:
502+
if a.Spec.Install.OLMOwnNamespace != nil {
503+
return a.Spec.Install.OLMOwnNamespace.AddonInstallOLMCommon, nil
504+
}
505+
}
506+
return AddonInstallOLMCommon{}, errors.New("addon install OLM common not found")
507+
}
508+
489509
// AddonList contains a list of Addon
490510
// +kubebuilder:object:root=true
491511
type AddonList struct {

internal/controllers/addon/olm_reconciler.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,38 @@ func (r *olmReconciler) Reconcile(ctx context.Context,
9393
func (r *olmReconciler) Name() string {
9494
return OLM_RECONCILER_NAME
9595
}
96+
97+
// Gets a subscription by ObjectKey
98+
func (r *olmReconciler) GetSubscription(
99+
ctx context.Context,
100+
name string,
101+
namespace string,
102+
) (*operatorsv1alpha1.Subscription, error) {
103+
destSub := operatorsv1alpha1.Subscription{}
104+
key := client.ObjectKey{
105+
Name: name,
106+
Namespace: namespace,
107+
}
108+
109+
if err := r.client.Get(ctx, key, &destSub); err != nil {
110+
return nil, err
111+
}
112+
return &destSub, nil
113+
}
114+
115+
// Gets an InstallPlan by ObjectKey
116+
func (r *olmReconciler) GetInstallPlan(
117+
ctx context.Context,
118+
name string,
119+
namespace string,
120+
) (*operatorsv1alpha1.InstallPlan, error) {
121+
destIp := operatorsv1alpha1.InstallPlan{}
122+
key := client.ObjectKey{
123+
Name: name,
124+
Namespace: namespace,
125+
}
126+
if err := r.client.Get(ctx, key, &destIp); err != nil {
127+
return nil, err
128+
}
129+
return &destIp, nil
130+
}

internal/controllers/addon/phase_ensure_subscription.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ func (r *olmReconciler) ensureSubscription(
3030
client.ObjectKey,
3131
error,
3232
) {
33-
var commonInstallOptions addonsv1alpha1.AddonInstallOLMCommon
34-
switch addon.Spec.Install.Type {
35-
case addonsv1alpha1.OLMAllNamespaces:
36-
commonInstallOptions = addon.Spec.Install.
37-
OLMAllNamespaces.AddonInstallOLMCommon
38-
case addonsv1alpha1.OLMOwnNamespace:
39-
commonInstallOptions = addon.Spec.Install.
40-
OLMOwnNamespace.AddonInstallOLMCommon
33+
commonInstallOptions, err := addon.GetInstallOLMCommon()
34+
if err != nil {
35+
return resultNil, client.ObjectKey{}, err
4136
}
37+
4238
subscriptionConfigObject := createSubscriptionConfigObject(commonInstallOptions)
4339
desiredSubscription := &operatorsv1alpha1.Subscription{
4440
ObjectMeta: metav1.ObjectMeta{
@@ -108,11 +104,11 @@ func (r *olmReconciler) reconcileSubscription(
108104
ctx context.Context,
109105
subscription *operatorsv1alpha1.Subscription,
110106
) (currentSubscription *operatorsv1alpha1.Subscription, err error) {
111-
currentSubscription = &operatorsv1alpha1.Subscription{}
112-
err = r.client.Get(ctx, client.ObjectKey{
113-
Name: subscription.Name,
114-
Namespace: subscription.Namespace,
115-
}, currentSubscription)
107+
currentSubscription, err = r.GetSubscription(
108+
ctx,
109+
subscription.Name,
110+
subscription.Namespace,
111+
)
116112
if err != nil {
117113
if apierrors.IsNotFound(err) {
118114
return subscription, r.client.Create(ctx, subscription)

internal/controllers/addon/phase_observe_operatorresource.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,37 @@ func (r *olmReconciler) observeOperatorResource(
2020
addon *addonsv1alpha1.Addon,
2121
csvKey client.ObjectKey,
2222
) (requeueResult, error) {
23+
installOLMCommon, err := addon.GetInstallOLMCommon()
24+
if err != nil {
25+
return resultRetry, err
26+
}
27+
28+
currentSub, err := r.GetSubscription(
29+
ctx,
30+
SubscriptionName(addon),
31+
installOLMCommon.Namespace,
32+
)
33+
if err != nil {
34+
return resultRetry, err
35+
}
36+
37+
if currentSub.GetInstallPlanApproval() == operatorsv1alpha1.ApprovalManual {
38+
currentIp, err := r.GetInstallPlan(
39+
ctx,
40+
currentSub.Status.InstallPlanRef.Name,
41+
currentSub.Status.InstallPlanRef.Namespace,
42+
)
43+
if err != nil {
44+
return resultNil, err
45+
}
46+
47+
if currentIp.Status.Phase == operatorsv1alpha1.InstallPlanPhaseRequiresApproval {
48+
reportInstallPlanPending(addon)
49+
// CSV will not be available at this stage
50+
return resultNil, nil
51+
}
52+
}
53+
2354
operatorKey := client.ObjectKey{
2455
Namespace: "",
2556
Name: generateOperatorResourceName(addon),

0 commit comments

Comments
 (0)