Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a .yaml file with kubeflow version #472

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/notebook-controller/config/component_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
releases:
- name: Kubeflow Notebook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Kubeflow Notebook Controller, according to the Slack thread.

version: 1.9.0
repoUrl: https://github.com/kubeflow/kubeflow
165 changes: 165 additions & 0 deletions components/notebook-controller/generate-metadata-yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env bash

set -uo pipefail

function trap_exit() {
rc=$?

set +x

exit $rc
}

trap "trap_exit" EXIT

_derive_metadata()
{
# inspired from https://stackoverflow.com/a/29835459
current_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)

kf_project_file="${current_dir}/PROJECT"
if [ -e "${kf_project_file}" ]; then

if [ -z "${metadata_repo_url}" ]; then
project_repo_reference=$(yq -e '.repo' "${kf_project_file}")
project_repo_parts=( $(printf "%s" ${project_repo_reference##https://} | tr '/' ' ') )
github_host="${project_repo_parts[0]}"
github_owner="${project_repo_parts[1]}"
github_repo="${project_repo_parts[2]}"

metadata_repo_url=$(printf "https://%s/%s/%s" "${github_host}" "${github_owner}" "${github_repo}")
fi

if [ -z "${metadata_name}" ]; then
project_domain=$(yq -e '.domain' "${kf_project_file}")
project_name=$(yq -e '.projectName' "${kf_project_file}")
metadata_name="${project_domain} ${project_name}"
fi

fi

if [ -z "${metadata_version}" ]; then
repo_root=$(git rev-parse --show-toplevel)
version_file="${repo_root}/releasing/version/VERSION"

metadata_version=$(cat "${version_file}" | head -n 1)
fi
}

_fallback_to_existing_values()
{
if [ -n "${existing_fallback}" ]; then
if [ -z "${metadata_repo_url}" ]; then
metadata_repo_url=$(yq -e '.releases[0].repoUrl' "${output_file}")
fi

if [ -z "${metadata_version}" ]; then
metadata_version=$(yq -e '.releases[0].version' "${output_file}")
fi

if [ -z "${metadata_name}" ]; then
metadata_name=$(yq -e '.releases[0].name' "${output_file}")
fi
fi
}

_check_for_missing_data()
{
missing_data=

if [ -z "${metadata_repo_url}" ]; then
printf "%s\n" "repoUrl attribute not specified and unable to be inferred"
missing_data=1
fi

if [ -z "${metadata_version}" ]; then
printf "%s\n" "version attribute not specified and unable to be inferred"
missing_data=1
fi

if [ -z "${metadata_name}" ]; then
printf "%s\n" "name attribute not specified and unable to be inferred"
missing_data=1
fi

if [ -n "${missing_data}" ]; then
exit 1
fi
}

_handle_metadata_file()
{

_derive_metadata

_fallback_to_existing_values

_check_for_missing_data

# NOTE: Does not handle multiple entries!!
yq_env_arg="${metadata_name}" yq -i '.releases[0].name = strenv(yq_env_arg)' "${output_file}"
yq_env_arg="${metadata_version}" yq -i '.releases[0].version = strenv(yq_env_arg)' "${output_file}"
yq_env_arg="${metadata_repo_url}" yq -i '.releases[0].repoUrl = strenv(yq_env_arg)' "${output_file}"
}

_usage()
{
printf "%s\n" "Usage: $(basename $0) -o <output file> [-n <name>] [-v <version>] [-r <repoUrl>] [-p] [-x] [-h]"
}

_parse_opts()
{
local OPTIND

while getopts ':o:n:v:r:exh' OPTION; do
case "${OPTION}" in
o )
output_file="${OPTARG}"

if ! [ -e "${output_file}" ]; then
touch "${output_file}"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation?

;;
n )
metadata_name="${OPTARG}"
;;
v )
metadata_version="${OPTARG}"
;;
r )
metadata_repo_url="${OPTARG}"
;;
e )
existing_fallback="t"
;;
h)
_usage
exit
;;
* )
_usage
exit 1
;;
esac
done
}

output_file=
metadata_repo_url=
metadata_version=
metadata_name=
existing_fallback=

if ! yq --version &> /dev/null; then
printf "%s" "yq not installed... aborting script."
exit 1
fi

_parse_opts "$@"

if [ -z "${output_file}" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering why we don't have a default here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could argue that the script should not take any parameters and everything should be defaulted (that's my view), but the aim of the jira is to create the metadata yaml and this script is just a little extra bonus, so it's important to review the yaml and the rest is just cherry on top; it's not even run automatically, so it's as if it was not even there

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very fair comment...

I had (perhaps wrongly) designed with the intention of being able to be executed by any team (not just IDE team)...

Under that scenario - the "where" to place the file then becomes a bit ambiguous..

  • that being said - I undermine my own argument here since I rely on the relative positioning of the file in the repository to check for a PROJECT file - so a similar mechanism can be done for the default target location

printf "%s" "-o <output file> argument is required"
exit 1
fi

_handle_metadata_file