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

Able to omit storageClassName to use the default storage class of Kubernetes #1581

Merged
merged 3 commits into from
Jan 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ spec:
{{ toYaml .Values.controllerManager.resources | indent 12 }}
command:
- /usr/local/bin/tidb-controller-manager
- -default-storage-class-name={{ .Values.defaultStorageClassName }}
{{- if .Values.tidbBackupManagerImage }}
- -tidb-backup-manager-image={{ .Values.tidbBackupManagerImage }}
- -tidb-discovery-image={{ .Values.operatorImage }}
{{- end }}
{{- if .Values.defaultBackupStorageClassName }}
- -default-backup-storage-class-name={{ .Values.defaultBackupStorageClassName }}
{{- end }}
- -cluster-scoped={{ .Values.clusterScoped }}
- -auto-failover={{ .Values.controllerManager.autoFailover | default true }}
- -pd-failover-period={{ .Values.controllerManager.pdFailoverPeriod | default "5m" }}
Expand Down
3 changes: 0 additions & 3 deletions charts/tidb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ timezone: UTC
operatorImage: pingcap/tidb-operator:v1.1.0-beta.1
imagePullPolicy: IfNotPresent

defaultStorageClassName: local-storage

# tidbBackupManagerImage is tidb backup manager image
# tidbBackupManagerImage: pingcap/tidb-backup-manager:latest
# defaultBackupStorageClassName: local-storage

