Skip to content
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

[ADXT-783] Made Runner interface for Remote and Local runners #1288

Merged
merged 21 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0f63992
[refactor-runner-adxt-783] Started refactoring
CelianR Dec 11, 2024
5057672
[refactor-runner-adxt-783] wip: components/os
CelianR Dec 11, 2024
f645c6d
[refactor-runner-adxt-783] Can build
CelianR Dec 11, 2024
254bf8f
[refactor-runner-adxt-783] Copy file
CelianR Dec 11, 2024
e9255ef
[refactor-runner-adxt-783] ad: Fixed
CelianR Dec 11, 2024
2b64d46
[refactor-runner-adxt-783] runner: Fixed lock warning
CelianR Dec 11, 2024
ab0b21a
[refactor-runner-adxt-783] wip
CelianR Dec 12, 2024
c0c3ac4
[refactor-runner-adxt-783] Fixed little error
CelianR Dec 13, 2024
c49c5fe
Fixed bug
CelianR Dec 16, 2024
d5ab53e
[refactor-runner-adxt-783] Cleaned code
CelianR Dec 17, 2024
2448f9d
[refactor-runner-adxt-783] command: Fixed env + refactored podman vm.go
CelianR Dec 17, 2024
74d4b02
[refactor-runner-adxt-783] Tested and cleaned code
CelianR Dec 18, 2024
846ecc0
Merge branch 'main' into celian/refactor-runner-adxt-783
CelianR Dec 18, 2024
18bea62
[refactor-runner-adxt-783] Cleaned code
CelianR Dec 18, 2024
3656bda
[refactor-runner-adxt-783] Cleaned code
CelianR Dec 18, 2024
36bcf5a
[refactor-runner-adxt-783] env: Vars are exported and not passed to t…
CelianR Dec 18, 2024
d1ef99f
[refactor-runner-adxt-783] renamed: MoveRemoteFile -> MoveFile
CelianR Dec 23, 2024
a6e0c8e
[refactor-runner-adxt-783] copy*file are not exported anymore
CelianR Dec 23, 2024
8654e05
[refactor-runner-adxt-783] copy*file: Moved implementation to commands
CelianR Dec 23, 2024
924ee08
Merge branch 'main' into celian/refactor-runner-adxt-783
CelianR Dec 23, 2024
ea4c5e1
[refactor-runner-adxt-783] Undone path sanitize modifications for cop…
CelianR Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions components/activedirectory/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package activedirectory
import (
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components/command"
pulumiRemote "github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumiverse/pulumi-time/sdk/go/time"
)
Expand Down Expand Up @@ -49,7 +48,7 @@ func WithDomain(domainFqdn, domainAdmin, domainAdminPassword string) Option {
}

