Skip to content

Commit

Permalink
Add attempt_fixes to Upgrade_2024_6_1._version_specific_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
smokestacklightnin committed Nov 10, 2024
1 parent afce2fb commit 91ecca0
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/_nebari/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,13 @@ class Upgrade_2024_6_1(UpgradeStep):

@override
def _version_specific_upgrade(
self, config, start_version, config_filename: Path, *args, **kwargs
self,
config,
start_version,
config_filename: Path,
*args,
attempt_fixes=False,
**kwargs,
):
# Prompt users to manually update kube-prometheus-stack CRDs if monitoring is enabled
if config.get("monitoring", {}).get("enabled", True):
Expand Down Expand Up @@ -1084,18 +1090,17 @@ def _version_specific_upgrade(
"\n-> [red bold]Nebari version 2024.6.1 comes with a new version of Grafana. Any custom dashboards that you created will be deleted after upgrading Nebari. Make sure to [link=https://grafana.com/docs/grafana/latest/dashboards/share-dashboards-panels/#export-a-dashboard-as-json]export them as JSON[/link] so you can [link=https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/import-dashboards/#import-a-dashboard]import them[/link] again afterwards.[/red bold]"
f"\n-> [red bold]Before upgrading, kube-prometheus-stack CRDs need to be updated and the {daemonset_name} daemonset needs to be deleted.[/red bold]"
)
run_commands = Prompt.ask(
run_commands = attempt_fixes or Confirm.ask(
"\nDo you want Nebari to update the kube-prometheus-stack CRDs and delete the prometheus-node-exporter for you? If not, you'll have to do it manually.",
choices=["y", "N"],
default="N",
default=False,
)

# By default, rich wraps lines by splitting them into multiple lines. This is
# far from ideal, as users copy-pasting the commands will get errors when running them.
# To avoid this, we use a rich console with a larger width to print the entire commands
# and let the terminal wrap them if needed.
console = rich.console.Console(width=220)
if run_commands == "y":
if run_commands:
try:
kubernetes.config.load_kube_config()
except kubernetes.config.config_exception.ConfigException:
Expand All @@ -1108,10 +1113,10 @@ def _version_specific_upgrade(
rich.print(
f"The following commands will be run for the [cyan bold]{cluster_name}[/cyan bold] cluster"
)
Prompt.ask("Hit enter to show the commands")
_ = attempt_fixes or Prompt.ask("Hit enter to show the commands")
console.print(commands)

Prompt.ask("Hit enter to continue")
_ = attempt_fixes or Prompt.ask("Hit enter to continue")
# We need to add a special constructor to the yaml loader to handle a specific
# tag as otherwise the kubernetes API will fail when updating the CRD.
yaml.constructor.add_constructor(
Expand Down Expand Up @@ -1153,16 +1158,15 @@ def _version_specific_upgrade(
rich.print(
"[red bold]Before upgrading, you need to manually delete the prometheus-node-exporter daemonset and update the kube-prometheus-stack CRDs. To do that, please run the following commands.[/red bold]"
)
Prompt.ask("Hit enter to show the commands")
_ = attempt_fixes or Prompt.ask("Hit enter to show the commands")
console.print(commands)

Prompt.ask("Hit enter to continue")
continue_ = Prompt.ask(
_ = attempt_fixes or Prompt.ask("Hit enter to continue")
continue_ = attempt_fixes or Confirm.ask(
f"Have you backed up your custom dashboards (if necessary), deleted the {daemonset_name} daemonset and updated the kube-prometheus-stack CRDs?",
choices=["y", "N"],
default="N",
default=False,
)
if not continue_ == "y":
if not continue_:
rich.print(
f"[red bold]You must back up your custom dashboards (if necessary), delete the {daemonset_name} daemonset and update the kube-prometheus-stack CRDs before upgrading to [green]{self.version}[/green] (or later).[/bold red]"
)
Expand All @@ -1187,12 +1191,11 @@ def _version_specific_upgrade(
If not, select "N" and the old default node groups will be added to the nebari config file.
"""
)
continue_ = Prompt.ask(
continue_ = attempt_fixes or Confirm.ask(
text,
choices=["y", "N"],
default="y",
default=True,
)
if continue_ == "N":
if not continue_:
config[provider_full_name]["node_groups"] = {
"general": {
"instance": "n1-standard-8",
Expand Down Expand Up @@ -1233,8 +1236,9 @@ def _version_specific_upgrade(
},
indent=4,
)
text += "\n\nHit enter to continue"
Prompt.ask(text)
rich.print(text)
if not attempt_fixes:
_ = Prompt.ask("\n\nHit enter to continue")
return config


Expand Down

0 comments on commit 91ecca0

Please sign in to comment.