Skip to content

Commit

Permalink
feat(apply): add support for --delete-existing flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrgadiya committed Feb 7, 2025
1 parent dadab65 commit 1710279
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
25 changes: 25 additions & 0 deletions riocli/apply/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
help="Number of parallel workers while running apply " "command. defaults to 6.",
type=int,
)
@click.option(
"--recreate",
"--delete-existing",
"delete_existing",
is_flag=True,
default=False,
help="Overwrite existing resources",
)
@click.option(
"-f",
"--force",
Expand Down Expand Up @@ -98,6 +106,7 @@ def apply(
files: Iterable[str],
retry_count: int = 50,
retry_interval: int = 6,
delete_existing: bool = False,
dryrun: bool = False,
workers: int = 6,
silent: bool = False,
Expand Down Expand Up @@ -150,6 +159,10 @@ def apply(
$ rio apply -v values1.yaml -v values2.yaml templates/**
Re-create existing resources from the manifests.
$ rio apply -v values.yaml --delete-existing templates/
"""
glob_files, abs_values, abs_secrets = process_files_values_secrets(
files, values, secrets
Expand Down Expand Up @@ -177,6 +190,18 @@ def apply(
if not silent and not dryrun:
click.confirm("\nDo you want to proceed?", default=True, abort=True)

if delete_existing:
deleter = Applier(glob_files, abs_values, abs_secrets)
deleter.parse_dependencies(print_resources=False)

print_centered_text("Deleting Resources")
deleter.delete(
dryrun=dryrun,
workers=workers,
retry_count=retry_count,
retry_interval=retry_interval,
)

print_centered_text("Applying Manifests")
applier.apply(
dryrun=dryrun,
Expand Down
7 changes: 4 additions & 3 deletions riocli/apply/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,16 @@ def _get_async_delete_order(self):
while stack:
yield stack.pop()

def parse_dependencies(self):
def parse_dependencies(self, print_resources: bool = True):
for _, data in self.files.items():
for model in data:
key = self._get_object_key(model)
self._parse_dependency(key, model)
self._add_graph_node(key)

print_centered_text("Parsed Resources")
print_resolved_objects(self.resolved_objects)
if print_resources:
print_centered_text("Parsed Resources")
print_resolved_objects(self.resolved_objects)

def show_dependency_graph(self):
"""Lauches mermaid.live dependency graph"""
Expand Down
30 changes: 23 additions & 7 deletions riocli/chart/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable

import click
from click_help_colors import HelpColorsCommand

Expand Down Expand Up @@ -61,6 +63,14 @@
"expects sops to be authorized for decoding files on "
"this computer",
)
@click.option(
"--recreate",
"--delete-existing",
"delete_existing",
is_flag=True,
default=False,
help="Overwrite existing resources",
)
@click.option(
"--workers",
"-w",
Expand All @@ -83,12 +93,13 @@
@click.argument("chart", type=str)
def apply_chart(
chart: str,
values: str,
secrets: str,
dryrun: bool,
workers: int = 6,
values: Iterable[str],
secrets: Iterable[str],
retry_count: int = 50,
retry_interval: int = 6,
delete_existing: bool = False,
dryrun: bool = False,
workers: int = 6,
silent: bool = False,
) -> None:
"""Install a chart from the rapyuta-charts repository.
Expand Down Expand Up @@ -118,6 +129,10 @@ def apply_chart(
Apply a chart with values and secrets files without confirmation
$ rio chart apply ioconfig-syncer -v values.yaml -s secrets.yaml -f
Re-create existing chart resources.
$ rio chart apply -v values.yaml --delete-existing
"""
versions = find_chart(chart)
if len(versions) > 1:
Expand All @@ -126,14 +141,15 @@ def apply_chart(
fg=Colors.RED,
)

chart = Chart(**versions[0])
chart.apply_chart(
c = Chart(**versions[0])
c.apply_chart(
values,
secrets,
dryrun=dryrun,
delete_existing=delete_existing,
workers=workers,
silent=silent,
retry_count=retry_count,
retry_interval=retry_interval,
)
chart.cleanup()
c.cleanup()
10 changes: 6 additions & 4 deletions riocli/chart/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def apply_chart(
self,
values: str = None,
secrets: str = None,
dryrun: bool = None,
delete_existing: bool = False,
dryrun: bool = False,
workers: int = 6,
retry_count: int = 50,
retry_interval: int = 6,
Expand All @@ -47,13 +48,14 @@ def apply_chart(

apply.callback(
values=values,
files=[templates_dir],
secrets=secrets,
files=[templates_dir],
retry_count=retry_count,
retry_interval=retry_interval,
delete_existing=delete_existing,
dryrun=dryrun,
workers=workers,
silent=silent,
retry_count=retry_count,
retry_interval=retry_interval,
)

def delete_chart(
Expand Down

0 comments on commit 1710279

Please sign in to comment.