From 96210de98f9463c05b1491ced3b22cf98dc0f261 Mon Sep 17 00:00:00 2001 From: Elior Erez Date: Sun, 6 Oct 2024 19:21:48 +0300 Subject: [PATCH] MGMT-18562: Update ignition registries.conf file by the generated MirrorRegistryConfig --- internal/bminventory/inventory.go | 47 ++-- internal/bminventory/inventory_test.go | 52 +++-- .../bminventory/mock_installer_internal.go | 16 +- .../controllers/infraenv_controller.go | 17 +- .../controllers/infraenv_controller_test.go | 141 +++++++---- .../preprovisioningimage_controller.go | 8 +- .../preprovisioningimage_controller_test.go | 39 ++-- internal/ignition/discovery.go | 50 ++-- internal/ignition/discovery_test.go | 218 ++++++++++++++---- internal/ignition/mock_ignition_builder.go | 9 +- 10 files changed, 414 insertions(+), 183 deletions(-) diff --git a/internal/bminventory/inventory.go b/internal/bminventory/inventory.go index 319bfdc5e66..dec80e87fb4 100644 --- a/internal/bminventory/inventory.go +++ b/internal/bminventory/inventory.go @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 } @@ -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 { @@ -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 @@ -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) } @@ -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 @@ -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) @@ -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 } @@ -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 @@ -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) } @@ -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 { @@ -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 @@ -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) diff --git a/internal/bminventory/inventory_test.go b/internal/bminventory/inventory_test.go index 2fe63fa0cf4..aad75eecd83 100644 --- a/internal/bminventory/inventory_test.go +++ b/internal/bminventory/inventory_test.go @@ -283,7 +283,7 @@ func mockInfraEnvRegisterSuccess() { mockOSImages.EXPECT().GetOsImage(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() mockStaticNetworkConfig.EXPECT().FormatStaticNetworkConfigForDB(gomock.Any()).Return("", nil).Times(1) mockSecretValidator.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName))).AnyTimes() } @@ -291,7 +291,7 @@ func mockInfraEnvRegisterSuccess() { func mockInfraEnvUpdateSuccess() { mockOSImages.EXPECT().GetOsImageOrLatest(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() mockOSImages.EXPECT().GetOsImage(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName))).AnyTimes() } @@ -8312,7 +8312,7 @@ var _ = Describe("infraEnvs", func() { err := db.Create(&cluster).Error Expect(err).ShouldNot(HaveOccurred()) mockInfraEnvRegisterSuccess() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.InfraEnvRegisteredEventName))).Times(1) mockUsage.EXPECT().Add(gomock.Any(), usage.IgnitionConfigOverrideUsage, gomock.Any()).Times(1) @@ -8337,7 +8337,7 @@ var _ = Describe("infraEnvs", func() { MinimalOpenShiftVersionForNoneHA := "4.8.0-fc.0" mockInfraEnvRegisterSuccess() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.InfraEnvRegisteredEventName))).Times(1) mockUsage.EXPECT().Add(gomock.Any(), usage.IgnitionConfigOverrideUsage, gomock.Any()).Times(0) @@ -8420,7 +8420,7 @@ var _ = Describe("infraEnvs", func() { *common.TestDefaultConfig.OsImage.CPUArchitecture).Return(common.TestDefaultConfig.OsImage, nil).Times(1) mockStaticNetworkConfig.EXPECT().FormatStaticNetworkConfigForDB(gomock.Any()).Return("", nil).Times(1) mockSecretValidator.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName))) @@ -8548,7 +8548,7 @@ var _ = Describe("infraEnvs", func() { mockOSImages.EXPECT().GetOsImageOrLatest(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() mockOSImages.EXPECT().GetOsImage(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() mockSecretValidator.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName))).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( @@ -8584,7 +8584,7 @@ var _ = Describe("infraEnvs", func() { mockOSImages.EXPECT().GetOsImageOrLatest(gomock.Any(), gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() mockStaticNetworkConfig.EXPECT().FormatStaticNetworkConfigForDB(gomock.Any()).Return("", nil).Times(1) mockSecretValidator.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(largeDiscoveryIgnition, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(largeDiscoveryIgnition, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.InfraEnvRegistrationFailedEventName))).Times(1) @@ -8896,7 +8896,7 @@ var _ = Describe("infraEnvs", func() { }) It("Update Ignition", func() { mockInfraEnvUpdateSuccess() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() override := `{"ignition": {"version": "3.1.0"}, "storage": {"files": [{"path": "/tmp/example", "contents": {"source": "data:text/plain;base64,aGVscGltdHJhcHBlZGluYXN3YWdnZXJzcGVj"}}]}}` reply := bm.UpdateInfraEnv(ctx, installer.UpdateInfraEnvParams{ InfraEnvID: *i.ID, @@ -9424,6 +9424,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{}, }, nil, + nil, ) Expect(err).ShouldNot(HaveOccurred()) Expect(reponse.GeneratedAt).ShouldNot(Equal(strfmt.NewDateTime())) @@ -9434,7 +9435,7 @@ var _ = Describe("infraEnvs", func() { Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(i.ID.String()), @@ -9445,6 +9446,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{ImageType: models.ImageTypeMinimalIso}, }, nil, + nil, ) Expect(err).ToNot(HaveOccurred()) @@ -9479,7 +9481,7 @@ var _ = Describe("infraEnvs", func() { Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(boundedInfraEnv.ID.String()), @@ -9490,6 +9492,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{ImageType: models.ImageTypeMinimalIso}, }, nil, + nil, ) Expect(err).ToNot(HaveOccurred()) @@ -9519,7 +9522,7 @@ var _ = Describe("infraEnvs", func() { i, err := bm.GetInfraEnvInternal(ctx, installer.GetInfraEnvParams{InfraEnvID: infraEnvID}) Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(i.ID.String()), @@ -9529,6 +9532,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{ImageType: models.ImageTypeMinimalIso}, }, nil, + nil, ) Expect(err).ToNot(HaveOccurred()) @@ -9547,7 +9551,7 @@ var _ = Describe("infraEnvs", func() { i, err := bm.GetInfraEnvInternal(ctx, installer.GetInfraEnvParams{InfraEnvID: infraEnvID}) Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(i.ID.String()), @@ -9557,6 +9561,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{ImageType: models.ImageTypeMinimalIso}, }, nil, + nil, ) Expect(err).ToNot(HaveOccurred()) @@ -9591,6 +9596,7 @@ var _ = Describe("infraEnvs", func() { InfraEnvUpdateParams: params, }, nil, + nil, ) Expect(err).ToNot(HaveOccurred()) return response.DownloadURL @@ -9600,7 +9606,7 @@ var _ = Describe("infraEnvs", func() { i, err := bm.GetInfraEnvInternal(ctx, installer.GetInfraEnvParams{InfraEnvID: infraEnvID}) Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(i.ID.String()), @@ -9616,8 +9622,8 @@ var _ = Describe("infraEnvs", func() { i, err := bm.GetInfraEnvInternal(ctx, installer.GetInfraEnvParams{InfraEnvID: infraEnvID}) Expect(err).ToNot(HaveOccurred()) mockOSImages.EXPECT().GetOsImageOrLatest(common.TestDefaultConfig.OpenShiftVersion, "").Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(7) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, false, bm.authHandler.AuthType(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, true, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return("ignitionconfigforlogging", nil).Times(7) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), bm.IgnitionConfig, false, bm.authHandler.AuthType(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(ctx, eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(i.ID.String()), @@ -11835,7 +11841,7 @@ var _ = Describe("V2DownloadInfraEnvFiles", func() { } It("should ensure the correct discovery iso type is passed to the ignition builder", func() { - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), "").Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), "", gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) body := getResponseData("discovery.ign", false, nil, "") config, report, err := ign_3_1.Parse(body) Expect(err).NotTo(HaveOccurred()) @@ -11845,7 +11851,7 @@ var _ = Describe("V2DownloadInfraEnvFiles", func() { It("returns discovery.ign successfully when asked to use full-iso", func() { discoveryIsoType := string(models.ImageTypeFullIso) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), discoveryIsoType).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), discoveryIsoType, gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) body := getResponseData("discovery.ign", false, nil, discoveryIsoType) config, report, err := ign_3_1.Parse(body) Expect(err).NotTo(HaveOccurred()) @@ -11855,7 +11861,7 @@ var _ = Describe("V2DownloadInfraEnvFiles", func() { It("returns discovery.ign successfully when asked to use minimal-iso", func() { discoveryIsoType := string(models.ImageTypeMinimalIso) - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), discoveryIsoType).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), discoveryIsoType, gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) body := getResponseData("discovery.ign", false, nil, discoveryIsoType) config, report, err := ign_3_1.Parse(body) Expect(err).NotTo(HaveOccurred()) @@ -11945,7 +11951,7 @@ var _ = Describe("V2DownloadInfraEnvFiles", func() { mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithInfraEnvIdMatcher(infraEnvID.String()))) mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), - gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) updateKernelArgs(kernelArguments...) By("get ipxe script again") content = getResponseData("ipxe-script", false, nil, "") @@ -12243,7 +12249,7 @@ var _ = Describe("UpdateInfraEnv - Ignition", func() { } mockUsageReports() mockOSImages.EXPECT().GetOsImageOrLatest("", gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(infraEnv.ID.String()))) @@ -12317,7 +12323,7 @@ var _ = Describe("UpdateInfraEnv - Ignition", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{IgnitionConfigOverride: override}, } mockOSImages.EXPECT().GetOsImageOrLatest("", gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).AnyTimes() mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(infraEnv.ID.String()))) @@ -12350,7 +12356,7 @@ var _ = Describe("UpdateInfraEnv - Ignition", func() { InfraEnvUpdateParams: &models.InfraEnvUpdateParams{IgnitionConfigOverride: override}, } mockOSImages.EXPECT().GetOsImageOrLatest("", gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery_ignition_3_1, nil).Times(1) mockEvents.EXPECT().SendInfraEnvEvent(gomock.Any(), eventstest.NewEventMatcher( eventstest.WithNameMatcher(eventgen.ImageInfoUpdatedEventName), eventstest.WithInfraEnvIdMatcher(infraEnv.ID.String()))) @@ -12371,7 +12377,7 @@ var _ = Describe("UpdateInfraEnv - Ignition", func() { override := `{"ignition": {"version": "3.1.0"}, "storage": {"files": [{"path": "/tmp/example", "contents": {"source": "data:text/plain;base64,aGVscGltdHJhcHBlZGluYXN3YWdnZXJzcGVj"}}]}}` mockOSImages.EXPECT().GetOsImageOrLatest("", gomock.Any()).Return(common.TestDefaultConfig.OsImage, nil).AnyTimes() - mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(largeDiscoveryIgnition, nil).AnyTimes() + mockIgnitionBuilder.EXPECT().FormatDiscoveryIgnitionFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(largeDiscoveryIgnition, nil).AnyTimes() mockUsage.EXPECT().Add(gomock.Any(), usage.IgnitionConfigOverrideUsage, gomock.Any()).Times(1) mockUsage.EXPECT().Save(gomock.Any(), gomock.Any(), gomock.Any()).Times(1) diff --git a/internal/bminventory/mock_installer_internal.go b/internal/bminventory/mock_installer_internal.go index 5b8d1a5bd83..e21bca987ed 100644 --- a/internal/bminventory/mock_installer_internal.go +++ b/internal/bminventory/mock_installer_internal.go @@ -339,18 +339,18 @@ func (mr *MockInstallerInternalsMockRecorder) RegisterClusterInternal(arg0, arg1 } // RegisterInfraEnvInternal mocks base method. -func (m *MockInstallerInternals) RegisterInfraEnvInternal(arg0 context.Context, arg1 *types.NamespacedName, arg2 installer.RegisterInfraEnvParams) (*common.InfraEnv, error) { +func (m *MockInstallerInternals) RegisterInfraEnvInternal(arg0 context.Context, arg1 *types.NamespacedName, arg2 *v1beta1.MirrorRegistryConfiguration, arg3 installer.RegisterInfraEnvParams) (*common.InfraEnv, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RegisterInfraEnvInternal", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "RegisterInfraEnvInternal", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*common.InfraEnv) ret1, _ := ret[1].(error) return ret0, ret1 } // RegisterInfraEnvInternal indicates an expected call of RegisterInfraEnvInternal. -func (mr *MockInstallerInternalsMockRecorder) RegisterInfraEnvInternal(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockInstallerInternalsMockRecorder) RegisterInfraEnvInternal(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInfraEnvInternal", reflect.TypeOf((*MockInstallerInternals)(nil).RegisterInfraEnvInternal), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInfraEnvInternal", reflect.TypeOf((*MockInstallerInternals)(nil).RegisterInfraEnvInternal), arg0, arg1, arg2, arg3) } // TransformClusterToDay2Internal mocks base method. @@ -428,18 +428,18 @@ func (mr *MockInstallerInternalsMockRecorder) UpdateHostApprovedInternal(arg0, a } // UpdateInfraEnvInternal mocks base method. -func (m *MockInstallerInternals) UpdateInfraEnvInternal(arg0 context.Context, arg1 installer.UpdateInfraEnvParams, arg2 *string) (*common.InfraEnv, error) { +func (m *MockInstallerInternals) UpdateInfraEnvInternal(arg0 context.Context, arg1 installer.UpdateInfraEnvParams, arg2 *string, arg3 *v1beta1.MirrorRegistryConfiguration) (*common.InfraEnv, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateInfraEnvInternal", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "UpdateInfraEnvInternal", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*common.InfraEnv) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateInfraEnvInternal indicates an expected call of UpdateInfraEnvInternal. -func (mr *MockInstallerInternalsMockRecorder) UpdateInfraEnvInternal(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockInstallerInternalsMockRecorder) UpdateInfraEnvInternal(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateInfraEnvInternal", reflect.TypeOf((*MockInstallerInternals)(nil).UpdateInfraEnvInternal), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateInfraEnvInternal", reflect.TypeOf((*MockInstallerInternals)(nil).UpdateInfraEnvInternal), arg0, arg1, arg2, arg3) } // V2DeregisterHostInternal mocks base method. diff --git a/internal/controller/controllers/infraenv_controller.go b/internal/controller/controllers/infraenv_controller.go index 1062351bb0d..9f257856b35 100644 --- a/internal/controller/controllers/infraenv_controller.go +++ b/internal/controller/controllers/infraenv_controller.go @@ -38,6 +38,7 @@ import ( "github.com/openshift/assisted-service/models" "github.com/openshift/assisted-service/pkg/auth" logutil "github.com/openshift/assisted-service/pkg/log" + "github.com/openshift/assisted-service/pkg/mirrorregistries" "github.com/openshift/assisted-service/restapi/operations/installer" conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" hivev1 "github.com/openshift/hive/apis/hive/v1" @@ -228,8 +229,13 @@ func (r *InfraEnvReconciler) updateInfraEnv(ctx context.Context, log logrus.Fiel updateParams.InfraEnvUpdateParams.KernelArguments = internalKernelArgs(infraEnv.Spec.KernelArguments) } - // UpdateInfraEnvInternal will generate an ISO only if there it was not generated before, - return r.Installer.UpdateInfraEnvInternal(ctx, updateParams, nil) + mirrorRegistryConfiguration, err := mirrorregistries.ProcessMirrorRegistryConfig(ctx, log, r.Client, infraEnv.Spec.MirrorRegistryRef) + if err != nil { + return nil, err + } + + // UpdateInfraEnvInternal will generate an ISO only if it was not generated before + return r.Installer.UpdateInfraEnvInternal(ctx, updateParams, nil, mirrorRegistryConfiguration) } func areKernelArgsIdentical(k1, k2 []aiv1beta1.KernelArgument) bool { @@ -507,7 +513,12 @@ func (r *InfraEnvReconciler) createInfraEnv(ctx context.Context, log logrus.Fiel createParams.InfraenvCreateParams.StaticNetworkConfig = staticNetworkConfig } - return r.Installer.RegisterInfraEnvInternal(ctx, key, createParams) + mirrorRegistryConfiguration, err := mirrorregistries.ProcessMirrorRegistryConfig(ctx, log, r.Client, infraEnv.Spec.MirrorRegistryRef) + if err != nil { + return nil, err + } + + return r.Installer.RegisterInfraEnvInternal(ctx, key, mirrorRegistryConfiguration, createParams) } func (r *InfraEnvReconciler) deregisterInfraEnvIfNeeded(ctx context.Context, log logrus.FieldLogger, key types.NamespacedName) (ctrl.Result, error) { diff --git a/internal/controller/controllers/infraenv_controller_test.go b/internal/controller/controllers/infraenv_controller_test.go index 033939b1d47..98f400861b2 100644 --- a/internal/controller/controllers/infraenv_controller_test.go +++ b/internal/controller/controllers/infraenv_controller_test.go @@ -16,6 +16,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + "github.com/openshift/assisted-service/api/hiveextension/v1beta1" aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1" "github.com/openshift/assisted-service/internal/bminventory" "github.com/openshift/assisted-service/internal/common" @@ -134,6 +135,52 @@ var _ = Describe("infraEnv reconcile", func() { Expect(result).To(Equal(ctrl.Result{})) }) + Context("Mirror registry", func() { + createUserMirrorRegistryConfigmap := func(registryToml string, certificate string) { + registryCM := newUserProvidedRegistryCM(registryToml, certificate) + Expect(c.Create(ctx, registryCM)).ShouldNot(HaveOccurred()) + } + + When("the user-provided valid image registry contains correct data", func() { + It("Successfully parse and set the given user configmap", func() { + createUserMirrorRegistryConfigmap(getSecureRegistryToml(), mirrorRegistryCertificate) + + clusterDeployment := newClusterDeployment("clusterDeployment", testNamespace, getDefaultClusterDeploymentSpec("clusterDeployment-test", "test-cluster-aci", "pull-secret")) + Expect(c.Create(ctx, clusterDeployment)).To(BeNil()) + mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) + mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) + mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { + Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) + Expect(mirrorRegistryConfiguration).To(Not(BeNil())) + Expect(mirrorRegistryConfiguration.RegistriesConf).To(Equal(getSecureRegistryToml())) + Expect(mirrorRegistryConfiguration.CaBundleCrt).To(Equal(mirrorRegistryCertificate)) + }).Return( + &common.InfraEnv{InfraEnv: models.InfraEnv{ClusterID: sId, ID: &sId, DownloadURL: downloadURL, CPUArchitecture: infraEnvArch, StaticNetworkConfig: "foobar"}, GeneratedAt: strfmt.DateTime(time.Now())}, nil).Times(1) + + infraEnvImage := newInfraEnvImage("infraEnvImage", testNamespace, aiv1beta1.InfraEnvSpec{ + ClusterRef: &aiv1beta1.ClusterReference{Name: "clusterDeployment", Namespace: testNamespace}, + PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"}, + MirrorRegistryRef: &v1beta1.MirrorRegistryConfigMapReference{Name: providedMirrorRegistryCMName, Namespace: testNamespace}, + }) + Expect(c.Create(ctx, infraEnvImage)).To(BeNil()) + + res, err := ir.Reconcile(ctx, newInfraEnvRequest(infraEnvImage)) + key := types.NamespacedName{ + Namespace: testNamespace, + Name: "infraEnvImage", + } + + Expect(err).To(BeNil()) + Expect(res).To(Equal(ctrl.Result{})) + Expect(c.Get(ctx, key, infraEnvImage)).To(BeNil()) + + }) + }) + + }) + It("create new infraEnv minimal-iso image - success", func() { imageInfo := models.ImageInfo{ DownloadURL: "https://downloadurl", @@ -144,8 +191,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return( @@ -184,8 +231,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeFullIso)) }).Return( @@ -229,7 +276,7 @@ var _ = Describe("infraEnv reconcile", func() { } mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Return(dbInfraEnv, nil).Times(1) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Return(dbInfraEnv, nil).Times(1) kubeInfraEnv := newInfraEnvImage("myInfraEnv", testNamespace, aiv1beta1.InfraEnvSpec{ PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"}, IPXEScriptType: aiv1beta1.BootOrderControl, @@ -287,7 +334,7 @@ var _ = Describe("infraEnv reconcile", func() { } mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Return(dbInfraEnv, nil).Times(1) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Return(dbInfraEnv, nil).Times(1) kubeInfraEnv := newInfraEnvImage("myInfraEnv", testNamespace, aiv1beta1.InfraEnvSpec{ PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"}, IPXEScriptType: aiv1beta1.DiscoveryImageAlways, @@ -390,8 +437,8 @@ var _ = Describe("infraEnv reconcile", func() { } Expect(c.Get(ctx, key, kubeInfraEnv)).To(BeNil()) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Times(1).DoAndReturn( - func(ctx context.Context, params installer.UpdateInfraEnvParams, _ *string) (*common.InfraEnv, error) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Times(1).DoAndReturn( + func(ctx context.Context, params installer.UpdateInfraEnvParams, _ *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.InfraEnv, error) { Expect(internalKernelArgs(updateKargs)).To(Equal(params.InfraEnvUpdateParams.KernelArguments)) return dbInfraEnv, nil }) @@ -420,7 +467,7 @@ var _ = Describe("infraEnv reconcile", func() { } mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Return(dbInfraEnv, nil).Times(1) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Return(dbInfraEnv, nil).Times(1) kubeInfraEnv := newInfraEnvImage("myInfraEnv", testNamespace, aiv1beta1.InfraEnvSpec{ PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"}, }) @@ -489,7 +536,7 @@ var _ = Describe("infraEnv reconcile", func() { } mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil).AnyTimes() mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Return(dbInfraEnv, nil).Times(2) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Return(dbInfraEnv, nil).Times(2) kubeInfraEnv := newInfraEnvImage("myInfraEnv", testNamespace, aiv1beta1.InfraEnvSpec{ PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"}, @@ -531,8 +578,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) }).Return(nil, expectedError).Times(1) @@ -626,8 +673,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) }).Return(nil, expectedError).Times(1) @@ -663,8 +710,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil).Times(2) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil).Times(2) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) }).Return(nil, expectedClientError).Times(1) infraEnvImage := newInfraEnvImage("infraEnvImage", testNamespace, aiv1beta1.InfraEnvSpec{ @@ -689,8 +736,8 @@ var _ = Describe("infraEnv reconcile", func() { expectedConflictError := common.NewApiError(http.StatusConflict, errors.New("Another request to generate an image has been recently submitted. Please wait a few seconds and try again.")) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) }).Return(nil, expectedConflictError).Times(1) res, err = ir.Reconcile(ctx, newInfraEnvRequest(infraEnvImage)) @@ -707,8 +754,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) }).Return(nil, expectedError).Times(1) infraEnvImage := newInfraEnvImage("infraEnvImage", testNamespace, aiv1beta1.InfraEnvSpec{ @@ -783,8 +830,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(swag.StringValue(params.InfraEnvUpdateParams.Proxy.HTTPProxy)).To(Equal("http://192.168.1.2")) Expect(swag.StringValue(params.InfraEnvUpdateParams.AdditionalNtpSources)).To(Equal("foo.com,bar.com")) @@ -811,8 +858,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal(ignitionConfigOverride)) }).Return(&common.InfraEnv{InfraEnv: models.InfraEnv{ClusterID: sId, ID: &sId, DownloadURL: downloadURL, CPUArchitecture: infraEnvArch}}, nil).Times(1) @@ -838,8 +885,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal(ignitionConfigOverride)) }).Return(nil, errors.Errorf("error")).Times(1) @@ -865,7 +912,7 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil).Return(nil, errors.Errorf("failure")).Times(1) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil).Return(nil, errors.Errorf("failure")).Times(1) res, err := ir.Reconcile(ctx, newInfraEnvRequest(infraEnvImage)) Expect(err).ToNot(BeNil()) @@ -886,8 +933,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return( @@ -934,8 +981,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return( @@ -981,8 +1028,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return( @@ -1041,8 +1088,8 @@ var _ = Describe("infraEnv reconcile", func() { Expect(c.Create(ctx, infraEnvImage)).To(BeNil()) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(nil, gorm.ErrRecordNotFound) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, kubeKey *types.NamespacedName, params installer.RegisterInfraEnvParams) { + mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) { Expect(params.InfraenvCreateParams.OpenshiftVersion).To(Equal(osImageVersion)) }).Return(backendInfraEnv, nil) mockOSImages.EXPECT().GetOsImage(gomock.Any(), gomock.Any()).Return(&models.OsImage{CPUArchitecture: swag.String(infraEnvArch), OpenshiftVersion: swag.String(osImageVersion)}, nil).AnyTimes() @@ -1087,8 +1134,8 @@ var _ = Describe("infraEnv reconcile", func() { Expect(c.Create(ctx, infraEnvImage)).To(BeNil()) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(nil, gorm.ErrRecordNotFound) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, kubeKey *types.NamespacedName, params installer.RegisterInfraEnvParams) { + mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) { Expect(params.InfraenvCreateParams.OpenshiftVersion).To(Equal("")) }).Return(backendInfraEnv, nil) @@ -1119,8 +1166,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(nil, gorm.ErrRecordNotFound) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, kubeKey *types.NamespacedName, params installer.RegisterInfraEnvParams) { + mockInstallerInternal.EXPECT().RegisterInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) { Expect(params.InfraenvCreateParams.OpenshiftVersion).To(Equal(ocpVersion)) }).Return(backendInfraEnv, nil) @@ -1144,8 +1191,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil).Times(2) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil).Times(2) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return( @@ -1261,8 +1308,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) Expect(params.InfraEnvUpdateParams.StaticNetworkConfig).To(Equal([]*models.HostStaticNetworkConfig{hostStaticNetworkConfig})) @@ -1296,8 +1343,8 @@ var _ = Describe("infraEnv reconcile", func() { mockInstallerInternal.EXPECT().GetClusterByKubeKey(gomock.Any()).Return(backEndCluster, nil) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) Expect(params.InfraEnvUpdateParams.StaticNetworkConfig).To(BeEmpty()) @@ -1333,8 +1380,8 @@ var _ = Describe("infraEnv reconcile", func() { expectedError := common.NewApiError(http.StatusBadRequest, errors.New("internal error")) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockInstallerInternal.EXPECT().ValidatePullSecret(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), nil, nil). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso)) }).Return(nil, expectedError).Times(1) diff --git a/internal/controller/controllers/preprovisioningimage_controller.go b/internal/controller/controllers/preprovisioningimage_controller.go index 49ae172dab2..1a562eddb55 100644 --- a/internal/controller/controllers/preprovisioningimage_controller.go +++ b/internal/controller/controllers/preprovisioningimage_controller.go @@ -35,6 +35,7 @@ import ( "github.com/openshift/assisted-service/internal/versions" "github.com/openshift/assisted-service/models" logutil "github.com/openshift/assisted-service/pkg/log" + "github.com/openshift/assisted-service/pkg/mirrorregistries" "github.com/openshift/assisted-service/restapi/operations/installer" conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" "github.com/pkg/errors" @@ -546,9 +547,14 @@ func (r *PreprovisioningImageReconciler) AddIronicAgentToInfraEnv(ctx context.Co return false, err } + mirrorRegistryConfiguration, err := mirrorregistries.ProcessMirrorRegistryConfig(ctx, log, r.Client, infraEnv.Spec.MirrorRegistryRef) + if err != nil { + return false, err + } + updated := false if string(conf) != infraEnvInternal.InternalIgnitionConfigOverride { - _, err = r.Installer.UpdateInfraEnvInternal(ctx, installer.UpdateInfraEnvParams{InfraEnvID: *infraEnvInternal.ID, InfraEnvUpdateParams: &models.InfraEnvUpdateParams{}}, swag.String(string(conf))) + _, err = r.Installer.UpdateInfraEnvInternal(ctx, installer.UpdateInfraEnvParams{InfraEnvID: *infraEnvInternal.ID, InfraEnvUpdateParams: &models.InfraEnvUpdateParams{}}, swag.String(string(conf)), mirrorRegistryConfiguration) if err != nil { return false, err } diff --git a/internal/controller/controllers/preprovisioningimage_controller_test.go b/internal/controller/controllers/preprovisioningimage_controller_test.go index 28e1e36e476..a9ab33474e9 100644 --- a/internal/controller/controllers/preprovisioningimage_controller_test.go +++ b/internal/controller/controllers/preprovisioningimage_controller_test.go @@ -13,6 +13,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" configv1 "github.com/openshift/api/config/v1" + "github.com/openshift/assisted-service/api/hiveextension/v1beta1" aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1" "github.com/openshift/assisted-service/internal/bminventory" "github.com/openshift/assisted-service/internal/common" @@ -183,8 +184,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { Expect(c.Create(ctx, infraEnv)).To(BeNil()) backendInfraEnv.ClusterID = "" mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal("")) Expect(*internalIgnitionConfig).Should(ContainSubstring(defaultIronicImage)) @@ -213,8 +214,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { backendCluster.ServiceNetworks = nil Expect(c.Create(ctx, infraEnv)).To(BeNil()) mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(*internalIgnitionConfig).Should(ContainSubstring(url.QueryEscape(ironicServiceIPs[1]))) Expect(*internalIgnitionConfig).Should(ContainSubstring(url.QueryEscape(ironicInspectorIPs[1]))) @@ -238,8 +239,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { Expect(c.Create(ctx, infraEnv)).To(BeNil()) backendInfraEnv.ClusterID = "" mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(*internalIgnitionConfig).Should(ContainSubstring(url.QueryEscape(ironicServiceIPs[1]))) Expect(*internalIgnitionConfig).Should(ContainSubstring(url.QueryEscape(ironicInspectorIPs[1]))) @@ -458,8 +459,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) mockOcRelease.EXPECT().GetImageArchitecture(gomock.Any(), iccConfig.IronicAgentImage, backendInfraEnv.PullSecret).Return([]string{"x86_64"}, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal("")) Expect(*internalIgnitionConfig).Should(ContainSubstring("ironic")) @@ -497,8 +498,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { mockOcRelease.EXPECT().GetImageArchitecture(gomock.Any(), iccConfig.IronicAgentImage, backendInfraEnv.PullSecret).Times(1).Return([]string{"arm64"}, nil) mockOcRelease.EXPECT().GetReleaseArchitecture(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Times(1).Return([]string{"arm64"}, nil) mockOcRelease.EXPECT().GetIronicAgentImage(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return("ironic-image:4.12.0", nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal("")) Expect(*internalIgnitionConfig).Should(ContainSubstring("ironic")) @@ -528,8 +529,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { mockOcRelease.EXPECT().GetReleaseArchitecture(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return([]string{"x86_64"}, nil) mockOcRelease.EXPECT().GetIronicAgentImage(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return(ironicAgentImage, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal("")) Expect(*internalIgnitionConfig).Should(ContainSubstring("ironic")) @@ -558,8 +559,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { mockOcRelease.EXPECT().GetReleaseArchitecture(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return([]string{"arm64"}, nil) mockOcRelease.EXPECT().GetIronicAgentImage(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return("ironic-image:4.12.0", nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(params.InfraEnvUpdateParams.IgnitionConfigOverride).To(Equal("")) Expect(*internalIgnitionConfig).Should(ContainSubstring("ironic")) @@ -592,8 +593,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { mockOcRelease.EXPECT().GetReleaseArchitecture(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return([]string{"x86_64"}, nil).Times(1) mockOcRelease.EXPECT().GetIronicAgentImage(gomock.Any(), hubReleaseImage, "", backendInfraEnv.PullSecret).Return(ironicAgentImage, nil).Times(1) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(*internalIgnitionConfig).Should(ContainSubstring(ironicAgentImage)) }).Return( @@ -626,8 +627,8 @@ var _ = Describe("PreprovisioningImage reconcile", func() { backendInfraEnv.PullSecret = "mypullsecret" mockInstallerInternal.EXPECT().GetInfraEnvByKubeKey(gomock.Any()).Return(backendInfraEnv, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()). - Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string) { + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Do(func(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) { Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID)) Expect(internalIgnitionConfig).Should(HaveValue(ContainSubstring(overrideAgentImage))) }) @@ -767,7 +768,7 @@ var _ = Describe("PreprovisioningImage reconcile", func() { Expect(c.Create(ctx, infraEnv)).To(BeNil()) mockBMOUtils.EXPECT().getICCConfig(gomock.Any()).Times(1).Return(nil, errors.Errorf("ICC configuration is not available")) mockBMOUtils.EXPECT().GetIronicIPs().AnyTimes().Return(ironicServiceIPs, ironicInspectorIPs, nil) - mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("Failed to update infraEnvInternal")) + mockInstallerInternal.EXPECT().UpdateInfraEnvInternal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("Failed to update infraEnvInternal")) res, err := pr.Reconcile(ctx, newPreprovisioningImageRequest(ppi)) Expect(err).To(HaveOccurred()) diff --git a/internal/ignition/discovery.go b/internal/ignition/discovery.go index 8f01591583c..f0f2a575039 100644 --- a/internal/ignition/discovery.go +++ b/internal/ignition/discovery.go @@ -14,6 +14,7 @@ import ( "text/template" "time" + hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1" clusterPkg "github.com/openshift/assisted-service/internal/cluster" "github.com/openshift/assisted-service/internal/common" "github.com/openshift/assisted-service/internal/constants" @@ -156,7 +157,7 @@ const tempNMConnectionsDir = "/etc/assisted/network" // //go:generate mockgen -source=discovery.go -package=ignition -destination=mock_ignition_builder.go type IgnitionBuilder interface { - FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string) (string, error) + FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string, mirrorRegistryConfiguration *hiveext.MirrorRegistryConfiguration) (string, error) FormatSecondDayWorkerIgnitionFile(url string, caCert *string, bearerToken, ignitionEndpointHTTPHeaders string, host *models.Host) ([]byte, error) } @@ -222,7 +223,37 @@ func (ib *ignitionBuilder) shouldAppendOKDFiles(ctx context.Context, infraEnv *c return okdRpmsImage, true } -func (ib *ignitionBuilder) FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string) (string, error) { +func (ib *ignitionBuilder) setIgnitionMirrorRegistry(ignitionParams *map[string]interface{}, configuration *hiveext.MirrorRegistryConfiguration) error { + mirrorRegistriesConfigKey := "MirrorRegistriesConfig" + mirrorRegistriesCAConfigKey := "MirrorRegistriesCAConfig" + + if ib.mirrorRegistriesBuilder.IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType) { + ib.log.Infof("Setting ignition cluster mirror registry to %s", configuration.RegistriesConf) + (*ignitionParams)[mirrorRegistriesConfigKey] = base64.StdEncoding.EncodeToString([]byte(configuration.RegistriesConf)) + (*ignitionParams)[mirrorRegistriesCAConfigKey] = base64.StdEncoding.EncodeToString([]byte(configuration.CaBundleCrt)) + return nil + + } + if ib.mirrorRegistriesBuilder.IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType) { + caContents, mirrorsErr := ib.mirrorRegistriesBuilder.GetMirrorCA(mirrorregistries.ServiceMirrorRegistryType) + if mirrorsErr != nil { + ib.log.WithError(mirrorsErr).Errorf("Failed to get the mirror registries CA contents") + return mirrorsErr + } + registriesContents, mirrorsErr := ib.mirrorRegistriesBuilder.GetMirrorRegistries() + if mirrorsErr != nil { + ib.log.WithError(mirrorsErr).Errorf("Failed to get the mirror registries config contents") + return mirrorsErr + } + (*ignitionParams)[mirrorRegistriesConfigKey] = base64.StdEncoding.EncodeToString(registriesContents) + (*ignitionParams)[mirrorRegistriesCAConfigKey] = base64.StdEncoding.EncodeToString(caContents) + return nil + } + + return nil +} + +func (ib *ignitionBuilder) FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string, mirrorRegistryConfiguration *hiveext.MirrorRegistryConfiguration) (string, error) { pullSecretToken, err := clusterPkg.AgentToken(infraEnv, authType) if err != nil { return "", err @@ -326,19 +357,8 @@ func (ib *ignitionBuilder) FormatDiscoveryIgnitionFile(ctx context.Context, infr } } - if ib.mirrorRegistriesBuilder.IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType) { - caContents, mirrorsErr := ib.mirrorRegistriesBuilder.GetMirrorCA(mirrorregistries.ServiceMirrorRegistryType) - if mirrorsErr != nil { - ib.log.WithError(mirrorsErr).Errorf("Failed to get the mirror registries CA contents") - return "", mirrorsErr - } - registriesContents, mirrorsErr := ib.mirrorRegistriesBuilder.GetMirrorRegistries() - if mirrorsErr != nil { - ib.log.WithError(mirrorsErr).Errorf("Failed to get the mirror registries config contents") - return "", mirrorsErr - } - ignitionParams["MirrorRegistriesConfig"] = base64.StdEncoding.EncodeToString(registriesContents) - ignitionParams["MirrorRegistriesCAConfig"] = base64.StdEncoding.EncodeToString(caContents) + if err = ib.setIgnitionMirrorRegistry(&ignitionParams, mirrorRegistryConfiguration); err != nil { + return "", err } if okdRpmsImage, ok := ib.shouldAppendOKDFiles(ctx, infraEnv, cfg); ok { diff --git a/internal/ignition/discovery_test.go b/internal/ignition/discovery_test.go index f9daddf8279..fb7c9bb1ad7 100644 --- a/internal/ignition/discovery_test.go +++ b/internal/ignition/discovery_test.go @@ -19,6 +19,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + configv1 "github.com/openshift/api/config/v1" + "github.com/openshift/assisted-service/api/hiveextension/v1beta1" "github.com/openshift/assisted-service/internal/common" "github.com/openshift/assisted-service/internal/oc" "github.com/openshift/assisted-service/internal/versions" @@ -134,15 +136,16 @@ var _ = Describe("IgnitionBuilder", func() { ID: &infraEnvID, PullSecretSet: false, }, PullSecret: "{\"auths\":{\"registry.redhat.com\":{\"auth\":\"dG9rZW46dGVzdAo=\",\"email\":\"coyote@acme.com\"}}}"} - _, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnvWithoutToken, ignitionConfig, false, auth.TypeRHSSO, "") + _, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnvWithoutToken, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).ShouldNot(BeNil()) }) It("ignition_file_contains_pull_secret_token", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("PULL_SECRET_TOKEN")) @@ -153,16 +156,18 @@ var _ = Describe("IgnitionBuilder", func() { // Try with bundle mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(2) infraEnv.AdditionalTrustBundle = magicString - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring(dataurl.EncodeBytes([]byte(magicString)))) // Try also without bundle mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) infraEnv.AdditionalTrustBundle = "" - text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring(dataurl.EncodeBytes([]byte(magicString)))) }) @@ -170,8 +175,9 @@ var _ = Describe("IgnitionBuilder", func() { It("auth_disabled_no_pull_secret_token", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeNone, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeNone, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring("PULL_SECRET_TOKEN")) @@ -181,8 +187,9 @@ var _ = Describe("IgnitionBuilder", func() { serviceBaseURL := "file://10.56.20.70:7878" ignitionConfig.ServiceBaseURL = serviceBaseURL mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring(fmt.Sprintf("--url %s", serviceBaseURL))) @@ -192,8 +199,9 @@ var _ = Describe("IgnitionBuilder", func() { serviceBaseURL := "file://10.56.20.70:7878" ignitionConfig.ServiceBaseURL = serviceBaseURL mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, true, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, true, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring("cloud.openshift.com")) @@ -203,8 +211,9 @@ var _ = Describe("IgnitionBuilder", func() { It("enabled_cert_verification", func() { ignitionConfig.SkipCertVerification = false mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("--insecure=false")) @@ -213,8 +222,9 @@ var _ = Describe("IgnitionBuilder", func() { It("disabled_cert_verification", func() { ignitionConfig.SkipCertVerification = true mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("--insecure=true")) @@ -222,8 +232,9 @@ var _ = Describe("IgnitionBuilder", func() { It("cert_verification_enabled_by_default", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("--insecure=false")) @@ -235,10 +246,11 @@ var _ = Describe("IgnitionBuilder", func() { serviceBaseURL := "file://10.56.20.70:7878" ignitionConfig.ServiceBaseURL = serviceBaseURL mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")) By("verify ignition file contains only the proxy config entries that are set") - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring(expectedIgnitionProxySetting)) @@ -325,8 +337,9 @@ var _ = Describe("IgnitionBuilder", func() { It("produces a valid ignition v3.1 spec by default", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) @@ -338,8 +351,9 @@ var _ = Describe("IgnitionBuilder", func() { // TODO(deprecate-ignition-3.1.0) It("produces a valid ignition v3.1 spec with overrides", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) @@ -349,8 +363,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.IgnitionConfigOverride = `{"ignition": {"version": "3.1.0"}, "storage": {"files": [{"path": "/tmp/example", "contents": {"source": "data:text/plain;base64,aGVscGltdHJhcHBlZGluYXN3YWdnZXJzcGVj"}}]}}` mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err = config_31.Parse([]byte(text)) @@ -362,8 +377,9 @@ var _ = Describe("IgnitionBuilder", func() { It("produces a valid ignition spec with internal overrides", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) @@ -375,8 +391,9 @@ var _ = Describe("IgnitionBuilder", func() { ironicIgn := `{ "ignition": { "version": "3.2.0" }, "storage": { "files": [ { "group": { }, "overwrite": false, "path": "/etc/ironic-python-agent.conf", "user": { }, "contents": { "source": "data:text/plain,%0A%5BDEFAULT%5D%0Aapi_url%20%3D%20https%3A%2F%2Fironic.redhat.com%3A6385%0Ainspection_callback_url%20%3D%20https%3A%2F%2Fironic.redhat.com%3A5050%2Fv1%2Fcontinue%0Ainsecure%20%3D%20True%0A%0Acollect_lldp%20%3D%20True%0Aenable_vlan_interfaces%20%3D%20all%0Ainspection_collectors%20%3D%20default%2Cextra-hardware%2Clogs%0Ainspection_dhcp_all_interfaces%20%3D%20True%0A", "verification": { } }, "mode": 420 } ] }, "systemd": { "units": [ { "contents": "[Unit]\nDescription=Ironic Agent\nAfter=network-online.target\nWants=network-online.target\n[Service]\nEnvironment=\"HTTP_PROXY=\"\nEnvironment=\"HTTPS_PROXY=\"\nEnvironment=\"NO_PROXY=\"\nTimeoutStartSec=0\nExecStartPre=/bin/podman pull some-ironic-image --tls-verify=false --authfile=/etc/authfile.json\nExecStart=/bin/podman run --privileged --network host --mount type=bind,src=/etc/ironic-python-agent.conf,dst=/etc/ironic-python-agent/ignition.conf --mount type=bind,src=/dev,dst=/dev --mount type=bind,src=/sys,dst=/sys --mount type=bind,src=/run/dbus/system_bus_socket,dst=/run/dbus/system_bus_socket --mount type=bind,src=/,dst=/mnt/coreos --env \"IPA_COREOS_IP_OPTIONS=ip=dhcp\" --name ironic-agent somce-ironic-image\n[Install]\nWantedBy=multi-user.target\n", "enabled": true, "name": "ironic-agent.service" } ] } }` infraEnv.IgnitionConfigOverride = ironicIgn mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) Expect(text).Should(ContainSubstring("ironic-agent.service")) Expect(text).Should(ContainSubstring("ironic.redhat.com")) @@ -391,8 +408,9 @@ var _ = Describe("IgnitionBuilder", func() { It("produces a valid ignition spec with v3.2 overrides", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) @@ -403,8 +421,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.IgnitionConfigOverride = `{"ignition": {"version": "3.2.0"}, "storage": {"files": [{"path": "/tmp/example", "contents": {"source": "data:text/plain;base64,aGVscGltdHJhcHBlZGluYXN3YWdnZXJzcGVj"}}]}}` mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err = builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config2, report, err := config_32.Parse([]byte(text)) @@ -417,8 +436,9 @@ var _ = Describe("IgnitionBuilder", func() { It("fails when given overrides with an incompatible version", func() { infraEnv.IgnitionConfigOverride = `{"ignition": {"version": "2.2.0"}, "storage": {"files": [{"path": "/tmp/example", "contents": {"source": "data:text/plain;base64,aGVscGltdHJhcHBlZGluYXN3YWdnZXJzcGVj"}}]}}` mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - _, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + _, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).To(HaveOccurred()) }) @@ -442,7 +462,8 @@ var _ = Describe("IgnitionBuilder", func() { It("no multipath and iscsistart for okd - config setting", func() { ignitionConfig.OKDRPMsImage = "image" mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring("multipathd")) @@ -452,7 +473,8 @@ var _ = Describe("IgnitionBuilder", func() { It("okd support disabled", func() { ignitionConfig.EnableOKDSupport = false mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring("okd-overlay.servicemultipathd")) @@ -460,6 +482,7 @@ var _ = Describe("IgnitionBuilder", func() { It("no multipath and iscsistart for okd - okd payload", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) okdNewImageVersion := "4.12.0-0.okd-2022-11-20-010424" okdNewImageURL := "registry.ci.openshift.org/origin/release:4.12.0-0.okd-2022-11-20-010424" okdNewImage := &models.ReleaseImage{ @@ -471,7 +494,7 @@ var _ = Describe("IgnitionBuilder", func() { } mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(okdNewImage, nil).Times(1) mockOcRelease.EXPECT().GetOKDRPMSImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("quay.io/foo/bar:okd-rpms", nil) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).ShouldNot(ContainSubstring("multipathd")) @@ -481,8 +504,9 @@ var _ = Describe("IgnitionBuilder", func() { It("multipath configured for non-okd", func() { config := ignitionConfig mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, config, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, config, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("multipathd")) @@ -491,8 +515,9 @@ var _ = Describe("IgnitionBuilder", func() { It("iscsistart configured for non-okd", func() { config := ignitionConfig mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, config, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, config, false, auth.TypeRHSSO, "", nil) Expect(err).Should(BeNil()) Expect(text).Should(ContainSubstring("iscsistart")) @@ -538,9 +563,10 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.Type = common.ImageTypePtr(models.ImageTypeFullIso) infraEnv.OpenshiftVersion = ocpVersionInvolvingGenerateKeyfiles mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(false, nil).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -561,8 +587,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.CPUArchitecture = common.X86CPUArchitecture mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(true, nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -583,8 +610,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.CPUArchitecture = common.ARM64CPUArchitecture mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(false, nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -601,8 +629,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.StaticNetworkConfig = formattedInput infraEnv.Type = common.ImageTypePtr(models.ImageTypeMinimalIso) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -624,7 +653,8 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.OpenshiftVersion = ocpVersionInvolvingGenerateKeyfiles mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(false, nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso)) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso), nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -646,7 +676,8 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.CPUArchitecture = common.X86CPUArchitecture mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(true, nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso)) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso), nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -668,7 +699,8 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.CPUArchitecture = common.ARM64CPUArchitecture mockStaticNetworkConfig.EXPECT().NMStatectlServiceSupported(infraEnv.OpenshiftVersion, infraEnv.CPUArchitecture).Return(false, nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso)) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeFullIso), nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -686,8 +718,9 @@ var _ = Describe("IgnitionBuilder", func() { infraEnv.StaticNetworkConfig = formattedInput infraEnv.Type = common.ImageTypePtr(models.ImageTypeFullIso) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso)) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso), nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -704,12 +737,13 @@ var _ = Describe("IgnitionBuilder", func() { Context("mirror registries config", func() { - It("produce ignition with mirror registries config", func() { + It("produce ignition with service mirror registries config", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(true).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().GetMirrorCA(mirrorregistries.ServiceMirrorRegistryType).Return([]byte("some ca config"), nil).Times(1) mockMirrorRegistriesConfigBuilder.EXPECT().GetMirrorRegistries().Return([]byte("some mirror registries config"), nil).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) config, report, err := config_31.Parse([]byte(text)) Expect(err).NotTo(HaveOccurred()) @@ -722,15 +756,108 @@ var _ = Describe("IgnitionBuilder", func() { } Expect(count).Should(Equal(2)) }) + + const ( + mirrorRegistryCertificate = " -----BEGIN CERTIFICATE-----\n certificate contents\n -----END CERTIFICATE------" + sourceRegistry = "quay.io" + mirrorRegistry = "example-user-registry.com" + ) + + getSecureRegistryToml := func() string { + return fmt.Sprintf(` +[[registry]] +location = "%s" + +[[registry.mirror]] +location = "%s" +`, + sourceRegistry, + mirrorRegistry, + ) + } + + getInsecureRegistryToml := func() string { + x := fmt.Sprintf(` + [[registry]] + location = "%s" + + [[registry.mirror]] + location = "%s" + insecure = true + `, + sourceRegistry, + mirrorRegistry, + ) + return x + } + + getMirrorRegistryConfigurations := func(registriesToml, certificate string) (*v1beta1.MirrorRegistryConfiguration, []configv1.ImageDigestMirrors) { + imageDigestMirrors, imageTagMirrors, insecure, err := mirrorregistries.GetImageRegistries(registriesToml) + Expect(err).To(Not(HaveOccurred())) + + mirrorInfo := v1beta1.MirrorRegistryConfigurationInfo{ + ImageDigestMirrors: imageDigestMirrors, + ImageTagMirrors: imageTagMirrors, + Insecure: insecure, + } + + mirrors := &v1beta1.MirrorRegistryConfiguration{ + MirrorRegistryConfigurationInfo: &mirrorInfo, + CaBundleCrt: certificate, + RegistriesConf: registriesToml, + } + + return mirrors, imageDigestMirrors + } + + It("produce ignition with secure cluster mirror registries config", func() { + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(true).Times(1) + mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) + + mirrorRegistryConf, _ := getMirrorRegistryConfigurations(getSecureRegistryToml(), mirrorRegistryCertificate) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", mirrorRegistryConf) + Expect(err).NotTo(HaveOccurred()) + config, report, err := config_31.Parse([]byte(text)) + Expect(err).NotTo(HaveOccurred()) + Expect(report.IsFatal()).To(BeFalse()) + count := 0 + for _, f := range config.Storage.Files { + if strings.HasSuffix(f.Path, "registries.conf") || strings.HasSuffix(f.Path, "domain.crt") { + count += 1 + } + } + Expect(count).Should(Equal(2)) + }) + + It("produce ignition with insecure cluster mirror registries config", func() { + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(true).Times(1) + mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) + + mirrorRegistryConf, _ := getMirrorRegistryConfigurations(getInsecureRegistryToml(), mirrorRegistryCertificate) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", mirrorRegistryConf) + Expect(err).NotTo(HaveOccurred()) + config, report, err := config_31.Parse([]byte(text)) + Expect(err).NotTo(HaveOccurred()) + Expect(report.IsFatal()).To(BeFalse()) + count := 0 + for _, f := range config.Storage.Files { + if strings.HasSuffix(f.Path, "registries.conf") || strings.HasSuffix(f.Path, "domain.crt") { + count += 1 + } + } + Expect(count).Should(Equal(2)) + }) + }) It("Adds NTP sources script and systemd service when one additional NTP source is given", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) // Generate a ignition config adding one additional NTP source: infraEnv.AdditionalNtpSources = "ntp1.example.com" - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).ToNot(HaveOccurred()) // Parse the generated configuration: @@ -779,11 +906,12 @@ var _ = Describe("IgnitionBuilder", func() { It("Adds NTP sources script and systemd service when two additional NTP sources are given", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) // Generate a ignition config adding one additional NTP source: infraEnv.AdditionalNtpSources = "ntp1.example.com,ntp2.example.com" - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).ToNot(HaveOccurred()) // Parse the generated configuration: @@ -833,11 +961,12 @@ var _ = Describe("IgnitionBuilder", func() { It("Doesn't add NTP sources script and systemd service when no additional NTP sources are given", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) // Generate a ignition config without additional NTP sources infraEnv.AdditionalNtpSources = "" - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).ToNot(HaveOccurred()) // Parse the generated configuration: @@ -870,11 +999,12 @@ var _ = Describe("IgnitionBuilder", func() { It("NTP sources script adds entries to existing 'chrony.conf' configuration file", func() { mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error")).Times(1) // Generate a ignition config with two additional NTP sources: infraEnv.AdditionalNtpSources = "ntp1.example.com,ntp2.example.com" - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).ToNot(HaveOccurred()) // Parse the generated configuration: @@ -953,7 +1083,7 @@ var _ = Describe("Ignition SSH key building", func() { buildIgnitionAndAssertSubString := func(SSHPublicKey string, shouldExist bool, subStr string) { ignitionConfig = IgnitionConfig{EnableOKDSupport: true} infraEnv.SSHAuthorizedKey = SSHPublicKey - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "") + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, ignitionConfig, false, auth.TypeRHSSO, "", nil) Expect(err).NotTo(HaveOccurred()) if shouldExist { Expect(text).Should(ContainSubstring(subStr)) @@ -981,6 +1111,7 @@ var _ = Describe("Ignition SSH key building", func() { builder, err = NewBuilder(logrus.New(), mockStaticNetworkConfig, mockMirrorRegistriesConfigBuilder, mockOcRelease, mockVersionHandler) Expect(err).ToNot(HaveOccurred()) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) }) AfterEach(func() { @@ -1148,6 +1279,7 @@ var _ = Describe("OKD overrides", func() { builder, err = NewBuilder(logrus.New(), mockStaticNetworkConfig, mockMirrorRegistriesConfigBuilder, mockOcRelease, mockVersionHandler) Expect(err).ToNot(HaveOccurred()) mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ServiceMirrorRegistryType).Return(false).Times(1) + mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured(mirrorregistries.ClusterMirrorRegistryType).Return(false).Times(1) ocpImage = common.TestDefaultConfig.ReleaseImage okdOldImageVersion := "4.11.0-0.okd-2022-11-19-050030" okdOldImageURL := "quay.io/openshift/okd:4.11.0-0.okd-2022-11-19-050030" @@ -1208,23 +1340,23 @@ var _ = Describe("OKD overrides", func() { It("OKD_RPMS config option unset", func() { mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(ocpImage, nil).Times(1) mockOcRelease.EXPECT().GetOKDRPMSImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", errors.New("some error")) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso)) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso), nil) checkOKDFiles(text, err, false) }) It("OKD_RPMS config option not set, OKD release has no RPM image", func() { mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(okdOldImage, nil).Times(1) mockOcRelease.EXPECT().GetOKDRPMSImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", errors.New("some error")) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso)) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso), nil) checkOKDFiles(text, err, false) }) It("OKD_RPMS config option set, OKD release has no RPM image", func() { - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, okdCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso)) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, okdCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso), nil) checkOKDFiles(text, err, true) }) It("OKD_RPMS config option not set, RPM image present in release payload", func() { mockVersionHandler.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(okdNewImage, nil).Times(1) mockOcRelease.EXPECT().GetOKDRPMSImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("quay.io/foo/bar:okd-rpms", nil) - text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso)) + text, err := builder.FormatDiscoveryIgnitionFile(context.Background(), &infraEnv, defaultCfg, false, auth.TypeRHSSO, string(models.ImageTypeMinimalIso), nil) checkOKDFiles(text, err, true) }) }) diff --git a/internal/ignition/mock_ignition_builder.go b/internal/ignition/mock_ignition_builder.go index 0b5442bfda1..f868193fbd9 100644 --- a/internal/ignition/mock_ignition_builder.go +++ b/internal/ignition/mock_ignition_builder.go @@ -9,6 +9,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + v1beta1 "github.com/openshift/assisted-service/api/hiveextension/v1beta1" common "github.com/openshift/assisted-service/internal/common" models "github.com/openshift/assisted-service/models" auth "github.com/openshift/assisted-service/pkg/auth" @@ -38,18 +39,18 @@ func (m *MockIgnitionBuilder) EXPECT() *MockIgnitionBuilderMockRecorder { } // FormatDiscoveryIgnitionFile mocks base method. -func (m *MockIgnitionBuilder) FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string) (string, error) { +func (m *MockIgnitionBuilder) FormatDiscoveryIgnitionFile(ctx context.Context, infraEnv *common.InfraEnv, cfg IgnitionConfig, safeForLogs bool, authType auth.AuthType, overrideDiscoveryISOType string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FormatDiscoveryIgnitionFile", ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType) + ret := m.ctrl.Call(m, "FormatDiscoveryIgnitionFile", ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType, mirrorRegistryConfiguration) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } // FormatDiscoveryIgnitionFile indicates an expected call of FormatDiscoveryIgnitionFile. -func (mr *MockIgnitionBuilderMockRecorder) FormatDiscoveryIgnitionFile(ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType interface{}) *gomock.Call { +func (mr *MockIgnitionBuilderMockRecorder) FormatDiscoveryIgnitionFile(ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType, mirrorRegistryConfiguration interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FormatDiscoveryIgnitionFile", reflect.TypeOf((*MockIgnitionBuilder)(nil).FormatDiscoveryIgnitionFile), ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FormatDiscoveryIgnitionFile", reflect.TypeOf((*MockIgnitionBuilder)(nil).FormatDiscoveryIgnitionFile), ctx, infraEnv, cfg, safeForLogs, authType, overrideDiscoveryISOType, mirrorRegistryConfiguration) } // FormatSecondDayWorkerIgnitionFile mocks base method.