Skip to content

Commit

Permalink
MGMT-18562: Update ignition registries.conf file by the generated Mir…
Browse files Browse the repository at this point in the history
…rorRegistryConfig
  • Loading branch information
eliorerz committed Oct 6, 2024
1 parent e83cbfc commit 96210de
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 183 deletions.
47 changes: 27 additions & 20 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ type InstallerInternals interface {
GetClusterSupportedPlatformsInternal(ctx context.Context, params installer.GetClusterSupportedPlatformsParams) (*[]models.PlatformType, error)
V2UpdateHostInternal(ctx context.Context, params installer.V2UpdateHostParams, interactivity Interactivity) (*common.Host, error)
GetInfraEnvByKubeKey(key types.NamespacedName) (*common.InfraEnv, error)
UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) (*common.InfraEnv, error)
RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error)
UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.InfraEnv, error)
RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error)
DeregisterInfraEnvInternal(ctx context.Context, params installer.DeregisterInfraEnvParams) error
UnbindHostInternal(ctx context.Context, params installer.UnbindHostParams, reclaimHost bool, interactivity Interactivity) (*common.Host, error)
BindHostInternal(ctx context.Context, params installer.BindHostParams) (*common.Host, error)
Expand Down Expand Up @@ -1087,7 +1087,7 @@ func (b *bareMetalInventory) deleteOrUnbindHosts(ctx context.Context, cluster *c
return nil
}

