Skip to content

Commit

Permalink
fix: panics on command initialsation (#4322) (#4323)
Browse files Browse the repository at this point in the history
* fix: panics on command initialsation

Signed-off-by: Javier Lopez <[email protected]>

* fix: panic

Signed-off-by: Javier Lopez <[email protected]>

---------

Signed-off-by: Javier Lopez <[email protected]>
(cherry picked from commit ad8c37c)

Co-authored-by: Javier López Barba <[email protected]>
  • Loading branch information
github-actions[bot] and jLopezbarb committed May 29, 2024
1 parent 13564db commit 85dd84d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Command struct {
AnalyticsTracker AnalyticsTrackerInterface
IoCtrl *io.Controller
K8sLogger *io.K8sLogger
insightsTracker buildDeployTrackerInterface
InsightsTracker buildDeployTrackerInterface

PipelineType model.Archetype
// onCleanUp is a list of functions to be executed when the execution is interrupted. This is a hack
Expand Down Expand Up @@ -237,7 +237,7 @@ func Deploy(ctx context.Context, at AnalyticsTrackerInterface, insightsTracker b
K8sLogger: k8sLogger,

onCleanUp: []cleanUpFunc{},
insightsTracker: insightsTracker,
InsightsTracker: insightsTracker,
}
startTime := time.Now()

Expand All @@ -251,7 +251,7 @@ func Deploy(ctx context.Context, at AnalyticsTrackerInterface, insightsTracker b
if options.Manifest != nil {
namespace = options.Manifest.Namespace
}
c.insightsTracker.TrackDeploy(ctx, options.Name, namespace, err == nil)
c.InsightsTracker.TrackDeploy(ctx, options.Name, namespace, err == nil)
c.TrackDeploy(options.Manifest, options.RunInRemote, startTime, err)
exit <- err
}()
Expand Down
8 changes: 7 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ type buildDeployTrackerInterface interface {
deployTrackerInterface
}

type analyticsTracker interface {
buildTrackerInterface
TrackDeploy(analytics.DeployMetadata)
}

// Init creates okteto manifest
func Init(at buildTrackerInterface, insights buildDeployTrackerInterface, ioCtrl *io.Controller) *cobra.Command {
func Init(at analyticsTracker, insights buildDeployTrackerInterface, ioCtrl *io.Controller) *cobra.Command {
opts := &manifest.InitOpts{}
cmd := &cobra.Command{
Use: "init",
Expand Down Expand Up @@ -79,6 +84,7 @@ func Init(at buildTrackerInterface, insights buildDeployTrackerInterface, ioCtrl
AnalyticsTracker: at,
InsightsTracker: insights,
IoCtrl: ioCtrl,
K8sLogger: io.NewK8sLogger(),
}

if opts.Version1 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/manifest/init-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type buildDeployTrackerInterface interface {
type Command struct {
manifest *model.Manifest
K8sClientProvider okteto.K8sClientProviderWithLogger
AnalyticsTracker buildTrackerInterface
AnalyticsTracker deploy.AnalyticsTrackerInterface
InsightsTracker buildDeployTrackerInterface

IoCtrl *io.Controller
Expand Down Expand Up @@ -249,6 +249,9 @@ func (mc *Command) deploy(ctx context.Context, opts *InitOpts) error {
DeployWaiter: deploy.NewDeployWaiter(mc.K8sClientProvider, mc.K8sLogger),
EndpointGetter: deploy.NewEndpointGetter,
IoCtrl: mc.IoCtrl,
InsightsTracker: mc.InsightsTracker,
K8sLogger: mc.K8sLogger,
AnalyticsTracker: mc.AnalyticsTracker,
}

err = c.Run(ctx, &deploy.Options{
Expand Down
11 changes: 10 additions & 1 deletion cmd/up/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ type analyticsTrackerInterface interface {
}

type buildTrackerInterface interface {
TrackImageBuild(context.Context, *analytics.ImageBuildMetadata)
TrackImageBuild(ctx context.Context, meta *analytics.ImageBuildMetadata)
}

type deployTrackerInterface interface {
TrackDeploy(ctx context.Context, name, namespace string, success bool)
}

type buildDeployTrackerInterface interface {
buildTrackerInterface
deployTrackerInterface
}

// upContext is the common context of all operations performed during the up command
Expand Down
14 changes: 11 additions & 3 deletions cmd/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Options struct {
}

// Up starts a development container
func Up(at analyticsTrackerInterface, insights buildTrackerInterface, ioCtrl *io.Controller, k8sLogger *io.K8sLogger) *cobra.Command {
func Up(at analyticsTrackerInterface, insights buildDeployTrackerInterface, ioCtrl *io.Controller, k8sLogger *io.K8sLogger) *cobra.Command {
upOptions := &Options{}
cmd := &cobra.Command{
Use: "up [service]",
Expand Down Expand Up @@ -169,7 +169,7 @@ func Up(at analyticsTrackerInterface, insights buildTrackerInterface, ioCtrl *io
return err
}

oktetoManifest, err = LoadManifestWithInit(ctx, upOptions.K8sContext, upOptions.Namespace, upOptions.ManifestPath)
oktetoManifest, err = LoadManifestWithInit(ctx, upOptions.K8sContext, upOptions.Namespace, upOptions.ManifestPath, at, ioCtrl, insights, k8sLogger)
if err != nil {
return err
}
Expand Down Expand Up @@ -219,6 +219,10 @@ func Up(at analyticsTrackerInterface, insights buildTrackerInterface, ioCtrl *io
if answer {
mc := &manifest.Command{
K8sClientProvider: okteto.NewK8sClientProviderWithLogger(k8sLogger),
AnalyticsTracker: at,
InsightsTracker: insights,
IoCtrl: ioCtrl,
K8sLogger: k8sLogger,
}
if upOptions.ManifestPath == "" {
upOptions.ManifestPath = utils.DefaultManifest
Expand Down Expand Up @@ -455,7 +459,7 @@ func (o *Options) AddArgs(cmd *cobra.Command, args []string) error {
return nil
}

func LoadManifestWithInit(ctx context.Context, k8sContext, namespace, devPath string) (*model.Manifest, error) {
func LoadManifestWithInit(ctx context.Context, k8sContext, namespace, devPath string, at analyticsTrackerInterface, ioCtrl *io.Controller, insights buildDeployTrackerInterface, k8sLogger *io.K8sLogger) (*model.Manifest, error) {
dir, err := os.Getwd()
if err != nil {
return nil, err
Expand All @@ -471,6 +475,10 @@ func LoadManifestWithInit(ctx context.Context, k8sContext, namespace, devPath st

mc := &manifest.Command{
K8sClientProvider: okteto.NewK8sClientProvider(),
AnalyticsTracker: at,
IoCtrl: ioCtrl,
InsightsTracker: insights,
K8sLogger: k8sLogger,
}
manifest, err := mc.RunInitV2(ctx, &manifest.InitOpts{DevPath: devPath, ShowCTA: false, Workdir: dir})
if err != nil {
Expand Down

0 comments on commit 85dd84d

Please sign in to comment.