mirror of https://github.com/harness/drone.git
feat: [CDE-679]: Pass infra config metadata to infra provider methods (#3550)
* feat: [CDE-679]: return err * feat: [CDE-679]: fix provider * feat: [CDE-679]: merge * feat: [CDE-679]: Pass infra config metadata to infra provider methods * feat: [CDE-679]: Pass infra config metadata to infra provider methods * feat: [CDE-661]: set starting state by default in resume * Merge branch 'main' into hybrid * feat: [CDE-661]: fix host and port (#3511) * feat: [CDE-661]: fix host and port * feat: [CDE-661]: fix host and port * feat: [CDE-661]: send remove request for hybrid (#3500) * feat: [CDE-661]: add debug logs * feat: [CDE-661]: send remove request for hybrid * feat: [CDE-661]: Fetch gateway host from infra config (#3494) * feat: [CDE-661]: fix wiring * feat: [CDE-661]: Fetch gateway host from infra config * Merge branch 'main' into hybrid * feat: [CDE-636]: Fixing infra provider config update logic. * feat: [CDE-636]: Adding config metadata to infra provider methods parameters. * feat: [CDE-636]: Adding config metadata to infra provider methods parameters. * feattry-new-ui
parent
61e69bdea3
commit
10a3e8bbc0
|
@ -99,6 +99,11 @@ func (i InfraProvisioner) TriggerInfraEventWithOpts(
|
|||
return err
|
||||
}
|
||||
|
||||
_, configMetadata, err := i.getAllParamsFromDB(ctx, gitspaceConfig.InfraProviderResource, infraProvider)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get all params from DB while provisioning: %w", err)
|
||||
}
|
||||
|
||||
switch eventType {
|
||||
case enum.InfraEventProvision:
|
||||
if infraProvider.ProvisioningType() == enum.InfraProvisioningTypeNew {
|
||||
|
@ -109,15 +114,22 @@ func (i InfraProvisioner) TriggerInfraEventWithOpts(
|
|||
|
||||
case enum.InfraEventDeprovision:
|
||||
if infraProvider.ProvisioningType() == enum.InfraProvisioningTypeNew {
|
||||
return i.deprovisionNewInfrastructure(ctx, infraProvider, gitspaceConfig, *infra, opts.CanDeleteUserData)
|
||||
return i.deprovisionNewInfrastructure(
|
||||
ctx,
|
||||
infraProvider,
|
||||
gitspaceConfig,
|
||||
*infra,
|
||||
opts.CanDeleteUserData,
|
||||
configMetadata,
|
||||
)
|
||||
}
|
||||
return infraProvider.Deprovision(ctx, *infra, opts.CanDeleteUserData)
|
||||
return infraProvider.Deprovision(ctx, *infra, opts.CanDeleteUserData, configMetadata)
|
||||
|
||||
case enum.InfraEventCleanup:
|
||||
return infraProvider.CleanupInstanceResources(ctx, *infra)
|
||||
|
||||
case enum.InfraEventStop:
|
||||
return infraProvider.Stop(ctx, *infra)
|
||||
return infraProvider.Stop(ctx, *infra, configMetadata)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unsupported event type: %s", eventType)
|
||||
|
@ -207,6 +219,7 @@ func (i InfraProvisioner) provisionNewInfrastructure(
|
|||
agentPort,
|
||||
requiredGitspacePorts,
|
||||
allParams,
|
||||
configMetadata,
|
||||
)
|
||||
if err != nil {
|
||||
infraProvisioned.InfraStatus = enum.InfraStatusUnknown
|
||||
|
@ -232,7 +245,7 @@ func (i InfraProvisioner) provisionExistingInfrastructure(
|
|||
gitspaceConfig types.GitspaceConfig,
|
||||
requiredGitspacePorts []types.GitspacePort,
|
||||
) error {
|
||||
allParams, _, err := i.getAllParamsFromDB(ctx, gitspaceConfig.InfraProviderResource, infraProvider)
|
||||
allParams, configMetadata, err := i.getAllParamsFromDB(ctx, gitspaceConfig.InfraProviderResource, infraProvider)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get all params from DB while provisioning: %w", err)
|
||||
}
|
||||
|
@ -251,6 +264,7 @@ func (i InfraProvisioner) provisionExistingInfrastructure(
|
|||
0, // NOTE: Agent port is not required for provisioning type Existing.
|
||||
requiredGitspacePorts,
|
||||
allParams,
|
||||
configMetadata,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
|
@ -269,6 +283,7 @@ func (i InfraProvisioner) deprovisionNewInfrastructure(
|
|||
gitspaceConfig types.GitspaceConfig,
|
||||
infra types.Infrastructure,
|
||||
canDeleteUserData bool,
|
||||
configMetadata map[string]any,
|
||||
) error {
|
||||
infraProvisionedLatest, err := i.infraProvisionedStore.FindLatestByGitspaceInstanceID(
|
||||
ctx, gitspaceConfig.GitspaceInstance.ID)
|
||||
|
@ -282,7 +297,7 @@ func (i InfraProvisioner) deprovisionNewInfrastructure(
|
|||
return nil
|
||||
}
|
||||
|
||||
err = infraProvider.Deprovision(ctx, infra, canDeleteUserData)
|
||||
err = infraProvider.Deprovision(ctx, infra, canDeleteUserData, configMetadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to trigger deprovision infra %+v: %w", infra, err)
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ func (d DockerProvider) Provision(
|
|||
_ int,
|
||||
requiredGitspacePorts []types.GitspacePort,
|
||||
inputParameters []types.InfraProviderParameter,
|
||||
_ map[string]any,
|
||||
) error {
|
||||
dockerClient, err := d.dockerClientFactory.NewDockerClient(ctx, types.Infrastructure{
|
||||
ProviderType: enum.InfraProviderTypeDocker,
|
||||
|
@ -163,7 +164,7 @@ func (d DockerProvider) FindInfraStatus(_ context.Context,
|
|||
}
|
||||
|
||||
// Stop is NOOP as this provider uses already running docker engine. It does not stop the docker engine.
|
||||
func (d DockerProvider) Stop(ctx context.Context, infra types.Infrastructure) error {
|
||||
func (d DockerProvider) Stop(ctx context.Context, infra types.Infrastructure, _ map[string]any) error {
|
||||
infra.Status = enum.InfraStatusDestroyed
|
||||
|
||||
event := &events.GitspaceInfraEventPayload{
|
||||
|
@ -200,7 +201,12 @@ func (d DockerProvider) CleanupInstanceResources(ctx context.Context, infra type
|
|||
// Deprovision is NOOP if canDeleteUserData = false
|
||||
// Deprovision deletes the volume created by Provision method if canDeleteUserData = false.
|
||||
// Deprovision does not stop the docker engine in any case.
|
||||
func (d DockerProvider) Deprovision(ctx context.Context, infra types.Infrastructure, canDeleteUserData bool) error {
|
||||
func (d DockerProvider) Deprovision(
|
||||
ctx context.Context,
|
||||
infra types.Infrastructure,
|
||||
canDeleteUserData bool,
|
||||
_ map[string]any,
|
||||
) error {
|
||||
if canDeleteUserData {
|
||||
err := d.deleteVolume(ctx, infra)
|
||||
if err != nil {
|
||||
|
|
|
@ -32,6 +32,7 @@ type InfraProvider interface {
|
|||
agentPort int,
|
||||
requiredGitspacePorts []types.GitspacePort,
|
||||
inputParameters []types.InfraProviderParameter,
|
||||
configMetadata map[string]any,
|
||||
) error
|
||||
|
||||
// Find finds infrastructure provisioned against a gitspace.
|
||||
|
@ -51,7 +52,7 @@ type InfraProvider interface {
|
|||
) (*enum.InfraStatus, error)
|
||||
|
||||
// Stop frees up the resources allocated against a gitspace, which can be freed.
|
||||
Stop(ctx context.Context, infra types.Infrastructure) error
|
||||
Stop(ctx context.Context, infra types.Infrastructure, configMetadata map[string]any) error
|
||||
|
||||
// CleanupInstanceResources cleans up resources exclusively allocated to a gitspace instance.
|
||||
CleanupInstanceResources(ctx context.Context, infra types.Infrastructure) error
|
||||
|
@ -59,7 +60,12 @@ type InfraProvider interface {
|
|||
// Deprovision removes infrastructure provisioned against a gitspace.
|
||||
// canDeleteUserData = false -> remove all resources except storage where user has stored it's data.
|
||||
// canDeleteUserData = true -> remove all resources including storage.
|
||||
Deprovision(ctx context.Context, infra types.Infrastructure, canDeleteUserData bool) error
|
||||
Deprovision(
|
||||
ctx context.Context,
|
||||
infra types.Infrastructure,
|
||||
canDeleteUserData bool,
|
||||
configMetadata map[string]any,
|
||||
) error
|
||||
|
||||
// AvailableParams provides a schema to define the infrastructure.
|
||||
AvailableParams() []types.InfraProviderParameterSchema
|
||||
|
|
Loading…
Reference in New Issue