mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-13 22:23:11 +01:00
chore: make metadata access type safe
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
d3660c9ee6
commit
6aba7c7502
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
|
barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
|
||||||
@ -20,7 +19,6 @@ import (
|
|||||||
|
|
||||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
|
||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -148,13 +146,6 @@ func (b BackupServiceImplementation) Backup(
|
|||||||
EndLsn: executedBackupInfo.EndLSN,
|
EndLsn: executedBackupInfo.EndLSN,
|
||||||
InstanceId: b.InstanceName,
|
InstanceId: b.InstanceName,
|
||||||
Online: true,
|
Online: true,
|
||||||
Metadata: map[string]string{
|
Metadata: newBackupResultMetadata(configuration.Cluster.ObjectMeta.UID, executedBackupInfo.TimeLine).toMap(),
|
||||||
"timeline": strconv.Itoa(executedBackupInfo.TimeLine),
|
|
||||||
"version": metadata.Data.Version,
|
|
||||||
"name": metadata.Data.Name,
|
|
||||||
"displayName": metadata.Data.DisplayName,
|
|
||||||
"clusterUID": string(configuration.Cluster.ObjectMeta.UID),
|
|
||||||
"pluginName": metadata.PluginName,
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -279,6 +279,7 @@ func useSameBackupLocation(backup *cnpgv1.BackupStatus, cluster *cnpgv1.Cluster)
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return backup.PluginMetadata["clusterUID"] == string(cluster.UID) &&
|
meta := newBackupResultMetadataFromMap(backup.PluginMetadata)
|
||||||
backup.PluginMetadata["pluginName"] == metadata.PluginName
|
|
||||||
|
return meta.clusterUID == string(cluster.UID) && meta.pluginName == metadata.PluginName
|
||||||
}
|
}
|
||||||
|
|||||||
56
internal/cnpgi/instance/types.go
Normal file
56
internal/cnpgi/instance/types.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package instance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type backupResultMetadata struct {
|
||||||
|
timeline string
|
||||||
|
version string
|
||||||
|
name string
|
||||||
|
displayName string
|
||||||
|
clusterUID string
|
||||||
|
pluginName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b backupResultMetadata) toMap() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"timeline": b.timeline,
|
||||||
|
"version": b.version,
|
||||||
|
"name": b.name,
|
||||||
|
"displayName": b.displayName,
|
||||||
|
"clusterUID": b.clusterUID,
|
||||||
|
"pluginName": b.pluginName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBackupResultMetadata(clusterUID types.UID, timeline int) backupResultMetadata {
|
||||||
|
return backupResultMetadata{
|
||||||
|
timeline: strconv.Itoa(timeline),
|
||||||
|
clusterUID: string(clusterUID),
|
||||||
|
// static values
|
||||||
|
version: metadata.Data.Version,
|
||||||
|
name: metadata.Data.Name,
|
||||||
|
displayName: metadata.Data.DisplayName,
|
||||||
|
pluginName: metadata.PluginName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBackupResultMetadataFromMap(m map[string]string) backupResultMetadata {
|
||||||
|
if m == nil {
|
||||||
|
return backupResultMetadata{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return backupResultMetadata{
|
||||||
|
timeline: m["timeline"],
|
||||||
|
version: m["version"],
|
||||||
|
name: m["name"],
|
||||||
|
displayName: m["displayName"],
|
||||||
|
clusterUID: m["clusterUID"],
|
||||||
|
pluginName: m["pluginName"],
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user