Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v1.9-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
ckhordiasma committed Jan 16, 2025
2 parents d4a5d8e + ffaa1fe commit a0e21f3
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 71 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,23 @@ jobs:
go mod tidy
$(go env GOPATH)/bin/govulncheck -show=verbose ./...
working-directory: ${{ matrix.component }}

check-generated-code:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Rerun all code generators we have
run: bash ci/generate_code.sh

- name: Check there aren't any modified files present
run: |
clean=$(git status --porcelain)
if [[ -z "$clean" ]]; then
echo "Empty git status --porcelain: $clean"
else
echo "::error::Please run 'bash ci/generate_code.sh' (the command from the previous step), commit the changed files locally, and push again."
echo "Uncommitted file changes detected: $clean"
git diff
exit 1
fi
12 changes: 12 additions & 0 deletions ci/generate_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -Eeuxo pipefail

# Run all code generators we use in this repository.
# It is used to check for mismatches in GitHub Actions workflow.

# go projects
(cd components/notebook-controller; make manifests generate fmt)
(cd components/odh-notebook-controller; make manifests generate fmt)

# component metadata yaml file
(cd components/notebook-controller; bash generate-metadata-yaml.sh -o config/component_metadata.yaml)
6 changes: 3 additions & 3 deletions components/notebook-controller/config/component_metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
releases:
- name: Kubeflow Notebook
version: 1.9.0
releases:
- name: Kubeflow Notebook Controller
version: 1.9.0
repoUrl: https://github.com/kubeflow/kubeflow
Original file line number Diff line number Diff line change
@@ -1 +1 @@
odh-kf-notebook-controller-image=quay.io/opendatahub/kubeflow-notebook-controller:1.9-58ee8e2
odh-kf-notebook-controller-image=quay.io/opendatahub/kubeflow-notebook-controller:1.9-84946ca
179 changes: 142 additions & 37 deletions components/notebook-controller/generate-metadata-yaml.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
#!/usr/bin/env bash
#! /usr/bin/env bash

## Description:
##
## This script will ensure a components/notebook-controller/config/component_metadata.yaml file exists and is compliant with
## https://issues.redhat.com/browse/RHOAISTRAT-327.
## - Lots of discussion around the acceptance criteria from this work was also captured in Slack
## - see: https://redhat-internal.slack.com/archives/C05NXTEHLGY/p1731327116001979
##
## By default, information to populate component_metadata.yaml is extracted from 2 files in the repo:
## - ./components/notebook-controller/PROJECT
## - ./releasing/version/VERSION
##
## If component_metadata.yaml file exists, and attempting to generate any of the required attributes results in an empty string,
## then the existing value is preserved.
##
## The script is designed to generate appropriate attribute values implicitly. It should be able to be executed without providing
## any of the optional arguments. In the event an optional argument is provided on the command line, that value is used as-is.
##
## It should be noted that while the component_metadata.yaml specification has a root level attribute of 'releases' that is a list,
## this script only interacts with index 0.
##
## Dependencies:
##
## - yq: https://mikefarah.gitbook.io/yq
##
## Usage:
##
## generate-metadata-yaml.sh [-o <output file>] [-n <name>] [-v <version>] [-r <repoUrl>] [-p] [-x] [-h]"
## - Intended (eventually) to be invoked as part of a GitHub Action workflow.
## - Arguments
## - [optional] -o <output file>
## - where the script will write its output
## - defaults to ./components/notebook-controller/config/component-metadata.yaml
## - [optional] -n <name>
## - name attribute of 'releases' element at index 0
## - defaults to a value derived from the 'domain' and 'projectName' attribute of ./components/notebook-controller/PROJECT
## - value of 'domain' is split on the '.' character, and only first word is uppercased, discarding all other words
## - ex: kubeflow.org -> Kubeflow
## - value of 'projectName' is split on the '-' character, each word has the 1st letter uppercased, and then
## results are joined back together delimited by whitespace
## - ex: notebook-controller -> Notebook Controller
## - [optional] -v <version>
## - version attribute of 'releases' element at index 0
## - defaults to a value derived from contents of ./releasing/version/VERSION
## - 1st line of VERSION is read, and any leading 'v' character is removed from content
## - ex: v1.9.0 -> 1.9.0
## - [optional] -r <repoUrl>
## - repoUrl attribute of 'releases' element at index 0
## - defaults to a value derived from the 'repo' attribute of ./components/notebook-controller/PROJECT
## - value of 'repo' is split on the '/' character, 1st 3 elements are joined together by the '/' character,
## and then 'https://' prefix is added
## - ex: github.com/kubeflow/kubeflow/components/notebook-controller -> https://github.com/kubeflow/kubeflow
## - [optional] -x
## - enables tracing on the shell script
## - [optional] -h
## - prints a simple usage message
##
##


set -uo pipefail

