Skip to content

Commit

Permalink
Watch tls certs for redis and memcached
Browse files Browse the repository at this point in the history
By adding the hash of the certificate to the statefulset we react
to certificate changes.

Let's also take the chance to remove pkg/redis/deployment (unused).
  • Loading branch information
lmiccini committed Sep 9, 2024
1 parent 12ffed6 commit 968a83a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 77 deletions.
2 changes: 1 addition & 1 deletion controllers/memcached/memcached_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)

// Statefulset for stable names
commonstatefulset := commonstatefulset.NewStatefulSet(memcached.StatefulSet(instance), time.Duration(5)*time.Second)
commonstatefulset := commonstatefulset.NewStatefulSet(memcached.StatefulSet(instance, hashOfHashes), time.Duration(5)*time.Second)
sfres, sferr := commonstatefulset.CreateOrPatch(ctx, helper)
if sferr != nil {
return sfres, sferr
Expand Down
2 changes: 1 addition & 1 deletion controllers/redis/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
//

// Statefulset
commonstatefulset := commonstatefulset.NewStatefulSet(redis.StatefulSet(instance), 5)
commonstatefulset := commonstatefulset.NewStatefulSet(redis.StatefulSet(instance, hashOfHashes), 5)
sfres, sferr := commonstatefulset.CreateOrPatch(ctx, helper)
if sferr != nil {
return sfres, sferr
Expand Down
8 changes: 7 additions & 1 deletion pkg/memcached/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
)

// StatefulSet returns a Stateful resource for the Memcached CR
func StatefulSet(m *memcachedv1.Memcached) *appsv1.StatefulSet {
func StatefulSet(
m *memcachedv1.Memcached,
configHash string,
) *appsv1.StatefulSet {
matchls := map[string]string{
common.AppSelector: m.Name,
"cr": m.Name,
Expand Down Expand Up @@ -75,6 +78,9 @@ func StatefulSet(m *memcachedv1.Memcached) *appsv1.StatefulSet {
FieldPath: "status.podIPs",
},
},
}, {
Name: "CONFIG_HASH",
Value: configHash,
},
},
VolumeMounts: getVolumeMounts(m),
Expand Down
73 changes: 0 additions & 73 deletions pkg/redis/deployment.go

This file was deleted.

8 changes: 7 additions & 1 deletion pkg/redis/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
)

// Deployment returns a Deployment resource for the Redis CR
func StatefulSet(r *redisv1.Redis) *appsv1.StatefulSet {
func StatefulSet(
r *redisv1.Redis,
configHash string,
) *appsv1.StatefulSet {
matchls := map[string]string{
common.AppSelector: "redis",
common.OwnerSelector: r.Name,
Expand Down Expand Up @@ -68,6 +71,9 @@ func StatefulSet(r *redisv1.Redis) *appsv1.StatefulSet {
// Headless services only publish dns entries that include cluster domain.
// For the time being, assume this is .cluster.local
Value: name + "." + r.GetNamespace() + ".svc.cluster.local",
}, {
Name: "CONFIG_HASH",
Value: configHash,
}}

sts := &appsv1.StatefulSet{
Expand Down

0 comments on commit 968a83a

Please sign in to comment.