-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ibu mgmt: move backup/restore tasks to separate utility (#47)
- Loading branch information
Showing
8 changed files
with
228 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/lca/imagebasedupgrade/mgmt/internal/brutil/brutil.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package brutil | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
) | ||
|
||
// NewBackRestoreObject returns a BackupRestoreObject. | ||
func NewBackRestoreObject(object runtime.Object, scheme *runtime.Scheme, gvr schema.GroupVersion) *BackupRestoreObject { | ||
return &BackupRestoreObject{ | ||
Scheme: scheme, | ||
GVR: gvr, | ||
Object: object, | ||
} | ||
} | ||
|
||
// String returns a string representation of the object passed to BackupRestoreObject. | ||
func (b *BackupRestoreObject) String() (string, error) { | ||
if b == nil { | ||
return "", fmt.Errorf("backuprestoreobject is nil") | ||
} | ||
|
||
stringRep, err := dataFromDefinition(b.Scheme, b.Object, b.GVR) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return stringRep, nil | ||
} | ||
|
||
// dataFromDefinition returns a json string representation of the provided resource. | ||
func dataFromDefinition(scheme *runtime.Scheme, obj runtime.Object, version schema.GroupVersion) (string, error) { | ||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(version) | ||
|
||
data, err := runtime.Encode(codec, obj) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(data), nil | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/lca/imagebasedupgrade/mgmt/internal/brutil/brutil_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package brutil | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// BackupRestoreObject contains information for generating | ||
// string representations of API resources. | ||
type BackupRestoreObject struct { | ||
Scheme *runtime.Scheme | ||
GVR schema.GroupVersion | ||
Object runtime.Object | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package brutil | ||
|
||
import ( | ||
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/mgmtparams" | ||
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" | ||
veleroScheme "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// WorkloadBackup represents ibu-workload backup. | ||
var WorkloadBackup = BackupRestoreObject{ | ||
Scheme: veleroScheme.Scheme, | ||
GVR: velerov1.SchemeGroupVersion, | ||
Object: &velerov1.Backup{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mgmtparams.LCAWorkloadName, | ||
Namespace: mgmtparams.LCAOADPNamespace, | ||
}, | ||
Spec: velerov1.BackupSpec{ | ||
IncludedNamespaces: []string{ | ||
mgmtparams.LCAWorkloadName, | ||
}, | ||
IncludedNamespaceScopedResources: []string{ | ||
"deployments", | ||
"services", | ||
"routes", | ||
}, | ||
ExcludedClusterScopedResources: []string{ | ||
"persistentVolumes", | ||
}, | ||
StorageLocation: "default", | ||
}, | ||
}, | ||
} | ||
|
||
// WorkloadRestore represents ibu-workload restore. | ||
var WorkloadRestore = BackupRestoreObject{ | ||
Scheme: veleroScheme.Scheme, | ||
GVR: velerov1.SchemeGroupVersion, | ||
Object: &velerov1.Restore{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mgmtparams.LCAWorkloadName, | ||
Namespace: mgmtparams.LCAOADPNamespace, | ||
Labels: map[string]string{ | ||
"velero.io/storage-location": "default", | ||
}, | ||
}, | ||
Spec: velerov1.RestoreSpec{ | ||
BackupName: mgmtparams.LCAWorkloadName, | ||
}, | ||
}, | ||
} | ||
|
||
// KlusterletBackup represents ibu klusterlet backup. | ||
var KlusterletBackup = BackupRestoreObject{ | ||
Scheme: veleroScheme.Scheme, | ||
GVR: velerov1.SchemeGroupVersion, | ||
Object: &velerov1.Backup{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mgmtparams.LCAKlusterletName, | ||
Namespace: mgmtparams.LCAOADPNamespace, | ||
}, | ||
Spec: velerov1.BackupSpec{ | ||
IncludedNamespaces: []string{ | ||
mgmtparams.LCAKlusterletNamespace, | ||
}, | ||
IncludedClusterScopedResources: []string{ | ||
"klusterlets.operator.open-cluster-management.io", | ||
"clusterclaims.cluster.open-cluster-management.io", | ||
"clusterroles.rbac.authorization.k8s.io", | ||
"clusterrolebindings.rbac.authorization.k8s.io", | ||
}, | ||
IncludedNamespaceScopedResources: []string{ | ||
"deployments", | ||
"serviceaccounts", | ||
"secrets", | ||
}, | ||
StorageLocation: "default", | ||
}, | ||
}, | ||
} | ||
|
||
// KlusterletRestore represents ibu klusterlet restore. | ||
var KlusterletRestore = BackupRestoreObject{ | ||
Scheme: veleroScheme.Scheme, | ||
GVR: velerov1.SchemeGroupVersion, | ||
Object: &velerov1.Restore{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mgmtparams.LCAKlusterletName, | ||
Namespace: mgmtparams.LCAOADPNamespace, | ||
Labels: map[string]string{ | ||
"velero.io/storage-location": "default", | ||
}, | ||
}, | ||
Spec: velerov1.RestoreSpec{ | ||
BackupName: mgmtparams.LCAKlusterletName, | ||
}, | ||
}, | ||
} |
20 changes: 0 additions & 20 deletions
20
tests/lca/imagebasedupgrade/mgmt/internal/configmapgenerator/configmapgenerator.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.