Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply improvements and milestone 4.0.0 requests #42

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jsonschema/json/
*.class

# Compiled Python bytecode
venv/
build/
*.egg-info/
*.py[cod]

# Log files
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ furo = "==2021.10.9"

[packages]
riocli = {path = "."}
pretty-traceback == "2022.1018"
ankitrgadiya marked this conversation as resolved.
Show resolved Hide resolved
argparse = ">=1.4.0"
click = ">=8.0.1"
click-completion = ">=0.5.2"
Expand Down
15 changes: 15 additions & 0 deletions examples/kiba-robots/secrets.staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of the kiba-robots and all other directories under examples. As discussed, these are housed under rapyuta-charts/manifests anyways.

dbHost: ENC[AES256_GCM,data:+7cvT+9J09CigDcvxm837Hfz0+WFwBzA1TcQvI75SFs5PmIs7A==,iv:km6KEq0AYSHBxgL1a1WlIa8gvguU4dEaB9oogaVTU4o=,tag:G+fxpM7FB7TQYsWeekrJ0g==,type:str]
dbUser: ENC[AES256_GCM,data:4j9zoiRsJhMJ0MWW0XEQCHt4,iv:Q4NboLJnT4oA6Z6uxp7ans1V4sjgYl/quemOXNEulco=,tag:AxLp7Xj75MN+JU0+x5YfSA==,type:str]
dbPass: ENC[AES256_GCM,data:YyfHySZ4bcAvR3qnIAa2BMLMFQuUkg==,iv:FJJTQ+TQcjnzo7iNXg/a7P5do8b8ButaaPALvf4Q+FQ=,tag:OZIrjBt0CGAhVbWpzvfAYg==,type:str]
sops:
kms: []
gcp_kms:
- resource_id: projects/rapyuta-io/locations/global/keyRings/sops_key/cryptoKeys/sops-key
created_at: '2022-04-12T19:53:13Z'
enc: CiQAJwkHSPloHZMqFLMdQRRActkGdVWHzMZOwLw/YrTDyS/ZE3gSSQD+fVSX3pLI/l0n8INc9C6nY+bGWBIxbuXWELl3d5jYVurpxGqXeikLhKsJZo6C2v1gknKv734uZgcPXVG7Y5dLDMGaMYeBpzA=
lastmodified: '2022-04-12T19:53:14Z'
mac: ENC[AES256_GCM,data:t/lH23kZ3lZymEpuiTwVxICJacw5jgRSXJ1REuCxcoN2GT9Dz76CsS5g9RYJpawx7LtdTU8SqRN17eZ/7f4gctuqvVWFOqu/vh/ui1SDYonkclh4JVxU4wTGAkXKnDJG5qGF/1z0d2zHr/I4CfWHmJFBWbvD1MxMCpJaU0T11n4=,iv:q62pfYu3Ku9EAKwvR0k+69A9goJ4KOz4FBO6DqRKN0U=,tag:ICqGK8A6+bHWnGam4ECIsg==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.0.5
3,030 changes: 0 additions & 3,030 deletions examples/simple-creation.cast

This file was deleted.

2 changes: 1 addition & 1 deletion jsonschema/deployment-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ definitions:
type: string
enum:
- always
- onFailure
- onfailure
- never
default: always
envArgs:
Expand Down
84 changes: 59 additions & 25 deletions riocli/apply/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from riocli.project.model import Project
from riocli.secret.model import Secret
from riocli.static_route.model import StaticRoute
from riocli.utils import run_bash

KIND_TO_CLASS = {
'Project': Project,
Expand All @@ -41,7 +42,45 @@
'Deployment': Deployment,
}

def parse_varidac_pathargs(pathItem):
wiresurfer marked this conversation as resolved.
Show resolved Hide resolved
glob_files = []
abs_path = os.path.abspath(pathItem)
#make it absolte
# does the path exist.
# is it a dir? scan recursively
# not a dir but has special charaters in it? [*?^!]
# assume its a valid glob, use it to glob recursively
# if all else fails
# consider it a file path directly.
if os.path.exists(abs_path):
if os.path.isdir(abs_path):
#TODO: Should we keep this recursive?
glob_files = glob.glob(abs_path + "/**/*", recursive=True)
else:
glob_files = glob.glob(abs_path, recursive=True)
return glob_files

def process_files_values_secrets(files, values, secrets):
glob_files = []

for pathItem in files:
path_glob = parse_varidac_pathargs(pathItem)
glob_files.extend(path_glob)

abs_values = values
if values and values != "":
abs_values = os.path.abspath(values)
if abs_values in glob_files:
glob_files.remove(abs_values)

abs_secret = secrets
if secrets and secrets != "":
abs_secrets = os.path.abspath(secrets)
if abs_secrets in glob_files:
glob_files.remove(abs_secrets)

glob_files = list(set(glob_files))
return glob_files, abs_values, abs_secret

@click.command(
'apply',
Expand All @@ -50,27 +89,27 @@
help_options_color='green',
)
@click.option('--dryrun', '-d', is_flag=True, default=False, help='dry run the yaml files without applying any change')
@click.option('--values')
@click.argument('files')
def apply(values: str, files: str, dryrun: bool = False) -> None:
@click.option('--values', '-v')
wiresurfer marked this conversation as resolved.
Show resolved Hide resolved
@click.option('--secrets', '-s')
@click.argument('files', nargs=-1)
def apply(values: str, secrets: str, files: list[str], dryrun: bool = False, ) -> None:
"""
Apply resource manifests
"""
abs_path = os.path.abspath(files)
glob_files = []
if os.path.exists(abs_path):
if os.path.isdir(abs_path):
glob_files = glob.glob(abs_path + "/**/*", recursive=True)
else:
glob_files = [files]
glob_files, abs_values, abs_secrets = process_files_values_secrets(files, values, secrets)

if len(glob_files) == 0:
click.secho('no files specified', fg='red')
exit(1)

rc = Applier(glob_files, values)

click.secho("----- Files Processed ----", fg="yellow")
for file in glob_files:
click.secho(file, fg="yellow")


rc = Applier(glob_files, abs_values, abs_secrets)
rc.parse_dependencies()

rc.apply(dryrun=dryrun)


Expand All @@ -80,25 +119,20 @@ def apply(values: str, files: str, dryrun: bool = False) -> None:
help_headers_color='yellow',
help_options_color='green',
)
@click.option('--values')
@click.argument('files')
@click.option('--dryrun', '-d', is_flag=True, default=False, help='dry run the yaml files without applying any change')
def delete(values: str, files: str, dryrun: bool = False) -> None:
@click.option('--values', '-v')
@click.option('--secrets', '-s')
@click.argument('files', nargs=-1)
def delete(values: str, secrets: str, files: list[str], dryrun: bool = False) -> None:
"""
Apply resource manifests
"""
abs_path = os.path.abspath(files)
glob_files = []
if os.path.exists(abs_path):
if os.path.isdir(abs_path):
glob_files = glob.glob(abs_path + "/**/*", recursive=True)
else:
glob_files = [files]
glob_files, abs_values, abs_secrets = process_files_values_secrets(files, values, secrets)

if len(glob_files) == 0:
click.secho('no files specified', fg='red')
exit(1)

rc = Applier(glob_files, values)
rc.parse_dependencies(check_missing=False)
rc = Applier(glob_files, abs_values, abs_secrets)
rc.parse_dependencies(check_missing=False, delete=True)
rc.delete(dryrun=dryrun)
9 changes: 3 additions & 6 deletions riocli/apply/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ def explain(resource: str, templates: str = None) -> None:
path = Path(templates)
else:
path = Path(__file__).parent.joinpath('manifests')

for each in path.glob('**/*'):
if resource in each.name:
with open(each) as f:
lines = ["---\n"]
lines.extend(f.readlines())
lines.extend(["---\n"])
click.secho("".join(lines))
click.secho(f.readlines())
exit(0)

click.secho("asdsa")
click.secho("Error in explain command. Exit Code -1", fg='red')
wiresurfer marked this conversation as resolved.
Show resolved Hide resolved
exit(1)
Loading