Skip to content

Commit 72d4479

Browse files
Default requests and limits (#331)
* initial commit * almost finished with the requests and limits * Add default requests and limits to gitsource sensors and controllers * small fix
1 parent f2d8571 commit 72d4479

30 files changed

+334
-33
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.302
1+
VERSION=v0.0.303
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/git-source.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/codefresh-io/cli-v2/pkg/util"
4141
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
4242
ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
43+
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
4344
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
4445
billyUtils "github.com/go-git/go-billy/v5/util"
4546
"github.com/juju/ansiterm"
@@ -352,6 +353,12 @@ func createCronExamplePipeline(opts *gitSourceCronExampleOptions) error {
352353
}
353354

354355
func createCronExampleEventSource() *eventsourcev1alpha1.EventSource {
356+
tpl := &eventsourcev1alpha1.Template{Container: &corev1.Container{}}
357+
358+
if store.Get().SetDefaultResources {
359+
eventsutil.SetDefaultResourceRequirements(tpl.Container)
360+
}
361+
355362
return &eventsourcev1alpha1.EventSource{
356363
TypeMeta: metav1.TypeMeta{
357364
Kind: eventsourcereg.Kind,
@@ -361,6 +368,7 @@ func createCronExampleEventSource() *eventsourcev1alpha1.EventSource {
361368
Name: store.Get().CronExampleEventSourceName,
362369
},
363370
Spec: eventsourcev1alpha1.EventSourceSpec{
371+
Template: tpl,
364372
EventBusName: store.Get().EventBusName,
365373
Calendar: map[string]eventsourcev1alpha1.CalendarEventSource{
366374
store.Get().CronExampleEventName: {
@@ -380,6 +388,15 @@ func createCronExampleSensor(triggers []sensorsv1alpha1.Trigger) (*sensorsv1alph
380388
},
381389
}
382390

391+
tpl := &sensorsv1alpha1.Template{
392+
ServiceAccountName: "argo-server",
393+
Container: &corev1.Container{},
394+
}
395+
396+
if store.Get().SetDefaultResources {
397+
eventsutil.SetDefaultResourceRequirements(tpl.Container)
398+
}
399+
383400
return &sensorsv1alpha1.Sensor{
384401
TypeMeta: metav1.TypeMeta{
385402
Kind: sensorreg.Kind,
@@ -390,9 +407,7 @@ func createCronExampleSensor(triggers []sensorsv1alpha1.Trigger) (*sensorsv1alph
390407
},
391408
Spec: sensorsv1alpha1.SensorSpec{
392409
EventBusName: "codefresh-eventbus",
393-
Template: &sensorsv1alpha1.Template{
394-
ServiceAccountName: "argo-server",
395-
},
410+
Template: tpl,
396411
Dependencies: dependencies,
397412
Triggers: triggers,
398413
},
@@ -814,6 +829,12 @@ func getRepoOwnerAndNameFromRepoURL(repoURL string) (owner string, name string)
814829
func createGithubExampleEventSource(repoURL string, ingressHost string, runtimeName string) *eventsourcev1alpha1.EventSource {
815830
repoOwner, repoName := getRepoOwnerAndNameFromRepoURL(repoURL)
816831

832+
tpl := &eventsourcev1alpha1.Template{Container: &corev1.Container{}}
833+
834+
if store.Get().SetDefaultResources {
835+
eventsutil.SetDefaultResourceRequirements(tpl.Container)
836+
}
837+
817838
return &eventsourcev1alpha1.EventSource{
818839
TypeMeta: metav1.TypeMeta{
819840
Kind: eventsourcereg.Kind,
@@ -824,6 +845,7 @@ func createGithubExampleEventSource(repoURL string, ingressHost string, runtimeN
824845
},
825846
Spec: eventsourcev1alpha1.EventSourceSpec{
826847
EventBusName: store.Get().EventBusName,
848+
Template: tpl,
827849
Service: &eventsourcev1alpha1.Service{
828850
Ports: []corev1.ServicePort{
829851
{
@@ -936,6 +958,15 @@ func createGithubExampleSensor() *sensorsv1alpha1.Sensor {
936958
},
937959
}
938960

961+
tpl := &sensorsv1alpha1.Template{
962+
Container: &corev1.Container{},
963+
ServiceAccountName: store.Get().WorkflowTriggerServiceAccount,
964+
}
965+
966+
if store.Get().SetDefaultResources {
967+
eventsutil.SetDefaultResourceRequirements(tpl.Container)
968+
}
969+
939970
return &sensorsv1alpha1.Sensor{
940971
TypeMeta: metav1.TypeMeta{
941972
Kind: sensorreg.Kind,
@@ -946,9 +977,7 @@ func createGithubExampleSensor() *sensorsv1alpha1.Sensor {
946977
},
947978
Spec: sensorsv1alpha1.SensorSpec{
948979
EventBusName: store.Get().EventBusName,
949-
Template: &sensorsv1alpha1.Template{
950-
ServiceAccountName: store.Get().WorkflowTriggerServiceAccount,
951-
},
980+
Template: tpl,
952981
Dependencies: dependencies,
953982
Triggers: triggers,
954983
},

cmd/commands/runtime.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ type (
116116
}
117117

118118
RuntimeUpgradeOptions struct {
119-
RuntimeName string
120-
Version *semver.Version
121-
CloneOpts *git.CloneOptions
122-
CommonConfig *runtime.CommonConfig
123-
DisableTelemetry bool
119+
RuntimeName string
120+
Version *semver.Version
121+
CloneOpts *git.CloneOptions
122+
CommonConfig *runtime.CommonConfig
123+
DisableTelemetry bool
124124
}
125125

126126
gvr struct {
@@ -267,6 +267,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
267267
cmd.Flags().BoolVar(&store.Get().SkipIngress, "skip-ingress", false, "Skips the creation of ingress resources")
268268
cmd.Flags().BoolVar(&store.Get().BypassIngressClassCheck, "bypass-ingress-class-check", false, "Disables the ingress class check during pre-installation")
269269
cmd.Flags().BoolVar(&installationOpts.DisableTelemetry, "disable-telemetry", false, "If true, will disable the analytics reporting for the installation process")
270+
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
270271

271272
installationOpts.InsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
272273
CreateIfNotExist: true,
@@ -1669,6 +1670,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
16691670

16701671
cmd.Flags().StringVar(&versionStr, "version", "", "The runtime version to upgrade to, defaults to latest")
16711672
cmd.Flags().BoolVar(&opts.DisableTelemetry, "disable-telemetry", false, "If true, will disable analytics reporting for the upgrade process")
1673+
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
16721674
opts.CloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{CloneForWrite: true})
16731675

16741676
return cmd

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cli-v2 runtime install [runtime_name] [flags]
4343
--provider string The git provider, one of: azure|gitea|github|gitlab
4444
--provider-api-url string Git provider API url
4545
--repo string Repository URL [GIT_REPO]
46+
--set-default-resources If true, will set default requests and limits on all of the runtime components
4647
--skip-cluster-checks Skips the cluster's checks
4748
--skip-ingress Skips the creation of ingress resources
4849
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist

docs/commands/cli-v2_runtime_upgrade.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ cli-v2 runtime upgrade [RUNTIME_NAME] [flags]
2828
### Options
2929

3030
```
31-
--disable-telemetry If true, will disable analytics reporting for the upgrade process
32-
-t, --git-token string Your git provider api token [GIT_TOKEN]
33-
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
34-
-h, --help help for upgrade
35-
--repo string Repository URL [GIT_REPO]
36-
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
37-
--version string The runtime version to upgrade to, defaults to latest
31+
--disable-telemetry If true, will disable analytics reporting for the upgrade process
32+
-t, --git-token string Your git provider api token [GIT_TOKEN]
33+
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
34+
-h, --help help for upgrade
35+
--repo string Repository URL [GIT_REPO]
36+
--set-default-resources If true, will set default requests and limits on all of the runtime components
37+
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
38+
--version string The runtime version to upgrade to, defaults to latest
3839
```
3940

4041
### Options inherited from parent commands

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.302/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.303/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.302/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.303/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/argo-events/eventbus.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ spec:
99
native:
1010
replicas: 3
1111
auth: token
12+
containerTemplate: {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
bases:
4+
- ../../app-proxy
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- op: add
2+
path: /spec/template/spec/containers/0/resources
3+
value:
4+
limits:
5+
cpu: 3.5
6+
memory: 4Gi
7+
requests:
8+
cpu: 500m
9+
memory: 500Mi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- op: add
2+
path: /spec/template/spec/containers/0/resources
3+
value:
4+
limits:
5+
cpu: 300m
6+
memory: 200Mi
7+
requests:
8+
cpu: 150m
9+
memory: 100Mi

0 commit comments

Comments
 (0)