Skip to content

Commit

Permalink
fix: DP_DB_HOST env is missing (#8605)
Browse files Browse the repository at this point in the history
Co-authored-by: x.zhou <[email protected]>
  • Loading branch information
gnolong and zjx20 authored Dec 9, 2024
1 parent ee8938b commit a88ad31
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/dataprotection/restore/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,22 @@ func (r *restoreJobBuilder) addTargetPodAndCredentialEnv(pod *corev1.Pod,
env = pod.Spec.Containers[0].Env
r.envFrom = pod.Spec.Containers[0].EnvFrom
}
if connectionCredential == nil {
addDBHostEnv := func() {
env = append(env, corev1.EnvVar{Name: dptypes.DPDBHost, Value: intctrlutil.BuildPodHostDNS(pod)})
if portEnv, err := utils.GetDPDBPortEnv(pod, target.ContainerPort); err == nil {
}
addDBPortEnv := func() {
portEnv, err := utils.GetDPDBPortEnv(pod, target.ContainerPort)
if err != nil {
// fallback to use the first port of the pod
portEnv, _ = utils.GetDPDBPortEnv(pod, nil)
}
if portEnv != nil {
env = append(env, *portEnv)
}
}
if connectionCredential == nil {
addDBHostEnv()
addDBPortEnv()
} else {
appendEnvFromSecret := func(envName, keyName string) {
if keyName == "" {
Expand All @@ -277,11 +288,12 @@ func (r *restoreJobBuilder) addTargetPodAndCredentialEnv(pod *corev1.Pod,
if connectionCredential.PortKey != "" {
appendEnvFromSecret(dptypes.DPDBPort, connectionCredential.PortKey)
} else {
portEnv, _ := utils.GetDPDBPortEnv(pod, nil)
env = append(env, *portEnv)
addDBPortEnv()
}
if connectionCredential.HostKey != "" {
appendEnvFromSecret(dptypes.DPDBHost, connectionCredential.HostKey)
} else {
addDBHostEnv()
}
}
r.env = utils.MergeEnv(r.env, env)
Expand Down

0 comments on commit a88ad31

Please sign in to comment.