Skip to content

Commit

Permalink
feat: added predefined edgefarm.io toleration
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
  • Loading branch information
siredmar committed May 10, 2023
1 parent 3774dd7 commit 7020315
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ render: traits-render components-render ## renders all templates
apply: traits-apply components-apply ## applies all templates
deploy: traits-deploy components-deploy ## deploys all templates

test: ## test example, e.g. `make test dev/manifests/applications/some-app.yaml`
test: ## test example, e.g. `make test examples/pure.yaml`
@vela dry-run -f $(filter-out $@,$(MAKECMDGOALS))

traits-render: ## renders all traits
Expand Down Expand Up @@ -37,4 +37,4 @@ install-vela: ## install kubevela
help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make [target]\033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m\t %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: all render apply deploy traits-render traits-apply traits-deploy components-render components-apply components-deploy install-vela help
.PHONY: all render apply deploy traits-render traits-apply traits-deploy components-render components-apply components-deploy install-vela help test
48 changes: 30 additions & 18 deletions cue/components/edgefarm-applications.cue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "list"

"edgefarm-applications": {
type: "component"
annotations: {}
Expand All @@ -11,6 +13,33 @@
}
}
template: {
predefinedTolerations: [
{
key: "edgefarm.io",
operator: "Exists",
effect: "NoSchedule"
}
]

parameterTolerations: [
if parameter.tolerations != _|_ {
for k in parameter.tolerations {
if k.key != _|_ {
key: k.key
}
if k.effect != _|_ {
effect: k.effect
}
if k.value != _|_ {
value: k.value
}
operator: k.operator
if k.tolerationSeconds != _|_ {
tolerationSeconds: k.tolerationSeconds
}
}
}]

output: {
apiVersion: "apps.openyurt.io/v1alpha1"
kind: "YurtAppDaemon"
Expand Down Expand Up @@ -48,24 +77,7 @@ template: {
}
}
spec: {
if parameter.tolerations != _|_ {
tolerations: [
for k in parameter.tolerations {
if k.key != _|_ {
key: k.key
}
if k.effect != _|_ {
effect: k.effect
}
if k.value != _|_ {
value: k.value
}
operator: k.operator
if k.tolerationSeconds != _|_ {
tolerationSeconds: k.tolerationSeconds
}
}]
}
tolerations: predefinedTolerations + parameterTolerations
containers: [{
name: context.name
image: parameter.image
Expand Down
24 changes: 24 additions & 0 deletions examples/stress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: stress
spec:
components:
- name: stress
type: edgefarm-applications
properties:
image: alexeiled/stress-ng
nodepoolSelector:
matchLabels:
app/stress: ""
name: stress
command:
- "/stress-ng"
- "--cpu"
- "4"
- "--io"
- "2"
- "--vm-bytes"
- "1G"
- "timeout"
- "600s"
4 changes: 0 additions & 4 deletions examples/with-network-and-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ spec:
- sh
- "-c"
- "sleep infinity"
tolerations:
- key: "edgefarm.io"
operator: "Exists"
effect: "NoSchedule"
traits:
- type: edgefarm-network
properties:
Expand Down
4 changes: 0 additions & 4 deletions examples/with-network-only.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ spec:
- sh
- "-c"
- "sleep infinity"
tolerations:
- key: "edgefarm.io"
operator: "Exists"
effect: "NoSchedule"
traits:
- type: edgefarm-network
properties:
Expand Down
2 changes: 1 addition & 1 deletion manifests/vela-caps/components/edgefarm-applications.yaml

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions test/expected1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# Application(pure) -- Component(pure)
---

apiVersion: apps.openyurt.io/v1alpha1
kind: YurtAppDaemon
metadata:
annotations: {}
labels:
app.oam.dev/appRevision: ""
app.oam.dev/component: pure
app.oam.dev/name: pure
app.oam.dev/namespace: default
app.oam.dev/resourceType: WORKLOAD
workload.oam.dev/type: edgefarm-applications
name: pure
namespace: default
spec:
nodepoolSelector:
matchLabels:
app/pure: ""
selector:
matchLabels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
workloadTemplate:
deploymentTemplate:
metadata:
labels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
template:
metadata:
labels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
spec:
containers:
- command:
- sh
- -c
- sleep infinity
image: bash:5.1-alpine3.17
name: pure
resources: {}
tolerations:
- effect: NoSchedule
key: edgefarm.io
operator: Exists

---


make: Nothing to be done for 'examples/pure.yaml'.
63 changes: 63 additions & 0 deletions test/expected2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# Application(pure) -- Component(pure)
---

apiVersion: apps.openyurt.io/v1alpha1
kind: YurtAppDaemon
metadata:
annotations: {}
labels:
app.oam.dev/appRevision: ""
app.oam.dev/component: pure
app.oam.dev/name: pure
app.oam.dev/namespace: default
app.oam.dev/resourceType: WORKLOAD
workload.oam.dev/type: edgefarm-applications
name: pure
namespace: default
spec:
nodepoolSelector:
matchLabels:
app/pure: ""
selector:
matchLabels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
workloadTemplate:
deploymentTemplate:
metadata:
labels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
template:
metadata:
labels:
app.kubernetes.io/app: pure
app.kubernetes.io/component: pure
spec:
containers:
- command:
- sh
- -c
- sleep infinity
image: bash:5.1-alpine3.17
name: pure
resources: {}
tolerations:
- effect: NoSchedule
key: edgefarm.io
operator: Exists
- effect: NoSchedule
key: foo
operator: Exists

---


make: Nothing to be done for 'test/test2.yaml'.
18 changes: 18 additions & 0 deletions test/test1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: pure
spec:
components:
- name: pure
type: edgefarm-applications
properties:
image: bash:5.1-alpine3.17
nodepoolSelector:
matchLabels:
app/pure: ""
name: pure
command:
- sh
- "-c"
- "sleep infinity"
22 changes: 22 additions & 0 deletions test/test2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: pure
spec:
components:
- name: pure
type: edgefarm-applications
properties:
image: bash:5.1-alpine3.17
nodepoolSelector:
matchLabels:
app/pure: ""
name: pure
tolerations:
- effect: NoSchedule
key: foo
operator: Exists
command:
- sh
- "-c"
- "sleep infinity"

0 comments on commit 7020315

Please sign in to comment.