<#4378 [BUG] Spark Task tolerations not applied wi...
# flyte-github
a
#4378 [BUG] Spark Task tolerations not applied with PodTemplate Issue created by tionichm Describe the bug We're running flyte binary on EKS. Everything is working at this point, including spark tasks. Recently it has become a requirement to move all flyte-related to a specific node group with a label and taint combo. Tolerations for spark tasks were added in this PR (PR#4183). I've spent some time trying to implement exactly what is shown in the PR, and I have had no success. Note, the node selector portion of this is done using spark configs and not PodTemplate, and it works as expected. I can confirm that the following task works as expected
Copy code
"""Simple tasks that can be used to debug flyte."""
import os

from flytekit import PodTemplate, Resources, task
from flytekitplugins.spark import Spark
from kubernetes.client import V1Container, V1PodSpec, V1Toleration

from .utils import SparkTaskHelper

task_helper = SparkTaskHelper(
    client=os.environ.get("CLIENT", "client"),
)


@task(
    requests=Resources(cpu="0.1", mem="128Mi"),
    limits=Resources(cpu="0.2", mem="256Mi"),
    container_image=task_helper.container_image,
    pod_template=PodTemplate(
        primary_container_name="primary",
        pod_spec=V1PodSpec(
            containers=[
                V1Container(
                    name="primary",
                    image="hello-world",
                ),
            ],
            node_selector={"app": "flyte"},
            tolerations=[
                V1Toleration(
                    key="app",
                    operator="Equal",
                    value="flyte",
                    effect="NoSchedule",
                ),
            ],
        ),
    ),
)
def hello_world_no_spark() -> None:
    """Print "hello world"."""
    print("hello world")


@task(
    task_config=Spark(
        spark_conf=task_helper.spark_confs,
        executor_path=task_helper.ex_path,
        applications_path=task_helper.app_path,
    ),
    container_image=task_helper.container_image,
    pod_template=PodTemplate(
        primary_container_name="primary",
        pod_spec=V1PodSpec(
            containers=[
                V1Container(
                    name="primary",
                    image="hello-world",
                ),
            ],
            node_selector={"app": "flyte"},
            tolerations=[
                V1Toleration(
                    key="app",
                    operator="Equal",
                    value="flyte",
                    effect="NoSchedule",
                ),
            ],
        ),
    ),
)
def hello_world_spark() -> None:
    """Print "hello world"."""
    print("hello world")
yields
Copy code
{"config":{"primary_container_name":"primary"},"id":{"resourceType":1,"project":"flint","domain":"development","name":"flint_tasks.test.hello_world.hello_world_no_spark","version":"5.2.0-5dca779"},"type":"python-task","metadata":{"tags":{},"runtime":{"type":1,"version":"1.10.0","flavor":"python"},"retries":{}},"interface":{"inputs":{"variables":{}},"outputs":{"variables":{}}},"k8sPod":{"metadata":{"labels":{},"annotations":{}},"podSpec":{"fields":{"containers":{"listValue":{"values":[{"structValue":{"fields":{"env":{"listValue":{"values":[]}},"image":{"stringValue":"275184421095.dkr.ecr.af-south-1.amazonaws.com/flint-spark:5.2.0-5dca779-flint"},"name":{"stringValue":"primary"},"command":{"listValue":{"values":[]}},"resources":{"structValue":{"fields":{"limits":{"structValue":{"fields":{"memory":{"stringValue":"256Mi"},"cpu":{"stringValue":"0.2"}}}},"requests":{"structValue":{"fields":{"cpu":{"stringValue":"0.1"},"memory":{"stringValue":"128Mi"}}}}}}},"args":{"listValue":{"values":[{"stringValue":"pyflyte-fast-execute"},{"stringValue":"--additional-distribution"},{"stringValue":*****},{"stringValue":"--dest-dir"},{"stringValue":"/root"},{"stringValue":"--"},{"stringValue":"pyflyte-execute"},{"stringValue":"--inputs"},{"stringValue":"{{.input}}"},{"stringValue":"--output-prefix"},{"stringValue":"{{.outputPrefix}}"},{"stringValue":"--raw-output-data-prefix"},{"stringValue":"{{.rawOutputDataPrefix}}"},{"stringValue":"--checkpoint-path"},{"stringValue":"{{.checkpointOutputPrefix}}"},{"stringValue":"--prev-checkpoint"},{"stringValue":"{{.prevCheckpointPrefix}}"},{"stringValue":"--resolver"},{"stringValue":"flytekit.core.python_auto_container.default_task_resolver"},{"stringValue":"--"},{"stringValue":"task-module"},{"stringValue":"flint_tasks.test.hello_world"},{"stringValue":"task-name"},{"stringValue":"hello_world_no_spark"}]}}}}}]}},"tolerations":{"listValue":{"values":[{"structValue":{"fields":{"effect":{"stringValue":"NoSchedule"},"operator":{"stringValue":"Equal"},"value":{"stringValue":"flyte"},"key":{"stringValue":"app"}}}}]}},"nodeSelector":{"structValue":{"fields":{"app":{"stringValue":"flyte"}}}}}}}}
for
hello_world_no_spark
and
Copy code
{
  "config": {
    "primary_container_name": "primary"
  },
  "id": {
    "resourceType": 1,
    "project": "flint",
    "domain": "development",
    "name": "flint_tasks.test.hello_world.hello_world_spark",
    "version": "5.2.0-dd4654f"
  },
  "type": "spark",
  "metadata": {
    "tags": {},
    "runtime": {
      "type": 1,
      "version": "1.10.0",
      "flavor": "python"
    },
    "retries": {}
  },
  "interface": {
    "inputs": {
      "variables": {}
    },
    "outputs": {
      "variables": {}
    }
  },
  "custom": {
    "fields": {
      "sparkConf": {
        "structValue": {
          "fields": {
            "spark.kubernetes.executor.request.cores": {
              "stringValue": "1"
            },
            "spark.executor.instances": {
              "stringValue": "4"
            },
            "spark.kubernetes.driver.limit.cores": {
              "stringValue": "1"
            },
            "spark.sql.hive.metastore.jars.path": {
              "stringValue": "file:///opt/spark/jars/hive/*.jar"
            },
            "spark.sql.hive.metastore.version": {
              "stringValue": "3.1.3"
            },
            "spark.hive.metastore.uris": {
              "stringValue": "thrift://poc-flint-metastore-thrift.flyte:9083"
            },
            "spark.sql.catalogImplementation": {
              "stringValue": "hive"
            },
            "spark.kubernetes.driver.request.cores": {
              "stringValue": "1"
            },
            "spark.executor.memory": {
              "stringValue": "2g"
            },
            "spark.kubernetes.executor.limit.cores": {
              "stringValue": "4"
            },
            "spark.sql.hive.metastore.jars": {
              "stringValue": "path"
            }
          }
        }
      },
      "databricksConf": {
        "structValue": {
          "fields": {}
        }
      },
      "mainApplicationFile": {
        "stringValue": "local:///usr/local/bin/entrypoint.py"
      },
      "executorPath": {
        "stringValue": "python"
      }
    }
  },
  "k8sPod": {
    "metadata": {
      "labels": {},
      "annotations": {}
    },
    "podSpec": {
      "fields": {
        "nodeSelector": {
          "structValue": {
            "fields": {
              "app": {
                "stringValue": "flyte"
              }
            }
          }
        },
        "containers": {
          "listValue": {
            "values": [
              {
                "structValue": {
                  "fields": {
                    "args": {
                      "listValue": {
                        "values": [
                          {
                            "stringValue": "pyflyte-fast-execute"
                          },
                          {
                            "stringValue": "--additional-distribution"
                          },
                          {
                            "stringValue": "s3://dev-flyte-s3-storage/flint/development/4LLRY7MSZOQFAUROC42QEWSXOY======/fast07b0f2c937e3074c9a67215953b107e2.tar.gz"
                          },
                          {
                            "stringValue": "--dest-dir"
                          },
                          {
                            "stringValue": "/root"
                          },
                          {
                            "stringValue": "--"
                          },
                          {
                            "stringValue": "pyflyte-execute"
                          },
                          {
                            "stringValue": "--inputs"
                          },
                          {
                            "stringValue": "{{.input}}"
                          },
                          {
                            "stringValue": "--output-prefix"
                          },
                          {
                            "stringValue": "{{.outputPrefix}}"
                          },
                          {
                            "stringValue": "--raw-output-data-prefix"
                          },
                          {
                            "stringValue": "{{.rawOutputDataPrefix}}"
                          },
                          {
                            "stringValue": "--checkpoint-path"
                          },
                          {
                            "stringValue": "{{.checkpointOutputPrefix}}"
                          },
                          {
                            "stringValue": "--prev-checkpoint"
                          },
                          {
                            "stringValue": "{{.prevCheckpointPrefix}}"
                          },
                          {
                            "stringValue": "--resolver"
                          },
                          {
                            "stringValue": "flytekit.core.python_auto_container.default_task_resolver"
                          },
                          {
                            "stringValue": "--"
                          },
                          {
                            "stringValue": "task-module"
                          },
                          {
                            "stringValue": "flint_tasks.test.hello_world"
                          },
                          {
                            "stringValue": "task-name"
                          },
                          {
                            "stringValue": "hello_world_spark"
                          }
                        ]
                      }
                    },
                    "env": {
                      "listValue": {
                        "values": []
                      }
                    },
                    "image": {
                      "stringValue": "275184421095.dkr.ecr.af-south-1.amazonaws.com/flint-spark:5.2.0-dd4654f-flint"
                    },
                    "name": {
                      "stringValue": "primary"
                    },
                    "command": {
                      "listValue": {
                        "values": []
                      }
                    }
                  }
                }
              }
            ]
          }
        },
        "tolerations": {
          "listValue": {
            "values": [
              {
                "structValue": {
                  "fields": {
                    "value": {
                      "stringValue": "flyte"
                    },
                    "key": {
                      "stringValue": "app"
                    },
                    "effect": {
                      "stringValue": "NoSchedule"
                    },
                    "operator": {
                      "stringValue": "Equal"
                    }
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}
for
hello_world_spark
On creation, the manifest… flyteorg/flyte