Skip to content

Commit 473f5e1

Browse files
committed
Add controller airgap storage space calculation
Signed-off-by: Evans Mungai <evans@replicated.com>
1 parent 668b930 commit 473f5e1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pkg-new/preflights/template.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
_ "embed"
77
"fmt"
8+
"math"
89
"text/template"
910

1011
"github.com/replicatedhq/embedded-cluster/pkg-new/preflights/types"
@@ -44,3 +45,28 @@ func renderTemplate(spec string, data types.TemplateData) (string, error) {
4445
}
4546
return buf.String(), nil
4647
}
48+
49+
// CalculateControllerAirgapStorageSpace calculates the required airgap storage space for controller nodes.
50+
// It multiplies the uncompressed size by 2, rounds up to the nearest natural number, and returns a string.
51+
// The quantity will be in Gi for sizes >= 1 Gi, or Mi for smaller sizes.
52+
func CalculateControllerAirgapStorageSpace(uncompressedSize int64) string {
53+
if uncompressedSize <= 0 {
54+
return ""
55+
}
56+
57+
// Controller nodes require 2x the extracted bundle size for processing
58+
requiredBytes := uncompressedSize * 2
59+
60+
// Convert to Gi if >= 1 Gi, otherwise use Mi
61+
if requiredBytes >= 1024*1024*1024 { // 1 Gi in bytes
62+
// Convert to Gi and round up to nearest natural number
63+
giValue := float64(requiredBytes) / (1024 * 1024 * 1024)
64+
roundedGi := math.Ceil(giValue)
65+
return fmt.Sprintf("%dGi", int64(roundedGi))
66+
} else {
67+
// Convert to Mi and round up to nearest natural number
68+
miValue := float64(requiredBytes) / (1024 * 1024)
69+
roundedMi := math.Ceil(miValue)
70+
return fmt.Sprintf("%dMi", int64(roundedMi))
71+
}
72+
}

0 commit comments

Comments
 (0)