func (b *bareMetalInventory) updateExternalImageInfo(ctx context.Context, infraEnv *common.InfraEnv, infraEnvProxyHash string, imageType models.ImageType) error {
func (b *bareMetalInventory) updateExternalImageInfo(ctx context.Context, infraEnv *common.InfraEnv, infraEnvProxyHash string, imageType models.ImageType, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) error {
updates := map[string]interface{}{}

// this is updated before now for the v2 (infraEnv) case, but not in the cluster ISO case so we need to check if we should save it here
Expand Down Expand Up @@ -1136,7 +1136,7 @@ func (b *bareMetalInventory) updateExternalImageInfo(ctx context.Context, infraE
return errors.Wrap(err, "failed to create download URL")
}

details := b.getIgnitionConfigForLogging(ctx, infraEnv, b.log, imageType)
details := b.getIgnitionConfigForLogging(ctx, infraEnv, b.log, imageType, mirrorRegistryConfiguration)

eventgen.SendImageInfoUpdatedEvent(ctx, b.eventsHandler, common.StrFmtUUIDPtr(infraEnv.ClusterID), *infraEnv.ID, details)
updates["download_url"] = infraEnv.DownloadURL
Expand All @@ -1154,7 +1154,7 @@ func (b *bareMetalInventory) updateExternalImageInfo(ctx context.Context, infraE
return nil
}

func (b *bareMetalInventory) GenerateInfraEnvISOInternal(ctx context.Context, infraEnv *common.InfraEnv) error {
func (b *bareMetalInventory) GenerateInfraEnvISOInternal(ctx context.Context, infraEnv *common.InfraEnv, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) error {
log := logutil.FromContext(ctx, b.log)
log.Infof("prepare image for infraEnv %s", infraEnv.ID)

Expand All @@ -1175,7 +1175,7 @@ func (b *bareMetalInventory) GenerateInfraEnvISOInternal(ctx context.Context, in
return common.NewApiError(http.StatusInternalServerError, errors.New(msg))
}

err := b.createAndUploadNewImage(ctx, log, infraEnv.ProxyHash, *infraEnv.ID, common.ImageTypeValue(infraEnv.Type))
err := b.createAndUploadNewImage(ctx, log, infraEnv.ProxyHash, *infraEnv.ID, common.ImageTypeValue(infraEnv.Type), mirrorRegistryConfiguration)
if err != nil {
return err
}
Expand All @@ -1184,7 +1184,7 @@ func (b *bareMetalInventory) GenerateInfraEnvISOInternal(ctx context.Context, in
}

func (b *bareMetalInventory) createAndUploadNewImage(ctx context.Context, log logrus.FieldLogger, infraEnvProxyHash string,
infraEnvID strfmt.UUID, imageType models.ImageType) error {
infraEnvID strfmt.UUID, imageType models.ImageType, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) error {

infraEnv, err := common.GetInfraEnvFromDB(b.db, infraEnvID)
if err != nil {
Expand All @@ -1193,11 +1193,11 @@ func (b *bareMetalInventory) createAndUploadNewImage(ctx context.Context, log lo
return err
}

return b.updateExternalImageInfo(ctx, infraEnv, infraEnvProxyHash, imageType)
return b.updateExternalImageInfo(ctx, infraEnv, infraEnvProxyHash, imageType, mirrorRegistryConfiguration)
}

func (b *bareMetalInventory) getIgnitionConfigForLogging(ctx context.Context, infraEnv *common.InfraEnv, log logrus.FieldLogger, imageType models.ImageType) string {
ignitionConfigForLogging, _ := b.IgnitionBuilder.FormatDiscoveryIgnitionFile(ctx, infraEnv, b.IgnitionConfig, true, b.authHandler.AuthType(), string(imageType))
func (b *bareMetalInventory) getIgnitionConfigForLogging(ctx context.Context, infraEnv *common.InfraEnv, log logrus.FieldLogger, imageType models.ImageType, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) string {
ignitionConfigForLogging, _ := b.IgnitionBuilder.FormatDiscoveryIgnitionFile(ctx, infraEnv, b.IgnitionConfig, true, b.authHandler.AuthType(), string(imageType), mirrorRegistryConfiguration)
log.Infof("Generated infra env <%s> image with ignition config", infraEnv.ID)
log.Debugf("Ignition for infra env <%s>: %s", infraEnv.ID, ignitionConfigForLogging)
var msgDetails []string
Expand Down Expand Up @@ -4488,7 +4488,7 @@ func (b *bareMetalInventory) ListInfraEnvs(ctx context.Context, params installer
}

func (b *bareMetalInventory) RegisterInfraEnv(ctx context.Context, params installer.RegisterInfraEnvParams) middleware.Responder {
i, err := b.RegisterInfraEnvInternal(ctx, nil, params)
i, err := b.RegisterInfraEnvInternal(ctx, nil, nil, params)
if err != nil {
return common.GenerateErrorResponder(err)
}
Expand Down Expand Up @@ -4554,6 +4554,7 @@ func (b *bareMetalInventory) handlerClusterInfoOnRegisterInfraEnv(
func (b *bareMetalInventory) RegisterInfraEnvInternal(
ctx context.Context,
kubeKey *types.NamespacedName,
mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration,
params installer.RegisterInfraEnvParams) (*common.InfraEnv, error) {

var infraEnv common.InfraEnv
Expand Down Expand Up @@ -4708,7 +4709,7 @@ func (b *bareMetalInventory) RegisterInfraEnvInternal(
var discoveryIgnition string
discoveryIgnition, err = b.IgnitionBuilder.FormatDiscoveryIgnitionFile(
ctx, &infraEnv, b.IgnitionConfig,
false, b.authHandler.AuthType(), string(params.InfraenvCreateParams.ImageType))
false, b.authHandler.AuthType(), string(params.InfraenvCreateParams.ImageType), mirrorRegistryConfiguration)
if err != nil {
log.WithError(err).Error("Failed to format discovery ignition config")
return common.NewApiError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -4744,7 +4745,7 @@ func (b *bareMetalInventory) RegisterInfraEnvInternal(
log.Info(msg)
eventgen.SendInfraEnvRegisteredEvent(ctx, b.eventsHandler, id)

if err = b.GenerateInfraEnvISOInternal(ctx, &infraEnv); err != nil {
if err = b.GenerateInfraEnvISOInternal(ctx, &infraEnv, mirrorRegistryConfiguration); err != nil {
return nil, err
}

Expand Down Expand Up @@ -4911,14 +4912,20 @@ func (b *bareMetalInventory) setDiscoveryKernelArgumentsUsage(db *gorm.DB, clust
}

func (b *bareMetalInventory) UpdateInfraEnv(ctx context.Context, params installer.UpdateInfraEnvParams) middleware.Responder {
i, err := b.UpdateInfraEnvInternal(ctx, params, nil)
i, err := b.UpdateInfraEnvInternal(ctx, params, nil, nil)
if err != nil {
return common.GenerateErrorResponder(err)
}
return installer.NewUpdateInfraEnvCreated().WithPayload(&i.InfraEnv)
}

func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) (*common.InfraEnv, error) {
func (b *bareMetalInventory) UpdateInfraEnvInternal(
ctx context.Context,
params installer.UpdateInfraEnvParams,
internalIgnitionConfig *string,
mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration,
) (*common.InfraEnv, error) {

log := logutil.FromContext(ctx, b.log)
var infraEnv *common.InfraEnv
var err error
Expand Down Expand Up @@ -5015,7 +5022,7 @@ func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params
}

// Validate discovery ignition after updating InfraEnv data
if err = b.validateDiscoveryIgnitionImageSize(ctx, infraEnv, params, tx, log); err != nil {
if err = b.validateDiscoveryIgnitionImageSize(ctx, infraEnv, params, tx, log, mirrorRegistryConfiguration); err != nil {
return common.NewApiError(http.StatusBadRequest, err)
}

Expand All @@ -5036,14 +5043,14 @@ func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params
}
}

if err = b.GenerateInfraEnvISOInternal(ctx, infraEnv); err != nil {
if err = b.GenerateInfraEnvISOInternal(ctx, infraEnv, mirrorRegistryConfiguration); err != nil {
return nil, err
}

return b.GetInfraEnvInternal(ctx, installer.GetInfraEnvParams{InfraEnvID: *infraEnv.ID})
}

func (b *bareMetalInventory) validateDiscoveryIgnitionImageSize(ctx context.Context, infraEnv *common.InfraEnv, params installer.UpdateInfraEnvParams, db *gorm.DB, log logrus.FieldLogger) error {
func (b *bareMetalInventory) validateDiscoveryIgnitionImageSize(ctx context.Context, infraEnv *common.InfraEnv, params installer.UpdateInfraEnvParams, db *gorm.DB, log logrus.FieldLogger, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) error {
if params.InfraEnvUpdateParams.IgnitionConfigOverride != "" && params.InfraEnvUpdateParams.IgnitionConfigOverride != infraEnv.IgnitionConfigOverride {
infraEnvAfterUpdate, err := common.GetInfraEnvFromDB(db, params.InfraEnvID)
if err != nil {
Expand All @@ -5052,7 +5059,7 @@ func (b *bareMetalInventory) validateDiscoveryIgnitionImageSize(ctx context.Cont
}
discoveryIgnition, err := b.IgnitionBuilder.FormatDiscoveryIgnitionFile(
ctx, infraEnvAfterUpdate, b.IgnitionConfig,
false, b.authHandler.AuthType(), string(common.ImageTypeValue(infraEnvAfterUpdate.Type)))
false, b.authHandler.AuthType(), string(common.ImageTypeValue(infraEnvAfterUpdate.Type)), mirrorRegistryConfiguration)
if err != nil {
log.WithError(err).Error("Failed to format discovery ignition config")
return err
Expand Down Expand Up @@ -5899,7 +5906,7 @@ func (b *bareMetalInventory) V2DownloadInfraEnvFiles(ctx context.Context, params
switch params.FileName {
case "discovery.ign":
discoveryIsoType := swag.StringValue(params.DiscoveryIsoType)
content, err = b.IgnitionBuilder.FormatDiscoveryIgnitionFile(ctx, infraEnv, b.IgnitionConfig, false, b.authHandler.AuthType(), discoveryIsoType)
content, err = b.IgnitionBuilder.FormatDiscoveryIgnitionFile(ctx, infraEnv, b.IgnitionConfig, false, b.authHandler.AuthType(), discoveryIsoType, nil)
if err != nil {
b.log.WithError(err).Error("Failed to format ignition config")
return common.GenerateErrorResponder(err)
Expand Down
Loading

0 comments on commit 96210de

Please sign in to comment.