Skip to content

Commit

Permalink
Validation: add bundleMismatchWarning helper to warn user
Browse files Browse the repository at this point in the history
This helper function is also going to used in follow up commit.
We also don't want user to show both warning in case user uses custom
bundle, so this patch also logs only respective warning as per bundle filename
or metadata.
  • Loading branch information
praveenkumar committed Sep 13, 2022
1 parent 1144bfa commit a6d08f3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/crc/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,7 @@ func ValidateBundlePath(bundlePath string, preset crcpreset.Preset) error {
}

userProvidedBundle := filepath.Base(bundlePath)
userProvidedBundle = bundle.GetBundleNameWithExtension(userProvidedBundle)
if userProvidedBundle != constants.GetDefaultBundle(preset) {
// Should append underscore (_) here, as we don't want crc_libvirt_4.7.15.crcbundle
// to be detected as a custom bundle for crc_libvirt_4.7.1.crcbundle
usingCustomBundle := strings.HasPrefix(bundle.GetBundleNameWithoutExtension(userProvidedBundle),
fmt.Sprintf("%s_", bundle.GetBundleNameWithoutExtension(constants.GetDefaultBundle(preset))))
if usingCustomBundle {
logging.Warnf("Using custom bundle %s", userProvidedBundle)
return nil
}
logging.Warnf("Using %s bundle, but %s is expected for this release", userProvidedBundle, constants.GetDefaultBundle(preset))
}
bundleMismatchWarning(userProvidedBundle, preset)
return nil
}

Expand All @@ -86,6 +75,21 @@ func ValidateBundle(bundlePath string, preset crcpreset.Preset) error {
return nil
}

func bundleMismatchWarning(userProvidedBundle string, preset crcpreset.Preset) {
userProvidedBundle = bundle.GetBundleNameWithExtension(userProvidedBundle)
if userProvidedBundle != constants.GetDefaultBundle(preset) {
// Should append underscore (_) here, as we don't want crc_libvirt_4.7.15.crcbundle
// to be detected as a custom bundle for crc_libvirt_4.7.1.crcbundle
usingCustomBundle := strings.HasPrefix(bundle.GetBundleNameWithoutExtension(userProvidedBundle),
fmt.Sprintf("%s_", bundle.GetBundleNameWithoutExtension(constants.GetDefaultBundle(preset))))
if usingCustomBundle {
logging.Warnf("Using custom bundle %s", userProvidedBundle)
} else {
logging.Warnf("Using %s bundle, but %s is expected for this release", userProvidedBundle, constants.GetDefaultBundle(preset))
}
}
}

// ValidateIPAddress checks if provided IP is valid
func ValidateIPAddress(ipAddress string) error {
ip := net.ParseIP(ipAddress).To4()
Expand Down

0 comments on commit a6d08f3

Please sign in to comment.