Skip to content

Commit

Permalink
fix: backup and restore failed when using hostnetwork (apecloud#6715)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Feb 29, 2024
1 parent 72f1770 commit 9f46d67
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
26 changes: 13 additions & 13 deletions config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -756,7 +756,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1049,7 +1049,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1350,7 +1350,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1653,7 +1653,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1961,7 +1961,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2256,7 +2256,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2554,7 +2554,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2851,7 +2851,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3141,7 +3141,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3451,7 +3451,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3783,7 +3783,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -4063,7 +4063,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down
26 changes: 13 additions & 13 deletions deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -756,7 +756,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1049,7 +1049,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1350,7 +1350,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1653,7 +1653,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -1961,7 +1961,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2256,7 +2256,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2554,7 +2554,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -2851,7 +2851,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3141,7 +3141,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3451,7 +3451,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -3783,7 +3783,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down Expand Up @@ -4063,7 +4063,7 @@ spec:
- Role
- Ordinal
type: string
timeoutSeconds:omitempty:
timeoutSeconds:
default: 0
description: Defines the timeout duration for the action
in seconds. This field cannot be updated.
Expand Down
5 changes: 4 additions & 1 deletion pkg/dataprotection/restore/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (r *restoreJobBuilder) addTargetPodAndCredentialEnv(pod *corev1.Pod,
r.envFrom = pod.Spec.Containers[0].EnvFrom
}
env = append(env, corev1.EnvVar{Name: dptypes.DPDBHost, Value: intctrlutil.BuildPodHostDNS(pod)})
env = append(env, corev1.EnvVar{Name: dptypes.DPDBPort, Value: strconv.Itoa(int(utils.GetPodFirstContainerPort(pod)))})
if connectionCredential != nil {
appendEnvFromSecret := func(envName, keyName string) {
if keyName == "" {
Expand All @@ -257,7 +258,9 @@ func (r *restoreJobBuilder) addTargetPodAndCredentialEnv(pod *corev1.Pod,
}
appendEnvFromSecret(dptypes.DPDBUser, connectionCredential.UsernameKey)
appendEnvFromSecret(dptypes.DPDBPassword, connectionCredential.PasswordKey)
appendEnvFromSecret(dptypes.DPDBPort, connectionCredential.PortKey)
if connectionCredential.PortKey != "" {
appendEnvFromSecret(dptypes.DPDBPort, connectionCredential.PortKey)
}
if connectionCredential.HostKey != "" {
appendEnvFromSecret(dptypes.DPDBHost, connectionCredential.HostKey)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/dataprotection/utils/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package utils

import (
"strconv"

corev1 "k8s.io/api/core/v1"

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
Expand Down Expand Up @@ -48,6 +50,8 @@ func BuildEnvByCredential(pod *corev1.Pod, credential *dpv1alpha1.ConnectionCred
}
if credential.PortKey != "" {
envVars = append(envVars, buildEnvBySecretKey(dptypes.DPDBPort, credential.SecretName, credential.PortKey))
} else {
envVars = append(envVars, corev1.EnvVar{Name: dptypes.DPDBPort, Value: strconv.Itoa(int(GetPodFirstContainerPort(pod)))})
}
return envVars
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/dataprotection/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,10 @@ func SupportsCronJobV1() bool {
}
return semver.Compare(kubeVersion, "v1.21") >= 0
}
func GetPodFirstContainerPort(pod *corev1.Pod) int32 {
ports := pod.Spec.Containers[0].Ports
if len(ports) == 0 {
return 0
}
return ports[0].ContainerPort
}

0 comments on commit 9f46d67

Please sign in to comment.