Skip to content

Commit

Permalink
Add CleanupResources flag to migration specs
Browse files Browse the repository at this point in the history
   - add annotation to migrating resources by stork
   - have stub to cleanup resources for dest cluster

Signed-off-by: Ram <[email protected]>
  • Loading branch information
ram-infrac committed Nov 27, 2019
1 parent a1da847 commit df796e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
19 changes: 10 additions & 9 deletions pkg/apis/stork/v1alpha1/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ const (

// MigrationSpec is the spec used to migrate apps between clusterpairs
type MigrationSpec struct {
ClusterPair string `json:"clusterPair"`
AdminClusterPair string `json:"adminClusterPair"`
Namespaces []string `json:"namespaces"`
IncludeResources *bool `json:"includeResources"`
IncludeVolumes *bool `json:"includeVolumes"`
StartApplications *bool `json:"startApplications"`
Selectors map[string]string `json:"selectors"`
PreExecRule string `json:"preExecRule"`
PostExecRule string `json:"postExecRule"`
ClusterPair string `json:"clusterPair"`
AdminClusterPair string `json:"adminClusterPair"`
Namespaces []string `json:"namespaces"`
IncludeResources *bool `json:"includeResources"`
IncludeVolumes *bool `json:"includeVolumes"`
StartApplications *bool `json:"startApplications"`
AllowCleaningResources *bool `json:"allowCleaningResources"`
Selectors map[string]string `json:"selectors"`
PreExecRule string `json:"preExecRule"`
PostExecRule string `json:"postExecRule"`
}

// MigrationStatus is the status of a migration operation
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/stork/v1alpha1/zz_generated.deepcopy.go

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

17 changes: 16 additions & 1 deletion pkg/migration/controllers/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
// StorkMigrationReplicasAnnotation is the annotation used to keep track of
// the number of replicas for an application when it was migrated
StorkMigrationReplicasAnnotation = "stork.libopenstorage.org/migrationReplicas"
// StorkMigrationAnnotation is the annotation used to keep track of resources
// migrated by stork
StorkMigrationAnnotation = "stork.libopenstorage.org/storkMigration"
// Max number of times to retry applying resources on the desination
maxApplyRetries = 10
)
Expand Down Expand Up @@ -284,7 +287,11 @@ func (m *MigrationController) Handle(ctx context.Context, event sdk.Event) error
}

case stork_api.MigrationStageFinal:
// Do Nothing
// delete resources on destination which are not present on source
// TODO: what should be idle location for this
if *migration.Spec.AllowCleaningResources {
return m.cleanupMigratedResources(migration)
}
return nil
default:
log.MigrationLog(migration).Errorf("Invalid stage for migration: %v", migration.Status.Stage)
Expand All @@ -293,6 +300,10 @@ func (m *MigrationController) Handle(ctx context.Context, event sdk.Event) error
return nil
}

func (m *MigrationController) cleanupMigratedResources(migration *stork_api.Migration) error {
return nil
}

func (m *MigrationController) namespaceMigrationAllowed(migration *stork_api.Migration) bool {
// Restrict migration to only the namespace that the object belongs
// except for the namespace designated by the admin
Expand Down Expand Up @@ -884,6 +895,10 @@ func (m *MigrationController) applyResources(
if !ok {
return fmt.Errorf("unable to cast object to unstructured: %v", o)
}

unstructured.SetAnnotations(map[string]string{StorkMigrationAnnotation: "true"})
log.MigrationLog(migration).Infof("Applied stork migration annotation %v %v", metadata.GetName(), unstructured.GetAnnotations())

retries := 0
for {
_, err = dynamicClient.Create(unstructured)
Expand Down

0 comments on commit df796e6

Please sign in to comment.