Skip to content

Commit

Permalink
Improve toolImage to be able to set without image tag (#4048) (#4050)
Browse files Browse the repository at this point in the history
* cherry pick #4048 to release-1.1
  • Loading branch information
ti-srebot authored Jul 1, 2021
1 parent cc74238 commit 6f4b099
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ string
<td>
<em>(Optional)</em>
<p>ToolImage specifies the tool image used in <code>Backup</code>, which supports BR and Dumpling images.
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/dumpling:v4.0.8</code></p>
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/dumpling:v4.0.8</code>
For BR image, if it does not contain tag, Pod will use image &lsquo;ToolImage:${TiKV_Version}&rsquo;.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -766,7 +767,8 @@ string
<td>
<em>(Optional)</em>
<p>ToolImage specifies the tool image used in <code>Restore</code>, which supports BR and TiDB Lightning images.
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/tidb-lightning:v4.0.8</code></p>
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/tidb-lightning:v4.0.8</code>
For BR image, if it does not contain tag, Pod will use image &lsquo;ToolImage:${TiKV_Version}&rsquo;.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -2552,7 +2554,8 @@ string
<td>
<em>(Optional)</em>
<p>ToolImage specifies the tool image used in <code>Backup</code>, which supports BR and Dumpling images.
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/dumpling:v4.0.8</code></p>
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/dumpling:v4.0.8</code>
For BR image, if it does not contain tag, Pod will use image &lsquo;ToolImage:${TiKV_Version}&rsquo;.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -9409,7 +9412,8 @@ string
<td>
<em>(Optional)</em>
<p>ToolImage specifies the tool image used in <code>Restore</code>, which supports BR and TiDB Lightning images.
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/tidb-lightning:v4.0.8</code></p>
For examples <code>spec.toolImage: pingcap/br:v4.0.8</code> or <code>spec.toolImage: pingcap/tidb-lightning:v4.0.8</code>
For BR image, if it does not contain tag, Pod will use image &lsquo;ToolImage:${TiKV_Version}&rsquo;.</p>
</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ type BackupSpec struct {
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// ToolImage specifies the tool image used in `Backup`, which supports BR and Dumpling images.
// For examples `spec.toolImage: pingcap/br:v4.0.8` or `spec.toolImage: pingcap/dumpling:v4.0.8`
// For BR image, if it does not contain tag, Pod will use image 'ToolImage:${TiKV_Version}'.
// +optional
ToolImage string `json:"toolImage,omitempty"`
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images.
Expand Down Expand Up @@ -1603,6 +1604,7 @@ type RestoreSpec struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
// ToolImage specifies the tool image used in `Restore`, which supports BR and TiDB Lightning images.
// For examples `spec.toolImage: pingcap/br:v4.0.8` or `spec.toolImage: pingcap/tidb-lightning:v4.0.8`
// For BR image, if it does not contain tag, Pod will use image 'ToolImage:${TiKV_Version}'.
// +optional
ToolImage string `json:"toolImage,omitempty"`
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images.
Expand Down
8 changes: 7 additions & 1 deletion pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package backup

import (
"fmt"
"strings"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/backup"
Expand Down Expand Up @@ -439,7 +440,12 @@ func (bm *backupManager) makeBackupJob(backup *v1alpha1.Backup) (*batchv1.Job, s

brImage := "pingcap/br:" + tikvVersion
if backup.Spec.ToolImage != "" {
brImage = backup.Spec.ToolImage
toolImage := backup.Spec.ToolImage
if !strings.ContainsRune(backup.Spec.ToolImage, ':') {
toolImage = fmt.Sprintf("%s:%s", toolImage, tikvVersion)
}

brImage = toolImage
}

podSpec := &corev1.PodTemplateSpec{
Expand Down
8 changes: 7 additions & 1 deletion pkg/backup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package restore

import (
"fmt"
"strings"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/backup"
Expand Down Expand Up @@ -412,7 +413,12 @@ func (rm *restoreManager) makeRestoreJob(restore *v1alpha1.Restore) (*batchv1.Jo

brImage := "pingcap/br:" + tikvVersion
if restore.Spec.ToolImage != "" {
brImage = restore.Spec.ToolImage
toolImage := restore.Spec.ToolImage
if !strings.ContainsRune(toolImage, ':') {
toolImage = fmt.Sprintf("%s:%s", toolImage, tikvVersion)
}

brImage = toolImage
}

podSpec := &corev1.PodTemplateSpec{
Expand Down

0 comments on commit 6f4b099

Please sign in to comment.