feat(platform): registry/uploads/backup PVC 容量可配置
This commit is contained in:
6 files changed
+154
-5
No files matched your search
@@ -1,5 +1,11 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
// Identity constants and the Params that parameterise the install bundle.
|
||||
//
|
||||
// The label and SA-name constants are PINNED here because three independent
|
||||
@@ -171,6 +177,35 @@ type Params struct {
|
||||
// must-match. It is reaper-only and has no default; empty (with WorldsHostPath set)
|
||||
// is rejected fail-loud by the generator.
|
||||
ArchiveLocalPath string
|
||||
// RegistryStorage, UploadsStorage and BackupStorage are the capacities the
|
||||
// registry, uploads and world-archive PVCs request ("20Gi"); empty keeps
|
||||
// 10Gi, 5Gi and 10Gi. A PVC's request can only grow, and only on a class that
|
||||
// allows expansion, so the installer keeps an existing PVC's size. On k3s
|
||||
// local-path the request is a label: the volume is a directory on the node's
|
||||
// disk and nothing stops it outgrowing the number; the registry pruner, the
|
||||
// uploads budget (user_uploads_max_bytes) and the archive cap
|
||||
// (max_local_bytes) are what bound them there.
|
||||
RegistryStorage string
|
||||
UploadsStorage string
|
||||
BackupStorage string
|
||||
}
|
||||
|
||||
// Validate reports a Params the renderer cannot turn into objects.
|
||||
func (p Params) Validate() error {
|
||||
for _, q := range []struct{ name, v string }{
|
||||
{"registry storage", p.RegistryStorage},
|
||||
{"uploads storage", p.UploadsStorage},
|
||||
{"backup storage", p.BackupStorage},
|
||||
} {
|
||||
if q.v == "" {
|
||||
continue
|
||||
}
|
||||
v, err := resource.ParseQuantity(q.v)
|
||||
if err != nil || v.Sign() <= 0 {
|
||||
return fmt.Errorf("%s %q is not a positive size such as 20Gi", q.name, q.v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// withDefaults returns a copy of p with zero namespace/registry fields filled.
|
||||
@@ -198,6 +233,15 @@ func (p Params) withDefaults() Params {
|
||||
if p.RegistryImage == "" {
|
||||
p.RegistryImage = defaultRegistryImage
|
||||
}
|
||||
if p.RegistryStorage == "" {
|
||||
p.RegistryStorage = registryStorageSize
|
||||
}
|
||||
if p.UploadsStorage == "" {
|
||||
p.UploadsStorage = uploadsStorageSize
|
||||
}
|
||||
if p.BackupStorage == "" {
|
||||
p.BackupStorage = backupStorageSize
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
@@ -1102,7 +1102,7 @@ func registryPVC(p Params) *corev1.PersistentVolumeClaim {
|
||||
Spec: corev1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
|
||||
Resources: corev1.VolumeResourceRequirements{
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(registryStorageSize)},
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(p.RegistryStorage)},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1123,7 +1123,7 @@ func uploadsPVC(p Params) *corev1.PersistentVolumeClaim {
|
||||
Spec: corev1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
|
||||
Resources: corev1.VolumeResourceRequirements{
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(uploadsStorageSize)},
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(p.UploadsStorage)},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1147,7 +1147,7 @@ func backupPVC(p Params) *corev1.PersistentVolumeClaim {
|
||||
Spec: corev1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
|
||||
Resources: corev1.VolumeResourceRequirements{
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(backupStorageSize)},
|
||||
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(p.BackupStorage)},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1131,3 +1131,37 @@ func TestOperatorMetricsService(t *testing.T) {
|
||||
t.Error("Workloads does not render the operator metrics Service")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPVCSizes proves the three claim sizes follow Params and default when unset,
|
||||
// and that Validate refuses a size the API server would reject.
|
||||
func TestPVCSizes(t *testing.T) {
|
||||
sizes := func(p Params) map[string]string {
|
||||
got := map[string]string{}
|
||||
for _, o := range Workloads(p.withDefaults()) {
|
||||
if pvc, ok := o.(*corev1.PersistentVolumeClaim); ok {
|
||||
got[pvc.Name] = pvc.Spec.Resources.Requests.Storage().String()
|
||||
}
|
||||
}
|
||||
return got
|
||||
}
|
||||
p := testParams()
|
||||
p.BackupPVC = "felis-backups"
|
||||
def := sizes(p)
|
||||
if def[registryName] != registryStorageSize || def[uploadsPVCName] != uploadsStorageSize || def["felis-backups"] != backupStorageSize {
|
||||
t.Errorf("default sizes = %v", def)
|
||||
}
|
||||
p.RegistryStorage, p.UploadsStorage, p.BackupStorage = "40Gi", "8Gi", "100Gi"
|
||||
if got := sizes(p); got[registryName] != "40Gi" || got[uploadsPVCName] != "8Gi" || got["felis-backups"] != "100Gi" {
|
||||
t.Errorf("configured sizes = %v", got)
|
||||
}
|
||||
if err := p.Validate(); err != nil {
|
||||
t.Errorf("Validate(%+v) = %v", p, err)
|
||||
}
|
||||
for _, bad := range []string{"lots", "0", "-1Gi"} {
|
||||
q := testParams()
|
||||
q.UploadsStorage = bad
|
||||
if err := q.Validate(); err == nil {
|
||||
t.Errorf("Validate accepted uploads storage %q", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user