Skip to content

Commit

Permalink
fix(endpoints): detect namespace from manifest and check for manifest…
Browse files Browse the repository at this point in the history
… file

Signed-off-by: Andrea Falzetti <andrea@okteto.com>
  • Loading branch information
andreafalzetti committed Feb 20, 2024
1 parent 31cbb7c commit a4e7a04
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions cmd/deploy/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import (
"strings"

contextCMD "github.com/okteto/okteto/cmd/context"
"github.com/okteto/okteto/cmd/utils"
"github.com/okteto/okteto/pkg/devenvironment"
"github.com/okteto/okteto/pkg/endpoints"
oktetoErrors "github.com/okteto/okteto/pkg/errors"
"github.com/okteto/okteto/pkg/format"
"github.com/okteto/okteto/pkg/k8s/ingresses"
oktetoLog "github.com/okteto/okteto/pkg/log"
"github.com/okteto/okteto/pkg/log/io"
"github.com/okteto/okteto/pkg/model"
"github.com/okteto/okteto/pkg/okteto"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -83,6 +82,7 @@ func NewEndpointGetter(k8sLogger *io.K8sLogger) (EndpointGetter, error) {
// Endpoints deploys the okteto manifest
func Endpoints(ctx context.Context, k8sLogger *io.K8sLogger) *cobra.Command {
options := &EndpointsOptions{}
fs := afero.NewOsFs()
cmd := &cobra.Command{
Use: "endpoints",
Short: "Show endpoints for an environment",
Expand All @@ -93,32 +93,17 @@ func Endpoints(ctx context.Context, k8sLogger *io.K8sLogger) *cobra.Command {
return err
}
options.ManifestPath = model.GetManifestPathFromWorkdir(options.ManifestPath, workdir)
}

ctxResource, err := utils.LoadManifestContext(options.ManifestPath)
if err != nil {
if oktetoErrors.IsNotExist(err) {
ctxResource = &model.ContextResource{}
// check whether the manifest file provided by -f exists or not
if _, err := fs.Stat(options.ManifestPath); err != nil {
return fmt.Errorf("%s file doesn't exist", options.ManifestPath)
}
}

if err := ctxResource.UpdateNamespace(options.Namespace); err != nil {
return err
}

if err := ctxResource.UpdateContext(options.K8sContext); err != nil {
return err
}

ctxOptions := &contextCMD.Options{
Context: ctxResource.Context,
Namespace: ctxResource.Namespace,
}
if options.Output == "" {
ctxOptions.Show = true
}
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); err != nil {
if err := contextCMD.NewContextCommand().Run(ctx, &contextCMD.Options{Namespace: options.Namespace}); err != nil {
return err
}
}

eg, err := NewEndpointGetter(k8sLogger)
Expand Down

0 comments on commit a4e7a04

Please sign in to comment.