diff --git a/go.mod b/go.mod index a7535e71..e1ae872e 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73 kmodules.xyz/client-go v0.25.39 kmodules.xyz/offshoot-api v0.25.5-0.20231004063620-dff8fb030d57 - kubestash.dev/apimachinery v0.2.0-rc.0.0.20231114115833-0b99d5ce666e + kubestash.dev/apimachinery v0.2.0-rc.1 sigs.k8s.io/controller-runtime v0.13.1 ) diff --git a/go.sum b/go.sum index 38a825e2..cfa86b9a 100644 --- a/go.sum +++ b/go.sum @@ -1068,8 +1068,8 @@ kmodules.xyz/offshoot-api v0.25.5-0.20231004063620-dff8fb030d57 h1:4ld/ujZum5JX6 kmodules.xyz/offshoot-api v0.25.5-0.20231004063620-dff8fb030d57/go.mod h1:PUk4EuJFhhyQykCflHj7EgXcljGIqs9vi0IN0RpxtY4= kmodules.xyz/prober v0.25.0 h1:R5uRLHJEvEtEoogj+vaTAob0Btph6+PX5IlS6hPh8PA= kmodules.xyz/prober v0.25.0/go.mod h1:z4RTnjaajNQa/vPltsiOnO3xI716I/ziD2ac2Exm+1M= -kubestash.dev/apimachinery v0.2.0-rc.0.0.20231114115833-0b99d5ce666e h1:Ya9b9/Z9E9kuB2zUyR4XWierZ9je5WdGuO2D4hN6D1Y= -kubestash.dev/apimachinery v0.2.0-rc.0.0.20231114115833-0b99d5ce666e/go.mod h1:vlT+qYeOTh5GjzdKw9qhJlXxS+PvvVZivm+l7y+OUIs= +kubestash.dev/apimachinery v0.2.0-rc.1 h1:K4Gmtw6cSQngFQMcBjnwOuqgKaRGXk9z9zR4bVLanpU= +kubestash.dev/apimachinery v0.2.0-rc.1/go.mod h1:vlT+qYeOTh5GjzdKw9qhJlXxS+PvvVZivm+l7y+OUIs= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/vendor/kubestash.dev/apimachinery/apis/constant.go b/vendor/kubestash.dev/apimachinery/apis/constant.go index deaf656d..d882efab 100644 --- a/vendor/kubestash.dev/apimachinery/apis/constant.go +++ b/vendor/kubestash.dev/apimachinery/apis/constant.go @@ -69,6 +69,15 @@ const ( KubeStashSessionName = "kubestash.com/session-name" ) +// Keys for snapshots labels +const ( + KubeStashRepositoryName = "kubestash.com/repo-name" + + KubeStashAppRefKind = "kubestash.com/app-ref-kind" + KubeStashAppRefNamespace = "kubestash.com/app-ref-namespace" + KubeStashAppRefName = "kubestash.com/app-ref-name" +) + // Keys for structure logging const ( KeyTargetKind = "target_kind" @@ -106,16 +115,26 @@ const ( // Addon related const ( - EnvDBVersion = "DB_VERSION" EnvComponentName = "COMPONENT_NAME" - ComponentPod = "pod" - ComponentDeployment = "deployment" - ComponentPVC = "pvc" + ComponentPod = "pod" + ComponentDeployment = "deployment" + ComponentPVC = "pvc" + ComponentDump = "dump" + ComponentManifests = "manifests" + ComponentVolumeSnapshots = "volumesnapshots" DirRepository = "repository" ) +// Interim Volume Related Constant +const ( + KeyDBVersion = "DB_VERSION" + + KeyInterimVolume = "INTERIM_VOLUME" + InterimVolumeName = "kubestash-interim-volume" +) + // PersistentVolumeClaim related const ( KeyPodOrdinal = "POD_ORDINAL" @@ -144,3 +163,8 @@ const ( KeyAppName = PopulatorKey + "/app-name" KubeStashPopulatorContainer = "kubestash-populator" ) + +// Snapshot version related constants +const ( + SnapshotVersionV1 = "v1" +) diff --git a/vendor/kubestash.dev/apimachinery/apis/storage/v1alpha1/snapshot_helpers.go b/vendor/kubestash.dev/apimachinery/apis/storage/v1alpha1/snapshot_helpers.go index bcb68ca0..2924afa8 100644 --- a/vendor/kubestash.dev/apimachinery/apis/storage/v1alpha1/snapshot_helpers.go +++ b/vendor/kubestash.dev/apimachinery/apis/storage/v1alpha1/snapshot_helpers.go @@ -97,6 +97,33 @@ func (s *Snapshot) GetIntegrity() *bool { return &result } +func (s *Snapshot) GetTotalBackupSizeInBytes() (uint64, error) { + if s.Status.Components == nil { + return 0, fmt.Errorf("no component found for snapshot %s/%s", s.Namespace, s.Name) + } + + var totalSizeInByte uint64 + for componentName, component := range s.Status.Components { + for _, stats := range component.ResticStats { + if stats.Size == "" { + return 0, fmt.Errorf("resticStats size of component %s is empty for the snapshot %s/%s", componentName, s.Namespace, s.Name) + } + + sizeWithUnit := strings.Split(component.Size, " ") + if len(sizeWithUnit) < 2 { + return 0, fmt.Errorf("resticStats size of component %s is invalid for the snapshot %s/%s", componentName, s.Namespace, s.Name) + } + + sizeInByte, err := convertSizeToByte(sizeWithUnit) + if err != nil { + return 0, err + } + totalSizeInByte += sizeInByte + } + } + return totalSizeInByte, nil +} + func (s *Snapshot) GetSize() string { if s.Status.Components == nil { return "" diff --git a/vendor/modules.txt b/vendor/modules.txt index f17d388d..5b1bd4a8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -822,7 +822,7 @@ kmodules.xyz/offshoot-api/api/v1 # kmodules.xyz/prober v0.25.0 ## explicit; go 1.18 kmodules.xyz/prober/api/v1 -# kubestash.dev/apimachinery v0.2.0-rc.0.0.20231114115833-0b99d5ce666e +# kubestash.dev/apimachinery v0.2.0-rc.1 ## explicit; go 1.20 kubestash.dev/apimachinery/apis kubestash.dev/apimachinery/apis/config/v1alpha1