Skip to content

Commit

Permalink
Merge pull request #38 from banzaicloud/azure-fixes
Browse files Browse the repository at this point in the history
Azure fixes
  • Loading branch information
Ecsy authored Apr 30, 2019
2 parents 311df88 + ad3d036 commit b5e8777
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 25 deletions.
4 changes: 4 additions & 0 deletions cmd/pke/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const (
FlagAzureLoadBalancerSku = "azure-loadbalancer-sku"
// FlagAzureRouteTableName the name of the route table attached to the subnet that the cluster is deployed in.
FlagAzureRouteTableName = "azure-route-table-name"
// FlagAzureStorageAccountType Azure storage account Sku tier.
FlagAzureStorageAccountType = "azure-storage-account-type"
// FlagAzureStorageKind possible values are shared, dedicated, and managed (default).
FlagAzureStorageKind = "azure-storage-kind"

// FlagDisableDefaultStorageClass adds default storage class.
FlagDisableDefaultStorageClass = "disable-default-storage-class"
Expand Down
42 changes: 31 additions & 11 deletions cmd/pke/app/phases/kubeadm/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ type ControlPlane struct {
azureVMType string
azureLoadBalancerSku string
azureRouteTableName string
azureStorageAccountType string
azureStorageKind string
azureExcludeMasterFromStandardLB bool
cidr string
disableDefaultStorageClass bool
Expand Down Expand Up @@ -169,6 +171,8 @@ func (c *ControlPlane) RegisterFlags(flags *pflag.FlagSet) {
flags.String(constants.FlagAzureVMType, "standard", "The type of azure nodes. Candidate values are: vmss and standard")
flags.String(constants.FlagAzureLoadBalancerSku, "basic", "Sku of Load Balancer and Public IP. Candidate values are: basic and standard")
flags.String(constants.FlagAzureRouteTableName, "kubernetes-routes", "The name of the route table attached to the subnet that the cluster is deployed in")
flags.String(constants.FlagAzureStorageAccountType, "Standard_LRS", "Azure storage account Sku tier")
flags.String(constants.FlagAzureStorageKind, "dedicated", "Possible values are shared, dedicated, and managed")
// Pipeline
flags.StringP(constants.FlagPipelineAPIEndpoint, constants.FlagPipelineAPIEndpointShort, "", "Pipeline API server url")
flags.StringP(constants.FlagPipelineAPIToken, constants.FlagPipelineAPITokenShort, "", "Token for accessing Pipeline API")
Expand Down Expand Up @@ -215,14 +219,16 @@ func (c *ControlPlane) Validate(cmd *cobra.Command) error {
// Azure specific required flags
if c.cloudProvider == constants.CloudProviderAzure {
if err := validator.NotEmpty(map[string]interface{}{
constants.FlagAzureTenantID: c.azureTenantID,
constants.FlagAzureSubnetName: c.azureSubnetName,
constants.FlagAzureSecurityGroupName: c.azureSecurityGroupName,
constants.FlagAzureVNetName: c.azureVNetName,
constants.FlagAzureVNetResourceGroup: c.azureVNetResourceGroup,
constants.FlagAzureVMType: c.azureVMType,
constants.FlagAzureLoadBalancerSku: c.azureLoadBalancerSku,
constants.FlagAzureRouteTableName: c.azureRouteTableName,
constants.FlagAzureTenantID: c.azureTenantID,
constants.FlagAzureSubnetName: c.azureSubnetName,
constants.FlagAzureSecurityGroupName: c.azureSecurityGroupName,
constants.FlagAzureVNetName: c.azureVNetName,
constants.FlagAzureVNetResourceGroup: c.azureVNetResourceGroup,
constants.FlagAzureVMType: c.azureVMType,
constants.FlagAzureLoadBalancerSku: c.azureLoadBalancerSku,
constants.FlagAzureRouteTableName: c.azureRouteTableName,
constants.FlagAzureStorageAccountType: c.azureStorageAccountType,
constants.FlagAzureStorageKind: c.azureStorageKind,
}); err != nil {
return err
}
Expand Down Expand Up @@ -519,6 +525,20 @@ func (c *ControlPlane) masterBootstrapParameters(cmd *cobra.Command) (err error)
if err != nil {
return
}
err = c.azureParameters(cmd)
if err != nil {
return
}
c.cidr, err = cmd.Flags().GetString(constants.FlagInfrastructureCIDR)
if err != nil {
return
}
c.disableDefaultStorageClass, err = cmd.Flags().GetBool(constants.FlagDisableDefaultStorageClass)

return
}

func (c *ControlPlane) azureParameters(cmd *cobra.Command) (err error) {
c.azureTenantID, err = cmd.Flags().GetString(constants.FlagAzureTenantID)
if err != nil {
return
Expand Down Expand Up @@ -551,11 +571,11 @@ func (c *ControlPlane) masterBootstrapParameters(cmd *cobra.Command) (err error)
if err != nil {
return
}
c.cidr, err = cmd.Flags().GetString(constants.FlagInfrastructureCIDR)
c.azureStorageAccountType, err = cmd.Flags().GetString(constants.FlagAzureStorageAccountType)
if err != nil {
return
}
c.disableDefaultStorageClass, err = cmd.Flags().GetBool(constants.FlagDisableDefaultStorageClass)
c.azureStorageKind, err = cmd.Flags().GetString(constants.FlagAzureStorageKind)

return
}
Expand Down Expand Up @@ -644,7 +664,7 @@ func (c *ControlPlane) installMaster(out io.Writer) error {
}

// apply default storage class
if err := applyDefaultStorageClass(out, c.disableDefaultStorageClass, c.cloudProvider); err != nil {
if err := applyDefaultStorageClass(out, c.disableDefaultStorageClass, c.cloudProvider, c.azureStorageAccountType, c.azureStorageKind); err != nil {
return err
}

Expand Down
12 changes: 7 additions & 5 deletions cmd/pke/app/phases/kubeadm/controlplane/storage_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/banzaicloud/pke/cmd/pke/app/util/runner"
)

func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cloudProvider string) error {
func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cloudProvider, azureStorageAccountType, azuerStorageKind string) error {
if disableDefaultStorageClass {
return nil
}
Expand All @@ -34,7 +34,7 @@ func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cl
case constants.CloudProviderAmazon:
err = writeStorageClassAmazon(out, storageClassConfig)
case constants.CloudProviderAzure:
err = writeStorageClassAzure(out, storageClassConfig)
err = writeStorageClassAzure(out, storageClassConfig, azureStorageAccountType, azuerStorageKind)
default:
err = writeStorageClassLocalPathStorage(out, storageClassConfig)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ parameters:
return tmpl.Execute(w, d)
}

func writeStorageClassAzure(out io.Writer, filename string) error {
func writeStorageClassAzure(out io.Writer, filename string, storageAccountType, kind string) error {
_, _ = fmt.Fprintf(out, "[%s] creating Azure default storage class\n", use)
// https://kubernetes.io/docs/concepts/storage/storage-classes/#new-azure-disk-storage-class-starting-from-v1-7-2
conf := `kind: StorageClass
Expand All @@ -95,6 +95,8 @@ metadata:
name: azure-disk
annotations:
storageclass.kubernetes.io/is-default-class: "true"
labels:
kubernetes.io/cluster-service: "true"
provisioner: kubernetes.io/azure-disk
volumeBindingMode: WaitForFirstConsumer
parameters:
Expand All @@ -120,8 +122,8 @@ parameters:
}

d := data{
StorageAccountType: "Standard_LRS",
Kind: "dedicated",
StorageAccountType: storageAccountType,
Kind: kind,
}

return tmpl.Execute(w, d)
Expand Down
3 changes: 2 additions & 1 deletion cmd/pke/app/util/pipeline/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func Client(out io.Writer, endpoint, token string) *pipeline.APIClient {
config.HTTPClient = oauth2.NewClient(nil, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
config.HTTPClient.Timeout = 30 * time.Second
// Since transport.NewRetryTransport is added, this timeout will affect only the cumulated retry calls.
config.HTTPClient.Timeout = 24 * time.Hour
tl := transport.NewLogger(out, config.HTTPClient.Transport)
config.HTTPClient.Transport = transport.NewRetryTransport(tl)

Expand Down
2 changes: 2 additions & 0 deletions cmd/pke/docs/pke_install_master.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pke install master [flags]
--azure-loadbalancer-sku string Sku of Load Balancer and Public IP. Candidate values are: basic and standard (default "basic")
--azure-route-table-name string The name of the route table attached to the subnet that the cluster is deployed in (default "kubernetes-routes")
--azure-security-group-name string The name of the security group attached to the cluster's subnet
--azure-storage-account-type string Azure storage account Sku tier (default "Standard_LRS")
--azure-storage-kind string Possible values are shared, dedicated, and managed (default "dedicated")
--azure-subnet-name string The name of the subnet that the cluster is deployed in
--azure-tenant-id string The AAD Tenant ID for the Subscription that the cluster is deployed in
--azure-vm-type string The type of azure nodes. Candidate values are: vmss and standard (default "standard")
Expand Down
2 changes: 2 additions & 0 deletions cmd/pke/docs/pke_install_master_kubernetes-controlplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pke install master kubernetes-controlplane [flags]
--azure-loadbalancer-sku string Sku of Load Balancer and Public IP. Candidate values are: basic and standard (default "basic")
--azure-route-table-name string The name of the route table attached to the subnet that the cluster is deployed in (default "kubernetes-routes")
--azure-security-group-name string The name of the security group attached to the cluster's subnet
--azure-storage-account-type string Azure storage account Sku tier (default "Standard_LRS")
--azure-storage-kind string Possible values are shared, dedicated, and managed (default "dedicated")
--azure-subnet-name string The name of the subnet that the cluster is deployed in
--azure-tenant-id string The AAD Tenant ID for the Subscription that the cluster is deployed in
--azure-vm-type string The type of azure nodes. Candidate values are: vmss and standard (default "standard")
Expand Down
2 changes: 2 additions & 0 deletions cmd/pke/docs/pke_install_single.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pke install single [flags]
--azure-loadbalancer-sku string Sku of Load Balancer and Public IP. Candidate values are: basic and standard (default "basic")
--azure-route-table-name string The name of the route table attached to the subnet that the cluster is deployed in (default "kubernetes-routes")
--azure-security-group-name string The name of the security group attached to the cluster's subnet
--azure-storage-account-type string Azure storage account Sku tier (default "Standard_LRS")
--azure-storage-kind string Possible values are shared, dedicated, and managed (default "dedicated")
--azure-subnet-name string The name of the subnet that the cluster is deployed in
--azure-tenant-id string The AAD Tenant ID for the Subscription that the cluster is deployed in
--azure-vm-type string The type of azure nodes. Candidate values are: vmss and standard (default "standard")
Expand Down
2 changes: 2 additions & 0 deletions cmd/pke/docs/pke_install_single_kubernetes-controlplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pke install single kubernetes-controlplane [flags]
--azure-loadbalancer-sku string Sku of Load Balancer and Public IP. Candidate values are: basic and standard (default "basic")
--azure-route-table-name string The name of the route table attached to the subnet that the cluster is deployed in (default "kubernetes-routes")
--azure-security-group-name string The name of the security group attached to the cluster's subnet
--azure-storage-account-type string Azure storage account Sku tier (default "Standard_LRS")
--azure-storage-kind string Possible values are shared, dedicated, and managed (default "dedicated")
--azure-subnet-name string The name of the subnet that the cluster is deployed in
--azure-tenant-id string The AAD Tenant ID for the Subscription that the cluster is deployed in
--azure-vm-type string The type of azure nodes. Candidate values are: vmss and standard (default "standard")
Expand Down
6 changes: 3 additions & 3 deletions docs/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ aws ec2 run-instances --image-id ami-3548444c \
Once you single master instance booted up, SSH into it with the key file configured. Run the following commands as root:

```
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand Down Expand Up @@ -129,7 +129,7 @@ export INTERNAL_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
export MAC=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
export VPC_CIDR=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-block/)
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand Down Expand Up @@ -162,7 +162,7 @@ pke token create
To install a worker node, run the following commands. Take note that you'd need to set the TOKEN and CERTHASH variables from above.

```
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion docs/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Install PKE.
> `--kubernetes-cluster-name` is used for load balancer naming.
```bash
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can also use the following commands as root to achieve this:


```
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
```
6 changes: 3 additions & 3 deletions docs/vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Once the node is up follow these instructions:
vagrant ssh node1
sudo -s
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand All @@ -47,7 +47,7 @@ Once the node is up follow these instructions:
vagrant ssh node1
sudo -s
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand Down Expand Up @@ -77,7 +77,7 @@ Take note that you'd need to export the TOKEN and CERTHASH environment variables
vagrant ssh node2
sudo -s
curl -v https://banzaicloud.com/downloads/pke/pke-0.2.3 -o /usr/local/bin/pke
curl -v https://banzaicloud.com/downloads/pke/pke-0.4.4 -o /usr/local/bin/pke
chmod +x /usr/local/bin/pke
export PATH=$PATH:/usr/local/bin/
Expand Down

0 comments on commit b5e8777

Please sign in to comment.