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
Fix okteto endpoints
namespace detection from okteto.yml
#4186
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
5ded92b
to
4994853
Compare
… file Signed-off-by: Andrea Falzetti <andrea@okteto.com>
4994853
to
a4e7a04
Compare
okteto endpoints
namespace detection from okteto.yml
} | ||
if err := contextCMD.NewContextCommand().Run(ctx, ctxOptions); err != nil { | ||
return err | ||
// Loads, updates and uses the context from path. If not found, it creates and uses a new context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same logic used in okteto deploy
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4186 +/- ##
==========================================
+ Coverage 45.55% 45.59% +0.03%
==========================================
Files 289 289
Lines 27108 27101 -7
==========================================
+ Hits 12350 12356 +6
+ Misses 13672 13661 -11
+ Partials 1086 1084 -2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing it I see that with the code in this PR, the context used is not printed in the CLI output.
You can see that when I use ok
(the binary built with the changes in this branch), the context is not displayed and it directly shows the endpoints
If I use okteto
(latest stable CLI version), it shows the context used (the wrong one)
cmd/context/utils.go
Outdated
@@ -224,7 +224,7 @@ func LoadStackWithContext(ctx context.Context, name, namespace string, stackPath | |||
} | |||
|
|||
// LoadContextFromPath initializes the okteto context taking into account command flags and manifest namespace/context fields | |||
func LoadContextFromPath(ctx context.Context, namespace, k8sContext, path string) error { | |||
func LoadContextFromPath(ctx context.Context, namespace, k8sContext, path string, defaultCtxOpts *Options) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a pointer for defaultCtxOpts
? I see we always pass a value. We could just pass the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to be pointer actually, the code is much better with a value type, changed in e0b7d6b
thanks!
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Good catch @ifbyol! I made the |
cmd/deploy/endpoints.go
Outdated
if err := contextCMD.NewContextCommand().Run(ctx, ctxOptions); err != nil { | ||
return err | ||
// Loads, updates and uses the context from path. If not found, it creates and uses a new context | ||
if err := contextCMD.LoadContextFromPath(ctx, options.Namespace, options.K8sContext, options.ManifestPath, contextCMD.Options{Show: options.Output == ""}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why for the endpoints command the Show
value would depend on the options.Output value but for the deploy and destroy command it is always true
. What is special about the endpoints
command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the okteto endpoints
command can be used as follows:
okteto endpoints --output=json | jq XYZ
or
okteto endpoints --output=md > README.md
In those scenarios we cannot output the plaintext header or it would break those scenarios. For build
and deploy
we don't have such use-cases, or at least I am not aware or them, so the Show
value - only for endpoints
depend on its --output
flag.
Worth mentioning that for "plaintext" in most commands of the CLI we use empty string. So by default an empty --output
flag means "plaintext". So the check is a bit odd. I hope that with 3.0 we can add a third allowed value for --output plaintext
or --output text
to make this more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For deploy
and destroy
we have the global flag --log-output
which could be also json
(I was confusing the flag output with that global flag). I was testing deploy and destroy, and when the --log-output
flag is set, we are not displaying the context information even if we set Show: true
in the context.
I see it working fine but I think this is confusing for the user. If I execute okteto endpoints --log-output=json
it doesn't print anything in the output
This comment was marked as off-topic.
This comment was marked as off-topic.
if err := contextCMD.NewContextCommand().Run(ctx, ctxOptions); err != nil { | ||
return err | ||
// false for 'json' and 'md' to avoid breaking their syntax | ||
showCtxHeader := options.Output == "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 Thanks for the comment clarifying the case
Proposed changes
okteto endpoints
ignores the propertynamespace
of theokteto.yml
.How to validate
okteto.yml
and add a top-levelnamespace: <NS2>
(replace<NS2>
with a namespace different from NS1)okteto endpoints
and observe how the CLI outputsUsing <NS1> @ <Context> as context
Build the CLI from this PR and repeat the steps:
okteto endpoints
print the correct namespaceExtra:
Currently if you run
okteto endpoints -f not-exists.yml
the endoints cmd falls back onokteto.yml
. This behavior is inconsistent with other cmds so I've changed it to return an error (likeokteto deploy
).Test Scenarios
okteto endpoints
okteto endpoints -n <NS>
okteto endpoints
withnamespace: <NS>
CLI Quality Reminders 🔧
For both authors and reviewers: