Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 1205e2c

Browse files
authored
Merge pull request #2215 from tylerslaton/default-volume-size
Add new --volume-size-default install flag
2 parents 4441b64 + 69b228e commit 1205e2c

File tree

14 files changed

+76
-14
lines changed

14 files changed

+76
-14
lines changed

docs/docs/100-reference/01-command-line/acorn_install.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ acorn install
7171
--set-pod-security-enforce-profile Set the PodSecurity profile on created namespaces (default true)
7272
--skip-checks Bypass installation checks
7373
--use-custom-ca-bundle Use CA bundle for admin supplied secret for all acorn control plane components. Defaults to false.
74-
-m, --workload-memory-default string Set the default memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and "." and "_" seperators (default 0)
75-
--workload-memory-maximum string Set the maximum memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and "." and "_" seperators (default 0)
74+
--volume-size-default string Set the default size for acorn volumes. Accepts storage suffixes (K, M, G, Ki, Mi, Gi, etc) and "." and "_" separators (default 0)
75+
-m, --workload-memory-default string Set the default memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and "." and "_" separators (default 0)
76+
--workload-memory-maximum string Set the maximum memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and "." and "_" separators (default 0)
7677
```
7778

7879
### Options inherited from parent commands

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,13 @@ type Config struct {
540540
AllowUserLabels []string `json:"allowUserLabels" name:"allow-user-label" usage:"Allow these labels to propagate to dependent objects, no effect if --ignore-user-labels-and-annotations not true"`
541541
AllowUserAnnotations []string `json:"allowUserAnnotations" name:"allow-user-annotation" usage:"Allow these annotations to propagate to dependent objects, no effect if --ignore-user-labels-and-annotations not true"`
542542
AllowUserMetadataNamespaces []string `json:"allowUserMetadataNamespaces" name:"allow-user-metadata-namespace" usage:"Allow these namespaces to propagate labels and annotations to dependent objects, no effect if --ignore-user-labels-and-annotations not true"`
543-
WorkloadMemoryDefault *int64 `json:"workloadMemoryDefault" name:"workload-memory-default" quantity:"true" usage:"Set the default memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and \".\" and \"_\" seperators (default 0)" short:"m"`
544-
WorkloadMemoryMaximum *int64 `json:"workloadMemoryMaximum" name:"workload-memory-maximum" quantity:"true" usage:"Set the maximum memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and \".\" and \"_\" seperators (default 0)"`
543+
WorkloadMemoryDefault *int64 `json:"workloadMemoryDefault" name:"workload-memory-default" quantity:"true" usage:"Set the default memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and \".\" and \"_\" separators (default 0)" short:"m"`
544+
WorkloadMemoryMaximum *int64 `json:"workloadMemoryMaximum" name:"workload-memory-maximum" quantity:"true" usage:"Set the maximum memory for acorn workloads. Accepts binary suffixes (Ki, Mi, Gi, etc) and \".\" and \"_\" separators (default 0)"`
545545
UseCustomCABundle *bool `json:"useCustomCABundle" name:"use-custom-ca-bundle" usage:"Use CA bundle for admin supplied secret for all acorn control plane components. Defaults to false."`
546546
PropagateProjectAnnotations []string `json:"propagateProjectAnnotations" name:"propagate-project-annotation" usage:"The list of keys of annotations to propagate from acorn project to app namespaces"`
547547
PropagateProjectLabels []string `json:"propagateProjectLabels" name:"propagate-project-label" usage:"The list of keys of labels to propagate from acorn project to app namespaces"`
548548
ManageVolumeClasses *bool `json:"manageVolumeClasses" name:"manage-volume-classes" usage:"Manually manage volume classes rather than sync with storage classes, setting to 'true' will delete Acorn-created volume classes"`
549+
VolumeSizeDefault string `json:"volumeSizeDefault" name:"volume-size-default" usage:"Set the default size for acorn volumes. Accepts storage suffixes (K, M, G, Ki, Mi, Gi, etc) and \".\" and \"_\" separators (default 0)"`
549550
NetworkPolicies *bool `json:"networkPolicies" name:"network-policies" usage:"Create Kubernetes NetworkPolicies which block cross-project network traffic (default false)"`
550551
IngressControllerNamespace *string `json:"ingressControllerNamespace" name:"ingress-controller-namespace" usage:"The namespace where the ingress controller runs - used to secure published HTTP ports with NetworkPolicies."`
551552
AllowTrafficFromNamespace []string `json:"allowTrafficFromNamespace" name:"allow-traffic-from-namespace" usage:"Namespaces that are allowed to send network traffic to all Acorn apps"`

pkg/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func complete(ctx context.Context, c *apiv1.Config, getter kclient.Reader, inclu
107107
if c.IngressControllerNamespace == nil {
108108
c.IngressControllerNamespace = profile.IngressControllerNamespace
109109
}
110+
if c.VolumeSizeDefault == "" {
111+
c.VolumeSizeDefault = profile.VolumeSizeDefault
112+
}
110113
if c.AWSIdentityProviderARN == nil {
111114
c.AWSIdentityProviderARN = profile.AWSIdentityProviderARN
112115
}
@@ -374,6 +377,9 @@ func merge(oldConfig, newConfig *apiv1.Config) *apiv1.Config {
374377
if newConfig.IngressControllerNamespace != nil {
375378
mergedConfig.IngressControllerNamespace = newConfig.IngressControllerNamespace
376379
}
380+
if newConfig.VolumeSizeDefault != "" {
381+
mergedConfig.VolumeSizeDefault = newConfig.VolumeSizeDefault
382+
}
377383
if newConfig.AWSIdentityProviderARN != nil {
378384
mergedConfig.AWSIdentityProviderARN = newConfig.AWSIdentityProviderARN
379385
}

pkg/controller/appdefinition/testdata/deployspec/filter-user-labels/expected.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ status:
407407
status: "True"
408408
success: true
409409
type: defined
410-
defaults: {}
410+
defaults:
411+
volumeSize: 10G
411412
namespace: app-created-namespace
412413
staged:
413414
appImage:

pkg/controller/appdefinition/testdata/deployspec/labels/expected.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ status:
415415
status: "True"
416416
success: true
417417
type: defined
418-
defaults: {}
418+
defaults:
419+
volumeSize: 10G
419420
namespace: app-created-namespace
420421
staged:
421422
appImage:

pkg/controller/appdefinition/testdata/deployspec/no-user-labels/expected.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ status:
285285
status: "True"
286286
success: true
287287
type: defined
288-
defaults: {}
288+
defaults:
289+
volumeSize: 10G
289290
namespace: app-created-namespace
290291
staged:
291292
appImage:

pkg/controller/appdefinition/testdata/volumes/empty/expected.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ status:
166166
status: "True"
167167
success: true
168168
type: defined
169-
defaults: {}
169+
defaults:
170+
volumeSize: 10G
170171
namespace: app-created-namespace
171172
staged:
172173
appImage:

pkg/controller/appdefinition/testdata/volumes/no-default-class/expected.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ status:
166166
status: "True"
167167
success: true
168168
type: defined
169-
defaults: {}
169+
defaults:
170+
volumeSize: 10G
170171
namespace: app-created-namespace
171172
staged:
172173
appImage:

pkg/controller/appdefinition/volume.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/acorn-io/runtime/pkg/secrets"
1717
"github.com/acorn-io/runtime/pkg/volume"
1818
name2 "github.com/rancher/wrangler/pkg/name"
19+
"github.com/sirupsen/logrus"
1920
corev1 "k8s.io/api/core/v1"
2021
apierrors "k8s.io/apimachinery/pkg/api/errors"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -200,7 +201,14 @@ func toPVCs(req router.Request, appInstance *v1.AppInstance) (result []kclient.O
200201
pvc.Spec.VolumeName = pvName
201202

202203
if volumeRequest.Size == "" {
203-
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = *v1.DefaultSize
204+
// This shouldn't happen because we set a default in the status. However
205+
// if this situation does occur, we'll just use the default size for runtime
206+
// and log it at the debug level. As an example, our unit tests hit this case.
207+
if appInstance.Status.Defaults.VolumeSize == nil {
208+
logrus.Debugf("no default volume size found in status, using static default size of %v", v1.DefaultSize)
209+
appInstance.Status.Defaults.VolumeSize = v1.DefaultSize
210+
}
211+
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = *appInstance.Status.Defaults.VolumeSize
204212
} else {
205213
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = *v1.MustParseResourceQuantity(volumeRequest.Size)
206214
}

pkg/controller/defaults/defaults.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
internalv1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
66
"github.com/acorn-io/runtime/pkg/condition"
77
"github.com/acorn-io/runtime/pkg/config"
8-
"github.com/acorn-io/z"
98
)
109

1110
// Calculate is a handler that sets the defaults for an AppInstance to its status if
@@ -31,8 +30,11 @@ func Calculate(req router.Request, resp router.Response) (err error) {
3130
}
3231
}()
3332

34-
if appInstance.Status.Defaults.VolumeSize == nil {
35-
appInstance.Status.Defaults.VolumeSize = z.Pointer(internalv1.DefaultSize.DeepCopy())
33+
// Only set the default volume size if it hasn't been set yet.
34+
if appInstance.Status.Defaults.Volumes == nil {
35+
if err := addDefaultVolumeSize(req.Ctx, req.Client, appInstance); err != nil {
36+
return err
37+
}
3638
}
3739

3840
if appInstance.Generation != appInstance.Status.ObservedGeneration {

0 commit comments

Comments
 (0)