mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-28 08:59:34 -05:00
cli: create namespaced folders for upgrade backups
Resource names are only unique per kind+ns. Without this patch it might happen that there are two resources with the same name in different namespaces. Upgrade might fail in that case.
This commit is contained in:
parent
7ab23c28b8
commit
3770cada91
@ -63,7 +63,11 @@ func (c *Client) backupCRs(ctx context.Context, crds []apiextensionsv1.CustomRes
|
||||
}
|
||||
|
||||
for _, cr := range crs {
|
||||
path := filepath.Join(backupFolder, cr.GetName()+".yaml")
|
||||
targetFolder := filepath.Join(backupFolder, cr.GetKind(), cr.GetNamespace())
|
||||
if err := c.fs.MkdirAll(targetFolder); err != nil {
|
||||
return fmt.Errorf("creating resource dir: %w", err)
|
||||
}
|
||||
path := filepath.Join(targetFolder, cr.GetName()+".yaml")
|
||||
yamlBytes, err := yaml.Marshal(cr.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -133,7 +133,7 @@ func TestBackupCRs(t *testing.T) {
|
||||
}
|
||||
assert.NoError(err)
|
||||
|
||||
data, err := afero.ReadFile(memFs, filepath.Join(backupFolder, tc.resource.GetName()+".yaml"))
|
||||
data, err := afero.ReadFile(memFs, filepath.Join(backupFolder, tc.resource.GetKind(), tc.resource.GetNamespace(), tc.resource.GetName()+".yaml"))
|
||||
require.NoError(err)
|
||||
assert.YAMLEq(tc.expectedFile, string(data))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user