1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-01 15:06:23 +00:00

Add support for enabling cri-dockerd

This commit is contained in:
Sebastiaan van Steenis
2021-06-08 19:05:54 +02:00
parent ff49352399
commit a4bebdb8bb
2 changed files with 51 additions and 0 deletions

View File

@@ -6,11 +6,13 @@ import (
"fmt"
"strings"
"github.com/blang/semver"
"github.com/rancher/rke/log"
"github.com/rancher/rke/metadata"
"github.com/rancher/rke/pki"
"github.com/rancher/rke/services"
"github.com/rancher/rke/util"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
)
@@ -47,6 +49,11 @@ func (c *Cluster) ValidateCluster(ctx context.Context) error {
return err
}
// validate enabling CRIDockerd
if err := validateCRIDockerdOption(c); err != nil {
return err
}
// validate services options
return validateServicesOptions(c)
}
@@ -576,3 +583,25 @@ func validateIngressImages(c *Cluster) error {
}
return nil
}
func validateCRIDockerdOption(c *Cluster) error {
if c.EnableCRIDockerd != nil && *c.EnableCRIDockerd {
k8sVersion := c.RancherKubernetesEngineConfig.Version
toMatch, err := semver.Make(k8sVersion[1:])
if err != nil {
return fmt.Errorf("%s is not valid semver", k8sVersion)
}
logrus.Debugf("Checking cri-dockerd for cluster version [%s]", k8sVersion)
// cri-dockerd can be enabled for k8s 1.21 and up
CRIDockerdAllowedRange, err := semver.ParseRange(">=1.21.0-rancher0")
if err != nil {
logrus.Warnf("Failed to parse semver range for checking cri-dockerd")
}
if !CRIDockerdAllowedRange(toMatch) {
logrus.Debugf("Cluster version [%s] is not allowed to enable cri-dockerd", k8sVersion)
return fmt.Errorf("Enabling cri-dockerd for cluster version [%s] is not supported", k8sVersion)
}
logrus.Infof("cri-dockerd is enabled for cluster version [%s]", k8sVersion)
}
return nil
}