Skip to content

Commit

Permalink
WIP adds config and deployment for WatcherDecisionEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
marios committed Jan 30, 2025
1 parent b9599e7 commit af91f16
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
3 changes: 3 additions & 0 deletions controllers/watcher_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const (
// WatcherApplierLabelPrefix - a unique, service binary specific prefix for the
// labels the WatcherApplier controller uses on children objects
WatcherApplierLabelPrefix = "watcher-applier"
// WatcherDecisionEngineLabelPrefix - a unique, service binary specific prefix
// for the labels the WatcherDecisionEngine controller uses on child objects
WatcherDecisionEngineLabelPrefix = "watcher-decisionengine"
)

// GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
Expand Down
75 changes: 69 additions & 6 deletions controllers/watcherdecisionengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ import (

"github.com/go-logr/logr"
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
watcherv1beta1 "github.com/openstack-k8s-operators/watcher-operator/api/v1beta1"
"github.com/openstack-k8s-operators/watcher-operator/pkg/watcher"

corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -289,12 +295,69 @@ func (r *WatcherDecisionEngineReconciler) generateServiceConfigs(
Log := r.GetLogger(ctx)
Log.Info("generateServiceConfigs - reconciling")

_ = instance
_ = secret
_ = memcachedInstance
_ = helper
_ = envVars
return nil
labels := labels.GetLabels(instance, labels.GetGroupLabel(WatcherDecisionEngineLabelPrefix), map[string]string{})

keystoneAPI, err := keystonev1.GetKeystoneAPI(ctx, helper, instance.Namespace, map[string]string{})
// KeystoneAPI not available we should not aggregate the error and continue
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ServiceConfigReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.ServiceConfigReadyErrorMessage,
"keystoneAPI not found"))
return err
}
keystoneInternalURL, err := keystoneAPI.GetEndpoint(endpoint.EndpointInternal)
if err != nil {
return err
}

databaseAccount := string(secret.Data[DatabaseAccount])
db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, watcher.DatabaseCRName, databaseAccount, instance.Namespace)
if err != nil {
return err
}
// customData hold any customization for the service.
var tlsCfg *tls.Service
if instance.Spec.TLS.Ca.CaBundleSecretName != "" {
tlsCfg = &tls.Service{}
}
// customData hold any customization for the service.
customData := map[string]string{
watcher.GlobalCustomConfigFileName: string(secret.Data[watcher.GlobalCustomConfigFileName]),
watcher.ServiceCustomConfigFileName: instance.Spec.CustomServiceConfig,
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
}

databaseUsername := string(secret.Data[DatabaseUsername])
databaseHostname := string(secret.Data[DatabaseHostname])
databasePassword := string(secret.Data[DatabasePassword])

var CaFilePath string
if instance.Spec.TLS.CaBundleSecretName != "" {
CaFilePath = tls.DownstreamTLSCABundlePath
}
templateParameters := map[string]interface{}{
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
databaseUsername,
databasePassword,
databaseHostname,
watcher.DatabaseName,
),
"KeystoneAuthURL": keystoneInternalURL,
"ServicePassword": string(secret.Data[instance.Spec.PasswordSelectors.Service]),
"ServiceUser": instance.Spec.ServiceUser,
"TransportURL": string(secret.Data[TransportURLSelector]),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
"MemcachedTLS": memcachedInstance.GetMemcachedTLSSupport(),
"LogFile": fmt.Sprintf("%s%s.log", watcher.WatcherLogPath, instance.Name),
"APIPublicPort": fmt.Sprintf("%d", watcher.WatcherPublicPort),
"CaFilePath": CaFilePath,
}

return GenerateConfigsGeneric(ctx, helper, instance, envVars, templateParameters, customData, labels, false)
}

func (r *WatcherDecisionEngineReconciler) reconcileDelete(ctx context.Context, instance *watcherv1beta1.WatcherDecisionEngine, helper *helper.Helper) (ctrl.Result, error) {
Expand Down

0 comments on commit af91f16

Please sign in to comment.