Make windows binary url configurable (#4103)

This commit is contained in:
James Sturtevant 2018-10-31 14:33:27 -07:00 коммит произвёл Tariq Ibrahim
Родитель 36c3173fc8
Коммит 400dfbb476
16 изменённых файлов: 231 добавлений и 29 удалений

Просмотреть файл

@ -45,7 +45,8 @@ To learn more about supported orchestrators and versions, run the orchestrators
| clusterSubnet | no | The IP subnet used for allocating IP addresses for pod network interfaces. The subnet must be in the VNET address space. With Azure CNI enabled, the default value is 10.240.0.0/12. Without Azure CNI, the default value is 10.244.0.0/16. |
| containerRuntime | no | The container runtime to use as a backend. The default is `docker`. The other options are `clear-containers`, `kata-containers`, and `containerd` |
| controllerManagerConfig | no | Configure various runtime configuration for controller-manager. See `controllerManagerConfig` [below](#feat-controller-manager-config) |
| customWindowsPackageURL | no | Configure custom windows Kubernetes release package URL for deployment on Windows |
| customWindowsPackageURL | no | Configure custom windows Kubernetes release package URL for deployment on Windows that is generated by scripts/build-windows-k8s.sh. The format of this file is a zip file with multiple items (binaries, cni, infra container) in it. This setting will be depreciated in future release of acs-engine where the binaries will be pulled in the format of Kubernetes releases that only contain the kubernetes binaries. |
| WindowsNodeBinariesURL | no | Windows Kubernetes Node binaries can be provided in the format of Kubernetes release (example: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#node-binaries-1). This setting allows overriding the binaries for custom builds. |
| dnsServiceIP | no | IP address for kube-dns to listen on. If specified must be in the range of `serviceCidr` |
| dockerBridgeSubnet | no | The specific IP and subnet used for allocating IP addresses for the docker bridge network created on the kubernetes master and agents. Default value is 172.17.0.1/16. This value is used to configure the docker daemon using the [--bip flag](https://docs.docker.com/engine/userguide/networking/default_network/custom-docker0) |
| enableAggregatedAPIs | no | Enable [Kubernetes Aggregated APIs](https://kubernetes.io/docs/concepts/api-extension/apiserver-aggregation/).This is required by [Service Catalog](https://github.com/kubernetes-incubator/service-catalog/blob/master/README.md). (boolean - default is true for k8s versions greater or equal to 1.9.0, false otherwise) |

Просмотреть файл

@ -35,13 +35,13 @@ Once the input is validated, the template generator is invoked which will conver
{{if .HasWindows}}
"kubeBinariesSASURL": {
"metadata": {
"description": "The download url for kubernetes windows binaries."
"description": "The download url for kubernetes windows binaries package that is created by scripts/build-windows-k8s.sh"
},
"type": "string"
},
"windowsPackageSASURLBase": {
"windowsKubeBinariesURL": {
"metadata": {
"description": "The download url base for windows packages for kubernetes."
"description": "The download url for kubernetes windows binaries produce by Kubernetes. This contains only the node binaries (example: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#node-binaries-1)"
},
"type": "string"
},

Просмотреть файл

@ -6,13 +6,13 @@
{{if .HasWindows}}
"kubeBinariesSASURL": {
"metadata": {
"description": "The download url for kubernetes windows binaries."
"description": "The download url for kubernetes windows binaries package that is created by scripts/build-windows-k8s.sh"
},
"type": "string"
},
"windowsPackageSASURLBase": {
"windowsKubeBinariesURL": {
"metadata": {
"description": "The download url base for windows packages for kubernetes."
"description": "The download url for kubernetes windows binaries produce by Kubernetes. This contains only the node binaries (example: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#node-binaries-1)"
},
"type": "string"
},

Просмотреть файл

@ -31,4 +31,11 @@ function DownloadFileOverHttp
Invoke-WebRequest $Url -UseBasicParsing -OutFile $DestinationPath -Verbose
Write-Log "Downloaded file to $DestinationPath"
}
# https://stackoverflow.com/a/34559554/697126
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}

Просмотреть файл

@ -53,8 +53,8 @@ $global:CACertificate = "{{WrapAsParameter "caCertificate"}}"
$global:AgentCertificate = "{{WrapAsParameter "clientCertificate"}}"
## Download sources provided by acs-engine
$global:KubeBinariesSASURL = "{{WrapAsParameter "kubeBinariesSASURL"}}"
$global:WindowsPackageSASURLBase = "{{WrapAsParameter "windowsPackageSASURLBase"}}"
$global:KubeBinariesPackageSASURL = "{{WrapAsParameter "kubeBinariesSASURL"}}"
$global:WindowsKubeBinariesURL = "{{WrapAsParameter "windowsKubeBinariesURL"}}"
$global:KubeBinariesVersion = "{{WrapAsParameter "kubeBinariesVersion"}}"
## Docker Version
@ -139,17 +139,27 @@ try
if ($true) {
Write-Log "Provisioning $global:DockerServiceName... with IP $MasterIP"
Write-Log "apply telemetry data setting"
Write-Log "Apply telemetry data setting"
Set-TelemetrySetting -WindowsTelemetryGUID $global:WindowsTelemetryGUID
Write-Log "resize os drive if possible"
Write-Log "Resize os drive if possible"
Resize-OSDrive
Write-Log "install docker"
Write-Log "Install docker"
Install-Docker -DockerVersion $global:DockerVersion
Write-Log "download kubelet binaries and unzip"
Get-KubeBinaries -KubeBinariesSASURL $global:KubeBinariesSASURL
Write-Log "Download kubelet binaries and unzip"
Get-KubePackage -KubeBinariesSASURL $global:KubeBinariesPackageSASURL
# this overwrite the binaries that are download from the custom packge with binaries
# The custom package has a few files that are nessary for future steps (nssm.exe)
# this is a temporary work around to get the binaries until we depreciate
# custom package and nssm.exe as defined in #3851.
if ($global:WindowsKubeBinariesURL){
Write-Log "Overwriting kube node binaries from $global:WindowsKubeBinariesURL"
Get-KubeBinaries -KubeBinariesURL $global:WindowsKubeBinariesURL
}
Write-Log "Write Azure cloud provider config"
Write-AzureConfig `
@ -206,7 +216,7 @@ try
Get-HnsPsm1 -HNSModule $global:HNSModule
}
Write-Log "write kubelet startfile with pod CIDR of $podCIDR"
Write-Log "Write kubelet startfile with pod CIDR of $podCIDR"
Install-KubernetesServices `
-KubeletConfigArgs $global:KubeletConfigArgs `
-KubeBinariesVersion $global:KubeBinariesVersion `

Просмотреть файл

@ -163,7 +163,7 @@ New-InfraContainer
# TODO: Deprecate this and replace with methods that get individual components instead of zip containing everything
# This expects the ZIP file to be created by scripts/build-windows-k8s.sh
function
Get-KubeBinaries
Get-KubePackage
{
Param(
[Parameter(Mandatory=$true)][string]
@ -183,6 +183,46 @@ Get-KubeBinaries
Expand-Archive -path $zipfile -DestinationPath C:\
}
function
Get-KubeBinaries
{
Param(
[Parameter(Mandatory=$true)][string]
$KubeBinariesURL
)
if ($computerInfo.WindowsVersion -eq "1709")
{
Write-Log "Server version 1709 does not support using kubernetes binaries in tar file."
return
}
$tempdir = New-TemporaryDirectory
$binaryPackage = "$tempdir\k.tar.gz"
for ($i=0; $i -le 10; $i++)
{
DownloadFileOverHttp -Url $KubeBinariesURL -DestinationPath $binaryPackage
if ($?) {
break
} else {
Write-Log $Error[0].Exception.Message
}
}
# using tar to minimize dependencies
# tar should be avalible on 1803+
tar -xzf $binaryPackage -C $tempdir
# copy binaries over to kube folder
$windowsbinariespath = "c:\k\"
if(!(Test-path $windowsbinariespath)) {
mkdir $windowsbinariespath
}
cp $tempdir\kubernetes\node\bin\* $windowsbinariespath -Recurse
#remove temp folder created when unzipping
del $tempdir -Recurse
}
# TODO: replace KubeletStartFile with a Kubelet config, remove NSSM, and use built-in service integration
function

Просмотреть файл

@ -171,7 +171,7 @@ func getParameters(cs *api.ContainerService, generatorCode string, acsengineVers
addValue(parametersMap, "dcosClusterPackageListID", dcosClusterPackageListID)
addValue(parametersMap, "dcosProviderPackageID", dcosProviderPackageID)
if properties.OrchestratorProfile.DcosConfig.BootstrapProfile != nil {
if properties.OrchestratorProfile.DcosConfig != nil && properties.OrchestratorProfile.DcosConfig.BootstrapProfile != nil {
addValue(parametersMap, "bootstrapStaticIP", properties.OrchestratorProfile.DcosConfig.BootstrapProfile.StaticIP)
addValue(parametersMap, "bootstrapVMSize", properties.OrchestratorProfile.DcosConfig.BootstrapProfile.VMSize)
}
@ -231,15 +231,24 @@ func getParameters(cs *api.ContainerService, generatorCode string, acsengineVers
if properties.OrchestratorProfile.IsKubernetes() || properties.OrchestratorProfile.IsOpenShift() {
k8sVersion := properties.OrchestratorProfile.OrchestratorVersion
kubeBinariesSASURL := properties.OrchestratorProfile.KubernetesConfig.CustomWindowsPackageURL
if kubeBinariesSASURL == "" {
kubeBinariesSASURL = cloudSpecConfig.KubernetesSpecConfig.KubeBinariesSASURLBase + api.K8sComponentsByVersionMap[k8sVersion]["windowszip"]
}
addValue(parametersMap, "kubeBinariesSASURL", kubeBinariesSASURL)
addValue(parametersMap, "windowsPackageSASURLBase", cloudSpecConfig.KubernetesSpecConfig.WindowsPackageSASURLBase)
addValue(parametersMap, "kubeBinariesVersion", k8sVersion)
addValue(parametersMap, "windowsTelemetryGUID", cloudSpecConfig.KubernetesSpecConfig.WindowsTelemetryGUID)
if properties.OrchestratorProfile.KubernetesConfig != nil {
// Kubernetes packages as zip file as created by scripts/build-windows-k8s.sh
// will be removed in future release as if gets phased out (https://github.com/Azure/acs-engine/issues/3851)
kubeBinariesSASURL := properties.OrchestratorProfile.KubernetesConfig.CustomWindowsPackageURL
if kubeBinariesSASURL == "" {
kubeBinariesSASURL = cloudSpecConfig.KubernetesSpecConfig.KubeBinariesSASURLBase + api.K8sComponentsByVersionMap[k8sVersion]["windowszip"]
}
addValue(parametersMap, "kubeBinariesSASURL", kubeBinariesSASURL)
// Kubernetes node binaries as packaged by upstream kubernetes
// example at https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#node-binaries-1
addValue(parametersMap, "windowsKubeBinariesURL", properties.OrchestratorProfile.KubernetesConfig.WindowsNodeBinariesURL)
addValue(parametersMap, "kubeBinariesVersion", k8sVersion)
addValue(parametersMap, "windowsTelemetryGUID", cloudSpecConfig.KubernetesSpecConfig.WindowsTelemetryGUID)
}
}
for i, s := range properties.WindowsProfile.Secrets {
addValue(parametersMap, fmt.Sprintf("windowsKeyVaultID%d", i), s.SourceVault.ID)

Просмотреть файл

@ -0,0 +1,48 @@
package acsengine
import (
"path"
"testing"
"github.com/Azure/acs-engine/pkg/api"
"github.com/Azure/acs-engine/pkg/i18n"
"github.com/leonelquinteros/gotext"
)
func TestAssignParameters(t *testing.T) {
// Initialize locale for translation
locale := gotext.NewLocale(path.Join("..", "..", "translations"), "en_US")
i18n.Initialize(locale)
apiloader := &api.Apiloader{
Translator: &i18n.Translator{
Locale: locale,
},
}
// iterate the test data directory
apiModelTestFiles := &[]APIModelTestFile{}
if e := IterateTestFilesDirectory(TestDataDir, apiModelTestFiles); e != nil {
t.Error(e.Error())
return
}
for _, tuple := range *apiModelTestFiles {
containerService, _, err := apiloader.LoadContainerServiceFromFile(tuple.APIModelFilename, true, false, nil)
if err != nil {
t.Errorf("Loading file %s got error: %s", tuple.APIModelFilename, err.Error())
continue
}
containerService.Location = "eastus"
parametersMap, err := getParameters(containerService, DefaultGeneratorCode, "testversion")
if err != nil {
t.Errorf("should not get error when populating parameters")
}
for k, v := range parametersMap {
switch val := v.(paramsMap)["value"].(type) {
case *bool:
t.Errorf("got a pointer to bool in paramsMap value, this is dangerous!: %s: %v", k, val)
}
}
}
}

62
pkg/acsengine/testdata/windows/kubernetes-kubernetesconfig.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,62 @@
{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes",
"orchestratorRelease": "1.10",
"kubernetesConfig": {
"useInstanceMetadata": false,
"windowsNodeBinariesURL": "http://test/test.tar.gz"
}
},
"masterProfile": {
"count": 1,
"dnsPrefix": "masterdns1",
"vmSize": "Standard_D2_v2"
},
"agentPoolProfiles": [
{
"name": "agentpool1",
"count": 3,
"vmSize": "Standard_D2_v2",
"availabilityProfile": "VirtualMachineScaleSets",
"osType": "Windows",
"storageProfile": "ManagedDisks"
}
],
"windowsProfile": {
"adminUsername": "azureuser",
"adminPassword": "replacepassword1234$"
},
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
{
"keyData": "ssh-rsa PUBLICKEY azureuser@linuxvm"
}
]
}
},
"servicePrincipalProfile": {
"clientId": "ServicePrincipalClientID",
"secret": "myServicePrincipalClientSecret"
},
"certificateProfile": {
"caCertificate": "caCertificate",
"caPrivateKey": "caPrivateKey",
"apiServerCertificate": "apiServerCertificate",
"apiServerPrivateKey": "apiServerPrivateKey",
"clientCertificate": "clientCertificate",
"clientPrivateKey": "clientPrivateKey",
"kubeConfigCertificate": "kubeConfigCertificate",
"kubeConfigPrivateKey": "kubeConfigPrivateKey",
"etcdClientCertificate": "etcdClientCertificate",
"etcdClientPrivateKey": "etcdClientPrivateKey",
"etcdServerCertificate": "etcdServerCertificate",
"etcdServerPrivateKey": "etcdServerPrivateKey",
"etcdPeerCertificates": ["etcdPeerCertificate0"],
"etcdPeerPrivateKeys": ["etcdPeerPrivateKey0"]
}
}
}

Просмотреть файл

@ -51,7 +51,6 @@ type KubernetesSpecConfig struct {
AzureCNIImageBase string
EtcdDownloadURLBase string
KubeBinariesSASURLBase string
WindowsPackageSASURLBase string
WindowsTelemetryGUID string
CNIPluginsDownloadURL string
VnetCNILinuxPluginsDownloadURL string

Просмотреть файл

@ -40,7 +40,6 @@ type KubernetesSpecConfig struct {
AzureCNIImageBase string
EtcdDownloadURLBase string
KubeBinariesSASURLBase string
WindowsPackageSASURLBase string
WindowsTelemetryGUID string
CNIPluginsDownloadURL string
VnetCNILinuxPluginsDownloadURL string
@ -71,7 +70,6 @@ var (
AzureCNIImageBase: "containernetworking/",
EtcdDownloadURLBase: "https://acs-mirror.azureedge.net/github-coreos",
KubeBinariesSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsPackageSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsTelemetryGUID: "fb801154-36b9-41bc-89c2-f4d4f05472b0",
CNIPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/cni-plugins-amd64-" + CNIPluginVer + ".tgz",
VnetCNILinuxPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/azure-vnet-cni-linux-amd64-" + AzureCniPluginVerLinux + ".tgz",
@ -245,7 +243,6 @@ var (
AzureCNIImageBase: "dockerhub.azk8s.cn/containernetworking/",
EtcdDownloadURLBase: "https://mirror.azk8s.cn/kubernetes/etcd",
KubeBinariesSASURLBase: DefaultKubernetesSpecConfig.KubeBinariesSASURLBase,
WindowsPackageSASURLBase: DefaultKubernetesSpecConfig.WindowsPackageSASURLBase,
WindowsTelemetryGUID: DefaultKubernetesSpecConfig.WindowsTelemetryGUID,
CNIPluginsDownloadURL: "https://mirror.azk8s.cn/kubernetes/containernetworking-plugins/cni-plugins-amd64-" + CNIPluginVer + ".tgz",
VnetCNILinuxPluginsDownloadURL: "https://mirror.azk8s.cn/kubernetes/azure-container-networking/azure-vnet-cni-linux-amd64-" + AzureCniPluginVerLinux + ".tgz",

Просмотреть файл

@ -740,6 +740,7 @@ func convertKubernetesConfigToVLabs(api *KubernetesConfig, vlabs *vlabs.Kubernet
vlabs.CustomCcmImage = api.CustomCcmImage
vlabs.UseCloudControllerManager = api.UseCloudControllerManager
vlabs.CustomWindowsPackageURL = api.CustomWindowsPackageURL
vlabs.WindowsNodeBinariesURL = api.WindowsNodeBinariesURL
vlabs.UseInstanceMetadata = api.UseInstanceMetadata
vlabs.LoadBalancerSku = api.LoadBalancerSku
vlabs.ExcludeMasterFromStandardLB = api.ExcludeMasterFromStandardLB

Просмотреть файл

@ -704,6 +704,7 @@ func convertVLabsKubernetesConfig(vlabs *vlabs.KubernetesConfig, api *Kubernetes
api.CustomCcmImage = vlabs.CustomCcmImage
api.UseCloudControllerManager = vlabs.UseCloudControllerManager
api.CustomWindowsPackageURL = vlabs.CustomWindowsPackageURL
api.WindowsNodeBinariesURL = vlabs.WindowsNodeBinariesURL
api.UseInstanceMetadata = vlabs.UseInstanceMetadata
api.LoadBalancerSku = vlabs.LoadBalancerSku
api.ExcludeMasterFromStandardLB = vlabs.ExcludeMasterFromStandardLB

Просмотреть файл

@ -217,6 +217,31 @@ func TestConvertVLabsOrchestratorProfile(t *testing.T) {
}
}
func TestConvertVLabsKubernetesConfigProfile(t *testing.T) {
tests := map[string]struct {
props *vlabs.KubernetesConfig
expect *KubernetesConfig
}{
"WindowsNodeBinariesURL": {
props: &vlabs.KubernetesConfig{
WindowsNodeBinariesURL: "http://test/test.tar.gz",
},
expect: &KubernetesConfig{
WindowsNodeBinariesURL: "http://test/test.tar.gz",
},
},
}
for name, test := range tests {
t.Logf("running scenario %q", name)
actual := &KubernetesConfig{}
convertVLabsKubernetesConfig(test.props, actual)
if !equality.Semantic.DeepEqual(test.expect, actual) {
t.Errorf(spew.Sprintf("Expected:\n%+v\nGot:\n%+v", test.expect, actual))
}
}
}
func makeKubernetesProperties() *Properties {
ap := &Properties{}
ap.OrchestratorProfile = &OrchestratorProfile{}

Просмотреть файл

@ -331,6 +331,7 @@ type KubernetesConfig struct {
CustomCcmImage string `json:"customCcmImage,omitempty"` // Image for cloud-controller-manager
UseCloudControllerManager *bool `json:"useCloudControllerManager,omitempty"`
CustomWindowsPackageURL string `json:"customWindowsPackageURL,omitempty"`
WindowsNodeBinariesURL string `json:"windowsNodeBinariesURL,omitempty"`
UseInstanceMetadata *bool `json:"useInstanceMetadata,omitempty"`
EnableRbac *bool `json:"enableRbac,omitempty"`
EnableSecureKubelet *bool `json:"enableSecureKubelet,omitempty"`

Просмотреть файл

@ -288,6 +288,7 @@ type KubernetesConfig struct {
CustomCcmImage string `json:"customCcmImage,omitempty"`
UseCloudControllerManager *bool `json:"useCloudControllerManager,omitempty"`
CustomWindowsPackageURL string `json:"customWindowsPackageURL,omitempty"`
WindowsNodeBinariesURL string `json:"windowsNodeBinariesURL,omitempty"`
UseInstanceMetadata *bool `json:"useInstanceMetadata,omitempty"`
EnableRbac *bool `json:"enableRbac,omitempty"`
EnableSecureKubelet *bool `json:"enableSecureKubelet,omitempty"`