Skip to content

Commit

Permalink
feat: [PIPE-22743]: Refactor code to make it reusable, remove unneces…
Browse files Browse the repository at this point in the history
…sary fields, cleanup code (#516)

* feat: [PIPE-22743]: Refactor code to make it reusable, remove unnecessary fields, cleanup code

* fix comment
  • Loading branch information
vistaarjuneja authored Nov 20, 2024
1 parent 742ca73 commit 7d2cdbc
Show file tree
Hide file tree
Showing 87 changed files with 409 additions and 170 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"text/template"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/drone-runners/drone-runner-aws/internal/cloudinit"
"github.com/drone-runners/drone-runner-aws/app/cloudinit"
"github.com/drone-runners/drone-runner-aws/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
itypes "github.com/drone-runners/drone-runner-aws/internal/types"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
itypes "github.com/drone-runners/drone-runner-aws/app/types"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"

"github.com/sirupsen/logrus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package amazon

import (
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package amazon
import (
"testing"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
)

func Test_tempdir(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/sirupsen/logrus"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/drivers/anka/util.go → app/drivers/anka/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package anka

import "github.com/drone-runners/drone-runner-aws/internal/oshelp"
import "github.com/drone-runners/drone-runner-aws/app/oshelp"

func tempdir(inputOS string) string {
const dir = "anka"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/dchest/uniuri"
"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"

"github.com/sirupsen/logrus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"

"github.com/sirupsen/logrus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone/runner-go/logger"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/sirupsen/logrus"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"

"github.com/sirupsen/logrus"
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions internal/drivers/imanager.go → app/drivers/imanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"time"

"github.com/drone-runners/drone-runner-aws/command/config"
"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/store"
"github.com/drone-runners/drone-runner-aws/types"
Expand All @@ -16,10 +15,9 @@ type IManager interface {
Find(ctx context.Context, instanceID string) (*types.Instance, error)
GetInstanceByStageID(ctx context.Context, poolName, stage string) (*types.Instance, error)
Update(ctx context.Context, instance *types.Instance) error
AddTmate(env *config.EnvConfig) error
Add(pools ...Pool) error
StartInstancePurger(ctx context.Context, maxAgeBusy, maxAgeFree time.Duration, purgerTime time.Duration) error
Provision(ctx context.Context, poolName, runnerName, serverName, ownerID, resourceClass string, env *config.EnvConfig, query *types.QueryParams, agentConfig *types.GitspaceAgentConfig, storageConfig *types.StorageConfig) (*types.Instance, error) //nolint
Provision(ctx context.Context, poolName, serverName, ownerID, resourceClass string, query *types.QueryParams, gitspaceAgentConfig *types.GitspaceAgentConfig, storageConfig *types.StorageConfig) (*types.Instance, error) //nolint
Destroy(ctx context.Context, poolName, instanceID string, storageCleanupType *storage.CleanupType) error
BuildPools(ctx context.Context) error
CleanPools(ctx context.Context, destroyBusy, destroyFree bool) error
Expand Down
42 changes: 25 additions & 17 deletions internal/drivers/manager.go → app/drivers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/drone-runners/drone-runner-aws/app/certs"
itypes "github.com/drone-runners/drone-runner-aws/app/types"
"github.com/drone-runners/drone-runner-aws/command/config"
"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/certs"
itypes "github.com/drone-runners/drone-runner-aws/internal/types"
"github.com/drone-runners/drone-runner-aws/store"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"
Expand Down Expand Up @@ -53,6 +53,7 @@ func New(
return &Manager{
globalCtx: globalContext,
instanceStore: instanceStore,
tmate: types.Tmate(env.Tmate),
runnerName: env.Runner.Name,
liteEnginePath: env.LiteEngine.Path,
harnessTestBinaryURI: env.Settings.HarnessTestBinaryURI,
Expand All @@ -65,17 +66,23 @@ func NewManager(
globalContext context.Context,
instanceStore store.InstanceStore,
stageOwnerStore store.StageOwnerStore,
env *config.EnvConfig,
tmate types.Tmate,
runnerName,
liteEnginePath,
harnessTestBinaryURI,
pluginBinaryURI,
autoInjectionBinaryURI string,
) *Manager {
return &Manager{
globalCtx: globalContext,
instanceStore: instanceStore,
tmate: tmate,
stageOwnerStore: stageOwnerStore,
runnerName: env.Runner.Name,
liteEnginePath: env.LiteEngine.Path,
harnessTestBinaryURI: env.Settings.HarnessTestBinaryURI,
pluginBinaryURI: env.Settings.PluginBinaryURI,
autoInjectionBinaryURI: env.Settings.AutoInjectionBinaryURI,
runnerName: runnerName,
liteEnginePath: liteEnginePath,
harnessTestBinaryURI: harnessTestBinaryURI,
pluginBinaryURI: pluginBinaryURI,
autoInjectionBinaryURI: autoInjectionBinaryURI,
}
}

Expand Down Expand Up @@ -174,11 +181,6 @@ func (m *Manager) Update(ctx context.Context, instance *types.Instance) error {
return m.instanceStore.Update(ctx, instance)
}

func (m *Manager) AddTmate(env *config.EnvConfig) error {
m.tmate = types.Tmate(env.Tmate)
return nil
}

func (m *Manager) Add(pools ...Pool) error {
if len(pools) == 0 {
return nil
Expand Down Expand Up @@ -312,10 +314,16 @@ func (m *Manager) StartInstancePurger(ctx context.Context, maxAgeBusy, maxAgeFre

// Provision returns an instance for a job execution and tags it as in use.
// This method and BuildPool method contain logic for maintaining pool size.
func (m *Manager) Provision(ctx context.Context, poolName, runnerName, serverName, ownerID, resourceClass string, env *config.EnvConfig, query *types.QueryParams, gitspaceAgentConfig *types.GitspaceAgentConfig, storageConfig *types.StorageConfig) (*types.Instance, error) { //nolint
m.runnerName = runnerName
m.liteEnginePath = env.LiteEngine.Path
m.tmate = types.Tmate(env.Tmate)
func (m *Manager) Provision(
ctx context.Context,
poolName,
serverName,
ownerID,
resourceClass string,
query *types.QueryParams,
gitspaceAgentConfig *types.GitspaceAgentConfig,
storageConfig *types.StorageConfig,
) (*types.Instance, error) { //nolint

pool := m.poolMap[poolName]
if pool == nil {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

cf "github.com/drone-runners/drone-runner-aws/command/config"
"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"
"github.com/hashicorp/nomad/api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"time"

cf "github.com/drone-runners/drone-runner-aws/command/config"
"github.com/drone-runners/drone-runner-aws/internal/cloudinit"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/cloudinit"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/hashicorp/nomad/api"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

cf "github.com/drone-runners/drone-runner-aws/command/config"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/hashicorp/nomad/api"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/google/uuid"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"time"

"github.com/drone-runners/drone-runner-aws/command/harness/storage"
"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/lehelper"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/lehelper"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/drone/runner-go/logger"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/sirupsen/logrus"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"syscall"
"time"

"github.com/drone-runners/drone-runner-aws/internal/drivers"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/drivers"
"github.com/drone-runners/drone-runner-aws/app/oshelp"

"github.com/sirupsen/logrus"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions internal/lehelper/lehelper.go → app/lehelper/lehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

"github.com/drone-runners/drone-runner-aws/internal/cloudinit"
"github.com/drone-runners/drone-runner-aws/internal/oshelp"
"github.com/drone-runners/drone-runner-aws/app/cloudinit"
"github.com/drone-runners/drone-runner-aws/app/oshelp"
"github.com/drone-runners/drone-runner-aws/types"
"github.com/harness/lite-engine/api"
lehttp "github.com/harness/lite-engine/cli/client"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7d2cdbc

Please sign in to comment.