Skip to content

Commit

Permalink
currency: use kubectl and bash to interact with tekton resources
Browse files Browse the repository at this point in the history
Signed-off-by: Varsha GS <[email protected]>
  • Loading branch information
GSVarsha committed May 14, 2024
1 parent 0d24cd7 commit dde2f2b
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 188 deletions.
6 changes: 3 additions & 3 deletions .tekton/.currency/currency-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ spec:
- name: revision
value: $(params.revision)
taskRef:
name: git-clone-task
name: ruby-git-clone-task
workspaces:
- name: task-pvc
workspace: ruby-currency-pvc
- name: generate-currency-report
runAfter:
- clone-repo
taskRef:
name: generate-currency-report-task
name: ruby-generate-currency-report-task
workspaces:
- name: task-pvc
workspace: ruby-currency-pvc
- name: upload-currency-report
runAfter:
- generate-currency-report
taskRef:
name: upload-currency-report-task
name: ruby-upload-currency-report-task
workspaces:
- name: task-pvc
workspace: ruby-currency-pvc
2 changes: 1 addition & 1 deletion .tekton/.currency/currency-pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
params:
- name: revision
value: "currency-update"
value: "master"
pipelineRef:
name: ruby-currency-pipeline
serviceAccountName: currency-serviceaccount
Expand Down
2 changes: 1 addition & 1 deletion .tekton/.currency/currency-scheduled-eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
serviceAccountName: currency-serviceaccount
params:
- name: revision
value: "currency-update"
value: "master"
workspaces:
- name: ruby-currency-pvc
volumeClaimTemplate:
Expand Down
36 changes: 19 additions & 17 deletions .tekton/.currency/currency-tasks.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: git-clone-task
name: ruby-git-clone-task
spec:
params:
- name: revision
Expand All @@ -24,7 +24,7 @@ spec:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: generate-currency-report-task
name: ruby-generate-currency-report-task
spec:
workspaces:
- name: task-pvc
Expand All @@ -34,7 +34,7 @@ spec:
# 3.10.13-bookworm
image: python@sha256:c970ff53939772f47b0672e380328afb50d8fd1c0568ed4f82c22effc54244fc
script: |
#!/bin/bash
#!/usr/bin/env bash
/usr/bin/curl -LO https://storage.googleapis.com/kubernetes-release/release/$(/usr/bin/curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x ./kubectl && \
mv ./kubectl /usr/local/bin/kubectl
Expand All @@ -44,15 +44,16 @@ spec:
python -m venv /tmp/venv
source /tmp/venv/bin/activate
pip install -r utils/requirements.txt
pip install -r resources/requirements.txt
chmod +x scripts/get-tekton-ci-output.sh && ./scripts/get-tekton-ci-output.sh
python scripts/generate_report.py
echo "Generated report..."
cat docs/report.md
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: upload-currency-report-task
name: ruby-upload-currency-report-task
spec:
params:
- name: github-token-secret
Expand All @@ -74,16 +75,17 @@ spec:
#!/bin/sh
cd /workspace
git clone https://oauth2:[email protected]/instana/tracer-reports.git tracer-reports
cd tracer-reports
git pull origin main
git clone https://oauth2:[email protected]/instana/tracer-reports.git
if [ $? -eq 0 ]; then
cd tracer-reports
cp ../ruby-sensor/.tekton/.currency/docs/report.md ./automated/currency/ruby/report.md
cp ../ruby-sensor/.tekton/.currency/docs/report.md ./automated/currency/ruby/report.md
git config user.name "Instanacd PAT for GitHub Enterprise"
git config user.email [email protected]
git add .
git commit -m "chore: Updated ruby currency report"
git push origin main
git config user.name "Instanacd PAT for GitHub Enterprise"
git config user.email [email protected]
git add .
git commit -m "chore: Updated ruby currency report"
git push origin main
fi
File renamed without changes.
94 changes: 94 additions & 0 deletions .tekton/.currency/resources/table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"table": [
{
"Package name": "Cuba",
"Support Policy": "On demand",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Rack",
"Support Policy": "0-day",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Rails",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Rails::API",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Rails LTS",
"Support Policy": "On demand",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Roda",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Sinatra",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Excon",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "Yes"
},
{
"Package name": "gRPC",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Net::HTTP",
"Support Policy": "0-day",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Rest-Client",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Dalli",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "No"
},
{
"Package name": "Resque",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "Yes"
},
{
"Package name": "Sidekiq",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "Yes"
},
{
"Package name": "GraphQL",
"Support Policy": "30-days",
"Beta version": "No",
"Cloud Native": "Yes"
}
]
}
89 changes: 37 additions & 52 deletions .tekton/.currency/scripts/generate_report.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Standard Libraries
import re
from json import load
from os import system

# Third Party
from requests import get
from pandas import DataFrame
from bs4 import BeautifulSoup

JSON_FILE = "utils/table.json"
JSON_FILE = "resources/table.json"
REPORT_FILE = "docs/report.md"
TEKTON_CI_OUT_SCRIPT = "scripts/get-tekton-ci-output.sh"
TEKTON_CI_OUT_FILE = "utils/tekton-ci-output.txt"
TEKTON_CI_OUT_FILE = "resources/tekton-ci-output.txt"
API_V1_ENDPOINT = "https://rubygems.org/api/v1/versions/"
LATEST_SUPPORTED_RUBY_VERSION = "3.3.0"

