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

Verify Kubernetes context before install #1739

Merged
merged 21 commits into from
Oct 13, 2022
Merged

Verify Kubernetes context before install #1739

merged 21 commits into from
Oct 13, 2022

Conversation

jmgrady
Copy link
Collaborator

@jmgrady jmgrady commented Sep 28, 2022

Update the setup_cluster.py and setup_combine.py scripts to prompt the user to verify the Kubernetes context before the setup tasks are run.

If there is more than one context available, then the script will list the selected context and ask the user to verify the context or select another.

Note that there should be no prompting when run in the CI/CD pipeline.


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Sep 28, 2022

Codecov Report

Base: 52.05% // Head: 52.19% // Increases project coverage by +0.14% 🎉

Coverage data is based on head (2f0fc26) compared to base (fc22049).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1739      +/-   ##
==========================================
+ Coverage   52.05%   52.19%   +0.14%     
==========================================
  Files         274      274              
  Lines        8481     8481              
  Branches      616      616              
==========================================
+ Hits         4415     4427      +12     
+ Misses       3574     3562      -12     
  Partials      492      492              
Flag Coverage Δ
backend 80.44% <ø> (+0.34%) ⬆️
frontend 32.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
Backend/Helper/DuplicateFinder.cs 94.38% <0.00%> (+6.74%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jmgrady jmgrady marked this pull request as ready for review October 11, 2022 14:24
Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 5 files at r1, 5 of 7 files at r2, all commit messages.
Reviewable status: 9 of 11 files reviewed, 2 unresolved discussions (waiting on @jmgrady)


deploy/scripts/aws_env.py line 66 at r2 (raw file):

        os.environ["AWS_SECRET_ACCESS_KEY"] = get_profile_var(aws_profile, "aws_secret_access_key")
        region = get_profile_var(aws_profile, "region")
        os.environ["AWS_DEFAULT_REGION"] = region

Looks like defining region creates an unnecessary extra line.

Code quote:

        region = get_profile_var(aws_profile, "region")
        os.environ["AWS_DEFAULT_REGION"] = region

deploy/scripts/kube_env.py line 80 at r2 (raw file):

    Add commandline arguments that are shared between scripts calling helm.

    Sets up '--verbose' as the equivalent of '--debug'.

This vestigial --verbose reference can be removed.

Code quote:

 Sets up '--verbose' as the equivalent of '--debug'.

Copy link
Collaborator Author

@jmgrady jmgrady left a comment

Choose a reason for hiding this comment

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

Reviewable status: 8 of 12 files reviewed, all discussions resolved (waiting on @imnasnainaec and @jmgrady)


deploy/scripts/aws_env.py line 66 at r2 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

Looks like defining region creates an unnecessary extra line.

Done.


deploy/scripts/kube_env.py line 80 at r2 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

This vestigial --verbose reference can be removed.

Done.

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r4, all commit messages.
Reviewable status: 10 of 12 files reviewed, 2 unresolved discussions (waiting on @jmgrady)


deploy/scripts/kube_env.py line 77 at r4 (raw file):

def add_kube_opts(parser: argparse.ArgumentParser) -> None:
    """Add commandline arguments for KUbernetes tools."""

Capital U in KUbern...?


deploy/scripts/utils.py line 70 at r4 (raw file):

    or has the curr_selection as its only member.
    """
    if len(options) > 1:

If curr_selection is None and len(options)=1, the present algorithm returns None instead of the single entry in options. Is that okay?

Copy link
Collaborator Author

@jmgrady jmgrady left a comment

Choose a reason for hiding this comment

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

Reviewable status: 10 of 12 files reviewed, 1 unresolved discussion (waiting on @imnasnainaec and @jmgrady)


deploy/scripts/kube_env.py line 77 at r4 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

Capital U in KUbern...?

Done.


deploy/scripts/utils.py line 70 at r4 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

If curr_selection is None and len(options)=1, the present algorithm returns None instead of the single entry in options. Is that okay?

No, it is not (and it doesn't match the description!

I have added a test for the case you mentioned at the beginning of the function:

    if len(options) == 1 and curr_selection is not None and curr_selection == options[0]:
       return curr_selection 

If this condition is not met, it will prompt the user if len(options) >= 1 instead of strictly > so if the curr_selection is None the user will be prompted to select the option. I don't want to blindly take the single option because if it is not the correct one, The Combine could be installed on the wrong Kubernetes cluster or with the wrong AWS permissions.

Copy link
Collaborator Author

@jmgrady jmgrady left a comment

Choose a reason for hiding this comment

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

Reviewable status: 10 of 12 files reviewed, all discussions resolved (waiting on @jmgrady)


deploy/scripts/utils.py line 70 at r4 (raw file):

Previously, jmgrady (Jim Grady) wrote…

No, it is not (and it doesn't match the description!

I have added a test for the case you mentioned at the beginning of the function:

    if len(options) == 1 and curr_selection is not None and curr_selection == options[0]:
       return curr_selection 

If this condition is not met, it will prompt the user if len(options) >= 1 instead of strictly > so if the curr_selection is None the user will be prompted to select the option. I don't want to blindly take the single option because if it is not the correct one, The Combine could be installed on the wrong Kubernetes cluster or with the wrong AWS permissions.

Done.

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r5, all commit messages.
Reviewable status: 11 of 12 files reviewed, 2 unresolved discussions (waiting on @jmgrady)


deploy/scripts/utils.py line 80 at r5 (raw file):

                prompt_str = f"Enter {name}: "
            else:
                prompt_str = f"Enter {name}(Default: {curr_selection}): "

A space between {name} and (Default might be nice.


deploy/scripts/utils.py line 101 at r5 (raw file):

                            curr_selection = None
                    except ValueError:
                        curr_selection = None

It looks like an invalid user selection will cause the initial default to no longer be the default. If that's the case, is that okay?

Copy link
Collaborator Author

@jmgrady jmgrady left a comment

Choose a reason for hiding this comment

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

Reviewable status: 11 of 12 files reviewed, 1 unresolved discussion (waiting on @imnasnainaec and @jmgrady)


deploy/scripts/utils.py line 80 at r5 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

A space between {name} and (Default might be nice.

Done.


deploy/scripts/utils.py line 101 at r5 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

It looks like an invalid user selection will cause the initial default to no longer be the default. If that's the case, is that okay?

I don't have a problem with that. By entering something the first time it is safe to assume that the user does not want the default so they just need to select a valid option. This also conforms to the usual practice that Ctrl-C will just exit completely in the case that the user does not want any of the suggestions.

I did, however, update it so that it will reprint the list if an invalid option is selected.

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @jmgrady)

@jmgrady jmgrady merged commit 0498b7b into master Oct 13, 2022
@jmgrady jmgrady deleted the kube-context-guard branch October 13, 2022 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants