[YUNIKORN-1266] Add some examples related to app placement rules (#463)
Exampes follow the website tutorial and provide how the examples can be
deployed.
Closes: #463
Signed-off-by: Wilfred Spiegelenburg <wilfreds@apache.org>
diff --git a/deployments/examples/README.md b/deployments/examples/README.md
index 8c62d3d..d716937 100644
--- a/deployments/examples/README.md
+++ b/deployments/examples/README.md
@@ -109,3 +109,15 @@
The pod spec does not specify a queue just a namespace but the application will be run in the `root.development` queue.
* run the sleep pod in the production namespace which creates a new `production` queue using the local [sleeppod_prod.yaml](namespace/sleeppod_prod.yaml): `kubectl create -f namespaces.yaml`.
The pod spec does not specify a queue just a namespace but the application will be run in the newly created `root.production` queue. This queue does not exist in the queue configuration.
+
+### placements
+The placements' rules are described in [Yunikorn website](https://yunikorn.apache.org/docs/user_guide/placement_rules).
+App placements rules in Yunikorn contains `Provided Rule`, `User Name Rule`, `Fixed Rule`, `Tag Rule`.
+Every placement example includes a example yaml file and a config yaml file.
+The sleep pod is described in the example file and the partition is provided in the config yaml file.
+Before deploying the pods, the configuration field in yunikorn-release/helm/yunikorn/value.yaml should be replaced by the configuration field in the config.yaml.
+
+* [Provided Rule](./placements/provided)
+* [User Name Rule](./placements/username)
+* [Fixed Rule](./placements/fixed)
+* [Tag Rule](./placements/tag)
diff --git a/deployments/examples/placements/README.md b/deployments/examples/placements/README.md
new file mode 100644
index 0000000..a2ffdec
--- /dev/null
+++ b/deployments/examples/placements/README.md
@@ -0,0 +1,77 @@
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+-->
+
+# Placements examples
+App placements rules in Yunikorn contains `Provided Rule`, `User Name Rule`, `Fixed Rule`, `Tag Rule`.
+Every placement example includes a example yaml file and a config yaml file.
+The sleep pod is described in the example file and the partition is provided in the config yaml file.
+Before deploying the pods, the configuration field in yunikorn-release/helm/yunikorn/value.yaml should be replaced by the configuration field in the config.yaml.
+
+* [Provided Rule](./provided)
+* [User Name Rule](./username)
+* [Fixed Rule](./fixed)
+* [Tag Rule](./tag)
+
+## Provided rule
+```
+placementrules:
+ - name: provided
+ create: true
+ parent:
+ name: user
+ create: true
+```
+Application submit request by the user `developer`, queue in the application on submit: `my_special_queue`.
+Result: `root.developer.my_special_queue`
+
+## User name rule
+```
+placementrules:
+ - name: user
+ create: false # The queue won't be created when the queue doesn't exist.
+```
+Application submit request by the user `finance.test`, queue does exist:
+Result: `root.finance_dot_test`
+
+Application submit request by the user `developer`, queue does not exist:
+Result: failed, next rule executed
+Solution: The second cases could be submmitted and there are two optional choices.
+1. `root.developer` is added to the queues.
+2. The user name rule in the placementrules field could allowed to create the queue which doesn't exist.
+
+## Fixed rule
+```
+placementrules:
+ - name: fixed
+ value: last_resort
+```
+Application submit request by the user `developer`, queue in the application on submit: `my_special_queue`.
+Result: `root.last_resort`
+
+## Tag rule
+```
+placementrules:
+ - name: tag
+ value: namespace
+ create: true
+```
+Application submit request for a kubernetes based application in the namespace `default` by the user developer, queue in the application on submit: `my_special_queue`.
+Result: `root.default`
+
+Application submit request for a kubernetes based application in the namespace `testing` by the user `developer`
+Result: `root.testing`
\ No newline at end of file
diff --git a/deployments/examples/placements/fixed/config.yaml b/deployments/examples/placements/fixed/config.yaml
new file mode 100644
index 0000000..caa8b85
--- /dev/null
+++ b/deployments/examples/placements/fixed/config.yaml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# The configutarion in value.yaml should be replaced by the following configuration before this yaml is applied.
+configuration: |
+ partitions:
+ - name: default
+ placementrules:
+ - name: fixed
+ value: last_resort
+ queues:
+ - name: root
+ submitacl: '*'
+ queues:
+ - name: last_resort
+
diff --git a/deployments/examples/placements/fixed/fixed_example.yaml b/deployments/examples/placements/fixed/fixed_example.yaml
new file mode 100644
index 0000000..633ea29
--- /dev/null
+++ b/deployments/examples/placements/fixed/fixed_example.yaml
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Pod
+metadata:
+ labels:
+ app: sleep
+ applicationId: "prvoided-rule-example01"
+ queue: "my_special_queue"
+ yunikorn.apache.org/username: developer
+ name: task0
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+
diff --git a/deployments/examples/placements/provided/config.yaml b/deployments/examples/placements/provided/config.yaml
new file mode 100644
index 0000000..e847427
--- /dev/null
+++ b/deployments/examples/placements/provided/config.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# The configutarion in value.yaml should be replaced by the following configuration before this yaml is applied.
+configuration: |
+ partitions:
+ - name: default
+ placementrules:
+ - name: provided
+ create: true
+ parent:
+ name: user
+ create: true
+ queues:
+ - name: root
+ submitacl: '*'
+
diff --git a/deployments/examples/placements/provided/provided_example.yaml b/deployments/examples/placements/provided/provided_example.yaml
new file mode 100644
index 0000000..0b78bb5
--- /dev/null
+++ b/deployments/examples/placements/provided/provided_example.yaml
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Pod
+metadata:
+ labels:
+ app: sleep
+ applicationId: "prvoided-rule-example01"
+ queue: "my_special_queue"
+ yunikorn.apache.org/username: "developer"
+ name: task0
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+
diff --git a/deployments/examples/placements/tag/config.yaml b/deployments/examples/placements/tag/config.yaml
new file mode 100644
index 0000000..e8ede58
--- /dev/null
+++ b/deployments/examples/placements/tag/config.yaml
@@ -0,0 +1,29 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# The configutarion in value.yaml should be replaced by the following configuration before this yaml is applied.
+configuration: |
+ partitions:
+ - name: default
+ placementrules:
+ - name: tag
+ value: namespace
+ create: true
+ queues:
+ - name: root
+ submitacl: '*'
+
diff --git a/deployments/examples/placements/tag/tag_example.yaml b/deployments/examples/placements/tag/tag_example.yaml
new file mode 100644
index 0000000..b0296f0
--- /dev/null
+++ b/deployments/examples/placements/tag/tag_example.yaml
@@ -0,0 +1,56 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Pod
+metadata:
+ labels:
+ app: sleep
+ applicationId: "prvoided-rule-example01"
+ yunikorn.apache.org/username: developer
+ name: task0
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+---
+apiVersion: v1
+kind: Pod
+metadata:
+ namespace: testing
+ labels:
+ app: sleep
+ applicationId: "prvoided-rule-example02"
+ yunikorn.apache.org/username: developer
+ name: task1
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+
diff --git a/deployments/examples/placements/username/config.yaml b/deployments/examples/placements/username/config.yaml
new file mode 100644
index 0000000..ebd3f35
--- /dev/null
+++ b/deployments/examples/placements/username/config.yaml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# The configutarion in value.yaml should be replaced by the following configuration before this yaml is applied.
+configuration: |
+ partitions:
+ - name: default
+ placementrules:
+ - name: user
+ create: false
+ queues:
+ - name: root
+ submitacl: '*'
+ queues:
+ - name: finance_dot_test
+
diff --git a/deployments/examples/placements/username/username_example.yaml b/deployments/examples/placements/username/username_example.yaml
new file mode 100644
index 0000000..20c50dd
--- /dev/null
+++ b/deployments/examples/placements/username/username_example.yaml
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Pod
+metadata:
+ labels:
+ app: sleep
+ applicationId: "username-rule-example01"
+ yunikorn.apache.org/username: finance.test
+ name: task0
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+---
+apiVersion: v1
+kind: Pod
+metadata:
+ labels:
+ app: sleep
+ applicationId: "username-rule-example02"
+ yunikorn.apache.org/username: developer
+ name: task1
+spec:
+ schedulerName: yunikorn
+ containers:
+ - name: sleep-30s
+ image: "alpine:latest"
+ command: ["sleep", "30"]
+ resources:
+ requests:
+ cpu: "100m"
+ memory: "500M"
+