Skip to content

Commit

Permalink
MGMT-18561: MGMT-18562:
Browse files Browse the repository at this point in the history
  • Loading branch information
eliorerz committed Nov 12, 2024
1 parent 2b31f57 commit 015f338
Show file tree
Hide file tree
Showing 24 changed files with 807 additions and 718 deletions.
11 changes: 11 additions & 0 deletions api/common/common_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package common

import "github.com/openshift/api/config/v1"

// +genclient

// +kubebuilder:object:generate=true
Expand All @@ -16,3 +18,12 @@ type ValidationsStatus map[string]ValidationResults

// +kubebuilder:object:generate=true
type ValidationResults []ValidationResult

// MirrorRegistryConfiguration holds the given mirror registry configuration
type MirrorRegistryConfiguration struct {
ImageDigestMirrors []v1.ImageDigestMirrors `json:"imageDigestMirrors,omitempty"`
ImageTagMirrors []v1.ImageTagMirrors `json:"imageTagMirrors,omitempty"`
Insecure []string `json:"insecure,omitempty"`
RegistriesConf string `json:"registriesConf,omitempty"`
CaBundleCrt string `json:"caBundleCrt,omitempty"`
}
10 changes: 0 additions & 10 deletions api/hiveextension/v1beta1/agentclusterinstall_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1beta1

import (
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/assisted-service/api/common"
hivev1 "github.com/openshift/hive/apis/hive/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -520,12 +519,3 @@ type MirrorRegistryConfigMapReference struct {
// Namespace of the ConfigMap
Namespace string `json:"namespace"`
}

// MirrorRegistryConfiguration holds the given mirror registry configuration
type MirrorRegistryConfiguration struct {
ImageDigestMirrors []configv1.ImageDigestMirrors `json:"imageDigestMirrors,omitempty"`
ImageTagMirrors []configv1.ImageTagMirrors `json:"imageTagMirrors,omitempty"`
Insecure []string `json:"insecure,omitempty"`
RegistriesConf string `json:"registriesConf,omitempty"`
CaBundleCrt string `json:"caBundleCrt,omitempty"`
}
35 changes: 0 additions & 35 deletions api/hiveextension/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 36 additions & 26 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/go-version"
"github.com/kennygrant/sanitize"
"github.com/openshift/assisted-service/api/hiveextension/v1beta1"
common_api "github.com/openshift/assisted-service/api/common"
clusterPkg "github.com/openshift/assisted-service/internal/cluster"
"github.com/openshift/assisted-service/internal/cluster/validations"
"github.com/openshift/assisted-service/internal/common"
Expand Down Expand Up @@ -60,7 +60,6 @@ import (
"github.com/openshift/assisted-service/pkg/k8sclient"
"github.com/openshift/assisted-service/pkg/leader"
logutil "github.com/openshift/assisted-service/pkg/log"
"github.com/openshift/assisted-service/pkg/mirrorregistries"
"github.com/openshift/assisted-service/pkg/ocm"
"github.com/openshift/assisted-service/pkg/s3wrapper"
"github.com/openshift/assisted-service/pkg/staticnetworkconfig"
Expand Down Expand Up @@ -146,12 +145,12 @@ type OCPClusterAPI interface {

//go:generate mockgen --build_flags=--mod=mod -package bminventory -destination mock_installer_internal.go . InstallerInternals
type InstallerInternals interface {
RegisterClusterInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.V2RegisterClusterParams) (*common.Cluster, error)
RegisterClusterInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration, params installer.V2RegisterClusterParams) (*common.Cluster, error)
GetClusterInternal(ctx context.Context, params installer.V2GetClusterParams) (*common.Cluster, error)
UpdateClusterNonInteractive(ctx context.Context, params installer.V2UpdateClusterParams) (*common.Cluster, error)
UpdateClusterNonInteractive(ctx context.Context, params installer.V2UpdateClusterParams, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) (*common.Cluster, error)
GetClusterByKubeKey(key types.NamespacedName) (*common.Cluster, error)
GetHostByKubeKey(key types.NamespacedName) (*common.Host, error)
InstallClusterInternal(ctx context.Context, params installer.V2InstallClusterParams, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.Cluster, error)
InstallClusterInternal(ctx context.Context, params installer.V2InstallClusterParams) (*common.Cluster, error)
DeregisterClusterInternal(ctx context.Context, cluster *common.Cluster) error
V2DeregisterHostInternal(ctx context.Context, params installer.V2DeregisterHostParams, interactivity Interactivity) error
GetCommonHostInternal(ctx context.Context, infraEnvId string, hostId string) (*common.Host, error)
Expand All @@ -163,14 +162,14 @@ type InstallerInternals interface {
V2DownloadClusterCredentialsInternal(ctx context.Context, params installer.V2DownloadClusterCredentialsParams) (io.ReadCloser, int64, error)
V2ImportClusterInternal(ctx context.Context, kubeKey *types.NamespacedName, id *strfmt.UUID, params installer.V2ImportClusterParams) (*common.Cluster, error)
InstallSingleDay2HostInternal(ctx context.Context, clusterId strfmt.UUID, infraEnvId strfmt.UUID, hostId strfmt.UUID) error
UpdateClusterInstallConfigInternal(ctx context.Context, params installer.V2UpdateClusterInstallConfigParams, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.Cluster, error)
UpdateClusterInstallConfigInternal(ctx context.Context, params installer.V2UpdateClusterInstallConfigParams) (*common.Cluster, error)
CancelInstallationInternal(ctx context.Context, params installer.V2CancelInstallationParams) (*common.Cluster, error)
TransformClusterToDay2Internal(ctx context.Context, clusterID strfmt.UUID) (*common.Cluster, error)
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, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.InfraEnv, error)
RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error)
UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) (*common.InfraEnv, error)
RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error)
DeregisterInfraEnvInternal(ctx context.Context, params installer.DeregisterInfraEnvParams) error
UnbindHostInternal(ctx context.Context, params installer.UnbindHostParams, reclaimHost bool, interactivity Interactivity) (*common.Host, error)
BindHostInternal(ctx context.Context, params installer.BindHostParams) (*common.Host, error)
Expand Down Expand Up @@ -504,7 +503,7 @@ func MarshalNewClusterParamsNoPullSecret(params installer.V2RegisterClusterParam
return jsonNewClusterParams
}

