Skip to content

Commit

Permalink
[wip] RedisInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
stuggi committed Apr 10, 2024
1 parent f4d5094 commit bb7d0d4
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 165 deletions.
10 changes: 5 additions & 5 deletions api/bases/octavia.openstack.org_octaviaamphoracontrollers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount which
will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -236,6 +235,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down
35 changes: 15 additions & 20 deletions api/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -680,6 +679,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -787,11 +787,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -877,6 +876,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -984,11 +984,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -1074,6 +1073,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -1265,11 +1265,6 @@ spec:
ContainerImage)
format: int64
type: integer
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
transportURLSecret:
description: TransportURLSecret - Secret containing RabbitMQ transportURL
type: string
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/amphoracontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ type OctaviaAmphoraControllerSpecCore struct {
// AmphoraCustomFlavors - User-defined flavors for Octavia
AmphoraCustomFlavors []OctaviaAmphoraFlavor `json:"amphoraCustomFlavors,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default={}
// List of Redis Host IP addresses
RedisHostIPs []string `json:"redisHostIPs,omitempty"`
// +kubebuilder:validation:Required
// +kubebuilder:default=redis
// Redis instance name.
RedisInstance string `json:"redisInstance"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.Ca `json:"tls,omitempty"`
Expand Down
3 changes: 0 additions & 3 deletions api/v1beta1/octavia_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ type OctaviaStatus struct {
// ReadyCount of octavia HealthManager instances
OctaviaHealthManagerReadyCount int32 `json:"healthmanagerreadyCount,omitempty"`

// List of Redis Host IP addresses
RedisHostIPs []string `json:"redisHostIPs,omitempty"`

// ObservedGeneration - the most recent generation observed for this
// service. If the observed generation is less than the spec generation,
// then the controller has not processed the latest changes injected by
Expand Down
10 changes: 0 additions & 10 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount which
will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -236,6 +235,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down
35 changes: 15 additions & 20 deletions config/crd/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -680,6 +679,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -787,11 +787,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -877,6 +876,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -984,11 +984,10 @@ spec:
description: PersistenceDatabaseAccount - name of MariaDBAccount
which will be used to connect for the persistence database
type: string
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
redisInstance:
default: redis
description: Redis instance name.
type: string
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -1074,6 +1073,7 @@ spec:
type: string
required:
- databaseInstance
- redisInstance
- role
- secret
- serviceAccount
Expand Down Expand Up @@ -1265,11 +1265,6 @@ spec:
ContainerImage)
format: int64
type: integer
redisHostIPs:
description: List of Redis Host IP addresses
items:
type: string
type: array
transportURLSecret:
description: TransportURLSecret - Secret containing RabbitMQ transportURL
type: string
Expand Down
73 changes: 71 additions & 2 deletions controllers/amphoracontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/go-logr/logr"
redisv1 "github.com/openstack-k8s-operators/infra-operator/apis/redis/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/daemonset"
Expand Down Expand Up @@ -159,6 +160,7 @@ func (r *OctaviaAmphoraControllerReconciler) Reconcile(ctx context.Context, req
condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.DeploymentReadyInitMessage),
condition.UnknownCondition(condition.NetworkAttachmentsReadyCondition, condition.InitReason, condition.NetworkAttachmentsReadyInitMessage),
condition.UnknownCondition(condition.TLSInputReadyCondition, condition.InitReason, condition.InputReadyInitMessage),
condition.UnknownCondition(condition.RedisReadyCondition, condition.InitReason, condition.RedisReadyInitMessage),
)

instance.Status.Conditions.Init(&cl)
Expand Down Expand Up @@ -219,6 +221,21 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileDelete(ctx context.Context
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service delete")

// Remove our finalizer from redis
redis, err := redisv1.GetRedisByName(ctx, helper, instance.Spec.RedisInstance, instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

if !k8s_errors.IsNotFound(err) && redis != nil {
if controllerutil.RemoveFinalizer(redis, helper.GetFinalizer()) {
err := r.Update(ctx, redis)
if err != nil {
return ctrl.Result{}, err
}
}
}

controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())

if err := r.Update(ctx, instance); err != nil && !k8s_errors.IsNotFound(err) {
Expand Down Expand Up @@ -304,6 +321,56 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
common.AppSelector: instance.ObjectMeta.Name,
}

//
// Check for required redis
//
redis, err := redisv1.GetRedisByName(ctx, helper, instance.Spec.RedisInstance, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.RedisReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.RedisReadyWaitingMessage))
return ctrl.Result{RequeueAfter: 10 * time.Second}, fmt.Errorf("redis %s not found", instance.Spec.RedisInstance)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.RedisReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.RedisReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}

// Add finalizer to redis to prevent it from being deleted now that we're using it
if controllerutil.AddFinalizer(redis, helper.GetFinalizer()) {
err := r.Update(ctx, redis)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.RedisReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.RedisReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
}

if !redis.IsReady() {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.RedisReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.RedisReadyWaitingMessage))
return ctrl.Result{RequeueAfter: 10 * time.Second}, fmt.Errorf("redis %s is not ready", redis.Name)
}

// Mark the Redis Service as Ready if we get to this point with no errors
instance.Status.Conditions.MarkTrue(
condition.RedisReadyCondition, condition.MemcachedReadyMessage)
// run check redis - end

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

Expand Down Expand Up @@ -359,7 +426,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
LbSecurityGroupID: instance.Spec.LbSecurityGroupID,
}

err = r.generateServiceConfigMaps(ctx, instance, helper, &configMapVars, templateVars, ospSecret)
err = r.generateServiceConfigMaps(ctx, instance, helper, &configMapVars, templateVars, ospSecret, redis)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ServiceConfigReadyCondition,
Expand Down Expand Up @@ -516,6 +583,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps(
envVars *map[string]env.Setter,
templateVars OctaviaTemplateVars,
ospSecret *corev1.Secret,
redis *redisv1.Redis,
) error {
r.Log.Info(fmt.Sprintf("generating service config map for %s (%s)", instance.Name, instance.Kind))
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})
Expand Down Expand Up @@ -678,7 +746,8 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps(
}
// TODO(gthiemonge) store keys/passwords/passphrases in a specific config file stored in a secret
templateParameters["HeartbeatKey"] = string(ospSecret.Data["OctaviaHeartbeatKey"])
templateParameters["JobboardBackendHosts"] = strings.Join(spec.RedisHostIPs[:], ",")
templateParameters["JobboardBackendHosts"] = redis.GetRedisServerListString()
templateParameters["RedisTLS"] = redis.GetRedisTLSSupport()

// TODO(beagles): populate the template parameters
cms := []util.Template{
Expand Down
Loading

0 comments on commit bb7d0d4

Please sign in to comment.