Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions apis/synapse/v1alpha1/synapse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,43 +160,19 @@ type SynapseStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Configuration of deployed bridges
BridgesConfiguration SynapseStatusBridgesConfiguration `json:"bridgesConfiguration,omitempty"`

// Connection information to the external PostgreSQL Database
DatabaseConnectionInfo SynapseStatusDatabaseConnectionInfo `json:"databaseConnectionInfo,omitempty"`

// Holds configuration information for Synapse
HomeserverConfiguration SynapseStatusHomeserverConfiguration `json:"homeserverConfiguration,omitempty"`

// Synapse IP address (corresponding to the Synapse Service IP address)
IP string `json:"ip,omitempty"`

// State of the Synapse instance
State string `json:"state,omitempty"`

// Reason for the current Synapse State
Reason string `json:"reason,omitempty"`
}

type SynapseStatusBridgesConfiguration struct {
// Status of the Heisenbridge
Heisenbridge SynapseStatusHeisenbridge `json:"heisenbridge,omitempty"`

// Status of the mautrix-signal bridge
MautrixSignal SynapseStatusMautrixSignal `json:"mautrixSignal,omitempty"`
}

type SynapseStatusHeisenbridge struct {
// IP at which the Heisenbridge is available
IP string `json:"ip,omitempty"`
}

type SynapseStatusMautrixSignal struct {
// IP at which the mautrix-signal bridge is available
IP string `json:"ip,omitempty"`
}

