Use generated deep copy functions
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>pull/157/head
parent
293674c40e
commit
aa253bf016
|
@ -39,7 +39,6 @@ import (
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/kubernetes/scheme"
|
|
||||||
kcorev1client "k8s.io/client-go/kubernetes/typed/core/v1"
|
kcorev1client "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
|
@ -194,11 +193,7 @@ func (s *server) run() error {
|
||||||
|
|
||||||
// watchConfig needs to examine the unmodified original config, so we keep that around as a
|
// watchConfig needs to examine the unmodified original config, so we keep that around as a
|
||||||
// separate object, and instead apply defaults to a clone.
|
// separate object, and instead apply defaults to a clone.
|
||||||
copy, err := scheme.Scheme.DeepCopy(originalConfig)
|
config := originalConfig.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
config := copy.(*api.Config)
|
|
||||||
applyConfigDefaults(config, s.logger)
|
applyConfigDefaults(config, s.logger)
|
||||||
|
|
||||||
s.watchConfig(originalConfig)
|
s.watchConfig(originalConfig)
|
||||||
|
|
|
@ -38,7 +38,6 @@ import (
|
||||||
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
"github.com/heptio/ark/pkg/backup"
|
"github.com/heptio/ark/pkg/backup"
|
||||||
"github.com/heptio/ark/pkg/cloudprovider"
|
"github.com/heptio/ark/pkg/cloudprovider"
|
||||||
"github.com/heptio/ark/pkg/generated/clientset/versioned/scheme"
|
|
||||||
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
||||||
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
||||||
|
@ -221,10 +220,7 @@ func (controller *backupController) processBackup(key string) error {
|
||||||
|
|
||||||
logContext.Debug("Cloning backup")
|
logContext.Debug("Cloning backup")
|
||||||
// don't modify items in the cache
|
// don't modify items in the cache
|
||||||
backup, err = cloneBackup(backup)
|
backup = backup.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// set backup version
|
// set backup version
|
||||||
backup.Status.Version = backupVersion
|
backup.Status.Version = backupVersion
|
||||||
|
@ -267,20 +263,6 @@ func (controller *backupController) processBackup(key string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneBackup(in interface{}) (*api.Backup, error) {
|
|
||||||
clone, err := scheme.Scheme.DeepCopy(in)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "error deep-copying Backup")
|
|
||||||
}
|
|
||||||
|
|
||||||
out, ok := clone.(*api.Backup)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.Errorf("unexpected type: %T", clone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (controller *backupController) getValidationErrors(itm *api.Backup) []string {
|
func (controller *backupController) getValidationErrors(itm *api.Backup) []string {
|
||||||
var validationErrors []string
|
var validationErrors []string
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import (
|
||||||
|
|
||||||
"github.com/heptio/ark/pkg/apis/ark/v1"
|
"github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
"github.com/heptio/ark/pkg/cloudprovider"
|
"github.com/heptio/ark/pkg/cloudprovider"
|
||||||
"github.com/heptio/ark/pkg/generated/clientset/versioned/scheme"
|
|
||||||
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
||||||
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
||||||
|
@ -210,11 +209,9 @@ const signedURLTTL = 10 * time.Minute
|
||||||
// generatePreSignedURL generates a pre-signed URL for downloadRequest, changes the phase to
|
// generatePreSignedURL generates a pre-signed URL for downloadRequest, changes the phase to
|
||||||
// Processed, and persists the changes to storage.
|
// Processed, and persists the changes to storage.
|
||||||
func (c *downloadRequestController) generatePreSignedURL(downloadRequest *v1.DownloadRequest) error {
|
func (c *downloadRequestController) generatePreSignedURL(downloadRequest *v1.DownloadRequest) error {
|
||||||
update, err := cloneDownloadRequest(downloadRequest)
|
update := downloadRequest.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var err error
|
||||||
update.Status.DownloadURL, err = c.backupService.CreateSignedURL(downloadRequest.Spec.Target, c.bucket, signedURLTTL)
|
update.Status.DownloadURL, err = c.backupService.CreateSignedURL(downloadRequest.Spec.Target, c.bucket, signedURLTTL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -259,18 +256,3 @@ func (c *downloadRequestController) resync() {
|
||||||
c.queue.Add(key)
|
c.queue.Add(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cloneDownloadRequest makes a deep copy of in.
|
|
||||||
func cloneDownloadRequest(in *v1.DownloadRequest) (*v1.DownloadRequest, error) {
|
|
||||||
clone, err := scheme.Scheme.DeepCopy(in)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "error deep-copying DownloadRequest")
|
|
||||||
}
|
|
||||||
|
|
||||||
out, ok := clone.(*v1.DownloadRequest)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.Errorf("unexpected type: %T", clone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import (
|
||||||
|
|
||||||
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
"github.com/heptio/ark/pkg/cloudprovider"
|
"github.com/heptio/ark/pkg/cloudprovider"
|
||||||
"github.com/heptio/ark/pkg/generated/clientset/versioned/scheme"
|
|
||||||
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
||||||
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
||||||
|
@ -226,10 +225,7 @@ func (controller *restoreController) processRestore(key string) error {
|
||||||
|
|
||||||
logContext.Debug("Cloning Restore")
|
logContext.Debug("Cloning Restore")
|
||||||
// don't modify items in the cache
|
// don't modify items in the cache
|
||||||
restore, err = cloneRestore(restore)
|
restore = restore.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
excludedResources := sets.NewString(restore.Spec.ExcludedResources...)
|
excludedResources := sets.NewString(restore.Spec.ExcludedResources...)
|
||||||
for _, nonrestorable := range nonRestorableResources {
|
for _, nonrestorable := range nonRestorableResources {
|
||||||
|
@ -271,20 +267,6 @@ func (controller *restoreController) processRestore(key string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneRestore(in interface{}) (*api.Restore, error) {
|
|
||||||
clone, err := scheme.Scheme.DeepCopy(in)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "error deep-copying Restore")
|
|
||||||
}
|
|
||||||
|
|
||||||
out, ok := clone.(*api.Restore)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.Errorf("unexpected type: %T", clone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (controller *restoreController) getValidationErrors(itm *api.Restore) []string {
|
func (controller *restoreController) getValidationErrors(itm *api.Restore) []string {
|
||||||
var validationErrors []string
|
var validationErrors []string
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
"github.com/heptio/ark/pkg/generated/clientset/versioned/scheme"
|
|
||||||
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
||||||
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
||||||
|
@ -232,10 +231,7 @@ func (controller *scheduleController) processSchedule(key string) error {
|
||||||
|
|
||||||
logContext.Debug("Cloning schedule")
|
logContext.Debug("Cloning schedule")
|
||||||
// don't modify items in the cache
|
// don't modify items in the cache
|
||||||
schedule, err = cloneSchedule(schedule)
|
schedule = schedule.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// validation - even if the item is Enabled, we can't trust it
|
// validation - even if the item is Enabled, we can't trust it
|
||||||
// so re-validate
|
// so re-validate
|
||||||
|
@ -270,20 +266,6 @@ func (controller *scheduleController) processSchedule(key string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneSchedule(in interface{}) (*api.Schedule, error) {
|
|
||||||
clone, err := scheme.Scheme.DeepCopy(in)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "error deep-copying Schedule")
|
|
||||||
}
|
|
||||||
|
|
||||||
out, ok := clone.(*api.Schedule)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.Errorf("unexpected type: %T", clone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseCronSchedule(itm *api.Schedule, logger *logrus.Logger) (cron.Schedule, []string) {
|
func parseCronSchedule(itm *api.Schedule, logger *logrus.Logger) (cron.Schedule, []string) {
|
||||||
var validationErrors []string
|
var validationErrors []string
|
||||||
var schedule cron.Schedule
|
var schedule cron.Schedule
|
||||||
|
@ -348,10 +330,7 @@ func (controller *scheduleController) submitBackupIfDue(item *api.Schedule, cron
|
||||||
return errors.Wrap(err, "error creating Backup")
|
return errors.Wrap(err, "error creating Backup")
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule, err := cloneSchedule(item)
|
schedule := item.DeepCopy()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
schedule.Status.LastBackup = metav1.NewTime(now)
|
schedule.Status.LastBackup = metav1.NewTime(now)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue