Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Enable copilot to use AWS default credential chain to get IAM creds (#37
Browse files Browse the repository at this point in the history
)

* Enable copilot to use AWS default credential chain to get IAM creds

Signed-off-by: Alex Bain (Level 5 US)/Alex Bain <[email protected]>

* Update boilerplate with make update_boilerplate

Signed-off-by: Alex Bain (Level 5 US)/Alex Bain <[email protected]>

Co-authored-by: Alex Bain (Level 5 US)/Alex Bain <[email protected]>
  • Loading branch information
convexquad and Alex Bain (Level 5 US)/Alex Bain authored Apr 8, 2022
1 parent d043142 commit 43938f5
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 52 deletions.
7 changes: 4 additions & 3 deletions boilerplate/flyte/end2end/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

.PHONY: end2end_execute
end2end_execute:
./boilerplate/flyte/end2end/end2end.sh

# TODO: These arguments could come from environment variables
./boilerplate/flyte/end2end/end2end.sh ./boilerplate/flyte/end2end/functional-test.config --return_non_zero_on_failure

.PHONY: k8s_integration_execute
k8s_integration_execute:
echo "pass"
echo "pass"
13 changes: 5 additions & 8 deletions boilerplate/flyte/end2end/end2end.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
CONFIG_FILE=$1; shift
EXTRA_FLAGS=( "$@" )

OUT="${DIR}/tmp"
rm -rf ${OUT}
git clone https://github.com/flyteorg/flyte.git "${OUT}"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

pushd ${OUT}
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/flyteorg/flytesnacks/releases/latest" | jq -r .tag_name)

make end2end_execute
popd
python ./boilerplate/flyte/end2end/run-tests.py $LATEST_VERSION P0,P1 $CONFIG_FILE ${EXTRA_FLAGS[@]}
3 changes: 3 additions & 0 deletions boilerplate/flyte/end2end/functional-test.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[platform]
url=127.0.0.1:30081
insecure=True
237 changes: 237 additions & 0 deletions boilerplate/flyte/end2end/run-tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#!/usr/bin/env python3

import click
import json
import sys
import time
import traceback
import requests
from typing import List, Mapping, Tuple, Dict
from flytekit.remote import FlyteRemote
from flytekit.models.core.execution import WorkflowExecutionPhase
from flytekit.configuration import Config, ImageConfig, SerializationSettings


WAIT_TIME = 10
MAX_ATTEMPTS = 60

# This dictionary maps the names found in the flytesnacks manifest to a list of workflow names and
# inputs. This is so we can progressively cover all priorities in the original flytesnacks manifest,
# starting with "core".
FLYTESNACKS_WORKFLOW_GROUPS: Mapping[str, List[Tuple[str, dict]]] = {
"core": [
("core.control_flow.chain_tasks.chain_tasks_wf", {}),
("core.control_flow.dynamics.wf", {"s1": "Pear", "s2": "Earth"}),
("core.control_flow.map_task.my_map_workflow", {"a": [1, 2, 3, 4, 5]}),
# Workflows that use nested executions cannot be launched via flyteremote.
# This issue is being tracked in https://github.com/flyteorg/flyte/issues/1482.
# ("core.control_flow.run_conditions.multiplier", {"my_input": 0.5}),
# ("core.control_flow.run_conditions.multiplier_2", {"my_input": 10}),
# ("core.control_flow.run_conditions.multiplier_3", {"my_input": 5}),
# ("core.control_flow.run_conditions.basic_boolean_wf", {"seed": 5}),
# ("core.control_flow.run_conditions.bool_input_wf", {"b": True}),
# ("core.control_flow.run_conditions.nested_conditions", {"my_input": 0.4}),
# ("core.control_flow.run_conditions.consume_outputs", {"my_input": 0.4, "seed": 7}),
# ("core.control_flow.run_merge_sort.merge_sort", {"numbers": [5, 4, 3, 2, 1], "count": 5}),
("core.control_flow.subworkflows.parent_wf", {"a": 3}),
("core.control_flow.subworkflows.nested_parent_wf", {"a": 3}),
("core.flyte_basics.basic_workflow.my_wf", {"a": 50, "b": "hello"}),
# Getting a 403 for the wikipedia image
# ("core.flyte_basics.files.rotate_one_workflow", {"in_image": "https://upload.wikimedia.org/wikipedia/commons/d/d2/Julia_set_%28C_%3D_0.285%2C_0.01%29.jpg"}),
("core.flyte_basics.folders.download_and_rotate", {}),
("core.flyte_basics.hello_world.my_wf", {}),
("core.flyte_basics.lp.my_wf", {"val": 4}),
("core.flyte_basics.lp.go_greet", {"day_of_week": "5", "number": 3, "am": True}),
("core.flyte_basics.named_outputs.my_wf", {}),
# # Getting a 403 for the wikipedia image
# # ("core.flyte_basics.reference_task.wf", {}),
("core.type_system.custom_objects.wf", {"x": 10, "y": 20}),
# Enums are not supported in flyteremote
# ("core.type_system.enums.enum_wf", {"c": "red"}),
("core.type_system.schema.df_wf", {"a": 42}),
("core.type_system.typed_schema.wf", {}),
("my.imperative.workflow.example", {"in1": "hello", "in2": "foo"}),
],
}


def run_launch_plan(remote, version, workflow_name, inputs):
print(f"Fetching workflow={workflow_name} and version={version}")
lp = remote.fetch_workflow(name=workflow_name, version=version)
return remote.execute(lp, inputs=inputs, wait=False)


def schedule_workflow_group(
tag: str,
workflow_group: str,
remote: FlyteRemote,
terminate_workflow_on_failure: bool,
) -> bool:
"""
Schedule all workflows executions and return True if all executions succeed, otherwise
return False.
"""
workflows = FLYTESNACKS_WORKFLOW_GROUPS.get(workflow_group, [])

launch_plans = [
run_launch_plan(remote, tag, workflow[0], workflow[1]) for workflow in workflows
]

# Wait for all launch plans to finish
attempt = 0
while attempt == 0 or (
not all([lp.is_complete for lp in launch_plans]) and attempt < MAX_ATTEMPTS
):
attempt += 1
print(
f"Not all executions finished yet. Sleeping for some time, will check again in {WAIT_TIME}s"
)
time.sleep(WAIT_TIME)
# Need to sync to refresh status of executions
for lp in launch_plans:
print(f"About to sync execution_id={lp.id.name}")
remote.sync(lp)

# Report result of each launch plan
for lp in launch_plans:
print(lp)

# Collect all failing launch plans
non_succeeded_lps = [
lp
for lp in launch_plans
if lp.closure.phase != WorkflowExecutionPhase.SUCCEEDED
]

if len(non_succeeded_lps) == 0:
print("All executions succeeded.")
return True

print("Failed executions:")
# Report failing cases
for lp in non_succeeded_lps:
print(f" workflow={lp.spec.launch_plan.name}, execution_id={lp.id.name}")
if terminate_workflow_on_failure:
remote.terminate(lp, "aborting execution scheduled in functional test")
return False


def valid(workflow_group):
"""
Return True if a workflow group is contained in FLYTESNACKS_WORKFLOW_GROUPS,
False otherwise.
"""
return workflow_group in FLYTESNACKS_WORKFLOW_GROUPS.keys()


def run(
flytesnacks_release_tag: str,
priorities: List[str],
config_file_path,
terminate_workflow_on_failure: bool,
) -> List[Dict[str, str]]:
remote = FlyteRemote(
Config.auto(config_file=config_file_path),
default_project="flytesnacks",
default_domain="development",
)

# For a given release tag and priority, this function filters the workflow groups from the flytesnacks
# manifest file. For example, for the release tag "v0.2.224" and the priority "P0" it returns [ "core" ].
manifest_url = "https://raw.githubusercontent.com/flyteorg/flytesnacks/" \
f"{flytesnacks_release_tag}/cookbook/flyte_tests_manifest.json"
r = requests.get(manifest_url)
parsed_manifest = r.json()

workflow_groups = [
group["name"] for group in parsed_manifest if group["priority"] in priorities
]
results = []
for workflow_group in workflow_groups:
if not valid(workflow_group):
results.append(
{
"label": workflow_group,
"status": "coming soon",
"color": "grey",
}
)
continue

try:
workflows_succeeded = schedule_workflow_group(
flytesnacks_release_tag,
workflow_group,
remote,
terminate_workflow_on_failure,
)
except Exception:
print(traceback.format_exc())
workflows_succeeded = False

if workflows_succeeded:
background_color = "green"
status = "passing"
else:
background_color = "red"
status = "failing"

# Workflow groups can be only in one of three states:
# 1. passing: this indicates all the workflow executions for that workflow group
# executed successfully
# 2. failing: this state indicates that at least one execution failed in that
# workflow group
# 3. coming soon: this state is used to indicate that the workflow group was not
# implemented yet.
#
# Each state has a corresponding status and color to be used in the badge for that
# workflow group.
result = {
"label": workflow_group,
"status": status,
"color": background_color,
}
results.append(result)
return results


@click.command()
@click.option(
"--return_non_zero_on_failure",
default=False,
is_flag=True,
help="Return a non-zero exit status if any workflow fails",
)
@click.option(
"--terminate_workflow_on_failure",
default=False,
is_flag=True,
help="Abort failing workflows upon exit",
)
@click.argument("flytesnacks_release_tag")
@click.argument("priorities")
@click.argument("config_file")
def cli(
flytesnacks_release_tag,
priorities,
config_file,
return_non_zero_on_failure,
terminate_workflow_on_failure,
):
print(f"return_non_zero_on_failure={return_non_zero_on_failure}")
results = run(
flytesnacks_release_tag, priorities, config_file, terminate_workflow_on_failure
)

# Write a json object in its own line describing the result of this run to stdout
print(f"Result of run:\n{json.dumps(results)}")

# Return a non-zero exit code if core fails
if return_non_zero_on_failure:
for result in results:
if result["status"] not in ("passing", "coming soon"):
sys.exit(1)


if __name__ == "__main__":
cli()
17 changes: 10 additions & 7 deletions boilerplate/flyte/golang_support_tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/alvaroloes/enumer v1.1.2
github.com/flyteorg/flytestdlib v0.4.7
github.com/flyteorg/flytestdlib v0.4.16
github.com/golangci/golangci-lint v1.38.0
github.com/pseudomuto/protoc-gen-doc v1.4.1
github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5
Expand All @@ -14,7 +14,10 @@ require (
4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect
cloud.google.com/go v0.75.0 // indirect
cloud.google.com/go/storage v1.12.0 // indirect
github.com/Azure/azure-sdk-for-go v51.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go v62.3.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.17 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.10 // indirect
Expand Down Expand Up @@ -46,6 +49,7 @@ require (
github.com/esimonov/ifshort v1.0.1 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/flyteorg/stow v0.3.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fzipp/gocyclo v0.3.1 // indirect
Expand All @@ -62,6 +66,7 @@ require (
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/flock v0.8.0 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.3 // indirect
Expand All @@ -82,7 +87,6 @@ require (
github.com/gostaticanalysis/comment v1.4.1 // indirect
github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5 // indirect
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/graymeta/stow v0.2.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.0.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
Expand Down Expand Up @@ -135,7 +139,6 @@ require (
github.com/ryancurrah/gomodguard v1.2.0 // indirect
github.com/ryanrolds/sqlclosecheck v0.3.0 // indirect
github.com/sanposhiho/wastedassign v0.1.3 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/securego/gosec/v2 v2.6.1 // indirect
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
github.com/sirupsen/logrus v1.8.0 // indirect
Expand Down Expand Up @@ -163,10 +166,10 @@ require (
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/mod v0.4.1 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/oauth2 v0.0.0-20210126194326-f9ce19ea3013 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
Expand Down
Loading

0 comments on commit 43938f5

Please sign in to comment.