func (adCtx *activeDirectoryContext) joinActiveDirectoryDomain(params *JoinDomainConfiguration) error {
var joinCmd *pulumiRemote.Command
var joinCmd command.Command
joinCmd, err := adCtx.comp.host.OS.Runner().Command(adCtx.comp.namer.ResourceName("join-domain"), &command.Args{
Create: pulumi.Sprintf(`
Add-Computer -DomainName %s -Credential (New-Object System.Management.Automation.PSCredential -ArgumentList %s, %s)
Expand Down Expand Up @@ -90,7 +89,7 @@ func WithDomainController(domainFqdn, adminPassword string) func(*Configuration)
}

func (adCtx *activeDirectoryContext) installDomainController(params *DomainControllerConfiguration) error {
var installCmd *pulumiRemote.Command
var installCmd command.Command
installCmd, err := adCtx.comp.host.OS.Runner().Command(adCtx.comp.namer.ResourceName("install-forest"), &command.Args{
Create: pulumi.Sprintf(`
Add-WindowsFeature -name ad-domain-services -IncludeManagementTools;
Expand Down
17 changes: 8 additions & 9 deletions components/command/filemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import (
"runtime"
"strings"

"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type FileManager struct {
runner *Runner
runner Runner
command OSCommand
}

func NewFileManager(runner *Runner) *FileManager {
func NewFileManager(runner Runner) *FileManager {
return &FileManager{
runner: runner,
command: runner.osCommand,
command: runner.OsCommand(),
}
}

Expand All @@ -31,26 +30,26 @@ func (fm *FileManager) IsPathAbsolute(path string) bool {
}

// CreateDirectoryFromPulumiString if it does not exist from directory name as a Pulumi String
func (fm *FileManager) CreateDirectoryFromPulumiString(name string, remotePath pulumi.String, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectoryFromPulumiString(name string, remotePath pulumi.String, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
return fm.command.CreateDirectory(fm.runner, name, remotePath, useSudo, opts...)
}

// CreateDirectoryForFile if the directory does not exist
// To avoid pulumi.URN collisions if multiple files use the same directory, use the full filePath as URN and path.Split out the folderPath for creation
func (fm *FileManager) CreateDirectoryForFile(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectoryForFile(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
// if given just a directory path, path.Split returns "" as file
// eg. path.Split("/a/b/c/") -> "/a/b/c/", ""
folderPath, _ := path.Split(remotePath)
return fm.command.CreateDirectory(fm.runner, "create-directory-"+remotePath, pulumi.String(folderPath), useSudo, opts...)
}

// CreateDirectory if it does not exist
func (fm *FileManager) CreateDirectory(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectory(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
return fm.command.CreateDirectory(fm.runner, "create-directory-"+remotePath, pulumi.String(remotePath), useSudo, opts...)
}

// TempDirectory creates a temporary directory
func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceOption) (*remote.Command, string, error) {
func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceOption) (Command, string, error) {
tempDir := path.Join(fm.command.GetTemporaryDirectory(), folderName)
folderCmd, err := fm.CreateDirectory(tempDir, false, opts...)
return folderCmd, tempDir, err
Expand All @@ -59,7 +58,7 @@ func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceO
// HomeDirectory creates a directory in home directory, if it does not exist
// A home directory is a file system directory on a multi-user operating system containing files for a given user of the system.
// It does not require sudo, using sudo in home directory allows to change default ownership and it is discouraged.
func (fm *FileManager) HomeDirectory(folderName string, opts ...pulumi.ResourceOption) (*remote.Command, string, error) {
func (fm *FileManager) HomeDirectory(folderName string, opts ...pulumi.ResourceOption) (Command, string, error) {
homeDir := path.Join(fm.command.GetHomeDirectory(), folderName)
folderCmd, err := fm.CreateDirectory(homeDir, false, opts...)
return folderCmd, homeDir, err
Expand Down
25 changes: 17 additions & 8 deletions components/command/osCommand.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package command

import (
"runtime"
"strings"

"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

Expand All @@ -13,11 +13,12 @@ type OSCommand interface {
GetHomeDirectory() string

CreateDirectory(
runner *Runner,
runner Runner,
resourceName string,
remotePath pulumi.StringInput,
useSudo bool,
opts ...pulumi.ResourceOption) (*remote.Command, error)
opts ...pulumi.ResourceOption) (Command, error)
MoveRemoteFile(runner Runner, name string, source, destination pulumi.StringInput, sudo bool, opts ...pulumi.ResourceOption) (Command, error)
CelianR marked this conversation as resolved.
Show resolved Hide resolved

BuildCommandString(
command pulumi.StringInput,
Expand All @@ -28,7 +29,7 @@ type OSCommand interface {

IsPathAbsolute(path string) bool

NewCopyFile(runner *Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
NewCopyFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
}

// ------------------------------
Expand All @@ -38,13 +39,13 @@ type OSCommand interface {
const backupExtension = "pulumi.backup"

func createDirectory(
runner *Runner,
runner Runner,
name string,
createCmd string,
deleteCmd string,
useSudo bool,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
) (Command, error) {
// If the folder was previously created, make sure to delete it before creating it.
opts = append(opts, pulumi.DeleteBeforeReplace(true))
return runner.Command(name,
Expand Down Expand Up @@ -73,13 +74,13 @@ func buildCommandString(
}

func copyRemoteFile(
runner *Runner,
runner Runner,
name string,
createCommand pulumi.StringInput,
deleteCommand pulumi.StringInput,
useSudo bool,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
) (Command, error) {
return runner.Command(name,
&Args{
Create: createCommand,
Expand All @@ -88,3 +89,11 @@ func copyRemoteFile(
Triggers: pulumi.Array{createCommand, deleteCommand, pulumi.BoolPtr(useSudo)},
}, opts...)
}

func NewLocalOSCommand() OSCommand {
if runtime.GOOS == "windows" {
return NewWindowsOSCommand()
}

return NewUnixOSCommand()
}
13 changes: 6 additions & 7 deletions components/command/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ import (

"github.com/DataDog/test-infra-definitions/common/namer"
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type GenericPackageManager struct {
namer namer.Namer
updateDBCommand *remote.Command
runner *Runner
updateDBCommand Command
runner Runner
opts []pulumi.ResourceOption
installCmd string
updateCmd string
env pulumi.StringMap
}

func NewGenericPackageManager(
runner *Runner,
runner Runner,
name string,
installCmd string,
updateCmd string,
env pulumi.StringMap,
) *GenericPackageManager {
packageManager := &GenericPackageManager{
namer: namer.NewNamer(runner.e.Ctx(), name),
namer: namer.NewNamer(runner.Environment().Ctx(), name),
runner: runner,
installCmd: installCmd,
updateCmd: updateCmd,
Expand All @@ -37,7 +36,7 @@ func NewGenericPackageManager(
return packageManager
}

func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer, checkBinary string, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer, checkBinary string, opts ...pulumi.ResourceOption) (Command, error) {
opts = append(opts, m.opts...)
if m.updateCmd != "" {
updateDB, err := m.updateDB(opts)
Expand Down Expand Up @@ -76,7 +75,7 @@ func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer,
return cmd, nil
}

func (m *GenericPackageManager) updateDB(opts []pulumi.ResourceOption) (*remote.Command, error) {
func (m *GenericPackageManager) updateDB(opts []pulumi.ResourceOption) (Command, error) {
if m.updateDBCommand != nil {
return m.updateDBCommand, nil
}
Expand Down
Loading
Loading