@@ -80,14 +80,16 @@ func (b *Backup) processItem(key string) error {
8080 }
8181 return nil
8282 }
83+ isPeriodic := isPeriodicBackup (& eb .Spec )
84+
8385 // don't process the CR if it has a status since
8486 // having a status means that the backup is either made or failed.
85- if ! isPeriodicBackup ( & eb . Spec ) &&
87+ if ! isPeriodic &&
8688 (eb .Status .Succeeded || len (eb .Status .Reason ) != 0 ) {
8789 return nil
8890 }
8991
90- if isPeriodicBackup ( & eb . Spec ) && b .isChanged (eb ) {
92+ if isPeriodic && b .isChanged (eb ) {
9193 // Stop previous backup runner if it exists
9294 b .deletePeriodicBackupRunner (eb .ObjectMeta .UID )
9395
@@ -107,9 +109,9 @@ func (b *Backup) processItem(key string) error {
107109 // Store cancel function for periodic
108110 b .backupRunnerStore .Store (eb .ObjectMeta .UID , BackupRunner {eb .Spec , cancel })
109111
110- } else if ! isPeriodicBackup ( & eb . Spec ) {
112+ } else if ! isPeriodic {
111113 // Perform backup
112- bs , err := b .handleBackup (nil , & eb .Spec )
114+ bs , err := b .handleBackup (nil , & eb .Spec , false )
113115 // Report backup status
114116 b .reportBackupStatus (bs , err , eb )
115117 }
@@ -146,10 +148,9 @@ func (b *Backup) addFinalizerOfPeriodicBackupIfNeed(eb *api.EtcdBackup) (*api.Et
146148 if err != nil {
147149 return eb , err
148150 }
149- } else {
150- return eb , nil
151+ return ebNew .(* api.EtcdBackup ), nil
151152 }
152- return ebNew .( * api. EtcdBackup ) , nil
153+ return eb , nil
153154}
154155
155156func (b * Backup ) removeFinalizerOfPeriodicBackup (eb * api.EtcdBackup ) error {
@@ -192,7 +193,7 @@ func (b *Backup) periodicRunnerFunc(ctx context.Context, t *time.Ticker, eb *api
192193 break
193194 }
194195 // Perform backup
195- bs , err := b .handleBackup (& ctx , & latestEb .Spec )
196+ bs , err := b .handleBackup (& ctx , & latestEb .Spec , true )
196197 // Report backup status
197198 b .reportBackupStatus (bs , err , latestEb )
198199 }
@@ -240,7 +241,7 @@ func (b *Backup) handleErr(err error, key interface{}) {
240241 b .logger .Infof ("Dropping etcd backup (%v) out of the queue: %v" , key , err )
241242}
242243
243- func (b * Backup ) handleBackup (parentContext * context.Context , spec * api.BackupSpec ) (* api.BackupStatus , error ) {
244+ func (b * Backup ) handleBackup (parentContext * context.Context , spec * api.BackupSpec , isPeriodic bool ) (* api.BackupStatus , error ) {
244245 err := validate (spec )
245246 if err != nil {
246247 return nil , err
@@ -265,21 +266,21 @@ func (b *Backup) handleBackup(parentContext *context.Context, spec *api.BackupSp
265266 switch spec .StorageType {
266267 case api .BackupStorageTypeS3 :
267268 bs , err := handleS3 (ctx , b .kubecli , spec .S3 , spec .EtcdEndpoints , spec .ClientTLSSecret ,
268- b .namespace , isPeriodicBackup ( spec ) , backupMaxCount )
269+ b .namespace , isPeriodic , backupMaxCount )
269270 if err != nil {
270271 return nil , err
271272 }
272273 return bs , nil
273274 case api .BackupStorageTypeABS :
274275 bs , err := handleABS (ctx , b .kubecli , spec .ABS , spec .EtcdEndpoints , spec .ClientTLSSecret ,
275- b .namespace , isPeriodicBackup ( spec ) , backupMaxCount )
276+ b .namespace , isPeriodic , backupMaxCount )
276277 if err != nil {
277278 return nil , err
278279 }
279280 return bs , nil
280281 case api .BackupStorageTypeGCS :
281282 bs , err := handleGCS (ctx , b .kubecli , spec .GCS , spec .EtcdEndpoints , spec .ClientTLSSecret ,
282- b .namespace , isPeriodicBackup ( spec ) , backupMaxCount )
283+ b .namespace , isPeriodic , backupMaxCount )
283284 if err != nil {
284285 return nil , err
285286 }
@@ -297,10 +298,10 @@ func validate(spec *api.BackupSpec) error {
297298 }
298299 if spec .BackupPolicy != nil {
299300 if spec .BackupPolicy .BackupIntervalInSecond < 0 {
300- return errors .New ("spec.backupPolicy.backupIntervalInSecond should not be lower than 0" )
301+ return errors .New ("spec.BackupPolicy.BackupIntervalInSecond should not be lower than 0" )
301302 }
302303 if spec .BackupPolicy .MaxBackups < 0 {
303- return errors .New ("spec.backupPolicy .MaxBackups should not be lower than 0" )
304+ return errors .New ("spec.BackupPolicy .MaxBackups should not be lower than 0" )
304305 }
305306 }
306307 return nil
0 commit comments