Skip to content

Commit

Permalink
Support for RabbitMQ notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Harley committed Oct 19, 2023
1 parent 7b1a1e5 commit 5298553
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ spec:
description: PreserveJobs - do not delete jobs after they finished
e.g. to check logs
type: boolean
rabbitMqClusterName:
default: rabbitmq
description: RabbitMQ instance name Needed to request a transportURL
that is created and used in Keystone
type: string
region:
default: regionOne
description: Region - optional region name for the keystone service
Expand Down Expand Up @@ -471,6 +476,9 @@ spec:
description: ReadyCount of keystone API instances
format: int32
type: integer
transportURLSecret:
description: TransportURLSecret - Secret containing RabbitMQ transportURL
type: string
type: object
type: object
served: true
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (

// KeystoneServiceOSUserReadyCondition Status=True condition which indicates if the service user got created in the keystone instance is ready/was successful
KeystoneServiceOSUserReadyCondition condition.Type = "KeystoneServiceOSUserReady"

// KeystoneRabbitMQTransportURLReadyCondition -
KeystoneRabbitMQTransportURLReadyCondition condition.Type = "KeystoneRabbitMQTransportURLReady"
)

// Common Messages used by API objects.
Expand Down Expand Up @@ -111,4 +114,12 @@ const (

// KeystoneServiceOSUserReadyErrorMessage
KeystoneServiceOSUserReadyErrorMessage = "Keystone Service user error occured %s"

// RabbitMQTransportURLReadyRunningMessage -
KeystoneRabbitMQTransportURLReadyRunningMessage = "KeystoneRabbitMQTransportURL creation in progress"
// RabbitMQTransportURLReadyMessage -
KeystoneRabbitMQTransportURLReadyMessage = "KeystoneRabbitMQTransportURL successfully created"
// RabbitMQTransportURLReadyErrorMessage -
KeystoneRabbitMQTransportURLReadyErrorMessage = "KeystoneRabbitMQTransportURL error occured %s"

)
13 changes: 13 additions & 0 deletions api/v1beta1/keystoneapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ type KeystoneAPISpec struct {
// +kubebuilder:validation:Optional
// Override, provides the ability to override the generated manifest of several child resources.
Override APIOverrideSpec `json:"override,omitempty"`

// +kubebuilder:validation:Optional
// ExternalEndpoints, expose a VIP using a pre-created IPAddressPool
//ExternalEndpoints []MetalLBConfig `json:"externalEndpoints,omitempty"`

// +kubebuilder:validation:Required
// +kubebuilder:default=rabbitmq
// RabbitMQ instance name
// Needed to request a transportURL that is created and used in Keystone
RabbitMqClusterName string `json:"rabbitMqClusterName"`
}

