Skip to content

Commit

Permalink
MGMT-16452: Change MCE subscription to use the default channel
Browse files Browse the repository at this point in the history
  • Loading branch information
danmanor committed Dec 27, 2023
1 parent 03e376c commit 20c3df0
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 191 deletions.
6 changes: 2 additions & 4 deletions Makefile
Expand Up @@ -143,7 +143,6 @@ REPORTS ?= $(ROOT_DIR)/reports
GO_TEST_FORMAT = pkgname
DEFAULT_RELEASE_IMAGES = $(shell (tr -d '\n\t ' < ${ROOT_DIR}/data/default_release_images.json))
DEFAULT_OS_IMAGES = $(shell (tr -d '\n\t ' < ${ROOT_DIR}/data/default_os_images.json))
DEFAULT_OCP_MCE_VERSION_MAP = $(shell (tr -d '\n\t ' < ${ROOT_DIR}/data/default_ocp_mce_version_map.json))

# Support all Release/OS images for CI
ifeq ($(CI), true)
Expand All @@ -152,7 +151,6 @@ endif

RELEASE_IMAGES := $(or ${RELEASE_IMAGES},${DEFAULT_RELEASE_IMAGES})
OS_IMAGES := $(or ${OS_IMAGES},${DEFAULT_OS_IMAGES})
OCP_MCE_VERSION_MAP := $(or ${OCP_MCE_VERSION_MAP},${DEFAULT_OCP_MCE_VERSION_MAP})

# Support given Release/OS images.
ifdef OPENSHIFT_VERSION
Expand Down Expand Up @@ -326,8 +324,8 @@ deploy-service-requirements: | deploy-namespace deploy-inventory-service-file
--storage $(STORAGE) --ipv6-support $(IPV6_SUPPORT) --enable-sno-dnsmasq $(ENABLE_SINGLE_NODE_DNSMASQ) \
--disk-encryption-support $(DISK_ENCRYPTION_SUPPORT) --hw-requirements '$(subst ",\",$(HW_REQUIREMENTS))' \
--disabled-host-validations "$(DISABLED_HOST_VALIDATIONS)" --disabled-steps "$(DISABLED_STEPS)" \
--enable-org-tenancy $(ENABLE_ORG_TENANCY) --enable-org-based-feature-gate $(ENABLE_ORG_BASED_FEATURE_GATES) \
--ocp-mce-version-map '$(subst ",\",$(OCP_MCE_VERSION_MAP))' $(ALLOW_CONVERGED_FLOW_CMD) $(DISABLE_TLS_CMD)
--enable-org-tenancy $(ENABLE_ORG_TENANCY) \
--enable-org-based-feature-gate $(ENABLE_ORG_BASED_FEATURE_GATES) $(ALLOW_CONVERGED_FLOW_CMD) $(DISABLE_TLS_CMD)
ifeq ($(MIRROR_REGISTRY_SUPPORT), True)
python3 ./tools/deploy_assisted_installer_configmap_registry_ca.py --target "$(TARGET)" \
--namespace "$(NAMESPACE)" --apply-manifest $(APPLY_MANIFEST) --ca-file-path $(MIRROR_REG_CA_FILE) --registries-file-path $(REGISTRIES_FILE_PATH)
Expand Down
7 changes: 0 additions & 7 deletions data/default_ocp_mce_version_map.json

This file was deleted.

2 changes: 0 additions & 2 deletions deploy/assisted-service-configmap.yaml
Expand Up @@ -26,5 +26,3 @@ data:
DISABLED_HOST_VALIDATIONS: REPLACE_DISABLED_HOST_VALIDATIONS
DISABLED_STEPS: REPLACE_DISABLED_STEPS
ISO_IMAGE_TYPE: REPLACE_ISO_IMAGE_TYPE
OCP_MCE_VERSION_MAP: REPLACE_OCP_MCE_VERSION_MAP

