代码拉取完成,页面将自动刷新
package clusterprovisioner
import (
"fmt"
"reflect"
"strings"
"github.com/rancher/kontainer-engine/service"
"github.com/rancher/rancher/pkg/clusterprovisioninglogger"
"github.com/rancher/rke/services"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
)
const DriverNameField = "driverName"
func (p *Provisioner) driverCreate(cluster *v3.Cluster, spec v3.ClusterSpec) (api string, token string, cert string, err error) {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionProvisioned)
defer logger.Close()
spec = cleanRKE(spec)
if newCluster, err := p.Clusters.Update(cluster); err == nil {
cluster = newCluster
}
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
return "", "", "", err
}
return p.engineService.Create(ctx, cluster.Name, kontainerDriver, spec)
}
func (p *Provisioner) getKontainerDriver(spec v3.ClusterSpec) (*v3.KontainerDriver, error) {
if spec.GenericEngineConfig != nil {
return p.KontainerDriverLister.Get("", (*spec.GenericEngineConfig)[DriverNameField].(string))
}
if spec.RancherKubernetesEngineConfig != nil {
return p.KontainerDriverLister.Get("", service.RancherKubernetesEngineDriverName)
}
if spec.ImportedConfig != nil {
return p.KontainerDriverLister.Get("", "import")
}
return nil, fmt.Errorf("no kontainer driver for cluster %v", spec.DisplayName)
}
func (p *Provisioner) driverUpdate(cluster *v3.Cluster, spec v3.ClusterSpec) (api string, token string, cert string, err error) {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionUpdated)
defer logger.Close()
spec = cleanRKE(spec)
applied := cleanRKE(cluster.Status.AppliedSpec)
if spec.RancherKubernetesEngineConfig != nil && cluster.Status.APIEndpoint != "" && cluster.Status.ServiceAccountToken != "" &&
reflect.DeepEqual(applied.RancherKubernetesEngineConfig, spec.RancherKubernetesEngineConfig) {
return cluster.Status.APIEndpoint, cluster.Status.ServiceAccountToken, cluster.Status.CACert, nil
}
if spec.RancherKubernetesEngineConfig != nil && spec.RancherKubernetesEngineConfig.Services.Etcd.Snapshot == nil &&
applied.RancherKubernetesEngineConfig != nil && applied.RancherKubernetesEngineConfig.Services.Etcd.Snapshot == nil {
_false := false
cluster.Spec.RancherKubernetesEngineConfig.Services.Etcd.Snapshot = &_false
}
if newCluster, err := p.Clusters.Update(cluster); err == nil {
cluster = newCluster
}
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
return "", "", "", err
}
return p.engineService.Update(ctx, cluster.Name, kontainerDriver, spec)
}
func (p *Provisioner) driverRemove(cluster *v3.Cluster, forceRemove bool) error {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionProvisioned)
defer logger.Close()
spec := cleanRKE(cluster.Spec)
_, err := v3.ClusterConditionUpdated.Do(cluster, func() (runtime.Object, error) {
if newCluster, err := p.Clusters.Update(cluster); err == nil {
cluster = newCluster
}
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
if apierrors.IsNotFound(err) {
logrus.Warnf("Could not find kontainer driver for cluster removal [%v]", err)
return nil, nil
}
return nil, err
}
return cluster, p.engineService.Remove(ctx, cluster.Name, kontainerDriver, spec, forceRemove)
})
return err
}
func (p *Provisioner) driverRestore(cluster *v3.Cluster, spec v3.ClusterSpec) (string, string, string, error) {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionUpdated)
defer logger.Close()
spec = cleanRKE(spec)
newCluster, err := p.Clusters.Update(cluster)
if err != nil {
return "", "", "", err
}
cluster = newCluster
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
return "", "", "", err
}
snapshot := strings.Split(spec.RancherKubernetesEngineConfig.Restore.SnapshotName, ":")[1]
return p.engineService.ETCDRestore(ctx, cluster.Name, kontainerDriver, spec, snapshot)
}
func (p *Provisioner) generateServiceAccount(cluster *v3.Cluster, spec v3.ClusterSpec) (string, error) {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionUpdated)
defer logger.Close()
spec = cleanRKE(spec)
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
return "", err
}
return p.engineService.GenerateServiceAccount(ctx, cluster.Name, kontainerDriver, spec)
}
func (p *Provisioner) removeLegacyServiceAccount(cluster *v3.Cluster, spec v3.ClusterSpec) error {
ctx, logger := clusterprovisioninglogger.NewLogger(p.Clusters, cluster, v3.ClusterConditionUpdated)
defer logger.Close()
spec = cleanRKE(spec)
kontainerDriver, err := p.getKontainerDriver(spec)
if err != nil {
return err
}
return p.engineService.RemoveLegacyServiceAccount(ctx, cluster.Name, kontainerDriver, spec)
}
func cleanRKE(spec v3.ClusterSpec) v3.ClusterSpec {
if spec.RancherKubernetesEngineConfig == nil {
return spec
}
result := spec.DeepCopy()
var filteredNodes []v3.RKEConfigNode
for _, node := range spec.RancherKubernetesEngineConfig.Nodes {
if len(node.Role) == 1 && node.Role[0] == services.WorkerRole {
continue
}
filteredNodes = append(filteredNodes, node)
}
result.RancherKubernetesEngineConfig.Nodes = filteredNodes
return *result
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。