From 32b6218ed9fad8d39829d077acf6e4ac65afe6c9 Mon Sep 17 00:00:00 2001 From: Armin Schlegel Date: Mon, 28 Mar 2022 15:03:11 +0200 Subject: [PATCH] feat: added labelSelector for cloud worker --- cue/components/cloud-worker.cue | 14 ++++++++++++++ cue/components/edge-worker.cue | 2 +- .../applications/mixed-app-network/nats-box.yaml | 13 +++++++++---- manifests/vela-caps/components/cloud-worker.yaml | 14 ++++++++++++++ manifests/vela-caps/components/edge-worker.yaml | 2 +- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/cue/components/cloud-worker.cue b/cue/components/cloud-worker.cue index fbbb754..d803ea0 100644 --- a/cue/components/cloud-worker.cue +++ b/cue/components/cloud-worker.cue @@ -78,6 +78,17 @@ template: { ] } + if parameter["labelSelector"] != _|_ { + affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [{ + matchExpressions: [ + for v in parameter.labelSelector { + { + key: v + operator: "Exists" + }} + ] + }] + } } } } @@ -88,6 +99,9 @@ template: { // +short=i image: string + // +usage=labelSelector define labels that must be present on cloud nodes to receive the application. If not specified, the application will be deployed to any cloud node. + labelSelector?: [...string] + // +usage=Specify image pull policy for your service imagePullPolicy?: string diff --git a/cue/components/edge-worker.cue b/cue/components/edge-worker.cue index 72352e8..ad25703 100644 --- a/cue/components/edge-worker.cue +++ b/cue/components/edge-worker.cue @@ -113,7 +113,7 @@ template: { image: string // +usage=Specify runtimes that shall receive the application. If not specified, the application will be deployed on all runtimes. - runtime: [...string] + runtime?: [...string] // +usage=Specify image pull policy for your service imagePullPolicy?: string diff --git a/dev/manifests/applications/mixed-app-network/nats-box.yaml b/dev/manifests/applications/mixed-app-network/nats-box.yaml index 3f37a9a..564515a 100644 --- a/dev/manifests/applications/mixed-app-network/nats-box.yaml +++ b/dev/manifests/applications/mixed-app-network/nats-box.yaml @@ -1,7 +1,3 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: nats-box --- apiVersion: core.oam.dev/v1beta1 kind: Application @@ -15,6 +11,8 @@ spec: properties: image: natsio/nats-box:latest name: nats-box + runtime: + - mydevice command: - /bin/sh - -c @@ -37,6 +35,8 @@ spec: type: cloud-worker properties: image: natsio/nats-box:latest + labelSelector: + - myCloudNode name: nats-box command: - /bin/sh @@ -58,3 +58,8 @@ spec: subjects: - data storage: file +--- +apiVersion: v1 +kind: Namespace +metadata: + name: nats-box diff --git a/manifests/vela-caps/components/cloud-worker.yaml b/manifests/vela-caps/components/cloud-worker.yaml index 34bf254..3bcae81 100644 --- a/manifests/vela-caps/components/cloud-worker.yaml +++ b/manifests/vela-caps/components/cloud-worker.yaml @@ -76,6 +76,17 @@ spec: ] } + if parameter["labelSelector"] != _|_ { + affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [{ + matchExpressions: [ + for v in parameter.labelSelector { + { + key: v + operator: "Exists" + }}, + ] + }] + } } } } @@ -85,6 +96,9 @@ spec: // +short=i image: string + // +usage=labelSelector define labels that must be present on cloud nodes to receive the application. If not specified, the application will be deployed to any cloud node. + labelSelector?: [...string] + // +usage=Specify image pull policy for your service imagePullPolicy?: string diff --git a/manifests/vela-caps/components/edge-worker.yaml b/manifests/vela-caps/components/edge-worker.yaml index de015ff..31cdb3e 100644 --- a/manifests/vela-caps/components/edge-worker.yaml +++ b/manifests/vela-caps/components/edge-worker.yaml @@ -106,7 +106,7 @@ spec: image: string // +usage=Specify runtimes that shall receive the application. If not specified, the application will be deployed on all runtimes. - runtime: [...string] + runtime?: [...string] // +usage=Specify image pull policy for your service imagePullPolicy?: string