// APIOverrideSpec to override the generated manifest of several child resources.
Expand Down Expand Up @@ -210,6 +220,9 @@ type KeystoneAPIStatus struct {

// NetworkAttachments status of the deployment pods
NetworkAttachments map[string][]string `json:"networkAttachments,omitempty"`

// TransportURLSecret - Secret containing RabbitMQ transportURL
TransportURLSecret string `json:"transportURLSecret,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ spec:
description: PreserveJobs - do not delete jobs after they finished
e.g. to check logs
type: boolean
rabbitMqClusterName:
default: rabbitmq
description: RabbitMQ instance name Needed to request a transportURL
that is created and used in Keystone
type: string
region:
default: regionOne
description: Region - optional region name for the keystone service
Expand Down Expand Up @@ -471,6 +476,9 @@ spec:
description: ReadyCount of keystone API instances
format: int32
type: integer
transportURLSecret:
description: TransportURLSecret - Secret containing RabbitMQ transportURL
type: string
type: object
type: object
served: true
Expand Down
1 change: 1 addition & 0 deletions config/samples/keystone_v1beta1_keystoneapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: KeystoneAPI
metadata:
name: keystone
spec:
containerImage: quay.io/podified-antelope-centos9/openstack-keystone:current-podified
adminProject: admin
adminUser: admin
customServiceConfig: |
Expand Down
69 changes: 65 additions & 4 deletions controllers/keystoneapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
keystone "github.com/openstack-k8s-operators/keystone-operator/pkg/keystone"
"github.com/openstack-k8s-operators/lib-common/modules/common"
Expand All @@ -36,6 +37,7 @@ import (
labels "github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
oko_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
Expand Down Expand Up @@ -632,9 +634,45 @@ func (r *KeystoneAPIReconciler) reconcileNormal(ctx context.Context, instance *k
l := GetLog(ctx)
l.Info("Reconciling Service")

serviceLabels := map[string]string{
common.AppSelector: keystone.ServiceName,
}

// ConfigMap
configMapVars := make(map[string]env.Setter)

//
// create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
//
transportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels)

if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
keystonev1.KeystoneRabbitMQTransportURLReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
keystonev1.KeystoneRabbitMQTransportURLReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
l.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op)))
}

instance.Status.TransportURLSecret = transportURL.Status.SecretName

if instance.Status.TransportURLSecret == "" {
l.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name))
instance.Status.Conditions.Set(condition.FalseCondition(
keystonev1.KeystoneRabbitMQTransportURLReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
keystonev1.KeystoneRabbitMQTransportURLReadyRunningMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}
l.Info(fmt.Sprintf("TransportURL secret name %s", transportURL.Status.SecretName))
instance.Status.Conditions.MarkTrue(keystonev1.KeystoneRabbitMQTransportURLReadyCondition, keystonev1.KeystoneRabbitMQTransportURLReadyMessage)

//
// check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
//
Expand Down Expand Up @@ -769,10 +807,6 @@ func (r *KeystoneAPIReconciler) reconcileNormal(ctx context.Context, instance *k
// TODO check when/if Init, Update, or Upgrade should/could be skipped
//

serviceLabels := map[string]string{
common.AppSelector: keystone.ServiceName,
}

// networks to attach to
for _, netAtt := range instance.Spec.NetworkAttachments {
_, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
Expand Down Expand Up @@ -921,6 +955,27 @@ func (r *KeystoneAPIReconciler) reconcileNormal(ctx context.Context, instance *k
return ctrl.Result{}, nil
}

func (r *KeystoneAPIReconciler) transportURLCreateOrUpdate(
ctx context.Context,
instance *keystonev1.KeystoneAPI,
serviceLabels map[string]string,
) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) {
transportURL := &rabbitmqv1.TransportURL{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-keystone-transport", instance.Name),
Namespace: instance.Namespace,
Labels: serviceLabels,
},
}
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error {
transportURL.Spec.RabbitmqClusterName = instance.Spec.RabbitMqClusterName
err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
return err
})

return transportURL, op, err
}

// generateServiceConfigMaps - create create configmaps which hold scripts and service configuration
// TODO add DefaultConfigOverwrite
func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
Expand Down Expand Up @@ -948,8 +1003,14 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
customData[key] = data
}

transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
if err != nil {
return err
}

templateParameters := map[string]interface{}{
"memcachedServers": strings.Join(mc.Status.ServerList, ","),
"TransportURL": string(transportURLSecret.Data["transport_url"]),
}

cms := []util.Template{
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"

Expand All @@ -52,6 +53,7 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(keystonev1.AddToScheme(scheme))
utilruntime.Must(mariadbv1.AddToScheme(scheme))
utilruntime.Must(rabbitmqv1.AddToScheme(scheme))
utilruntime.Must(memcachedv1.AddToScheme(scheme))
utilruntime.Must(networkv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
Expand Down
7 changes: 7 additions & 0 deletions templates/keystoneapi/config/keystone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ db_max_retries=-1
[fernet_tokens]
key_repository=/etc/keystone/fernet-keys
max_active_keys=2

{{ if (index . "TransportURL") }}
[oslo_messaging_notifications]
driver=messagingv2
transport_url={{ .TransportURL }}
topics = barbican_notifications
{{ end }}

0 comments on commit 5298553

Please sign in to comment.