1
0
mirror of https://github.com/rancher/rke.git synced 2025-07-30 22:44:50 +00:00

Merge pull request #3623 from vardhaman22/deprecate-weave

[release v1.6] added validation error for weave for k8s version >=1.30.0
This commit is contained in:
Vardhaman Surana 2024-07-02 22:39:04 +05:30 committed by GitHub
commit 314176fedd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 76 additions and 0 deletions

View File

@ -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")
}

View File

@ -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)
})
}

View File

@ -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