#
# Enable or disable tidb-operator features:
Expand Down
2 changes: 0 additions & 2 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func init() {
flag.BoolVar(&printVersion, "version", false, "Show version and quit")
flag.IntVar(&workers, "workers", 5, "The number of workers that are allowed to sync concurrently. Larger number = more responsive management, but more CPU (and network) load")
flag.BoolVar(&controller.ClusterScoped, "cluster-scoped", true, "Whether tidb-operator should manage kubernetes cluster wide TiDB Clusters")
flag.StringVar(&controller.DefaultStorageClassName, "default-storage-class-name", "standard", "Default storage class name")
flag.StringVar(&controller.DefaultBackupStorageClassName, "default-backup-storage-class-name", "standard", "Default storage class name for backup and restore")
flag.BoolVar(&autoFailover, "auto-failover", true, "Auto failover")
flag.DurationVar(&pdFailoverPeriod, "pd-failover-period", time.Duration(5*time.Minute), "PD failover period default(5m)")
flag.DurationVar(&tikvFailoverPeriod, "tikv-failover-period", time.Duration(5*time.Minute), "TiKV failover period default(5m)")
Expand Down
36 changes: 15 additions & 21 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1853,10 +1853,8 @@ spec:
type: string
type: object
storageClassName:
description: 'The storageClassName of the persistent volume for
PD data storage, empty string means not explicitly set and use
the cluster default set by admission controller. Optionals: Defaults
to the default-storage-class-name set in the tidb-operator'
description: The storageClassName of the persistent volume for PD
data storage. Defaults to Kubernetes default storage class.
type: string
tolerations:
description: 'Tolerations of the component. Override the cluster-level
Expand Down Expand Up @@ -2693,10 +2691,8 @@ spec:
one if present Optional: Defaults to cluster-level setting'
type: string
storageClassName:
description: 'The storageClassName of the persistent volume for
Pump data storage, empty string means not explicitly set and use
the cluster default set by admission controller. Optionals: Defaults
to the default-storage-class-name set in the tidb-operator'
description: The storageClassName of the persistent volume for Pump
data storage. Defaults to Kubernetes default storage class.
type: string
tolerations:
description: 'Tolerations of the component. Override the cluster-level
Expand Down Expand Up @@ -6001,10 +5997,8 @@ spec:
one if present Optional: Defaults to cluster-level setting'
type: string
storageClassName:
description: 'The storageClassName of the persistent volume for
TiKV data storage, empty string means not explicitly set and use
the cluster default set by admission controller. Optionals: Defaults
to the default-storage-class-name set in the tidb-operator'
description: The storageClassName of the persistent volume for TiKV
data storage. Defaults to Kubernetes default storage class.
type: string
tolerations:
description: 'Tolerations of the component. Override the cluster-level
Expand Down Expand Up @@ -6316,8 +6310,8 @@ spec:
- secretName
type: object
storageClassName:
description: StorageClassName is the storage class for backup job's
PV.
description: The storageClassName of the persistent volume for Backup
data storage. Defaults to Kubernetes default storage class.
type: string
storageSize:
description: StorageSize is the request storage size for backup job
Expand Down Expand Up @@ -6448,8 +6442,8 @@ spec:
- secretName
type: object
storageClassName:
description: StorageClassName is the storage class for backup job's
PV.
description: The storageClassName of the persistent volume for Restore
data storage. Defaults to Kubernetes default storage class.
type: string
storageSize:
description: StorageSize is the request storage size for backup job
Expand Down Expand Up @@ -6479,7 +6473,6 @@ spec:
type: object
required:
- to
- storageClassName
- storageSize
type: object
type: object
Expand Down Expand Up @@ -6694,8 +6687,8 @@ spec:
- secretName
type: object
storageClassName:
description: StorageClassName is the storage class for backup job's
PV.
description: The storageClassName of the persistent volume for Backup
data storage. Defaults to Kubernetes default storage class.
type: string
storageSize:
description: StorageSize is the request storage size for backup
Expand All @@ -6718,8 +6711,9 @@ spec:
description: Schedule specifies the cron string used for backup scheduling.
type: string
storageClassName:
description: StorageClassName is the storage class for backup job's
PV.
description: The storageClassName of the persistent volume for Backup
data storage if not storage class name set in BackupSpec. Defaults
to Kubernetes default storage class.
type: string
storageSize:
description: StorageSize is the request storage size for backup job
Expand Down
14 changes: 7 additions & 7 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.

33 changes: 18 additions & 15 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ type PDSpec struct {
// +optional
Service *ServiceSpec `json:"service,omitempty"`

// The storageClassName of the persistent volume for PD data storage, empty string means not explicitly set
// and use the cluster default set by admission controller.
// Optionals: Defaults to the default-storage-class-name set in the tidb-operator
// The storageClassName of the persistent volume for PD data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`

Expand Down Expand Up @@ -261,9 +260,8 @@ type TiKVSpec struct {
// +optional
MaxFailoverCount *int32 `json:"maxFailoverCount,omitempty"`

// The storageClassName of the persistent volume for TiKV data storage, empty string means not explicitly set
// and use the cluster default set by admission controller.
// Optionals: Defaults to the default-storage-class-name set in the tidb-operator
// The storageClassName of the persistent volume for TiKV data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`

Expand Down Expand Up @@ -343,9 +341,8 @@ type PumpSpec struct {
// +optional
BaseImage string `json:"baseImage"`

// The storageClassName of the persistent volume for Pump data storage, empty string means not explicitly set
// and use the cluster default set by admission controller.
// Optionals: Defaults to the default-storage-class-name set in the tidb-operator
// The storageClassName of the persistent volume for Pump data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`

Expand Down Expand Up @@ -744,8 +741,10 @@ type BackupSpec struct {
Type BackupType `json:"backupType,omitempty"`
// StorageProvider configures where and how backups should be stored.
StorageProvider `json:",inline"`
// StorageClassName is the storage class for backup job's PV.
StorageClassName string `json:"storageClassName,omitempty"`
// The storageClassName of the persistent volume for Backup data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply the same change from #1409 to backup/restore spec

// StorageSize is the request storage size for backup job
StorageSize string `json:"storageSize,omitempty"`
// BRConfig is the configs for BR
Expand Down Expand Up @@ -866,8 +865,10 @@ type BackupScheduleSpec struct {
MaxReservedTime *string `json:"maxReservedTime,omitempty"`
// BackupTemplate is the specification of the backup structure to get scheduled.
BackupTemplate BackupSpec `json:"backupTemplate"`
// StorageClassName is the storage class for backup job's PV.
StorageClassName string `json:"storageClassName,omitempty"`
// The storageClassName of the persistent volume for Backup data storage if not storage class name set in BackupSpec.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// StorageSize is the request storage size for backup job
StorageSize string `json:"storageSize,omitempty"`
}
Expand Down Expand Up @@ -944,8 +945,10 @@ type RestoreSpec struct {
Type BackupType `json:"backupType,omitempty"`
// StorageProvider configures where and how backups should be stored.
StorageProvider `json:",inline"`
// StorageClassName is the storage class for backup job's PV.
StorageClassName string `json:"storageClassName"`
// The storageClassName of the persistent volume for Restore data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// StorageSize is the request storage size for backup job
StorageSize string `json:"storageSize"`
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 1 addition & 5 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,13 @@ func (bm *backupManager) ensureBackupPVCExist(backup *v1alpha1.Backup) (string,
}

// not found PVC, so we need to create PVC for backup job
storageClassName := controller.DefaultBackupStorageClassName
if backup.Spec.StorageClassName != "" {
storageClassName = backup.Spec.StorageClassName
}
pvc := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: backupPVCName,
Namespace: ns,
Labels: label.NewBackup().Instance(backup.GetInstanceName()),
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: &storageClassName,
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Expand All @@ -347,6 +342,7 @@ func (bm *backupManager) ensureBackupPVCExist(backup *v1alpha1.Backup) (string,
corev1.ResourceStorage: rs,
},
},
StorageClassName: backup.Spec.StorageClassName,
},
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/backup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,8 @@ func (bm *backupScheduleManager) createBackup(bs *v1alpha1.BackupSchedule, times

backupSpec := *bs.Spec.BackupTemplate.DeepCopy()
if backupSpec.BR == nil {
if backupSpec.StorageClassName == "" {
if bs.Spec.StorageClassName != "" {
backupSpec.StorageClassName = bs.Spec.StorageClassName
} else {
backupSpec.StorageClassName = controller.DefaultBackupStorageClassName
}
if backupSpec.StorageClassName == nil || *backupSpec.StorageClassName == "" {
backupSpec.StorageClassName = bs.Spec.StorageClassName
}

if backupSpec.StorageSize == "" {
Expand Down
6 changes: 1 addition & 5 deletions pkg/backup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,13 @@ func (rm *restoreManager) ensureRestorePVCExist(restore *v1alpha1.Restore) (stri
if err != nil {
// get the object from the local cache, the error can only be IsNotFound,
// so we need to create PVC for restore job
storageClassName := controller.DefaultBackupStorageClassName
if restore.Spec.StorageClassName != "" {
storageClassName = restore.Spec.StorageClassName
}
pvc := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: restorePVCName,
Namespace: ns,
Labels: label.NewRestore().Instance(restore.GetInstanceName()),
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: &storageClassName,
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Expand All @@ -242,6 +237,7 @@ func (rm *restoreManager) ensureRestorePVCExist(restore *v1alpha1.Restore) (stri
corev1.ResourceStorage: rs,
},
},
StorageClassName: restore.Spec.StorageClassName,
},
}
if err := rm.pvcControl.CreatePVC(restore, pvc); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions pkg/backup/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ func ValidateBackup(backup *v1alpha1.Backup) error {
if backup.Spec.From.SecretName == "" {
return fmt.Errorf("missing tidbSecretName config in spec of %s/%s", ns, name)
}
if backup.Spec.StorageClassName == "" {
return fmt.Errorf("missing storageClassName config in spec of %s/%s", ns, name)
}
if backup.Spec.StorageSize == "" {
return fmt.Errorf("missing StorageSize config in spec of %s/%s", ns, name)
}
Expand Down
Loading