Skip to content

Commit

Permalink
MGMT-19844: Validate the internal ignition override (#7254) (#7264)
Browse files Browse the repository at this point in the history
* Validate the internal ignition override

Users have seen some situations where they are unable to download the
discovery ISO because the ignition doesn't generate correctly on the
service side.

The only explanation seems to be that there is a malformed override and
the only override we're adding in all of these cases is the internal one
which also happens to not be validated.

Relates to https://issues.redhat.com/browse/MGMT-19855

* Add ignition error report to parse error

This should give some additional information about why a particular
ignition config could not be parsed correctly.
  • Loading branch information
carbonin authored Feb 3, 2025
1 parent 9365ae5 commit da7af47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4789,7 +4789,7 @@ func (b *bareMetalInventory) validateInfraEnvCreateParams(ctx context.Context, p
}
}

if err = b.validateInfraEnvIgnitionParams(ctx, params.InfraenvCreateParams.IgnitionConfigOverride); err != nil {
if err = b.validateInfraEnvIgnitionParams(ctx, params.InfraenvCreateParams.IgnitionConfigOverride, nil); err != nil {
return err
}

Expand Down Expand Up @@ -4955,7 +4955,7 @@ func (b *bareMetalInventory) UpdateInfraEnvInternal(ctx context.Context, params
}
}

if err = b.validateInfraEnvIgnitionParams(ctx, params.InfraEnvUpdateParams.IgnitionConfigOverride); err != nil {
if err = b.validateInfraEnvIgnitionParams(ctx, params.InfraEnvUpdateParams.IgnitionConfigOverride, internalIgnitionConfig); err != nil {
return common.NewApiError(http.StatusBadRequest, err)
}

Expand Down Expand Up @@ -5174,7 +5174,7 @@ func (b *bareMetalInventory) validateAndUpdateInfraEnvParams(ctx context.Context
return *params, nil
}

func (b *bareMetalInventory) validateInfraEnvIgnitionParams(ctx context.Context, ignitionConfigOverride string) error {
func (b *bareMetalInventory) validateInfraEnvIgnitionParams(ctx context.Context, ignitionConfigOverride string, internalIgnitionOverride *string) error {

log := logutil.FromContext(ctx, b.log)

Expand All @@ -5186,6 +5186,14 @@ func (b *bareMetalInventory) validateInfraEnvIgnitionParams(ctx context.Context,
}
}

if internalIgnitionOverride != nil && *internalIgnitionOverride != "" {
_, err := ignition.ParseToLatest([]byte(*internalIgnitionOverride))
if err != nil {
log.WithError(err).Errorf("Failed to parse internal ignition config patch %s", *internalIgnitionOverride)
return err
}
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions internal/bminventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9504,6 +9504,15 @@ var _ = Describe("infraEnvs", func() {
Expect(pathList[5]).To(Equal(common.TestDefaultConfig.OpenShiftVersion))
})

It("fails when the internal ignition config is invalid", func() {
invalidIgnition := "{\"foo\": \"bar\"}"
_, err := bm.UpdateInfraEnvInternal(ctx, installer.UpdateInfraEnvParams{
InfraEnvID: infraEnvID,
InfraEnvUpdateParams: &models.InfraEnvUpdateParams{},
}, &invalidIgnition)
Expect(err).To(HaveOccurred())
})

Context("with rhsso auth", func() {
BeforeEach(func() {
_, cert := auth.GetTokenAndCert(false)
Expand Down
4 changes: 2 additions & 2 deletions internal/ignition/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func ParseToLatest(content []byte) (*config_latest_types.Config, error) {
// TODO(deprecate-ignition-3.1.0)
// We always want to work with the object of the type v3.2 but carry a value of v3.1 inside.
// For this reason we are translating the config to v3.2 and manually override the Version.
configBackwards, _, err := config_31.Parse(content)
configBackwards, report, err := config_31.Parse(content)
if err != nil {
return nil, errors.Errorf("error parsing ignition: %v", err)
return nil, errors.Errorf("error parsing ignition: %v, error report: %s", err, report.String())
}
config = config_latest_trans.Translate(configBackwards)
config.Ignition.Version = "3.1.0"
Expand Down

0 comments on commit da7af47

Please sign in to comment.