Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Add use-context command #96

Merged

Conversation

rafiramadhana
Copy link
Contributor

@rafiramadhana rafiramadhana commented Sep 17, 2023

Why this matters

Resolves #89

Solution

Add command use-context to use the selected current context.

How to test it

Run the e2e.yml.

Note to reviewers

# fails if command succeeds
! layerform config select-context test-does-not-exist # context does not exist

layerform config set-context test-local -t local --dir test && layerform config select-context test-local
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still wondering what is the default layerform/configurations.yml file in our CI/CD testing env.

As the mitigation to ensure that a config exists, I do set-context first to create a config.

Copy link
Member

@vieiralucas vieiralucas Sep 17, 2023

Choose a reason for hiding this comment

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

Well, it is the last one that run in the previous step (check line 50).
At this point, the current context is the test-local, your set-context ends up being a no-op.
What I think you should do to test is somehow check if the use-context actually works.
You can use the config get-contexts command alongside with grep for that. The selected context will have a * in it's line.
I'll make a comment with suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 9e15b35

Copy link
Member

@vieiralucas vieiralucas left a comment

Choose a reason for hiding this comment

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

Hi @rafiramadhana,

Thank you so much for the contribution, overall the implementation seems correct.
I think you got confused with the name of the command, the idea was to call it use-context. Do you mind changing it? Also change the name of the file and stuff.

os.Exit(1)
}

fmt.Fprintf(os.Stdout, "Context \"%s\" selected.\n", name)
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to:

Suggested change
fmt.Fprintf(os.Stdout, "Context \"%s\" selected.\n", name)
fmt.Fprintf(os.Stdout, "Switched to context \"%s\".\n", name)

FYI I'm getting inspiration from kubectl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 978e3c6

if !ok {
fmt.Fprintf(
os.Stderr,
"context %s does not exist\n",
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to:

Suggested change
"context %s does not exist\n",
"no context exists with the name \"%s\".\n",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 978e3c6

Fix typo in grep command.
@rafiramadhana
Copy link
Contributor Author

@vieiralucas it looks like the configure s3 pipeline is broken

fail to get layers backend: fail to read file: fail to load layers from s3: NoCredentialProviders: no valid providers in chain. Deprecated.
	For verbose messaging see aws.Config.CredentialsChainVerboseErrors
Error: Process completed with exit code 1.

https://github.com/ergomake/layerform/actions/runs/6229934241/job/16909208767?pr=96

could this be related to my PR changes?

@rafiramadhana rafiramadhana changed the title Add select context Add use-context command Sep 19, 2023
@vieiralucas
Copy link
Member

Hi @rafiramadhana, this happens because your changes to the tests leave a context of type s3 as active. Then later commands will try to use s3 as the backend but we don't have AWS setup here in the workflows.
You can just switch the ortder of the tests you added, put the test-local as the last one.

Comment on lines 57 to 67
# switch context to test-local
layerform config use-context test-local
layerform config get-contexts | tee usecontext
grep -E '^\*\s+test-local' usecontext
! grep -E '^\*\s+test-s3' usecontext

# switch context to test-s3
layerform config use-context test-s3
layerform config get-contexts | tee usecontext
! grep -E '^\*\s+test-local' usecontext
grep -E '^\*\s+test-s3' usecontext
Copy link
Member

Choose a reason for hiding this comment

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

I think this change should "fix" the tests

Suggested change
# switch context to test-local
layerform config use-context test-local
layerform config get-contexts | tee usecontext
grep -E '^\*\s+test-local' usecontext
! grep -E '^\*\s+test-s3' usecontext
# switch context to test-s3
layerform config use-context test-s3
layerform config get-contexts | tee usecontext
! grep -E '^\*\s+test-local' usecontext
grep -E '^\*\s+test-s3' usecontext
# switch context to test-s3
layerform config use-context test-s3
layerform config get-contexts | tee usecontext
! grep -E '^\*\s+test-local' usecontext
grep -E '^\*\s+test-s3' usecontext
# switch context to test-local
layerform config use-context test-local
layerform config get-contexts | tee usecontext
grep -E '^\*\s+test-local' usecontext
! grep -E '^\*\s+test-s3' usecontext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 3f94a83

thanks for the pointers

Copy link
Member

@vieiralucas vieiralucas left a comment

Choose a reason for hiding this comment

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

Awesome @rafiramadhana

Thank you so much for this <3

@vieiralucas vieiralucas merged commit 5055275 into briefercloud:main Sep 20, 2023
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a command to select the current context
2 participants