@@ -30,9 +30,13 @@ import (
3030 "sigs.k8s.io/controller-runtime/pkg/reconcile"
3131
3232 "github.com/go-logr/logr"
33+ keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
3334 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
35+ "github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
3436 "github.com/openstack-k8s-operators/lib-common/modules/common/env"
3537 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
38+ "github.com/openstack-k8s-operators/lib-common/modules/common/labels"
39+ "github.com/openstack-k8s-operators/lib-common/modules/common/service"
3640 mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
3741
3842 watcherv1beta1 "github.com/openstack-k8s-operators/watcher-operator/api/v1beta1"
@@ -59,6 +63,9 @@ func (r *WatcherAPIReconciler) GetLogger(ctx context.Context) logr.Logger {
5963//+kubebuilder:rbac:groups=watcher.openstack.org,resources=watcherapis/status,verbs=get;update;patch
6064//+kubebuilder:rbac:groups=watcher.openstack.org,resources=watcherapis/finalizers,verbs=update
6165//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete;
66+ //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneapis,verbs=get;list;watch;
67+ //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete;
68+ //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete;
6269
6370// Reconcile is part of the main kubernetes reconciliation loop which aims to
6471// move the current state of the cluster closer to the desired state.
@@ -181,9 +188,6 @@ func (r *WatcherAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request)
181188}
182189
183190// generateServiceConfigs - create Secret which holds the service configuration
184- // NOTE - jgilaber this function is WIP, currently implements a fraction of its
185- // functionality and will be expanded of further iteration to actually generate
186- // the service configs
187191func (r * WatcherAPIReconciler ) generateServiceConfigs (
188192 ctx context.Context , instance * watcherv1beta1.WatcherAPI ,
189193 secret corev1.Secret , db * mariadbv1.Database ,
@@ -192,14 +196,58 @@ func (r *WatcherAPIReconciler) generateServiceConfigs(
192196 Log := r .GetLogger (ctx )
193197 Log .Info ("generateServiceConfigs - reconciling" )
194198
195- // replace by actual usage in future iterations
196- _ = db
197- _ = helper
198- _ = instance
199- _ = secret
200- _ = envVars
199+ labels := labels .GetLabels (instance , labels .GetGroupLabel (watcher .ServiceName ), map [string ]string {})
200+ // jgilaber this might be wrong? we should probably get keystonapi in the
201+ // watcher controller and set the url in the spec eventually?
202+ keystoneAPI , err := keystonev1 .GetKeystoneAPI (ctx , helper , instance .Namespace , map [string ]string {})
203+ // KeystoneAPI not available we should not aggregate the error and continue
204+ if err != nil {
205+ instance .Status .Conditions .Set (condition .FalseCondition (
206+ condition .ServiceConfigReadyCondition ,
207+ condition .ErrorReason ,
208+ condition .SeverityWarning ,
209+ condition .ServiceConfigReadyErrorMessage ,
210+ "keystoneAPI not found" ))
211+ return err
212+ }
213+ keystoneInternalURL , err := keystoneAPI .GetEndpoint (endpoint .EndpointInternal )
214+ if err != nil {
215+ return err
216+ }
217+ // customData hold any customization for the service.
218+ // NOTE jgilaber making an empty map for now, we'll probably want to
219+ // implement CustomServiceConfig later
220+ customData := map [string ]string {}
221+
222+ databaseAccount := db .GetAccount ()
223+ databaseSecret := db .GetSecret ()
224+ templateParameters := map [string ]interface {}{
225+ "DatabaseConnection" : fmt .Sprintf ("mysql+pymysql://%s:%s@%s/%s?charset=utf8&plugin=dbcounter" ,
226+ databaseAccount .Spec .UserName ,
227+ string (databaseSecret .Data [mariadbv1 .DatabasePasswordSelector ]),
228+ db .GetDatabaseHostname (),
229+ watcher .DatabaseName ,
230+ ),
231+ "KeystoneAuthURL" : keystoneInternalURL ,
232+ "ServicePassword" : string (secret .Data [instance .Spec .PasswordSelectors .Service ]),
233+ "ServiceUser" : instance .Spec .ServiceUser ,
234+ "TransportURL" : "" , // TODO jgilaber implement getting this URL once we
235+ // have rabbitmq support added to the Watcher controller
236+ "MemcachedServers" : "" , // TODO jgilaber implement getting this URL once we
237+ // have memchache support
238+ }
201239
202- return nil
240+ // create httpd vhost template parameters
241+ httpdVhostConfig := map [string ]interface {}{}
242+ for _ , endpt := range []service.Endpoint {service .EndpointInternal , service .EndpointPublic } {
243+ endptConfig := map [string ]interface {}{}
244+ endptConfig ["ServerName" ] = fmt .Sprintf ("%s-%s.%s.svc" , watcher .ServiceName , endpt .String (), instance .Namespace )
245+ endptConfig ["TLS" ] = false // default TLS to false, and set it below when implemented
246+ httpdVhostConfig [endpt .String ()] = endptConfig
247+ }
248+ templateParameters ["VHosts" ] = httpdVhostConfig
249+
250+ return GenerateConfigsGeneric (ctx , helper , instance , envVars , templateParameters , customData , labels , false )
203251}
204252
205253func (r * WatcherAPIReconciler ) reconcileDelete (ctx context.Context , instance * watcherv1beta1.WatcherAPI , helper * helper.Helper ) (ctrl.Result , error ) {
0 commit comments