type SynapseStatusDatabaseConnectionInfo struct {
// Endpoint to connect to the PostgreSQL database
ConnectionURL string `json:"connectionURL,omitempty"`
Expand Down
48 changes: 0 additions & 48 deletions apis/synapse/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions bundle/manifests/synapse.opdev.io_synapses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,6 @@ spec:
status:
description: SynapseStatus defines the observed state of Synapse
properties:
bridgesConfiguration:
description: Configuration of deployed bridges
properties:
heisenbridge:
description: Status of the Heisenbridge
properties:
ip:
description: IP at which the Heisenbridge is available
type: string
type: object
mautrixSignal:
description: Status of the mautrix-signal bridge
properties:
ip:
description: IP at which the mautrix-signal bridge is available
type: string
type: object
type: object
databaseConnectionInfo:
description: Connection information to the external PostgreSQL Database
properties:
Expand Down Expand Up @@ -201,10 +183,6 @@ spec:
description: The public-facing domain of the server
type: string
type: object
ip:
description: Synapse IP address (corresponding to the Synapse Service
IP address)
type: string
reason:
description: Reason for the current Synapse State
type: string
Expand Down
22 changes: 0 additions & 22 deletions config/crd/bases/synapse.opdev.io_synapses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,6 @@ spec:
status:
description: SynapseStatus defines the observed state of Synapse
properties:
bridgesConfiguration:
description: Configuration of deployed bridges
properties:
heisenbridge:
description: Status of the Heisenbridge
properties:
ip:
description: IP at which the Heisenbridge is available
type: string
type: object
mautrixSignal:
description: Status of the mautrix-signal bridge
properties:
ip:
description: IP at which the mautrix-signal bridge is available
type: string
type: object
type: object
databaseConnectionInfo:
description: Connection information to the external PostgreSQL Database
properties:
Expand Down Expand Up @@ -198,10 +180,6 @@ spec:
description: The public-facing domain of the server
type: string
type: object
ip:
description: Synapse IP address (corresponding to the Synapse Service
IP address)
type: string
reason:
description: Reason for the current Synapse State
type: string
Expand Down
134 changes: 44 additions & 90 deletions controllers/synapse/synapse_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ func (r *SynapseReconciler) GetMautrixSignalResourceName(synapse synapsev1alpha1
return strings.Join([]string{synapse.Name, "mautrixsignal"}, "-")
}

func (r *SynapseReconciler) GetSynapseServiceFQDN(synapse synapsev1alpha1.Synapse) string {
return strings.Join([]string{synapse.Name, synapse.Namespace, "svc", "cluster", "local"}, ".")
}

func (r *SynapseReconciler) GetHeisenbridgeServiceFQDN(synapse synapsev1alpha1.Synapse) string {
return strings.Join([]string{r.GetHeisenbridgeResourceName(synapse), synapse.Namespace, "svc", "cluster", "local"}, ".")
}

func (r *SynapseReconciler) GetMautrixSignalServiceFQDN(synapse synapsev1alpha1.Synapse) string {
return strings.Join([]string{r.GetMautrixSignalResourceName(synapse), synapse.Namespace, "svc", "cluster", "local"}, ".")
}

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
//
Expand Down Expand Up @@ -205,59 +217,11 @@ func (r *SynapseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
}

// We first need to create the Synapse Service as its IP address is potentially
// needed by the Bridges
synapseKey := types.NamespacedName{Name: synapse.Name, Namespace: synapse.Namespace}
createdService := &corev1.Service{}
if err := r.reconcileResource(
ctx,
r.serviceForSynapse,
&synapse,
createdService,
objectMetaForSynapse,
); err != nil {
return ctrl.Result{}, err
}

// Fetch Synapse IP and update the resource status
synapseIP, err := r.getServiceIP(ctx, synapseKey, createdService)
if err != nil {
return ctrl.Result{}, err
}
synapse.Status.IP = synapseIP
if err := r.updateSynapseStatus(ctx, &synapse); err != nil {
return ctrl.Result{}, err
}

if synapse.Spec.Bridges.Heisenbridge.Enabled {
log.Info("Heisenbridge is enabled - deploying Heisenbridge")
// Heisenbridge is composed of a ConfigMap, a Service and a Deployment.
// Resources associated to the Heisenbridge are append with "-heisenbridge"
createdHeisenbridgeService := &corev1.Service{}
objectMetaHeisenbridge := setObjectMeta(r.GetHeisenbridgeResourceName(synapse), synapse.Namespace, map[string]string{})
heisenbridgeKey := types.NamespacedName{Name: r.GetHeisenbridgeResourceName(synapse), Namespace: synapse.Namespace}

// First create the service as we need its IP address for the
// heisenbridge.yaml configuration file
if err := r.reconcileResource(
ctx,
r.serviceForHeisenbridge,
&synapse,
createdHeisenbridgeService,
objectMetaHeisenbridge,
); err != nil {
return ctrl.Result{}, err
}

// Get Service IP and update the Synapse status
heisenbridgeIP, err := r.getServiceIP(ctx, heisenbridgeKey, createdHeisenbridgeService)
if err != nil {
return ctrl.Result{}, err
}
synapse.Status.BridgesConfiguration.Heisenbridge.IP = heisenbridgeIP
if err := r.updateSynapseStatus(ctx, &synapse); err != nil {
return ctrl.Result{}, err
}

// The ConfigMap for Heisenbridge, containing the heisenbridge.yaml
// config file. It's either a copy of a user-provided ConfigMap, if
Expand Down Expand Up @@ -338,6 +302,17 @@ func (r *SynapseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
}

// Create Service for Heisenbridge
if err := r.reconcileResource(
ctx,
r.serviceForHeisenbridge,
&synapse,
&corev1.Service{},
objectMetaHeisenbridge,
); err != nil {
return ctrl.Result{}, err
}

// Create Deployment for Heisenbridge
if err := r.reconcileResource(
ctx,
Expand Down Expand Up @@ -366,33 +341,9 @@ func (r *SynapseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
// mautrix-signal is composed of a ConfigMap, a Service and 1 Deployment.
// Resources associated to the mautrix-signal are append with "-mautrixsignal"
// In addition, a second deployment is needed to run signald. This is append with "-signald"
createdMautrixSignalService := &corev1.Service{}
objectMetaMautrixSignal := setObjectMeta(r.GetMautrixSignalResourceName(synapse), synapse.Namespace, map[string]string{})
mautrixSignalKey := types.NamespacedName{Name: r.GetMautrixSignalResourceName(synapse), Namespace: synapse.Namespace}
objectMetaSignald := setObjectMeta(r.GetSignaldResourceName(synapse), synapse.Namespace, map[string]string{})

// First create the service as we need its IP address for the
// config.yaml configuration file
if err := r.reconcileResource(
ctx,
r.serviceForMautrixSignal,
&synapse,
createdMautrixSignalService,
objectMetaMautrixSignal,
); err != nil {
return ctrl.Result{}, err
}

// Get Service IP and update the Synapse status
mautrixSignalIP, err := r.getServiceIP(ctx, mautrixSignalKey, createdMautrixSignalService)
if err != nil {
return ctrl.Result{}, err
}
synapse.Status.BridgesConfiguration.MautrixSignal.IP = mautrixSignalIP
if err := r.updateSynapseStatus(ctx, &synapse); err != nil {
return ctrl.Result{}, err
}

// The ConfigMap for mautrix-signal, containing the config.yaml config
// file. It's either a copy of a user-provided ConfigMap, if defined in
// Spec.Bridges.MautrixSignal.ConfigMap, or a new ConfigMap containing
Expand Down Expand Up @@ -516,6 +467,17 @@ func (r *SynapseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, err
}

// Create a Service for mautrix-signal
if err := r.reconcileResource(
ctx,
r.serviceForMautrixSignal,
&synapse,
&corev1.Service{},
objectMetaMautrixSignal,
); err != nil {
return ctrl.Result{}, err
}

// Create a PVC for mautrix-signal
if err := r.reconcileResource(
ctx,
Expand Down Expand Up @@ -562,6 +524,16 @@ func (r *SynapseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}

// Reconcile Synapse resources: PVC, Deployment and Service
if err := r.reconcileResource(
ctx,
r.serviceForSynapse,
&synapse,
&corev1.Service{},
objectMetaForSynapse,
); err != nil {
return ctrl.Result{}, err
}

if err := r.reconcileResource(
ctx,
r.serviceAccountForSynapse,
Expand Down Expand Up @@ -828,24 +800,6 @@ func (r *SynapseReconciler) updateSynapseStatusDatabase(
return nil
}

func (r *SynapseReconciler) getServiceIP(
ctx context.Context,
synapseKey types.NamespacedName,
service *corev1.Service,
) (string, error) {
if err := r.Get(ctx, synapseKey, service); err != nil {
return "", err
}

serviceIP := service.Spec.ClusterIP
if serviceIP == "" {
err := errors.New("service IP not set")
return "", err
}

return serviceIP, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *SynapseReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down
Loading