mirror of
https://github.com/harness/drone.git
synced 2025-05-04 01:11:59 +08:00
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. * feat
This commit is contained in:
parent
61e69bdea3
commit
10a3e8bbc0
@ -99,6 +99,11 @@ func (i InfraProvisioner) TriggerInfraEventWithOpts(
|
|||||||
return err
|
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 {
|
switch eventType {
|
||||||
case enum.InfraEventProvision:
|
case enum.InfraEventProvision:
|
||||||
if infraProvider.ProvisioningType() == enum.InfraProvisioningTypeNew {
|
if infraProvider.ProvisioningType() == enum.InfraProvisioningTypeNew {
|
||||||
@ -109,15 +114,22 @@ func (i InfraProvisioner) TriggerInfraEventWithOpts(
|
|||||||
|
|
||||||
case enum.InfraEventDeprovision:
|
case enum.InfraEventDeprovision:
|
||||||
if infraProvider.ProvisioningType() == enum.InfraProvisioningTypeNew {
|
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:
|
case enum.InfraEventCleanup:
|
||||||
return infraProvider.CleanupInstanceResources(ctx, *infra)
|
return infraProvider.CleanupInstanceResources(ctx, *infra)
|
||||||
|
|
||||||
case enum.InfraEventStop:
|
case enum.InfraEventStop:
|
||||||
return infraProvider.Stop(ctx, *infra)
|
return infraProvider.Stop(ctx, *infra, configMetadata)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported event type: %s", eventType)
|
return fmt.Errorf("unsupported event type: %s", eventType)
|
||||||
@ -207,6 +219,7 @@ func (i InfraProvisioner) provisionNewInfrastructure(
|
|||||||
agentPort,
|
agentPort,
|
||||||
requiredGitspacePorts,
|
requiredGitspacePorts,
|
||||||
allParams,
|
allParams,
|
||||||
|
configMetadata,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
infraProvisioned.InfraStatus = enum.InfraStatusUnknown
|
infraProvisioned.InfraStatus = enum.InfraStatusUnknown
|
||||||
@ -232,7 +245,7 @@ func (i InfraProvisioner) provisionExistingInfrastructure(
|
|||||||
gitspaceConfig types.GitspaceConfig,
|
gitspaceConfig types.GitspaceConfig,
|
||||||
requiredGitspacePorts []types.GitspacePort,
|
requiredGitspacePorts []types.GitspacePort,
|
||||||
) error {
|
) error {
|
||||||
allParams, _, err := i.getAllParamsFromDB(ctx, gitspaceConfig.InfraProviderResource, infraProvider)
|
allParams, configMetadata, err := i.getAllParamsFromDB(ctx, gitspaceConfig.InfraProviderResource, infraProvider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get all params from DB while provisioning: %w", err)
|
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.
|
0, // NOTE: Agent port is not required for provisioning type Existing.
|
||||||
requiredGitspacePorts,
|
requiredGitspacePorts,
|
||||||
allParams,
|
allParams,
|
||||||
|
configMetadata,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
@ -269,6 +283,7 @@ func (i InfraProvisioner) deprovisionNewInfrastructure(
|
|||||||
gitspaceConfig types.GitspaceConfig,
|
gitspaceConfig types.GitspaceConfig,
|
||||||
infra types.Infrastructure,
|
infra types.Infrastructure,
|
||||||
canDeleteUserData bool,
|
canDeleteUserData bool,
|
||||||
|
configMetadata map[string]any,
|
||||||
) error {
|
) error {
|
||||||
infraProvisionedLatest, err := i.infraProvisionedStore.FindLatestByGitspaceInstanceID(
|
infraProvisionedLatest, err := i.infraProvisionedStore.FindLatestByGitspaceInstanceID(
|
||||||
ctx, gitspaceConfig.GitspaceInstance.ID)
|
ctx, gitspaceConfig.GitspaceInstance.ID)
|
||||||
@ -282,7 +297,7 @@ func (i InfraProvisioner) deprovisionNewInfrastructure(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = infraProvider.Deprovision(ctx, infra, canDeleteUserData)
|
err = infraProvider.Deprovision(ctx, infra, canDeleteUserData, configMetadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to trigger deprovision infra %+v: %w", infra, err)
|
return fmt.Errorf("unable to trigger deprovision infra %+v: %w", infra, err)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ func (d DockerProvider) Provision(
|
|||||||
_ int,
|
_ int,
|
||||||
requiredGitspacePorts []types.GitspacePort,
|
requiredGitspacePorts []types.GitspacePort,
|
||||||
inputParameters []types.InfraProviderParameter,
|
inputParameters []types.InfraProviderParameter,
|
||||||
|
_ map[string]any,
|
||||||
) error {
|
) error {
|
||||||
dockerClient, err := d.dockerClientFactory.NewDockerClient(ctx, types.Infrastructure{
|
dockerClient, err := d.dockerClientFactory.NewDockerClient(ctx, types.Infrastructure{
|
||||||
ProviderType: enum.InfraProviderTypeDocker,
|
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.
|
// 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
|
infra.Status = enum.InfraStatusDestroyed
|
||||||
|
|
||||||
event := &events.GitspaceInfraEventPayload{
|
event := &events.GitspaceInfraEventPayload{
|
||||||
@ -200,7 +201,12 @@ func (d DockerProvider) CleanupInstanceResources(ctx context.Context, infra type
|
|||||||
// Deprovision is NOOP if canDeleteUserData = false
|
// Deprovision is NOOP if canDeleteUserData = false
|
||||||
// Deprovision deletes the volume created by Provision method if canDeleteUserData = false.
|
// Deprovision deletes the volume created by Provision method if canDeleteUserData = false.
|
||||||
// Deprovision does not stop the docker engine in any case.
|
// 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 {
|
if canDeleteUserData {
|
||||||
err := d.deleteVolume(ctx, infra)
|
err := d.deleteVolume(ctx, infra)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,6 +32,7 @@ type InfraProvider interface {
|
|||||||
agentPort int,
|
agentPort int,
|
||||||
requiredGitspacePorts []types.GitspacePort,
|
requiredGitspacePorts []types.GitspacePort,
|
||||||
inputParameters []types.InfraProviderParameter,
|
inputParameters []types.InfraProviderParameter,
|
||||||
|
configMetadata map[string]any,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Find finds infrastructure provisioned against a gitspace.
|
// Find finds infrastructure provisioned against a gitspace.
|
||||||
@ -51,7 +52,7 @@ type InfraProvider interface {
|
|||||||
) (*enum.InfraStatus, error)
|
) (*enum.InfraStatus, error)
|
||||||
|
|
||||||
// Stop frees up the resources allocated against a gitspace, which can be freed.
|
// 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 cleans up resources exclusively allocated to a gitspace instance.
|
||||||
CleanupInstanceResources(ctx context.Context, infra types.Infrastructure) error
|
CleanupInstanceResources(ctx context.Context, infra types.Infrastructure) error
|
||||||
@ -59,7 +60,12 @@ type InfraProvider interface {
|
|||||||
// Deprovision removes infrastructure provisioned against a gitspace.
|
// Deprovision removes infrastructure provisioned against a gitspace.
|
||||||
// canDeleteUserData = false -> remove all resources except storage where user has stored it's data.
|
// canDeleteUserData = false -> remove all resources except storage where user has stored it's data.
|
||||||
// canDeleteUserData = true -> remove all resources including storage.
|
// 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 provides a schema to define the infrastructure.
|
||||||
AvailableParams() []types.InfraProviderParameterSchema
|
AvailableParams() []types.InfraProviderParameterSchema
|
||||||
|
Loading…
Reference in New Issue
Block a user