Skip to content

Commit

Permalink
Merge pull request #218 from omersch381/clean_operator_files
Browse files Browse the repository at this point in the history
Clean operator files
  • Loading branch information
omersch381 authored Sep 20, 2024
2 parents 05bf532 + 34e9283 commit f08edb8
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 140 deletions.
88 changes: 42 additions & 46 deletions controllers/designate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,52 +354,6 @@ func (r *DesignateReconciler) reconcileInit(
// ConfigMap
configMapVars := make(map[string]env.Setter)

//
// check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
//
ospSecret, hash, err := oko_secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("OpenStack secret %s not found", instance.Spec.Secret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}

configMapVars[ospSecret.Name] = env.SetValue(hash)

transportURLSecret, hash, err := oko_secret.GetSecret(ctx, helper, instance.Status.TransportURLSecret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Status.TransportURLSecret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
configMapVars[transportURLSecret.Name] = env.SetValue(hash)

designateDb, result, err := r.ensureDB(ctx, helper, instance)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -1153,6 +1107,48 @@ func (r *DesignateReconciler) generateServiceConfigMaps(
}
templateParameters["ServiceUser"] = instance.Spec.ServiceUser

transportURLSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Status.TransportURLSecret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return err
}
templateParameters["TransportURL"] = string(transportURLSecret.Data["transport_url"])

adminPasswordSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("AdminPassword secret %s not found", instance.Spec.Secret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return err
}
templateParameters["AdminPassword"] = string(adminPasswordSecret.Data["DesignatePassword"])

cms := []util.Template{
// ScriptsConfigMap
{
Expand Down
42 changes: 42 additions & 0 deletions controllers/designateapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,48 @@ func (r *DesignateAPIReconciler) generateServiceConfigMaps(
}
templateParameters["VHosts"] = httpdVhostConfig

transportURLSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Spec.TransportURLSecret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Spec.TransportURLSecret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return err
}
templateParameters["TransportURL"] = string(transportURLSecret.Data["transport_url"])

adminPasswordSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info(fmt.Sprintf("AdminPassword secret %s not found", instance.Spec.Secret))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return err
}
templateParameters["AdminPassword"] = string(adminPasswordSecret.Data["DesignatePassword"])

cms := []util.Template{
// ScriptsConfigMap
{
Expand Down
4 changes: 2 additions & 2 deletions controllers/designatebackendbind9_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (r *DesignateBackendbind9Reconciler) reconcileNormal(ctx context.Context, i
//

serviceLabels := map[string]string{
common.AppSelector: designate.ServiceName,
common.AppSelector: instance.ObjectMeta.Name,
common.ComponentSelector: designatebackendbind9.Component,
}

Expand Down Expand Up @@ -652,7 +652,7 @@ func (r *DesignateBackendbind9Reconciler) generateServiceConfigMaps(
// - %-config-data configmap holding custom config for the service's designate.conf
//

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(designate.ServiceName), serviceLabels)
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), serviceLabels)

// customData hold any customization for the service.
// custom.conf is going to be merged into /etc/designate/conder.conf
Expand Down
4 changes: 2 additions & 2 deletions controllers/designatecentral_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (r *DesignateCentralReconciler) reconcileNormal(ctx context.Context, instan
//

serviceLabels := map[string]string{
common.AppSelector: designate.ServiceName,
common.AppSelector: instance.ObjectMeta.Name,
common.ComponentSelector: designatecentral.Component,
}

Expand Down Expand Up @@ -721,7 +721,7 @@ func (r *DesignateCentralReconciler) generateServiceConfigMaps(
// - %-config-data configmap holding custom config for the service's designate.conf
//

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(designate.ServiceName), map[string]string{})
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})

db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, designate.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/designatemdns_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (r *DesignateMdnsReconciler) reconcileNormal(ctx context.Context, instance
//

serviceLabels := map[string]string{
common.AppSelector: designate.ServiceName,
common.AppSelector: instance.ObjectMeta.Name,
common.ComponentSelector: designatemdns.Component,
}

Expand Down Expand Up @@ -720,7 +720,7 @@ func (r *DesignateMdnsReconciler) generateServiceConfigMaps(
// - %-config-data configmap holding custom config for the service's designate.conf
//

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(designate.ServiceName), map[string]string{})
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})

db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, designate.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/designateproducer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (r *DesignateProducerReconciler) reconcileNormal(ctx context.Context, insta
//

serviceLabels := map[string]string{
common.AppSelector: designate.ServiceName,
common.AppSelector: instance.ObjectMeta.Name,
common.ComponentSelector: designateproducer.Component,
}

Expand Down Expand Up @@ -720,7 +720,7 @@ func (r *DesignateProducerReconciler) generateServiceConfigMaps(
// - %-config-data configmap holding custom config for the service's designate.conf
//

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(designate.ServiceName), map[string]string{})
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})