1 change: 0 additions & 1 deletion deploy/podman/configmap.yml
Expand Up @@ -30,4 +30,3 @@ data:
SERVICE_BASE_URL: http://127.0.0.1:8090
STORAGE: filesystem
ENABLE_UPGRADE_AGENT: "true"
OCP_MCE_VERSION_MAP: '[{"openshift_version": "4.11", "mce_channel": "stable-2.3"}, {"openshift_version": "4.12", "mce_channel": "stable-2.4"}, {"openshift_version": "4.13", "mce_channel": "stable-2.3"}, {"openshift_version": "4.14", "mce_channel": "stable-2.4"}, {"openshift_version": "4.15", "mce_channel": "stable-2.4"}]'
3 changes: 1 addition & 2 deletions internal/operators/builder.go
Expand Up @@ -29,12 +29,11 @@ var OperatorConsole = models.MonitoredOperator{
type Options struct {
CheckClusterVersion bool
CNVConfig cnv.Config
MCEConfig mce.EnvironmentalConfig
}

// NewManager creates new instance of an Operator Manager
func NewManager(log logrus.FieldLogger, manifestAPI manifestsapi.ManifestsAPI, options Options, objectHandler s3wrapper.API, extracter oc.Extracter) *Manager {
return NewManagerWithOperators(log, manifestAPI, options, objectHandler, lso.NewLSOperator(), odf.NewOcsOperator(log), odf.NewOdfOperator(log, extracter), cnv.NewCNVOperator(log, options.CNVConfig, extracter), lvm.NewLvmOperator(log, extracter), mce.NewMceOperator(log, options.MCEConfig))
return NewManagerWithOperators(log, manifestAPI, options, objectHandler, lso.NewLSOperator(), odf.NewOcsOperator(log), odf.NewOdfOperator(log, extracter), cnv.NewCNVOperator(log, options.CNVConfig, extracter), lvm.NewLvmOperator(log, extracter), mce.NewMceOperator(log))
}

// NewManagerWithOperators creates new instance of an Operator Manager and configures it with given operators
Expand Down
4 changes: 1 addition & 3 deletions internal/operators/manager_test.go
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/internal/operators/cnv"
"github.com/openshift/assisted-service/internal/operators/lso"
"github.com/openshift/assisted-service/internal/operators/mce"
"github.com/openshift/assisted-service/internal/operators/odf"
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/conversions"
Expand Down Expand Up @@ -60,8 +59,7 @@ var _ = BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
manifestsAPI = manifestsapi.NewMockManifestsAPI(ctrl)
mockS3Api = s3wrapper.NewMockAPI(ctrl)
defaultocpMceVersionMap := "[{\"openshift_version\": \"4.10\", \"mce_channel\": \"stable-2.3\"}, {\"openshift_version\": \"4.11\", \"mce_channel\": \"stable-2.3\"}, {\"openshift_version\": \"4.12\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.13\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.14\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.15\", \"mce_channel\": \"stable-2.4\"}]"
manager = operators.NewManager(log, manifestsAPI, operators.Options{MCEConfig: mce.EnvironmentalConfig{OCPMCEVersionMap: defaultocpMceVersionMap}}, mockS3Api, nil)
manager = operators.NewManager(log, manifestsAPI, operators.Options{}, mockS3Api, nil)
})

