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

feat:[CI-15644]: add image name to dlite #539

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion app/drivers/imanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type IManager interface {
Update(ctx context.Context, instance *types.Instance) error
Add(pools ...Pool) error
StartInstancePurger(ctx context.Context, maxAgeBusy, maxAgeFree time.Duration, purgerTime time.Duration) error
Provision(ctx context.Context, poolName, serverName, ownerID, resourceClass string, query *types.QueryParams, gitspaceAgentConfig *types.GitspaceAgentConfig, storageConfig *types.StorageConfig) (*types.Instance, error) //nolint
Provision(ctx context.Context, poolName, serverName, ownerID, resourceClass string, imageName 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
11 changes: 7 additions & 4 deletions app/drivers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (m *Manager) Provision(
serverName,
ownerID,
resourceClass string,
imageName string,
query *types.QueryParams,
gitspaceAgentConfig *types.GitspaceAgentConfig,
storageConfig *types.StorageConfig,
Expand All @@ -335,7 +336,7 @@ func (m *Manager) Provision(
if pool.Driver.DriverName() != string(types.Nomad) && pool.Driver.DriverName() != string(types.Google) {
return nil, fmt.Errorf("incorrect pool, gitspaces is only supported on nomad/google")
}
inst, err := m.setupInstance(ctx, pool, serverName, ownerID, resourceClass, true, gitspaceAgentConfig, storageConfig)
inst, err := m.setupInstance(ctx, pool, serverName, ownerID, resourceClass, imageName, true, gitspaceAgentConfig, storageConfig)
return inst, err
}

Expand All @@ -358,7 +359,7 @@ func (m *Manager) Provision(
return nil, ErrorNoInstanceAvailable
}
var inst *types.Instance
inst, err = m.setupInstance(ctx, pool, serverName, ownerID, resourceClass, true, gitspaceAgentConfig, storageConfig)
inst, err = m.setupInstance(ctx, pool, serverName, ownerID, resourceClass, imageName, true, gitspaceAgentConfig, storageConfig)
if err != nil {
return nil, fmt.Errorf("provision: failed to create instance: %w", err)
}
Expand Down Expand Up @@ -389,7 +390,7 @@ func (m *Manager) Provision(
// the go routine here uses the global context because this function is called
// from setup API call (and we can't use HTTP request context for async tasks)
go func(ctx context.Context) {
_, _ = m.setupInstance(ctx, pool, serverName, "", "", false, nil, nil)
_, _ = m.setupInstance(ctx, pool, serverName, "", "", "", false, nil, nil)
}(m.globalCtx)

return inst, nil
Expand Down Expand Up @@ -550,7 +551,7 @@ func (m *Manager) buildPool(ctx context.Context, pool *poolEntry, tlsServerName
defer wg.Done()

// generate certs cert
inst, err := m.setupInstance(ctx, pool, tlsServerName, "", "", false, nil, nil)
inst, err := m.setupInstance(ctx, pool, tlsServerName, "", "", "", false, nil, nil)
if err != nil {
logr.WithError(err).Errorln("build pool: failed to create instance")
return
Expand Down Expand Up @@ -582,6 +583,7 @@ func (m *Manager) setupInstance(
tlsServerName,
ownerID,
resourceClass string,
imageName string,
inuse bool,
agentConfig *types.GitspaceAgentConfig,
storageConfig *types.StorageConfig,
Expand All @@ -602,6 +604,7 @@ func (m *Manager) setupInstance(
createOptions.Tmate = m.tmate
createOptions.AccountID = ownerID
createOptions.ResourceClass = resourceClass
createOptions.ImageName = imageName
if storageConfig != nil {
createOptions.StorageOpts = types.StorageOpts{
CephPoolIdentifier: storageConfig.CephPoolIdentifier,
Expand Down
5 changes: 5 additions & 0 deletions app/drivers/nomad/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (p *config) Create(ctx context.Context, opts *types.InstanceCreateOpts) (*t
class = p.virtualizer.GetGlobalAccountID()
}

image := opts.ImageName
if image == "" {
image = p.vmImage
raghavharness marked this conversation as resolved.
Show resolved Hide resolved
}

// Create a resource job which occupies resources until the VM is alive to avoid
// oversubscribing the node
var resourceJob *api.Job
Expand Down
3 changes: 2 additions & 1 deletion command/harness/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type SetupVMRequest struct {
LogKey string `json:"log_key"`
Context Context `json:"context,omitempty"`
ResourceClass string `json:"resource_class"`
ImageName string `json:"image_name"`
api.SetupRequest `json:"setup_request"`
GitspaceAgentConfig types.GitspaceAgentConfig `json:"gitspace_agent_config"`
StorageConfig types.StorageConfig `json:"storage_config"`
Expand Down Expand Up @@ -230,7 +231,7 @@ func handleSetup(
RunnerName: runnerName,
}
}
instance, err := poolManager.Provision(ctx, pool, poolManager.GetTLSServerName(), owner, r.ResourceClass, query, &r.GitspaceAgentConfig, &r.StorageConfig)
instance, err := poolManager.Provision(ctx, pool, poolManager.GetTLSServerName(), owner, r.ResourceClass, r.ImageName, query, &r.GitspaceAgentConfig, &r.StorageConfig)
if err != nil {
return nil, fmt.Errorf("failed to provision instance: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion command/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *setupCommand) run(*kingpin.ParseContext) error { //nolint
Fatalln("setup: unable to add pool")
}
// provision
instance, provisionErr := poolManager.Provision(ctx, testPoolName, runnerName, "drone", "", nil, nil, nil)
instance, provisionErr := poolManager.Provision(ctx, testPoolName, runnerName, "drone", "", "", nil, nil, nil)
if provisionErr != nil {
consoleLogs, consoleErr := poolManager.InstanceLogs(ctx, testPoolName, instance.ID)
logrus.Infof("setup: instance logs for %s: %s", instance.ID, consoleLogs)
Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e *Engine) Setup(ctx context.Context, specv runtime.Spec) error {
}

// lets see if there is anything in the pool
instance, err := manager.Provision(ctx, poolName, e.config.Runner.Name, "drone", "", nil, nil, nil)
instance, err := manager.Provision(ctx, poolName, e.config.Runner.Name, "drone", "", "", nil, nil, nil)
if err != nil {
logr.WithError(err).Errorln("failed to provision an instance")
return err
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type InstanceCreateOpts struct {
AccountID string
IsHosted bool
ResourceClass string
ImageName string
GitspaceOpts GitspaceOpts
StorageOpts StorageOpts
AutoInjectionBinaryURI string
Expand Down