diff --git a/cluster/validation.go b/cluster/validation.go index 339066c6..ff3a8e0c 100644 --- a/cluster/validation.go +++ b/cluster/validation.go @@ -215,6 +215,16 @@ func validateNetworkOptions(c *Cluster) error { } if c.Network.Plugin == WeaveNetworkPlugin { + supported, err := isWeaveSupportedK8sVersion(c.Version) + if err != nil { + return fmt.Errorf("error while checking weave support for cluster version: %w", err) + } + + if !supported { + logrus.Errorf("weave CNI support is removed for k8s version >=1.30.0") + return fmt.Errorf("weave CNI support is removed for k8s version >=1.30.0") + } + if err := warnWeaveDeprecation(c.Version); err != nil { return fmt.Errorf("Error while printing Weave deprecation message: %w", err) } @@ -732,3 +742,8 @@ func warnWeaveDeprecation(k8sVersion string) error { } return nil } + +// isWeaveSupportedK8sVersion checks if weave CNI is supported for a given kubernetes version +func isWeaveSupportedK8sVersion(k8sVersion string) (bool, error) { + return util.SemVerMatchRange(k8sVersion, "<1.30.0-rancher0") +} diff --git a/cluster/validation_test.go b/cluster/validation_test.go new file mode 100644 index 00000000..20b56d4d --- /dev/null +++ b/cluster/validation_test.go @@ -0,0 +1,49 @@ +package cluster + +import ( + "testing" + + "github.com/rancher/rke/types" + "github.com/stretchr/testify/assert" +) + +func TestValidateNetworkOptions(t *testing.T) { + t.Run("weave with k8s v1.30.0 or greater", func(tt *testing.T) { + cluster := &Cluster{ + RancherKubernetesEngineConfig: types.RancherKubernetesEngineConfig{ + Version: "v1.30.0-rancher1", + Network: types.NetworkConfig{ + Plugin: WeaveNetworkPlugin, + }, + }, + } + + err := validateNetworkOptions(cluster) + assert.NotNil(t, err) + assert.EqualError(t, err, "weave CNI support is removed for k8s version >=1.30.0") + + cluster.Version = "v1.30.1-rancher1" + err = validateNetworkOptions(cluster) + assert.NotNil(t, err) + assert.EqualError(t, err, "weave CNI support is removed for k8s version >=1.30.0") + }) + + t.Run("weave with k8s version less than v1.30.0", func(tt *testing.T) { + cluster := &Cluster{ + RancherKubernetesEngineConfig: types.RancherKubernetesEngineConfig{ + Version: "v1.29.0-rancher1", + Network: types.NetworkConfig{ + Plugin: WeaveNetworkPlugin, + }, + }, + } + + err := validateNetworkOptions(cluster) + assert.Nil(t, err) + + cluster.Version = "v1.28.5-rancher1" + err = validateNetworkOptions(cluster) + assert.Nil(t, err) + }) + +} diff --git a/scripts/integration b/scripts/integration index 4af9d954..ceb29335 100755 --- a/scripts/integration +++ b/scripts/integration @@ -82,6 +82,12 @@ for ver in "${!versions_to_test[@]}"; do version_to_test=${versions_to_test["${ver}"]} echo_with_time "Testing version ${version_to_test}" + MINOR_VERSION=$(echo ${version_to_test} | cut -d. -f2) + if [ ${MINOR_VERSION} -ge 30 ] && [ "${NETWORK_PLUGIN}" == "weave" ]; then + echo "Skipping weave testing with ${version_to_test} since weave is not supported for version >=1.30.0" + continue + fi + # Create cluster yaml with random node names node=$(cat /dev/urandom | tr -dc a-z | head -c8) cat << EOF > "./bin/cluster-${version_to_test}.yml" @@ -223,6 +229,12 @@ for ver in "${!versions_to_test[@]}"; do # Example $all_versions: "v1.16.15-rancher1-2 v1.17.12-rancher1-1 v1.18.9-rancher1-1 v1.19.2-rancher1-1" upgrade_to_version=$(echo $all_versions | grep -oP '(?<='"${versions_to_test["${ver}"]}"' )[^ ]*') + MINOR_VERSION=$(echo ${upgrade_to_version} | cut -d. -f2) + if [ ${MINOR_VERSION} -ge 30 ] && [ "${NETWORK_PLUGIN}" == "weave" ]; then + echo "Skipping cluster upgrade testing to ${upgrade_to_version} with weave since weave is not supported for version >=1.30.0" + continue + fi + if [ "${upgrade_to_version}" = "" ]; then echo_with_time "No newer version found for ${versions_to_test["${ver}"]} to upgrade to" continue