-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from galal-hussein/azure_provider
Add azure cloud provider
- Loading branch information
Showing
13 changed files
with
282 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cluster | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/docker/docker/api/types/container" | ||
"github.com/rancher/rke/docker" | ||
"github.com/rancher/rke/hosts" | ||
"github.com/rancher/rke/log" | ||
"github.com/rancher/types/apis/management.cattle.io/v3" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
CloudConfigDeployer = "cloud-config-deployer" | ||
CloudConfigServiceName = "cloud" | ||
CloudConfigPath = "/etc/kubernetes/cloud-config.json" | ||
CloudConfigEnv = "RKE_CLOUD_CONFIG" | ||
) | ||
|
||
func deployCloudProviderConfig(ctx context.Context, uniqueHosts []*hosts.Host, cloudProvider v3.CloudProvider, alpineImage string, prsMap map[string]v3.PrivateRegistry) error { | ||
cloudConfig, err := getCloudConfigFile(ctx, cloudProvider) | ||
if err != nil { | ||
return err | ||
} | ||
for _, host := range uniqueHosts { | ||
log.Infof(ctx, "[%s] Deploying cloud config file to node [%s]", CloudConfigServiceName, host.Address) | ||
if err := doDeployConfigFile(ctx, host, cloudConfig, alpineImage, prsMap); err != nil { | ||
return fmt.Errorf("Failed to deploy cloud config file on node [%s]: %v", host.Address, err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func getCloudConfigFile(ctx context.Context, cloudProvider v3.CloudProvider) (string, error) { | ||
if len(cloudProvider.CloudConfig) == 0 { | ||
return "", nil | ||
} | ||
tmpMap := make(map[string]interface{}) | ||
for key, value := range cloudProvider.CloudConfig { | ||
tmpBool, err := strconv.ParseBool(value) | ||
if err == nil { | ||
tmpMap[key] = tmpBool | ||
continue | ||
} | ||
tmpInt, err := strconv.ParseInt(value, 10, 64) | ||
if err == nil { | ||
tmpMap[key] = tmpInt | ||
continue | ||
} | ||
tmpFloat, err := strconv.ParseFloat(value, 64) | ||
if err == nil { | ||
tmpMap[key] = tmpFloat | ||
continue | ||
} | ||
tmpMap[key] = value | ||
} | ||
jsonString, err := json.MarshalIndent(tmpMap, "", "\n") | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(jsonString), nil | ||
} | ||
|
||
func doDeployConfigFile(ctx context.Context, host *hosts.Host, cloudConfig, alpineImage string, prsMap map[string]v3.PrivateRegistry) error { | ||
// remove existing container. Only way it's still here is if previous deployment failed | ||
if err := docker.DoRemoveContainer(ctx, host.DClient, CloudConfigDeployer, host.Address); err != nil { | ||
return err | ||
} | ||
containerEnv := []string{CloudConfigEnv + "=" + cloudConfig} | ||
imageCfg := &container.Config{ | ||
Image: alpineImage, | ||
Cmd: []string{ | ||
"sh", | ||
"-c", | ||
fmt.Sprintf("if [ ! -f %s ]; then echo -e \"$%s\" > %s;fi", CloudConfigPath, CloudConfigEnv, CloudConfigPath), | ||
}, | ||
Env: containerEnv, | ||
} | ||
hostCfg := &container.HostConfig{ | ||
Binds: []string{ | ||
"/etc/kubernetes:/etc/kubernetes", | ||
}, | ||
Privileged: true, | ||
} | ||
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, CloudConfigDeployer, host.Address, CloudConfigServiceName, prsMap); err != nil { | ||
return err | ||
} | ||
if err := docker.DoRemoveContainer(ctx, host.DClient, CloudConfigDeployer, host.Address); err != nil { | ||
return err | ||
} | ||
logrus.Debugf("[%s] Successfully started cloud config deployer container on node [%s]", CloudConfigServiceName, host.Address) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
vendor/github.com/rancher/types/apis/management.cattle.io/v3/alerting_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 27 additions & 2 deletions
29
vendor/github.com/rancher/types/apis/management.cattle.io/v3/k8s_defaults.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
vendor/github.com/rancher/types/apis/management.cattle.io/v3/logging_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 9 additions & 8 deletions
17
vendor/github.com/rancher/types/apis/management.cattle.io/v3/machine_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
vendor/github.com/rancher/types/apis/management.cattle.io/v3/pipeline_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.