@@ -18,10 +18,7 @@ package controllers
1818
1919import  (
2020	"context" 
21- 	"strings" 
2221
23- 	operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" 
24- 	"github.com/operator-framework/operator-controller/internal/resolution" 
2522	"k8s.io/apimachinery/pkg/api/equality" 
2623	apimeta "k8s.io/apimachinery/pkg/api/meta" 
2724	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
@@ -30,6 +27,10 @@ import (
3027	ctrl "sigs.k8s.io/controller-runtime" 
3128	"sigs.k8s.io/controller-runtime/pkg/client" 
3229	"sigs.k8s.io/controller-runtime/pkg/log" 
30+ 
31+ 	operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" 
32+ 	"github.com/operator-framework/operator-controller/internal/resolution" 
33+ 	"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies" 
3334)
3435
3536// OperatorReconciler reconciles a Operator object 
@@ -99,47 +100,47 @@ func checkForUnexpectedFieldChange(a, b operatorsv1alpha1.Operator) bool {
99100
100101// Helper function to do the actual reconcile 
101102func  (r  * OperatorReconciler ) reconcile (ctx  context.Context , op  * operatorsv1alpha1.Operator ) (ctrl.Result , error ) {
103+ 	// define condition parameters 
104+ 	var  status  =  metav1 .ConditionTrue 
105+ 	var  reason  =  operatorsv1alpha1 .ReasonResolutionSucceeded 
106+ 	var  message  =  "resolution was successful" 
102107
103- 	// todo(perdasilva): this is a _hack_ we probably want to find a better way to ride or die resolve and update  
108+ 	// run resolution  
104109	solution , err  :=  r .resolver .Resolve (ctx )
105- 	status  :=  metav1 .ConditionTrue 
106- 	reason  :=  operatorsv1alpha1 .ReasonResolutionSucceeded 
107- 	message  :=  "resolution was successful" 
108110	if  err  !=  nil  {
109111		status  =  metav1 .ConditionTrue 
110112		reason  =  operatorsv1alpha1 .ReasonResolutionFailed 
111113		message  =  err .Error ()
112- 	}
113- 
114- 	// todo(perdasilva): more hacks - need to fix up the solution structure to be more useful 
115- 	packageVariableIDMap  :=  map [string ]string {}
116- 	for  variableID , ok  :=  range  solution  {
117- 		if  ok  {
118- 			idComponents  :=  strings .Split (string (variableID ), "/" )
119- 			packageVariableIDMap [idComponents [1 ]] =  string (variableID )
114+ 	} else  {
115+ 		// extract package bundle path from resolved variable 
116+ 		for  _ , variable  :=  range  solution .SelectedVariables () {
117+ 			switch  v  :=  variable .(type ) {
118+ 			case  * bundles_and_dependencies.BundleVariable :
119+ 				packageName , err  :=  v .BundleEntity ().PackageName ()
120+ 				if  err  !=  nil  {
121+ 					return  ctrl.Result {}, err 
122+ 				}
123+ 				if  packageName  ==  op .Spec .PackageName  {
124+ 					bundlePath , err  :=  v .BundleEntity ().BundlePath ()
125+ 					if  err  !=  nil  {
126+ 						return  ctrl.Result {}, err 
127+ 					}
128+ 					// TODO(perdasilva): use bundlePath to stamp out bundle deployment 
129+ 					_  =  bundlePath 
130+ 					break 
131+ 				}
132+ 			}
120133		}
121134	}
122135
123- 	operatorList  :=  & operatorsv1alpha1.OperatorList {}
124- 	if  err  :=  r .Client .List (ctx , operatorList ); err  !=  nil  {
125- 		return  ctrl.Result {}, err 
126- 	}
127- 
128- 	for  _ , operator  :=  range  operatorList .Items  {
129- 		apimeta .SetStatusCondition (& operator .Status .Conditions , metav1.Condition {
130- 			Type :               operatorsv1alpha1 .TypeReady ,
131- 			Status :             status ,
132- 			Reason :             reason ,
133- 			Message :            message ,
134- 			ObservedGeneration : op .GetGeneration (),
135- 		})
136- 		if  varID , ok  :=  packageVariableIDMap [operator .Spec .PackageName ]; ok  {
137- 			operator .Status .BundlePath  =  varID 
138- 		}
139- 		if  err  :=  r .Client .Status ().Update (ctx , & operator ); err  !=  nil  {
140- 			return  ctrl.Result {}, err 
141- 		}
142- 	}
136+ 	// update operator status 
137+ 	apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
138+ 		Type :               operatorsv1alpha1 .TypeReady ,
139+ 		Status :             status ,
140+ 		Reason :             reason ,
141+ 		Message :            message ,
142+ 		ObservedGeneration : op .GetGeneration (),
143+ 	})
143144
144145	return  ctrl.Result {}, nil 
145146}
0 commit comments