func (b *bareMetalInventory) RegisterClusterInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.V2RegisterClusterParams) (*common.Cluster, error) {
func (b *bareMetalInventory) RegisterClusterInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration, params installer.V2RegisterClusterParams) (*common.Cluster, error) {
id := strfmt.UUID(uuid.New().String())
url := installer.V2GetClusterURL{ClusterID: id}

Expand Down Expand Up @@ -1281,7 +1280,7 @@ func (b *bareMetalInventory) integrateWithAMSClusterPreInstallation(ctx context.
return nil
}

func (b *bareMetalInventory) InstallClusterInternal(ctx context.Context, params installer.V2InstallClusterParams, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.Cluster, error) {
func (b *bareMetalInventory) InstallClusterInternal(ctx context.Context, params installer.V2InstallClusterParams) (*common.Cluster, error) {
log := logutil.FromContext(ctx, b.log)
var err error
var cluster *common.Cluster
Expand Down Expand Up @@ -1649,7 +1648,7 @@ func (b *bareMetalInventory) GetArchitecturesSupportLevelListInternal(_ context.
return featuresupport.GetCpuArchitectureSupportList(params.OpenshiftVersion), nil
}

func (b *bareMetalInventory) UpdateClusterInstallConfigInternal(ctx context.Context, params installer.V2UpdateClusterInstallConfigParams, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.Cluster, error) {
func (b *bareMetalInventory) UpdateClusterInstallConfigInternal(ctx context.Context, params installer.V2UpdateClusterInstallConfigParams) (*common.Cluster, error) {
log := logutil.FromContext(ctx, b.log)
var cluster *common.Cluster
var clusterInfraenvs []*common.InfraEnv
Expand All @@ -1672,13 +1671,6 @@ func (b *bareMetalInventory) UpdateClusterInstallConfigInternal(ctx context.Cont
return common.NewApiError(http.StatusBadRequest, err)
}

if mirrorregistries.IsMirrorConfigurationSet(mirrorRegistryConfiguration) {
err = cluster.SetMirrorRegistryConfiguration(mirrorRegistryConfiguration)
if err != nil {
log.WithError(err).Errorf("failed to set mirror registry for cluster %s", params.ClusterID)
}
}

// Set install config overrides feature usage
err = b.setInstallConfigOverridesUsage(cluster.Cluster.FeatureUsage, params.InstallConfigParams, params.ClusterID, tx)
if err != nil {
Expand Down Expand Up @@ -1924,15 +1916,15 @@ func (b *bareMetalInventory) validateAndUpdateClusterParams(ctx context.Context,
}

func (b *bareMetalInventory) V2UpdateCluster(ctx context.Context, params installer.V2UpdateClusterParams) middleware.Responder {
c, err := b.v2UpdateClusterInternal(ctx, params, Interactive)
c, err := b.v2UpdateClusterInternal(ctx, params, Interactive, nil)
if err != nil {
return common.GenerateErrorResponder(err)
}
return installer.NewV2UpdateClusterCreated().WithPayload(&c.Cluster)
}

func (b *bareMetalInventory) UpdateClusterNonInteractive(ctx context.Context, params installer.V2UpdateClusterParams) (*common.Cluster, error) {
return b.v2UpdateClusterInternal(ctx, params, NonInteractive)
func (b *bareMetalInventory) UpdateClusterNonInteractive(ctx context.Context, params installer.V2UpdateClusterParams, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) (*common.Cluster, error) {
return b.v2UpdateClusterInternal(ctx, params, NonInteractive, mirrorRegistryConfiguration)
}

func getPlatformType(platform *models.Platform) string {
Expand Down Expand Up @@ -2020,7 +2012,7 @@ func (b *bareMetalInventory) setUpdatedPlatformParams(log logrus.FieldLogger, cl
return params, nil
}

func (b *bareMetalInventory) v2UpdateClusterInternal(ctx context.Context, params installer.V2UpdateClusterParams, interactivity Interactivity) (*common.Cluster, error) {
func (b *bareMetalInventory) v2UpdateClusterInternal(ctx context.Context, params installer.V2UpdateClusterParams, interactivity Interactivity, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) (*common.Cluster, error) {
log := logutil.FromContext(ctx, b.log)
var cluster *common.Cluster
var err error
Expand All @@ -2045,7 +2037,7 @@ func (b *bareMetalInventory) v2UpdateClusterInternal(ctx context.Context, params
return err
}

err = b.updateClusterData(ctx, cluster, params, usages, tx, log, interactivity)
err = b.updateClusterData(ctx, cluster, params, usages, tx, log, interactivity, mirrorRegistryConfiguration)
if err != nil {
log.WithError(err).Error("updateClusterData")
return err
Expand Down Expand Up @@ -2273,7 +2265,7 @@ func (b *bareMetalInventory) setDiskEncryptionUsage(c *models.Cluster, diskEncry
b.setUsage(swag.StringValue(c.DiskEncryption.EnableOn) != models.DiskEncryptionEnableOnNone, usage.DiskEncryption, &props, usages)
}

func (b *bareMetalInventory) updateClusterData(_ context.Context, cluster *common.Cluster, params installer.V2UpdateClusterParams, usages map[string]models.Usage, db *gorm.DB, log logrus.FieldLogger, interactivity Interactivity) error {
func (b *bareMetalInventory) updateClusterData(_ context.Context, cluster *common.Cluster, params installer.V2UpdateClusterParams, usages map[string]models.Usage, db *gorm.DB, log logrus.FieldLogger, interactivity Interactivity, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) error {
var err error
updates := map[string]interface{}{}
optionalParam(params.ClusterUpdateParams.Name, "name", updates)
Expand All @@ -2290,6 +2282,10 @@ func (b *bareMetalInventory) updateClusterData(_ context.Context, cluster *commo
return err
}

if err = b.updateClusterMirrorRegistry(cluster, mirrorRegistryConfiguration, updates); err != nil {
return err
}

if err = b.updateNetworkParams(params, cluster, updates, usages, db, log, interactivity); err != nil {
return err
}
Expand Down Expand Up @@ -2581,6 +2577,20 @@ func setUpdatesForPlatformParams(params installer.V2UpdateClusterParams, updates
}
}

func (b *bareMetalInventory) updateClusterMirrorRegistry(cluster *common.Cluster, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration, updates map[string]interface{}) error {
mirrorConfigString, err := common.ConvertMirrorRegistryConfigToString(mirrorRegistryConfiguration)
if err != nil {
return common.NewApiError(http.StatusInternalServerError, err)
}

if mirrorConfigString == cluster.MirrorRegistryConfiguration {
return nil
}

updates["mirror_registry_configuration"] = mirrorConfigString
return nil
}

func (b *bareMetalInventory) updatePlatformParams(params installer.V2UpdateClusterParams, updates map[string]interface{}, usages map[string]models.Usage) error {
if params.ClusterUpdateParams.Platform == nil || common.PlatformTypeValue(params.ClusterUpdateParams.Platform.Type) == "" {
return nil
Expand Down Expand Up @@ -4558,7 +4568,7 @@ func (b *bareMetalInventory) handlerClusterInfoOnRegisterInfraEnv(
return nil
}

func (b *bareMetalInventory) RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error) {
func (b *bareMetalInventory) RegisterInfraEnvInternal(ctx context.Context, kubeKey *types.NamespacedName, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration, params installer.RegisterInfraEnvParams) (*common.InfraEnv, error) {

var infraEnv common.InfraEnv
var id strfmt.UUID
Expand Down Expand Up @@ -4926,7 +4936,7 @@ func (b *bareMetalInventory) UpdateInfraEnv(ctx context.Context, params installe
return installer.NewUpdateInfraEnvCreated().WithPayload(&i.InfraEnv)
}

func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *v1beta1.MirrorRegistryConfiguration) (*common.InfraEnv, error) {
func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params installer.UpdateInfraEnvParams, internalIgnitionConfig *string, mirrorRegistryConfiguration *common_api.MirrorRegistryConfiguration) (*common.InfraEnv, error) {
log := logutil.FromContext(ctx, b.log)
var infraEnv *common.InfraEnv
var err error
Expand Down
Loading

0 comments on commit 015f338

Please sign in to comment.