Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: support the x.x.x.x:/dbbackup nfs address. #716 #717

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions api/v1alpha1/mysqlcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ func (r *MysqlCluster) ValidateDelete() error {
return nil
}

// TODO: Add NFSServerAddress webhook & backup schedule.
// Add NFSServerAddress webhook & backup schedule.
func (r *MysqlCluster) validateNFSServerAddress(oldCluster *MysqlCluster) error {
isIP := net.ParseIP(r.Spec.NFSServerAddress) != nil
//nfsaddress format is x.x.x.x:/yyy such as 10.233.55.172:/backup
ipStr := strings.Split(r.Spec.NFSServerAddress, ":")
if len(r.Spec.NFSServerAddress) != 0 && len(ipStr) == 0 {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP:/PATH or IP"))
}
isIP := net.ParseIP(ipStr[0]) != nil
if len(r.Spec.NFSServerAddress) != 0 && !isIP {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP"))
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP:/PATH or IP"))
}
if len(r.Spec.BackupSchedule) != 0 && len(r.Spec.BackupSecretName) == 0 && !isIP {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("backupSchedule is set without any backupSecretName or nfsServerAddress"))
Expand Down
6 changes: 4 additions & 2 deletions backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ func (s *jobSyncer) ensurePodSpec(in corev1.PodSpec) corev1.PodSpec {
in.Containers[0].Image = fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), s.backup.Spec.Image)
in.ServiceAccountName = s.backup.Spec.ClusterName
if len(s.backup.Spec.NFSServerAddress) != 0 {
//parse NFSServerAddress to IP:/Path
ip, path := utils.ParseIPAndPath(s.backup.Spec.NFSServerAddress)
// add volumn about pvc
in.Volumes = []corev1.Volume{
{
Name: utils.XtrabackupPV,
VolumeSource: corev1.VolumeSource{
NFS: &corev1.NFSVolumeSource{
Server: s.backup.Spec.NFSServerAddress,
Path: "/",
Server: ip,
Path: path,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/samples/nfs_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
containers:
- name: nfs-server
## TODO: radondb/volume-nfs:0.8
image: k8s.gcr.io/volume-nfs:0.8
image: gcr.azk8s.cn/google_containers/volume-nfs:0.8
ports:
- name: nfs
containerPort: 2049
Expand Down
5 changes: 3 additions & 2 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ func (c *MysqlCluster) EnsureVolumes() []corev1.Volume {
)
// add the nfs volumn mount
if len(c.Spec.NFSServerAddress) != 0 {
ip, path := utils.ParseIPAndPath(c.Spec.NFSServerAddress)
volumes = append(volumes, corev1.Volume{
Name: utils.XtrabackupPV,
VolumeSource: corev1.VolumeSource{
NFS: &corev1.NFSVolumeSource{
Server: c.Spec.NFSServerAddress,
Path: "/",
Server: ip,
Path: path,
},
},
})
Expand Down
9 changes: 9 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,12 @@ func ParseImageName(image string) (string, string, string, error) {
imageTag := imageNameArry[1]
return imagePrefix, imageName, imageTag, nil
}

func ParseIPAndPath(nfsaddr string) (string, string) {
res := strings.Split(nfsaddr, ":")
if len(res) == 2 {
return res[0], res[1]
} else {
return res[0], "/"
}
}