Skip to content

Commit

Permalink
K8SPXC-1462 Restart PXC pods only if sidecars have secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
s10 committed Oct 23, 2024
1 parent 53e363b commit 0b9e1de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions pkg/apis/pxc/v1/pxc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,35 @@ type PodSpec struct {
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
}

func (spec *PodSpec) HasSidecarInternalSecret(secret *corev1.Secret) bool {
if spec.Sidecars != nil {
for _, container := range spec.Sidecars {
for _, env := range container.Env {
if env.ValueFrom != nil && env.ValueFrom.SecretKeyRef != nil {
if env.ValueFrom.SecretKeyRef.Name == secret.Name {
return true
}
}
}
}
}
if spec.SidecarVolumes != nil {
for _, volume := range spec.SidecarVolumes {
if volume.Secret != nil && volume.Secret.SecretName == secret.Name {
return true
}
if volume.Projected != nil {
for _, source := range volume.Projected.Sources {
if source.Secret != nil && source.Secret.Name == secret.Name {
return true
}
}
}
}
}
return false
}

type ProxySQLSpec struct {
PodSpec `json:",inline"`
Expose ServiceExpose `json:"expose,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/pxc/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,12 @@ func (r *ReconcilePerconaXtraDBCluster) handleMonitorUser(ctx context.Context, c
}

actions.restartProxySQL = true
actions.restartPXC = true
if cr.Spec.PMM != nil && cr.Spec.PMM.IsEnabled(internalSecrets) {
actions.restartPXC = true
}
if cr.Spec.PXC.Sidecars != nil && cr.Spec.PXC.HasSidecarInternalSecret(internalSecrets) {
actions.restartPXC = true
}

err = r.discardOldPassword(cr, secrets, internalSecrets, user)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/pxc/users_without_dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ func (r *ReconcilePerconaXtraDBCluster) handleMonitorUserWithoutDP(ctx context.C
actions.restartHAProxy = true

actions.restartProxySQL = true
actions.restartPXC = true
if cr.Spec.PMM != nil && cr.Spec.PMM.IsEnabled(internalSecrets) {
actions.restartPXC = true
}
if cr.Spec.PXC.Sidecars != nil && cr.Spec.PXC.HasSidecarInternalSecret(internalSecrets) {
actions.restartPXC = true
}

orig := internalSecrets.DeepCopy()
internalSecrets.Data[user.Name] = secrets.Data[user.Name]
Expand Down

0 comments on commit 0b9e1de

Please sign in to comment.