Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-ocm-2.10] MGMT-19017: Handle skipping hostPrefix validation for IPv6 #6805

Open
wants to merge 1 commit into
base: release-ocm-2.10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions internal/cluster/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
type ValidationStatus string

const (
ValidationSuccess ValidationStatus = "success"
ValidationFailure ValidationStatus = "failure"
ValidationPending ValidationStatus = "pending"
ValidationError ValidationStatus = "error"
ValidationSuccess ValidationStatus = "success"
ValidationFailure ValidationStatus = "failure"
ValidationPending ValidationStatus = "pending"
ValidationError ValidationStatus = "error"
DefaultIPV4HostPrefix = 25
DefaultIPV6HostPrefix = 64
)

func (v ValidationStatus) String() string {
Expand Down Expand Up @@ -531,17 +533,12 @@ func (v *clusterValidator) networkPrefixValid(c *clusterPreprocessContext) (Vali
return ValidationPending, "The Cluster Network CIDR is undefined."
}

skipHostPrefix := v.skipNetworkHostPrefixCheck(c)
skipHostPrefixCheck := v.skipNetworkHostPrefixCheck(c)

validClusterNetworks := funk.Filter(c.cluster.ClusterNetworks, func(clusterNetwork *models.ClusterNetwork) bool {
var hostPrefixForCidrValidation int
if !skipHostPrefix {
hostPrefixForCidrValidation = int(clusterNetwork.HostPrefix)
} else {
hostPrefixForCidrValidation = 25 // default to 128 addresses
}
hostPrefixForCidrValidation := getHostPrefixForCidrValidation(skipHostPrefixCheck, clusterNetwork)
return clusterNetwork != nil &&
(skipHostPrefix || network.VerifyNetworkHostPrefix(clusterNetwork.HostPrefix) == nil) &&
(skipHostPrefixCheck || network.VerifyNetworkHostPrefix(clusterNetwork.HostPrefix) == nil) &&
network.VerifyClusterCidrSize(hostPrefixForCidrValidation, string(clusterNetwork.Cidr), len(c.cluster.Hosts)) == nil
}).([]*models.ClusterNetwork)

Expand All @@ -551,10 +548,14 @@ func (v *clusterValidator) networkPrefixValid(c *clusterPreprocessContext) (Vali

var err error
for _, clusterNetwork := range c.cluster.ClusterNetworks {
if err = network.VerifyNetworkHostPrefix(clusterNetwork.HostPrefix); err != nil {
return ValidationFailure, fmt.Sprintf("Invalid Cluster Network prefix: %s.", err.Error())
if !skipHostPrefixCheck {
if err = network.VerifyNetworkHostPrefix(clusterNetwork.HostPrefix); err != nil {
return ValidationFailure, fmt.Sprintf("Invalid Cluster Network prefix: %s.", err.Error())
}
}
if err = network.VerifyClusterCidrSize(int(clusterNetwork.HostPrefix), string(clusterNetwork.Cidr), len(c.cluster.Hosts)); err != nil {

hostPrefixForCidrValidation := getHostPrefixForCidrValidation(skipHostPrefixCheck, clusterNetwork)
if err = network.VerifyClusterCidrSize(hostPrefixForCidrValidation, string(clusterNetwork.Cidr), len(c.cluster.Hosts)); err != nil {
return ValidationFailure, err.Error()
}
}
Expand All @@ -573,7 +574,7 @@ func (v *clusterValidator) isNtpServerConfigured(c *clusterPreprocessContext) (V
"please configure an NTP server via DHCP or set clocks manually.", common.MaximumAllowedTimeDiffMinutes)
}

// Ignore hostPrefix for non-OVN/SDN plugins.
// skipNetworkHostPrefixCheck returns true if the hostPrefix should be ignored for non-OVN/SDN plugins.
func (v *clusterValidator) skipNetworkHostPrefixCheck(c *clusterPreprocessContext) bool {
// list of known plugins that require hostPrefix to be set
var pluginsUsingHostPrefix = []string{models.ClusterNetworkTypeOVNKubernetes, models.ClusterNetworkTypeOpenShiftSDN}
Expand All @@ -600,3 +601,16 @@ func (v *clusterValidator) skipNetworkHostPrefixCheck(c *clusterPreprocessContex
}
return false
}

// getHostPrefixForCidrValidation returns the prefix to use when validating CIDR.
func getHostPrefixForCidrValidation(skipHostPrefix bool, clusterNetwork *models.ClusterNetwork) int {
hostPrefix := int(clusterNetwork.HostPrefix)
if skipHostPrefix {
if network.IsIPv6CIDR(string(clusterNetwork.Cidr)) {
hostPrefix = DefaultIPV6HostPrefix
} else {
hostPrefix = DefaultIPV4HostPrefix
}
}
return hostPrefix
}