Skip to content

Commit 10f7e82

Browse files
authored
impr: add requests and limits to deploy (#697)
1 parent 0179023 commit 10f7e82

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

deploy/Pulumi.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ config:
6363
secret: true
6464
description: A kubeconfig to use rather than the default ServiceAccount.
6565
default: ""
66+
requests.cpu:
67+
type: string
68+
description: The number of CPUs to use.
69+
default: "1.0"
70+
requests.memory:
71+
type: string
72+
description: The memory size to use.
73+
default: "1Gi"
74+
limits.cpu:
75+
type: string
76+
description: The maximum number of CPUs to use.
77+
default: "4.0"
78+
limits.memory:
79+
type: string
80+
description: The maximum memory size to use.
81+
default: "5Gi"
6682
otel.endpoint:
6783
type: string
6884
description: The OpenTelemetry Collector endpoint to set signals to. (Optional)

deploy/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func main() {
3838
Expose: cfg.Expose,
3939
RomeoClaimName: pulumi.String(cfg.RomeoClaimName),
4040
Kubeconfig: cfg.Kubeconfig,
41+
Requests: pulumi.ToStringMap(cfg.Requests),
42+
Limits: pulumi.ToStringMap(cfg.Limits),
4143
}
4244
if cfg.Etcd != nil {
4345
args.EtcdReplicas = pulumi.IntPtr(cfg.Etcd.Replicas)
@@ -80,6 +82,8 @@ type (
8082
Expose bool
8183
LogLevel string
8284
RomeoClaimName string
85+
Requests map[string]string
86+
Limits map[string]string
8387
Otel *OtelConfig
8488

8589
// Secrets
@@ -119,6 +123,14 @@ func loadConfig(ctx *pulumi.Context) *Config {
119123
Kubeconfig: cfg.GetSecret("kubeconfig"),
120124
}
121125

126+
if err := cfg.TryObject("requests", &c.Requests); err != nil {
127+
panic(err)
128+
}
129+
130+
if err := cfg.TryObject("limits", &c.Limits); err != nil {
131+
panic(err)
132+
}
133+
122134
var etcdC EtcdConfig
123135
if err := cfg.TryObject("etcd", &etcdC); err == nil && etcdC.Replicas != 0 {
124136
c.Etcd = &etcdC

deploy/services/chall-manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ type (
8080
// created by default for Chall-Manager.
8181
Kubeconfig pulumi.StringInput
8282

83+
// Requests for the Chall-Manager container. For more infos:
84+
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
85+
Requests pulumi.StringMapInput
86+
87+
// Limits for the Chall-Manager container. For more infos:
88+
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
89+
Limits pulumi.StringMapInput
90+
8391
Swagger, Expose bool
8492

8593
Otel *common.OtelArgs
@@ -255,6 +263,8 @@ func (cm *ChallManager) provision(ctx *pulumi.Context, args *ChallManagerArgs, o
255263
Otel: nil,
256264
RomeoClaimName: args.RomeoClaimName,
257265
Kubeconfig: args.Kubeconfig,
266+
Requests: args.Requests,
267+
Limits: args.Limits,
258268
}
259269
if args.EtcdReplicas != nil {
260270
cmArgs.Etcd = &parts.ChallManagerEtcdArgs{

deploy/services/parts/chall-manager.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ type (
8383
Kubeconfig pulumi.StringInput
8484
mountKubeconfig bool
8585

86+
// Requests for the Chall-Manager container. For more infos:
87+
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
88+
Requests pulumi.StringMapInput
89+
requests pulumi.StringMapOutput
90+
91+
// Limits for the Chall-Manager container. For more infos:
92+
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
93+
Limits pulumi.StringMapInput
94+
limits pulumi.StringMapOutput
95+
8696
Swagger bool
8797

8898
Etcd *ChallManagerEtcdArgs
@@ -220,14 +230,24 @@ func (cm *ChallManager) defaults(args *ChallManagerArgs) *ChallManagerArgs {
220230
wg.Wait()
221231
}
222232

233+
args.requests = pulumi.StringMap{}.ToStringMapOutput()
234+
if args.Requests != nil {
235+
args.requests = args.Requests.ToStringMapOutput()
236+
}
237+
238+
args.limits = pulumi.StringMap{}.ToStringMapOutput()
239+
if args.Limits != nil {
240+
args.limits = args.Limits.ToStringMapOutput()
241+
}
242+
223243
return args
224244
}
225245

226246
func (cm *ChallManager) provision(ctx *pulumi.Context, args *ChallManagerArgs, opts ...pulumi.ResourceOption) (err error) {
227247
// Start chall-manager cluster
228248
// Labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels
229249

230-
// build custom target ops
250+
// Create a specific provider for distant resources ("target").
231251
topts := opts
232252
if args.Kubeconfig != nil {
233253
extcl, err := kubernetes.NewProvider(ctx, "external-cluster-pv", &kubernetes.ProviderArgs{
@@ -238,6 +258,7 @@ func (cm *ChallManager) provision(ctx *pulumi.Context, args *ChallManagerArgs, o
238258
}
239259
topts = append(topts, pulumi.Provider(extcl))
240260
}
261+
241262
// => Namespace to deploy to
242263
cm.tgtns, err = corev1.NewNamespace(ctx, "chall-manager-target-ns", &corev1.NamespaceArgs{
243264
Metadata: metav1.ObjectMetaArgs{
@@ -757,6 +778,10 @@ func (cm *ChallManager) provision(ctx *pulumi.Context, args *ChallManagerArgs, o
757778
Port: pulumi.Int(port),
758779
},
759780
},
781+
Resources: corev1.ResourceRequirementsArgs{
782+
Requests: args.requests,
783+
Limits: args.limits,
784+
},
760785
},
761786
},
762787
Volumes: func() corev1.VolumeArrayOutput {

0 commit comments

Comments
 (0)