mirror of https://github.com/harness/drone.git
fix: [CDE-706]: add ip-config for generating pool identifier (#3612)
* fix: [CDE-706]: lint * fix: [CDE-706]: add ip-config for generating pool identifiermain
parent
17473844e3
commit
edcad7b744
|
@ -100,7 +100,7 @@ func (c *Controller) CreateResources(
|
|||
return nil, fmt.Errorf("failed to find infraprovider config by ref: %q %w", configIdentifier, err)
|
||||
}
|
||||
resources := c.MapToResourceEntity(in, space, now)
|
||||
err = c.infraproviderSvc.CreateResources(ctx, space.ID, resources, infraProviderConfig.ID)
|
||||
err = c.infraproviderSvc.CreateResources(ctx, space.ID, resources, infraProviderConfig.ID, configIdentifier)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ func (c *Service) CreateConfigAndResources(
|
|||
if err != nil {
|
||||
return fmt.Errorf("could not create the config: %q %w", infraProviderConfig.Identifier, err)
|
||||
}
|
||||
err = c.createMissingResources(ctx, infraProviderConfig.Resources, configID, infraProviderConfig.SpaceID)
|
||||
err = c.createMissingResources(ctx, infraProviderConfig.Resources, configID,
|
||||
infraProviderConfig.SpaceID, infraProviderConfig.Identifier)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create the resources: %v %w", infraProviderConfig.Resources, err)
|
||||
}
|
||||
|
|
|
@ -30,9 +30,10 @@ func (c *Service) CreateResources(
|
|||
spaceID int64,
|
||||
resources []types.InfraProviderResource,
|
||||
configID int64,
|
||||
configIdentifier string,
|
||||
) error {
|
||||
err := c.tx.WithTx(ctx, func(ctx context.Context) error {
|
||||
return c.createMissingResources(ctx, resources, configID, spaceID)
|
||||
return c.createMissingResources(ctx, resources, configID, spaceID, configIdentifier)
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to complete create txn for the infraprovider resource %w", err)
|
||||
|
@ -45,6 +46,7 @@ func (c *Service) createMissingResources(
|
|||
resources []types.InfraProviderResource,
|
||||
configID int64,
|
||||
spaceID int64,
|
||||
configIdentifier string,
|
||||
) error {
|
||||
emptyStr := ""
|
||||
for idx := range resources {
|
||||
|
@ -61,7 +63,7 @@ func (c *Service) createMissingResources(
|
|||
resource.Network = &emptyStr
|
||||
}
|
||||
// updating metadata based on infra provider type
|
||||
updatedMetadata, err := c.updateResourceMetadata(resource)
|
||||
updatedMetadata, err := c.updateResourceMetadata(resource, configIdentifier)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating missing infra resources: %w", err)
|
||||
}
|
||||
|
@ -82,13 +84,16 @@ func (c *Service) createMissingResources(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Service) updateResourceMetadata(resource *types.InfraProviderResource) (map[string]string, error) {
|
||||
func (c *Service) updateResourceMetadata(
|
||||
resource *types.InfraProviderResource,
|
||||
configIdentifier string,
|
||||
) (map[string]string, error) {
|
||||
infraProvider, err := c.infraProviderFactory.GetInfraProvider(resource.InfraProviderType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch infra impl for type : %q %w", resource.InfraProviderType, err)
|
||||
}
|
||||
|
||||
params, err := infraProvider.UpdateParams(toResourceParams(resource.Metadata))
|
||||
params, err := infraProvider.UpdateParams(toResourceParams(resource.Metadata), configIdentifier)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ func (c *Service) upsertConfigAndResources(
|
|||
}
|
||||
|
||||
log.Info().Msgf("updated infraconfig %s", infraProviderConfig.Identifier)
|
||||
if err = c.createMissingResources(ctx, infraProviderResources, infraProviderConfigID, space.ID); err != nil {
|
||||
if err = c.createMissingResources(ctx, infraProviderResources, infraProviderConfigID, space.ID,
|
||||
infraProviderConfig.Identifier); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -288,7 +288,8 @@ func (d DockerProvider) ValidateParams(_ []types.InfraProviderParameter) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d DockerProvider) UpdateParams(ip []types.InfraProviderParameter) ([]types.InfraProviderParameter, error) {
|
||||
func (d DockerProvider) UpdateParams(ip []types.InfraProviderParameter,
|
||||
_ string) ([]types.InfraProviderParameter, error) {
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ type InfraProvider interface {
|
|||
AvailableParams() []types.InfraProviderParameterSchema
|
||||
|
||||
// UpdateParams updates input Parameters to add or modify given inputParameters.
|
||||
UpdateParams(inputParameters []types.InfraProviderParameter) ([]types.InfraProviderParameter, error)
|
||||
UpdateParams(inputParameters []types.InfraProviderParameter,
|
||||
configIdentifier string) ([]types.InfraProviderParameter, error)
|
||||
|
||||
// ValidateParams validates the supplied params before defining the infrastructure resource .
|
||||
ValidateParams(inputParameters []types.InfraProviderParameter) error
|
||||
|
|
Loading…
Reference in New Issue