Expand Down Expand Up @@ -42,9 +40,6 @@ def get_upstream_version(dependency):
return latest_version


## Get the tekton ci output of the installed ruby dependencies
system("bash " + TEKTON_CI_OUT_SCRIPT)

with open(TEKTON_CI_OUT_FILE) as file:
content = file.read()

Expand All @@ -66,55 +61,45 @@ def isUptodate(last_supported_version, latest_version):

return up_to_date

def main():
# Read the JSON file
with open(JSON_FILE) as file:
data = load(file)

# Read the JSON file
with open(JSON_FILE) as file:
data = load(file)
items = data["table"]

for item in items:
package = item["Package name"]
package = package.lower().replace("::", "-")

items = data["table"]
if package == "net-http":
last_supported_version = LATEST_SUPPORTED_RUBY_VERSION
latest_version = get_latest_stable_ruby_version()

for index in range(len(items)):
item = items[index]
package = item["package_name"]
package = package.lower().replace("::", "-")
else:
latest_version = get_upstream_version(package)

if package == "net-http":
last_supported_version = LATEST_SUPPORTED_RUBY_VERSION
latest_version = get_latest_stable_ruby_version()
if not package in ["rails lts", "rails-api"]:
last_supported_version = get_last_supported_version(package)
else:
last_supported_version = latest_version

else:
latest_version = get_upstream_version(package)
up_to_date = isUptodate(last_supported_version, latest_version)

if not package in ["rails lts", "rails-api"]:
last_supported_version = get_last_supported_version(package)
else:
last_supported_version = latest_version

up_to_date = isUptodate(last_supported_version, latest_version)

item.update(
{
"last_supported_version": last_supported_version,
"latest_version": latest_version,
"up_to_date": up_to_date,
},
)

# Create a DataFrame from the list of dictionaries
df = DataFrame(items)
df.insert(len(df.columns) - 1, "cloud_native", df.pop("cloud_native"))

# Rename Columns
df.columns = [
"Package name",
"Support Policy",
"Beta version",
"Last Supported Version",
"Latest version",
"Up-to-date",
"Cloud Native",
]

# Save the DataFrame as Markdown
df.to_markdown(REPORT_FILE, index=False)
item.update(
{
"Last Supported Version": last_supported_version,
"Latest version": latest_version,
"Up-to-date": up_to_date,
},
)

# Create a DataFrame from the list of dictionaries
df = DataFrame(items)
df.insert(len(df.columns) - 1, "Cloud Native", df.pop("Cloud Native"))

# Save the DataFrame as Markdown
df.to_markdown(REPORT_FILE, index=False)

if __name__ == "__main__":
main()
14 changes: 6 additions & 8 deletions .tekton/.currency/scripts/get-tekton-ci-output.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash

TEKTON_CI_OUT_FILE=utils/tekton-ci-output.txt

# Empty the file
>$TEKTON_CI_OUT_FILE
TEKTON_CI_OUT_FILE=resources/tekton-ci-output.txt

taskrun_list=$(kubectl get taskrun --sort-by=.metadata.creationTimestamp | grep -v "pr\|Failed\|currency")

Expand All @@ -13,7 +10,8 @@ for library in "${!pattern_map1[@]}"
do
pattern=${pattern_map1[$library]}

successful_taskruns=( $(echo "${taskrun_list}" | grep "unittest-default-ruby-33-${pattern}\s" | awk '{print $1}') )
successful_taskruns=( $(echo "${taskrun_list}" | awk -v pattern="${pattern}" '{ if ($1 ~ /unittest-default-ruby-33-'"$pattern"'$/) { print $1 } }' ) )
# looping through the taskruns in reverse order to get the latest successful taskrun
for ((i=${#successful_taskruns[@]}-1; i>=0; i--)); do
pod_name=$(kubectl get taskrun "${successful_taskruns[$i]}" -o jsonpath='{.status.podName}')
ci_output=$(kubectl logs ${pod_name} -c step-unittest | grep -o "Installing ${library} [^ ]*")
Expand All @@ -25,13 +23,13 @@ do
echo ${latest_successful_taskrun_output} >> ${TEKTON_CI_OUT_FILE}
done

declare -A pattern_map2=( ["rails"]="rails-\w*-11" ["dalli"]="memcached-11" ["resque"]="unittest-redis-ruby-32-33-9" ["sidekiq"]="unittest-redis-ruby-32-33-18" )
declare -A pattern_map2=( ["rails"]="rails-[[:alnum:]]*-11" ["dalli"]="memcached-11" ["resque"]="unittest-redis-ruby-32-33-9" ["sidekiq"]="unittest-redis-ruby-32-33-18" )

for library in "${!pattern_map2[@]}"
do
pattern=${pattern_map2[$library]}

successful_taskruns=( $(echo "${taskrun_list}" | grep "${pattern}" | awk '{print $1}') )
successful_taskruns=( $(echo "${taskrun_list}" | awk -v pattern="${pattern}" '{ if ($0 ~ pattern) {print $1} }' ) )
for ((i=${#successful_taskruns[@]}-1; i>=0; i--)); do
pod_name=$(kubectl get taskrun "${successful_taskruns[$i]}" -o jsonpath='{.status.podName}')
ci_output=$(kubectl logs ${pod_name} -c step-unittest | grep -o "Installing ${library} [^ ]*")
Expand Down
Loading

0 comments on commit dde2f2b

Please sign in to comment.