var _ = AfterEach(func() {
Expand Down
69 changes: 4 additions & 65 deletions internal/operators/mce/config.go
@@ -1,27 +1,8 @@
package mce

import (
_ "embed"
"encoding/json"
"fmt"

"github.com/openshift/assisted-service/internal/common"
)

type EnvironmentalConfig struct {
OCPMCEVersionMap string `envconfig:"OCP_MCE_VERSION_MAP" default:"[{\"openshift_version\": \"4.11\", \"mce_channel\": \"stable-2.3\"}, {\"openshift_version\": \"4.12\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.14\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.14\", \"mce_channel\": \"stable-2.4\"}, {\"openshift_version\": \"4.15\", \"mce_channel\": \"stable-2.4\"}]"`
}

type OcpMceVersionMap struct {
OpenshiftVersion string `json:"openshift_version"`
MceChannel string `json:"mce_channel"`
}

type Config struct {
OcpMceVersionMap []OcpMceVersionMap
}

const (
MceMinOpenshiftVersion string = "4.10.0"

// Memory value provided in GiB
MinimumMemory int64 = 16
MinimumCPU int64 = 4
Expand All @@ -31,48 +12,6 @@ const (
SNOMinimumCpu int64 = 8
)

func getMinMceOpenshiftVersion(ocpMceVersionMap []OcpMceVersionMap) (*string, error) {
lowestVersion := ocpMceVersionMap[0].OpenshiftVersion
for _, version := range ocpMceVersionMap {
isLower, err := common.BaseVersionLessThan(lowestVersion, version.OpenshiftVersion)
if err != nil {
return nil, err
}
if isLower {
lowestVersion = version.OpenshiftVersion
}
}

return &lowestVersion, nil
}

func parseMCEConfig(config EnvironmentalConfig) (*Config, error) {
var parsedConfig []OcpMceVersionMap
if err := json.Unmarshal([]byte(config.OCPMCEVersionMap), &parsedConfig); err != nil {
return nil, fmt.Errorf("failed to unmarshal ocp mce release config: %w", err)
}

return &Config{
OcpMceVersionMap: parsedConfig,
}, nil
}

func getMCEVersion(openshiftVersion string, ocpMceVersionMap []OcpMceVersionMap) (*string, error) {
baseVersion, err := common.GetMajorMinorVersion(openshiftVersion)
if err != nil {
return nil, fmt.Errorf("failed to get base version of %s", openshiftVersion)
}

var mceChannel string
for _, record := range ocpMceVersionMap {
if record.OpenshiftVersion == *baseVersion {
mceChannel = record.MceChannel
}
}

if mceChannel == "" {
return nil, fmt.Errorf("failed to find mce channel for the given openshift version %s", openshiftVersion)
}

return &mceChannel, nil
type Config struct {
MceMinOpenshiftVersion string `envconfig:"MCE_MIN_OPENSHIFT_VERSION" default:"4.10.0"`
}
17 changes: 5 additions & 12 deletions internal/operators/mce/manifest.go
Expand Up @@ -6,7 +6,7 @@ import (
)

// Manifests returns manifests needed to deploy MCE.
func Manifests(openshiftVersion string, config *Config) (openshiftManifests map[string][]byte, customManifests []byte, err error) {
func Manifests() (openshiftManifests map[string][]byte, customManifests []byte, err error) {
// Generate the OpenShift manifests:
namespaceManifest, err := getNamespace()
if err != nil {
Expand All @@ -16,7 +16,7 @@ func Manifests(openshiftVersion string, config *Config) (openshiftManifests map[
if err != nil {
return
}
operatorSubscriptionManifest, err := getSubscription(openshiftVersion, config)
operatorSubscriptionManifest, err := getSubscription()
if err != nil {
return
}
Expand All @@ -34,16 +34,10 @@ func Manifests(openshiftVersion string, config *Config) (openshiftManifests map[
return openshiftManifests, mceManifest, nil
}

func getSubscription(openshiftVersion string, config *Config) ([]byte, error) {
mceChannel, err := getMCEVersion(openshiftVersion, config.OcpMceVersionMap)
if err != nil {
return nil, err
}

func getSubscription() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
"OPERATOR_SUBSCRIPTION_NAME": Operator.SubscriptionName,
"OPERATOR_SUBSCRIPTION_CHANNEL": *mceChannel,
"OPERATOR_NAMESPACE": Operator.Namespace,
"OPERATOR_SUBSCRIPTION_NAME": Operator.SubscriptionName,
}
return executeTemplate(data, operatorSubscriptionManifestTemplate)
}
Expand Down Expand Up @@ -97,7 +91,6 @@ metadata:
namespace: "{{ .OPERATOR_NAMESPACE }}"
name: "{{.OPERATOR_SUBSCRIPTION_NAME}}"
spec:
channel: "{{.OPERATOR_SUBSCRIPTION_CHANNEL}}"
sourceNamespace: openshift-marketplace
source: redhat-operators
name: multicluster-engine
Expand Down
66 changes: 1 addition & 65 deletions internal/operators/mce/manifest_test.go
Expand Up @@ -9,33 +9,7 @@ import (
)

var _ = Describe("MCE manifest generation", func() {

config := Config{
OcpMceVersionMap: []OcpMceVersionMap{
{
OpenshiftVersion: "4.11",
MceChannel: "stable-2.3",
},
{
OpenshiftVersion: "4.12",
MceChannel: "stable-2.4",
},
{
OpenshiftVersion: "4.13",
MceChannel: "stable-2.4",
},
{
OpenshiftVersion: "4.14",
MceChannel: "stable-2.4",
},
{
OpenshiftVersion: "4.15",
MceChannel: "stable-2.4",
},
},
}

operator := NewMceOperator(common.GetTestLog(), EnvironmentalConfig{})
operator := NewMceOperator(common.GetTestLog())
var cluster *common.Cluster

getCluster := func(openshiftVersion string) *common.Cluster {
Expand All @@ -46,44 +20,6 @@ var _ = Describe("MCE manifest generation", func() {
}

Context("MCE Manifest", func() {
It("Get MCE channel", func() {
var (
version *string
err error
)

version, err = getMCEVersion("4.15", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.4"))

version, err = getMCEVersion("4.14", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.4"))

version, err = getMCEVersion("4.13", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.4"))

version, err = getMCEVersion("4.12", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.4"))

version, err = getMCEVersion("4.11", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.3"))

_, err = getMCEVersion("4.10", config.OcpMceVersionMap)
Expect(err).To(HaveOccurred())

version, err = getMCEVersion("4.12.0-0.nightly-2022-10-25-210451", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.4"))

version, err = getMCEVersion("4.11.0-ec.3", config.OcpMceVersionMap)
Expect(err).ToNot(HaveOccurred())
Expect(*version).To(Equal("stable-2.3"))
})

It("Check YAMLs of MCE", func() {
cluster = getCluster("4.11.0")
openshiftManifests, manifest, err := operator.GenerateManifests(cluster)
Expand Down
31 changes: 13 additions & 18 deletions internal/operators/mce/mce_operator.go
Expand Up @@ -29,25 +29,21 @@ var Operator = models.MonitoredOperator{
}

// NewMceOperator creates new MCE operator.
func NewMceOperator(log logrus.FieldLogger, config EnvironmentalConfig) *operator {
err := envconfig.Process(common.EnvConfigPrefix, &config)
func NewMceOperator(log logrus.FieldLogger) *operator {
cfg := Config{}
err := envconfig.Process(common.EnvConfigPrefix, &cfg)
if err != nil {
log.Fatal(err.Error())
}

parsedConfig, err := parseMCEConfig(config)
if err != nil {
log.Fatal(err.Error())
}

return newMceOperatorWithConfig(log, parsedConfig)
return newMceOperatorWithConfig(log, &cfg)
}

// newMceOperatorWithConfig creates new MCE operator with the given configuration.
func newMceOperatorWithConfig(log logrus.FieldLogger, parsedConfig *Config) *operator {
func newMceOperatorWithConfig(log logrus.FieldLogger, config *Config) *operator {
return &operator{
log: log,
config: parsedConfig,
config: config,
}
}

Expand Down Expand Up @@ -84,16 +80,15 @@ func (o *operator) ValidateCluster(_ context.Context, cluster *common.Cluster) (
if err != nil {
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{err.Error()}}, nil
}
mceMinOpenshiftVersion, err := getMinMceOpenshiftVersion(o.config.OcpMceVersionMap)
if err != nil {
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{err.Error()}}, nil
}
minOpenshiftVersionForMce, err = version.NewVersion(*mceMinOpenshiftVersion)

minOpenshiftVersionForMce, err = version.NewVersion(o.config.MceMinOpenshiftVersion)

if err != nil {
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{err.Error()}}, nil
}

if ocpVersion.LessThan(minOpenshiftVersionForMce) {
message := fmt.Sprintf("multicluster engine is only supported for openshift versions %s and above", *mceMinOpenshiftVersion)
message := fmt.Sprintf("multicluster engine is only supported for openshift versions %s and above", o.config.MceMinOpenshiftVersion)
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetClusterValidationID(), Reasons: []string{message}}, nil
}

Expand Down Expand Up @@ -140,8 +135,8 @@ func (o *operator) ValidateHost(ctx context.Context, cluster *common.Cluster, ho
}

// GenerateManifests generates manifests for the operator.
func (o *operator) GenerateManifests(cluster *common.Cluster) (map[string][]byte, []byte, error) {
return Manifests(cluster.OpenshiftVersion, o.config)
func (o *operator) GenerateManifests(_ *common.Cluster) (map[string][]byte, []byte, error) {
return Manifests()
}

// GetProperties provides description of operator properties.
Expand Down
9 changes: 3 additions & 6 deletions internal/operators/mce/mce_operator_test.go
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("MCE Operator", func() {

var (
ctx = context.TODO()
operator = NewMceOperator(common.GetTestLog(), EnvironmentalConfig{})
operator = NewMceOperator(common.GetTestLog())
hostWithNoInventory = &models.Host{}
hostWithInsufficientResources = &models.Host{
Inventory: Inventory(&InventoryResources{
Expand Down Expand Up @@ -78,19 +78,16 @@ var _ = Describe("MCE Operator", func() {
)
})
Context("ValidateCluster", func() {
mceMinOpenshiftVersion, err := getMinMceOpenshiftVersion(operator.config.OcpMceVersionMap)
Expect(err).ToNot((HaveOccurred()))

table.DescribeTable("validate cluster when ", func(cluster *common.Cluster, expectedResult api.ValidationResult) {
res, _ := operator.ValidateCluster(ctx, cluster)
Expect(res).Should(Equal(expectedResult))
},
table.Entry("Openshift version less than minimal",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}, OpenshiftVersion: "4.9.0"}},
api.ValidationResult{Status: api.Failure, ValidationId: operator.GetHostValidationID(), Reasons: []string{fmt.Sprintf("multicluster engine is only supported for openshift versions %s and above", *mceMinOpenshiftVersion)}},
api.ValidationResult{Status: api.Failure, ValidationId: operator.GetHostValidationID(), Reasons: []string{fmt.Sprintf("multicluster engine is only supported for openshift versions %s and above", MceMinOpenshiftVersion)}},
),
table.Entry("Openshift version more than minimal",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}, OpenshiftVersion: *mceMinOpenshiftVersion}},
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}, OpenshiftVersion: MceMinOpenshiftVersion}},
api.ValidationResult{Status: api.Success, ValidationId: operator.GetHostValidationID()},
),
)
Expand Down
4 changes: 0 additions & 4 deletions openshift/template.yaml
Expand Up @@ -202,8 +202,6 @@ parameters:
value: "false"
- name: ENVOY_CONFIGMAP_NAME
value: assisted-service-envoy-config
- name: OCP_MCE_VERSION_MAP
value: '[{"openshift_version": "4.11", "mce_channel": "stable-2.3"}, {"openshift_version": "4.12", "mce_channel": "stable-2.4"}, {"openshift_version": "4.13", "mce_channel": "stable-2.3"}, {"openshift_version": "4.14", "mce_channel": "stable-2.4"}, {"openshift_version": "4.15", "mce_channel": "stable-2.4"}]'
apiVersion: v1
kind: Template
metadata:
Expand Down Expand Up @@ -463,8 +461,6 @@ objects:
value: ${INSTALLER_CACHE_CAPACITY}
- name: ENABLE_OKD_SUPPORT
value: ${ENABLE_OKD_SUPPORT}
- name: OCP_MCE_VERSION_MAP
value: ${OCP_MCE_VERSION_MAP}
volumeMounts:
- name: route53-creds
mountPath: "/etc/.aws"
Expand Down

0 comments on commit 20c3df0

Please sign in to comment.