db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, designate.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/designateworker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (r *DesignateWorkerReconciler) reconcileNormal(ctx context.Context, instanc
//

serviceLabels := map[string]string{
common.AppSelector: designate.ServiceName,
common.AppSelector: instance.ObjectMeta.Name,
common.ComponentSelector: designateworker.Component,
}

Expand Down Expand Up @@ -715,7 +715,7 @@ func (r *DesignateWorkerReconciler) generateServiceConfigMaps(
// - %-config-data configmap holding custom config for the service's designate.conf
//

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(designate.ServiceName), map[string]string{})
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})

db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, designate.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace)
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions templates/designate/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ set -ex
# copies the result to the ephemeral /var/lib/config-data/merged volume.
#
# Secrets are obtained from ENV variables.
export PASSWORD=${AdminPassword:?"Please specify a AdminPassword variable."}
export TRANSPORTURL=${TransportURL:-""}
export BACKENDURL=${BackendURL:-"redis://redis:6379/"}

VERBOSE="True"

SVC_CFG=/etc/designate/designate.conf
Expand Down Expand Up @@ -88,15 +84,6 @@ for dir in /var/lib/config-data/default; do
merge_config_dir ${dir}
done

# set secrets in the config-data
crudini --set ${SVC_CFG_MERGED} keystone_authtoken password $PASSWORD
if [ -n "$TRANSPORTURL" ]; then
crudini --set ${SVC_CFG_MERGED} DEFAULT transport_url $TRANSPORTURL
fi
if [ -n "$BACKENDURL" ]; then
crudini --set ${SVC_CFG_MERGED} coordination backend_url $BACKENDURL
fi

# NOTE:dkehn - REMOVED because Kolla_set & start copy eveyrthing.
# I'm doing this to get the designate.conf w/all the tags with values.
cp -a ${SVC_CFG_MERGED} ${SVC_CFG}
26 changes: 2 additions & 24 deletions templates/designate/config/designate.conf
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
[DEFAULT]
debug=True
rpc_response_timeout=60

quota_api_export_size=1000
quota_recordset_records=20
quota_zone_records=500
quota_zone_recordsets=500
quota_zones=10
root-helper=sudo
state_path=/etc/designate/data
debug=True
transport_url=rabbit://stackrabbit:[email protected]:5672/

healthcheck_enabled=True
transport_url={{ .TransportURL }}

[database]
connection={{ .DatabaseConnection }}
Expand All @@ -23,15 +18,13 @@ connection={{ .DatabaseConnection }}
[coordination]
backend_url=memcached://127.0.0.1:11211


[service:api]
quotas_verify_project_id=True
auth_strategy=keystone
enable_api_admin=True
enable_api_v2=True
enable_host_header=True
enabled_extensions_admin=quotas
enabled_extension_v2 =

[service:central]
workers=2
Expand Down Expand Up @@ -59,26 +52,11 @@ lock_path=/opt/stack/data/designate
enforce_scope=True
enforce_new_defaults=True

[health_manager]
health_update_threads=4
stats_update_threads=4
# heartbeat_key=FIXMEkey1

[keystone_authtoken]
username={{ .ServiceUser }}
# password=FIXMEpw3
project_name=service
project_domain_name=Default
user_domain_name=Default
auth_type=password
# memcache_use_advanced_pool=True
# memcached_servers=FIXMEhost1:11211
# region_name=regionOne

#interface=internal

# cafile=/opt/stack/data/ca-bundle.pem
#cafile=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

[keystone]
password={{ .AdminPassword }}
region_name=RegionOne
3 changes: 0 additions & 3 deletions templates/designate/config/init_setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
echo "This is for debugging purposes only, setups the env for the init.sh to run"
export AdminPassword=12345678
export DatabaseHost=openstack
export DatabaseUser=designate
export DatabasePassword=12345678
export DatabaseName=designate
export TransportURL=rabbit://default_user_P3R2c2-n3Pzpj1Gx6lf:[email protected]:5672
export BackendURL=redis://redis:6379/
12 changes: 0 additions & 12 deletions templates/designateapi/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ set -ex
# copies the result to the ephemeral /var/lib/config-data/merged volume.
#
# Secrets are obtained from ENV variables.
export PASSWORD=${AdminPassword:?"Please specify a AdminPassword variable."}
export TRANSPORTURL=${TransportURL:-""}

VERBOSE="True"

SVC_CFG=/etc/designate/designate.conf
Expand All @@ -39,15 +36,6 @@ for dir in /var/lib/config-data/default; do
merge_config_dir ${dir}
done

# set secrets in the config-data
crudini --set ${SVC_CFG_MERGED} keystone_authtoken password $PASSWORD
if [ -n "$TRANSPORTURL" ]; then
crudini --set ${SVC_CFG_MERGED} DEFAULT transport_url $TRANSPORTURL
fi
if [ -n "$BACKENDURL" ]; then
crudini --set ${SVC_CFG_MERGED} coordination backend_url $BACKENDURL
fi

# NOTE:dkehn - REMOVED because Kolla_set & start copy eveyrthing.
# I'm doing this to get the designate.conf w/all the tags with values.
cp -a ${SVC_CFG_MERGED} ${SVC_CFG}
Loading

0 comments on commit f08edb8

Please sign in to comment.