forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clusterconfigcopier.go
45 lines (34 loc) · 1.25 KB
/
clusterconfigcopier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package clusterconfigcopier
import (
"context"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"k8s.io/apimachinery/pkg/runtime"
)
type controller struct {
}
func Register(ctx context.Context, management *config.ManagementContext) {
c := controller{}
management.Management.Clusters("").AddHandler(ctx, "clusterconfigcopier", c.sync)
}
func (c *controller) sync(key string, cluster *v3.Cluster) (runtime.Object, error) {
if key == "" {
return cluster, nil
}
if cluster.Spec.GenericEngineConfig != nil {
return cluster, nil
}
if cluster.Spec.AmazonElasticContainerServiceConfig != nil {
cluster.Spec.GenericEngineConfig = cluster.Spec.AmazonElasticContainerServiceConfig
(*cluster.Spec.GenericEngineConfig)["driverName"] = "amazonelasticcontainerservice"
}
if cluster.Spec.AzureKubernetesServiceConfig != nil {
cluster.Spec.GenericEngineConfig = cluster.Spec.AzureKubernetesServiceConfig
(*cluster.Spec.GenericEngineConfig)["driverName"] = "azurekubernetesservice"
}
if cluster.Spec.GoogleKubernetesEngineConfig != nil {
cluster.Spec.GenericEngineConfig = cluster.Spec.GoogleKubernetesEngineConfig
(*cluster.Spec.GenericEngineConfig)["driverName"] = "googlekubernetesengine"
}
return nil, nil
}