# Description:
# Simple trap function that ensures shell tracing is disabled upon script exit.
function trap_exit() {
rc=$?

Expand All @@ -12,60 +73,101 @@ function trap_exit() {

trap "trap_exit" EXIT

# Description:
# Helper function that gets invoked when '-h' passed as a command line argument.
#
# Returns:
# Simple string outlining functionality of the script
_usage()
{
printf "%s\n" "Usage: $(basename "${0}") -o <output file> [-n <name>] [-v <version>] [-r <repoUrl>] [-p] [-x] [-h]"
}

# Description:
# Computes the default component_metadata.yaml 'name', 'version', and 'repoUrl' attributes for the 0th element of 'releases'. If the
# value of any attribute was provided on the command line, that value is used as-is and subsequent processing is skipped.
#
# Outputs:
# metadata_repo_url
# metadata_name
# metadata_version
_derive_metadata()
{
# inspired from https://stackoverflow.com/a/29835459
current_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)

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

if [ -z "${metadata_repo_url}" ]; then
local project_repo_reference=
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]}"
readarray -td/ project_repo_parts <<< "${project_repo_reference##https://}/"
local github_host="${project_repo_parts[0]}"
local github_owner="${project_repo_parts[1]}"
local 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}"

readarray -td. org_parts <<< "$(yq e '.domain' "${kf_project_file}")-"
unset 'org_parts[-1]'
org_parts[0]="$(tr '[:lower:]' '[:upper:]' <<< "${org_parts[0]:0:1}")${org_parts[0]:1}"

readarray -td- name_parts <<< "$(yq e '.projectName' "${kf_project_file}")-"
unset 'name_parts[-1]'
for i in "${!name_parts[@]}"; do
name_parts[i]="$(tr '[:lower:]' '[:upper:]' <<< "${name_parts[i]:0:1}")${name_parts[i]:1}"
done
metadata_name="$(printf '%s' "${org_parts[0]} ${name_parts[*]}")"
fi

fi

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

metadata_version=$(cat "${version_file}" | head -n 1)
local raw_version=
raw_version=$(head -n 1 < "${version_file}")
metadata_version="${raw_version##v}"
fi
}

# Description:
# Computes the component_metadata.yaml 'name', 'version', and 'repoUrl' attributes for the 0th element of 'releases'
# based on an existing component_metadata.yaml file. Processing is skipped for any output variable that already has
# a non-zero length string value.
#
# Outputs:
# metadata_repo_url
# metadata_name
# metadata_version
_fallback_to_existing_values()
{
if [ -n "${existing_fallback}" ]; then
if [ -e "${output_file}" ]; then
if [ -z "${metadata_repo_url}" ]; then
metadata_repo_url=$(yq -e '.releases[0].repoUrl' "${output_file}")
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}")
metadata_version=$(yq -e '.releases[0].version // ""' "${output_file}")
fi

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

# Description:
# Validation function that ensures all required attributes have non-zero length. Any attributes in violation of
# this check will log an error message and cause script to exit with a 1 status code.
#
_check_for_missing_data()
{
missing_data=
local missing_data=

if [ -z "${metadata_repo_url}" ]; then
printf "%s\n" "repoUrl attribute not specified and unable to be inferred"
Expand All @@ -87,6 +189,11 @@ _check_for_missing_data()
fi
}

# Description:
# Orchestration logic that generates the component_metadata.yaml file.
#
# NOTE: Multiple entries for the 'releases' attribute is not supported. Only the 0th index is operated against.
#
_handle_metadata_file()
{

Expand All @@ -96,17 +203,21 @@ _handle_metadata_file()

_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]"
}

# Description:
# Helper function that processes command line arguments provided to the script.
# - '-h' will cause script to exit with 0 (successful) status code
# - any unsupported options will cause script to exit with 1 (failure) status code
#
# Outputs:
# output_file
# metadata_repo_url
# metadata_name
# metadata_version
_parse_opts()
{
local OPTIND
Expand All @@ -115,11 +226,7 @@ _parse_opts()
case "${OPTION}" in
o )
output_file="${OPTARG}"

if ! [ -e "${output_file}" ]; then
touch "${output_file}"
fi
;;
;;
n )
metadata_name="${OPTARG}"
;;
Expand All @@ -129,9 +236,6 @@ _parse_opts()
r )
metadata_repo_url="${OPTARG}"
;;
e )
existing_fallback="t"
;;
h)
_usage
exit
Expand All @@ -144,11 +248,12 @@ _parse_opts()
done
}

output_file=
# inspired from https://stackoverflow.com/a/29835459
current_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
output_file="${current_dir}/config/component_metadata.yaml"
metadata_repo_url=
metadata_version=
metadata_name=
existing_fallback=

if ! yq --version &> /dev/null; then
printf "%s" "yq not installed... aborting script."
Expand All @@ -157,9 +262,9 @@ fi

_parse_opts "$@"

if [ -z "${output_file}" ]; then
printf "%s" "-o <output file> argument is required"
exit 1

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

_handle_metadata_file
8 changes: 4 additions & 4 deletions components/notebook-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
20 changes: 10 additions & 10 deletions components/notebook-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=
golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -166,24 +166,24 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion components/odh-notebook-controller/config/base/params.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
odh-notebook-controller-image=quay.io/opendatahub/odh-notebook-controller:1.9-58ee8e2
odh-notebook-controller-image=quay.io/opendatahub/odh-notebook-controller:1.9-84946ca
Loading

0 comments on commit a0e21f3

Please sign in to comment.