Skip to content

Commit

Permalink
MGMT-15699: Service changes for avoiding MCO reboot
Browse files Browse the repository at this point in the history
In order to avoid MCO reboot the release image and the pull secret are
needed by assisted installer.  Therefore, they were added to the install
command.
In addition feature flag was added.  If this flag is set, the pull
secret is sent in the install command.
Only if the pull secret is ent, the MCO reboot will be avoided.
  • Loading branch information
ori-amizur committed Sep 3, 2023
1 parent 6420e49 commit 567b1c6
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 31 deletions.

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

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

3 changes: 3 additions & 0 deletions internal/feature/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ type Flags struct {
// EnableRejectUnknownFields is a boolean flag to enable or disable rejecting unknown fields
// in JSON request bodies.
EnableRejectUnknownFields bool `envconfig:"ENABLE_REJECT_UNKNOWN_FIELDS" default:"true"`

// EnableSkipMcoReboot is a boolean flag to enable MCO reboot by assisted installer
EnableSkipMcoReboot bool `envconfig:"ENABLE_SKIP_MCO_REBOOT" default:"true"`
}
67 changes: 48 additions & 19 deletions internal/host/hostcommands/install_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@ import (

type installCmd struct {
baseCmd
db *gorm.DB
hwValidator hardware.Validator
ocRelease oc.Release
instructionConfig InstructionConfig
eventsHandler eventsapi.Handler
versionsHandler versions.Handler
db *gorm.DB
hwValidator hardware.Validator
ocRelease oc.Release
instructionConfig InstructionConfig
eventsHandler eventsapi.Handler
versionsHandler versions.Handler
enableSkipMcoReboot bool
}

func NewInstallCmd(log logrus.FieldLogger, db *gorm.DB, hwValidator hardware.Validator, ocRelease oc.Release,
instructionConfig InstructionConfig, eventsHandler eventsapi.Handler, versionsHandler versions.Handler) *installCmd {
instructionConfig InstructionConfig, eventsHandler eventsapi.Handler, versionsHandler versions.Handler, enableSkipMcoReboot bool) *installCmd {
return &installCmd{
baseCmd: baseCmd{log: log},
db: db,
hwValidator: hwValidator,
ocRelease: ocRelease,
instructionConfig: instructionConfig,
eventsHandler: eventsHandler,
versionsHandler: versionsHandler,
baseCmd: baseCmd{log: log},
db: db,
hwValidator: hwValidator,
ocRelease: ocRelease,
instructionConfig: instructionConfig,
eventsHandler: eventsHandler,
versionsHandler: versionsHandler,
enableSkipMcoReboot: enableSkipMcoReboot,
}
}

Expand Down Expand Up @@ -102,6 +104,11 @@ func (i *installCmd) getFullInstallerCommand(ctx context.Context, cluster *commo
haMode = *cluster.HighAvailabilityMode
}

releaseImage, err := i.versionsHandler.GetReleaseImage(ctx, cluster.OpenshiftVersion, cluster.CPUArchitecture, cluster.PullSecret)
if err != nil {
return "", err
}

request := models.InstallCmdRequest{
Role: &role,
ClusterID: host.ClusterID,
Expand All @@ -112,22 +119,23 @@ func (i *installCmd) getFullInstallerCommand(ctx context.Context, cluster *commo
CheckCvo: swag.Bool(i.instructionConfig.CheckClusterVersion),
InstallerImage: swag.String(i.instructionConfig.InstallerImage),
BootDevice: swag.String(bootdevice),
ReleaseImage: swag.StringValue(releaseImage.URL),
}
if i.enableSkipMcoReboot {
request.PullSecret = cluster.PullSecret
}

// those flags are not used on day2 installation
if swag.StringValue(cluster.Kind) != models.ClusterKindAddHostsCluster {
releaseImage, err := i.versionsHandler.GetReleaseImage(ctx, cluster.OpenshiftVersion, cluster.CPUArchitecture, cluster.PullSecret)
if err != nil {
return "", err
}

request.McoImage, err = i.ocRelease.GetMCOImage(i.log, *releaseImage.URL, i.instructionConfig.ReleaseImageMirror, cluster.PullSecret)
if err != nil {
return "", err
}
i.log.Infof("Install command releaseImage: %s, mcoImage: %s", *releaseImage.URL, request.McoImage)

mustGatherMap, err := i.versionsHandler.GetMustGatherImages(cluster.OpenshiftVersion, cluster.CPUArchitecture, cluster.PullSecret)
var mustGatherMap versions.MustGatherVersion
mustGatherMap, err = i.versionsHandler.GetMustGatherImages(cluster.OpenshiftVersion, cluster.CPUArchitecture, cluster.PullSecret)
if err != nil {
return "", err
}
Expand All @@ -137,6 +145,7 @@ func (i *installCmd) getFullInstallerCommand(ctx context.Context, cluster *commo
}

request.OpenshiftVersion = cluster.OpenshiftVersion

}

hostInstallerArgs, err := constructHostInstallerArgs(cluster, host, inventory, infraEnv, i.log)
Expand Down Expand Up @@ -391,3 +400,23 @@ func toJSONString(args []string) (string, error) {
}
return string(argsBytes), nil
}

func hideInstallArgs(args []string, log logrus.FieldLogger) []string {
if len(args) == 0 {
return args
}
var request models.InstallCmdRequest
if err := json.Unmarshal([]byte(args[0]), &request); err != nil {
log.WithError(err).Warnf("failed to unmarshal argument for printing")
return []string{}
}
if request.PullSecret != "" {
request.PullSecret = "*****"
}
b, err := json.Marshal(&request)
if err != nil {
log.WithError(err).Warnf("failed to marshal argument for printing")
return []string{}
}
return []string{string(b)}
}
20 changes: 10 additions & 10 deletions internal/host/hostcommands/install_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("installcmd", func() {
mockEvents = eventsapi.NewMockHandler(ctrl)
mockVersions = versions.NewMockHandler(ctrl)
mockRelease = oc.NewMockRelease(ctrl)
installCmd = NewInstallCmd(common.GetTestLog(), db, mockValidator, mockRelease, instructionConfig, mockEvents, mockVersions)
installCmd = NewInstallCmd(common.GetTestLog(), db, mockValidator, mockRelease, instructionConfig, mockEvents, mockVersions, true)
cluster = createClusterInDb(db, models.ClusterHighAvailabilityModeFull)
clusterId = *cluster.ID
infraEnv = createInfraEnvInDb(db, clusterId)
Expand Down Expand Up @@ -374,7 +374,7 @@ var _ = Describe("installcmd arguments", func() {
Context("configuration_params", func() {
It("check_cluster_version_is_false_by_default", func() {
config := &InstructionConfig{}
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -386,7 +386,7 @@ var _ = Describe("installcmd arguments", func() {
config := &InstructionConfig{
CheckClusterVersion: false,
}
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -398,7 +398,7 @@ var _ = Describe("installcmd arguments", func() {
config := &InstructionConfig{
CheckClusterVersion: true,
}
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, *config, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -407,7 +407,7 @@ var _ = Describe("installcmd arguments", func() {
})

It("verify high-availability-mode is None", func() {
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -420,7 +420,7 @@ var _ = Describe("installcmd arguments", func() {
mockRelease.EXPECT().GetMCOImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", nil).AnyTimes()
mockVersions.EXPECT().GetMustGatherImages(gomock.Any(), gomock.Any(), gomock.Any()).Return(defaultMustGatherVersion, nil).AnyTimes()

installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -430,7 +430,7 @@ var _ = Describe("installcmd arguments", func() {

It("no must-gather , mco and openshift version in day2 installation", func() {
db.Model(&cluster).Update("kind", models.ClusterKindAddHostsCluster)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions)
installCmd := NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, InstructionConfig{}, mockEvents, mockVersions, true)
stepReply, err := installCmd.GetSteps(ctx, &host)
Expect(err).NotTo(HaveOccurred())
Expect(stepReply).NotTo(BeNil())
Expand All @@ -449,7 +449,7 @@ var _ = Describe("installcmd arguments", func() {

BeforeEach(func() {
instructionConfig = DefaultInstructionConfig
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions)
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions, true)
})

It("valid installer args", func() {
Expand Down Expand Up @@ -529,7 +529,7 @@ var _ = Describe("installcmd arguments", func() {

BeforeEach(func() {
instructionConfig = DefaultInstructionConfig
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions)
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions, true)
})

It("single argument with ocp image only", func() {
Expand Down Expand Up @@ -561,7 +561,7 @@ var _ = Describe("installcmd arguments", func() {

BeforeEach(func() {
instructionConfig = DefaultInstructionConfig
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions)
installCmd = NewInstallCmd(common.GetTestLog(), db, validator, mockRelease, instructionConfig, mockEvents, mockVersions, true)
})
It("no-proxy without httpProxy", func() {
args := installCmd.getProxyArguments("t-cluster", "proxy.org", "", "", "domain.com,192.168.1.0/24")
Expand Down
13 changes: 11 additions & 2 deletions internal/host/hostcommands/instruction_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewInstructionManager(log logrus.FieldLogger, db *gorm.DB, hwValidator hard
instructionConfig InstructionConfig, connectivityValidator connectivity.Validator, eventsHandler eventsapi.Handler,
versionHandler versions.Handler, osImages versions.OSImages, kubeApiEnabled bool) *InstructionManager {
connectivityCmd := NewConnectivityCheckCmd(log, db, connectivityValidator, instructionConfig.AgentImage)
installCmd := NewInstallCmd(log, db, hwValidator, ocRelease, instructionConfig, eventsHandler, versionHandler)
installCmd := NewInstallCmd(log, db, hwValidator, ocRelease, instructionConfig, eventsHandler, versionHandler, instructionConfig.EnableSkipMcoReboot)
inventoryCmd := NewInventoryCmd(log, instructionConfig.AgentImage)
freeAddressesCmd := newFreeAddressesCmd(log, kubeApiEnabled)
stopCmd := NewStopInstallationCmd(log)
Expand Down Expand Up @@ -279,11 +279,20 @@ func createStepID(stepType models.StepType) string {
return fmt.Sprintf("%s-%s", stepType, uuid.New().String()[:8])
}

func hideSecretArgs(stepType models.StepType, args []string, log logrus.FieldLogger) []string {
switch stepType {
case models.StepTypeInstall:
return hideInstallArgs(args, log)
}
return args
}

func logSteps(steps models.Steps, infraEnvId strfmt.UUID, hostId *strfmt.UUID, log logrus.FieldLogger) {
if len(steps.Instructions) == 0 {
log.Infof("No steps required for infraEnv <%s> host <%s>", infraEnvId, hostId)
}
for _, step := range steps.Instructions {
log.Infof("Submitting step <%s> id <%s> to infra_env <%s> host <%s> Arguments: <%+v>", step.StepType, step.StepID, infraEnvId, hostId, step.Args)
log.Infof("Submitting step <%s> id <%s> to infra_env <%s> host <%s> Arguments: <%+v>", step.StepType, step.StepID, infraEnvId, hostId,
hideSecretArgs(step.StepType, step.Args, log))
}
}
6 changes: 6 additions & 0 deletions models/install_cmd_request.go

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

16 changes: 16 additions & 0 deletions restapi/embedded_spec.go

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

6 changes: 6 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6447,6 +6447,12 @@ definitions:
skip_installation_disk_cleanup:
type: boolean
description: Skip formatting installation disk
pull_secret:
type: string
description: Pull secret for extraction of OS image from release image
release_image:
type: string
description: The release image used for the extraction of OS image

ntp_synchronization_request:
type: object
Expand Down

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

0 comments on commit 567b1c6

Please sign in to comment.