Skip to content

Commit

Permalink
chore: add quiet mode to dependency_checker
Browse files Browse the repository at this point in the history
The idea is for the checker to output nothing if there's nothing to
change. This makes running it in CI much easier.
  • Loading branch information
swiatekm committed Nov 13, 2023
1 parent 78e2156 commit b789654
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ check-configuration-keys:

.PHONY: check-dependencies
check-dependencies:
@python ./ci/check_dependencies/main.py
@python ./ci/check_dependencies/main.py --quiet

.PHONY: template-tests-lint
template-tests-lint:
Expand Down
4 changes: 2 additions & 2 deletions ci/check_dependencies/aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_supported_releases(html_calendar):
return supported_releases


def get_info():
def get_info() -> list[str]:
cache_file = "cache/aks_calendar.html"
calendar_web_page = "https://learn.microsoft.com/en-us/azure/aks/supported-kubernetes-versions?tabs=azure-cli#aks-kubernetes-release-calendar"
html_calendar = common.get_page(calendar_web_page, cache_file)
officially_supported = get_supported_releases(html_calendar)
common.get_info("AKS", officially_supported)
return common.get_info("AKS", officially_supported)
29 changes: 16 additions & 13 deletions ci/check_dependencies/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def get_page(web_page, cache_file):
return calendar


def get_info(platform, officially_supported):
def get_info(platform, officially_supported) -> list[str]:
output_lines = []
if platform == "OpenShift":
line_pattern = platform
else:
Expand All @@ -53,28 +54,30 @@ def get_info(platform, officially_supported):
versions_to_remove = sorted(set(now_suppported) - set(officially_supported))

if len(versions_to_add) == 0 and len(versions_to_remove) == 0:
return
return []

print(f"")
print(f"#### {platform} ####")
print("{} officially supported versions".format(platform))
print(officially_supported)
output_lines.append(f"")
output_lines.append(f"#### {platform} ####")
output_lines.append("{} officially supported versions".format(platform))
output_lines.append(officially_supported)

print(
output_lines.append(
"Currently supported {} versions for Sumologic Kubernetes Collection Helm Chart".format(
platform
)
)

print(now_suppported)
print("\n")
output_lines.append(now_suppported)
output_lines.append("\n")


if len(versions_to_add) != 0:
print("Please add support to following {} versions:".format(platform))
print(versions_to_add)
output_lines.append("Please add support to following {} versions:".format(platform))
output_lines.append(versions_to_add)


if len(versions_to_remove) != 0:
print("Please remove support to following {} versions:".format(platform))
print(versions_to_remove)
output_lines.append("Please remove support to following {} versions:".format(platform))
output_lines.append(versions_to_remove)

return output_lines
4 changes: 2 additions & 2 deletions ci/check_dependencies/eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ def get_eks_officially_supported_releases():
return sorted(eks_supported_releases)


def get_info():
def get_info() -> list[str]:
officially_supported = get_eks_officially_supported_releases()
common.get_info("EKS", officially_supported)
return common.get_info("EKS", officially_supported)
4 changes: 2 additions & 2 deletions ci/check_dependencies/gke.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def get_supported_releases(html_calendar):
return supported_releases


def get_info():
def get_info() -> list[str]:
cache_file = "cache/gke_calendar.html"
calendar_web_page = "https://cloud.google.com/kubernetes-engine/docs/release-schedule#schedule_for_release_channels"
html_calendar = common.get_page(calendar_web_page, cache_file)
officially_supported = get_supported_releases(html_calendar)
common.get_info("GKE", officially_supported)
return common.get_info("GKE", officially_supported)
14 changes: 10 additions & 4 deletions ci/check_dependencies/helm_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# We ignore Prometheus here, as we're locked to whatever version is CRD-compatible with OpenShift
DEPENDENCIES_TO_IGNORE=("kube-prometheus-stack")

def get_info():
def get_info() -> list[str]:
output_lines = []
cache_file = "cache/Chart.yaml"
chart_yaml_url = "https://raw.githubusercontent.com/SumoLogic/sumologic-kubernetes-collection/main/deploy/helm/sumologic/Chart.yaml"
collection_chart_yaml_str = common.get_page(chart_yaml_url, cache_file)
Expand Down Expand Up @@ -52,18 +53,23 @@ def get_info():
)

if current_release[VERSION_IDX] != latest_release[VERSION_IDX]:
print(
output_lines.append(
"Please check newer version of {} subchart, version: {}, created: {}".format(
dep["name"].upper(),
latest_release[VERSION_IDX],
latest_release[CREATED_IDX],
)
)
print(
output_lines.append(
"Currently used {} subchart, version: {}, created: {}".format(
dep["name"].upper(),
current_release[VERSION_IDX],
current_release[CREATED_IDX],
)
)
print("")
output_lines.append("")

if len(output_lines) > 0:
output_lines = ["#### Subcharts in Sumologic Kubernetes Collection Helm Chart ####", ""] + output_lines

return output_lines
4 changes: 2 additions & 2 deletions ci/check_dependencies/kops.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def get_expected_supported_kops(kops_releases):
return kops_releases[-5:]


def get_info():
def get_info() -> list[str]:
# Figure out which versions we need to add/remove
kops_minor_releases = get_minor_releases("kubernetes", "kops")
officially_supported = get_expected_supported_kops(kops_minor_releases)
common.get_info("Kops", officially_supported)
return common.get_info("Kops", officially_supported)
42 changes: 30 additions & 12 deletions ci/check_dependencies/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import argparse

import kops
import eks
import gke
Expand All @@ -6,16 +8,32 @@

import helm_charts

parser = argparse.ArgumentParser(
prog="dependency_checker",
description="dependency_checker checks whether any dependencies or supported platforms need to be updated"
)
parser.add_argument("-q", "--quiet", action="store_true")

if __name__ == "__main__":
print("Gardener helper")
print("#####################################################################\n")
kops.get_info()
eks.get_info()
gke.get_info()
aks.get_info()
openshift.get_info()
print("")

print("#### Subcharts in Sumologic Kubernetes Collection Helm Chart ####")
print("")
helm_charts.get_info()
args = parser.parse_args()
output_lines = []
output_lines.append("Gardener helper")
output_lines.append("#####################################################################")
output_lines.append("")
output_lines.extend(kops.get_info())
output_lines.extend(eks.get_info())
output_lines.extend(gke.get_info())
output_lines.extend(aks.get_info())
output_lines.extend(openshift.get_info())

if not len(output_lines) == 3:
output_lines.append("")

output_lines.extend(helm_charts.get_info())

if len(output_lines) == 3:
output_lines.append("No changes are required")

if not args.quiet or len(output_lines) > 4:
for line in output_lines:
print(line)
4 changes: 2 additions & 2 deletions ci/check_dependencies/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def get_supported_releases(html_calendar):
return sorted(supported_versions)


def get_info():
def get_info() -> str:
cache_file = "cache/openshift_calendar.html"
# template for https://docs.openshift.com/container-platform/4.11/welcome/index.html
calendar_web_page = "https://raw.githubusercontent.com/openshift/openshift-docs/main/_templates/_page_openshift.html.erb"
html_calendar = common.get_page(calendar_web_page, cache_file)
officially_supported = get_supported_releases(html_calendar)
common.get_info("OpenShift", officially_supported)
return common.get_info("OpenShift", officially_supported)

0 comments on commit b789654

Please sign in to comment.