github.com/openshift/installer@v1.4.17/pkg/asset/manifests/azure/cloudproviderconfig.go (about)

     1  package azure
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  
     7  	"github.com/openshift/installer/pkg/types/azure"
     8  )
     9  
    10  // CloudProviderConfig is the azure cloud provider config
    11  type CloudProviderConfig struct {
    12  	CloudName                azure.CloudEnvironment
    13  	TenantID                 string
    14  	SubscriptionID           string
    15  	ResourceGroupName        string
    16  	GroupLocation            string
    17  	ResourcePrefix           string
    18  	NetworkResourceGroupName string
    19  	NetworkSecurityGroupName string
    20  	VirtualNetworkName       string
    21  	SubnetName               string
    22  	ResourceManagerEndpoint  string
    23  	ARO                      bool
    24  }
    25  
    26  // JSON generates the cloud provider json config for the azure platform.
    27  // managed resource names are matching the convention defined by capz
    28  func (params CloudProviderConfig) JSON() (string, error) {
    29  
    30  	// Config requires type *bool for excludeMasterFromStandardLB, so define a variable here to get an address in the config.
    31  	excludeMasterFromStandardLB := false
    32  
    33  	config := config{
    34  		authConfig: authConfig{
    35  			Cloud:                       params.CloudName.Name(),
    36  			TenantID:                    params.TenantID,
    37  			SubscriptionID:              params.SubscriptionID,
    38  			UseManagedIdentityExtension: true,
    39  			// The cloud provider needs the clientID which is only known after terraform has run.
    40  			// When left empty, the existing managed identity on the VM will be used.
    41  			// By leaving it empty, we don't have to create the identity before running the installer.
    42  			// We only need to know that there will be one assigned to the VM, and we control this.
    43  			// ref: https://github.com/kubernetes/kubernetes/blob/4b7c607ba47928a7be77fadef1550d6498397a4c/staging/src/k8s.io/legacy-cloud-providers/azure/auth/azure_auth.go#L69
    44  			UserAssignedIdentityID: "",
    45  		},
    46  		ResourceGroup:     params.ResourceGroupName,
    47  		Location:          params.GroupLocation,
    48  		SubnetName:        params.SubnetName,
    49  		SecurityGroupName: params.NetworkSecurityGroupName,
    50  		VnetName:          params.VirtualNetworkName,
    51  		VnetResourceGroup: params.NetworkResourceGroupName,
    52  		RouteTableName:    params.ResourcePrefix + "-node-routetable",
    53  		// client side rate limiting is problematic for scaling operations. We disable it by default.
    54  		// https://github.com/kubernetes-sigs/cloud-provider-azure/issues/247
    55  		// https://bugzilla.redhat.com/show_bug.cgi?id=1782516#c7
    56  		CloudProviderBackoff:         true,
    57  		CloudProviderBackoffDuration: 6,
    58  		VMType:                       "standard",
    59  
    60  		UseInstanceMetadata: true,
    61  		// default to standard load balancer, supports tcp resets on idle
    62  		// https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-tcp-reset
    63  		LoadBalancerSku:             "standard",
    64  		ExcludeMasterFromStandardLB: &excludeMasterFromStandardLB,
    65  	}
    66  
    67  	if params.ARO {
    68  		config.authConfig.UseManagedIdentityExtension = false
    69  	}
    70  
    71  	if params.CloudName == azure.StackCloud {
    72  		config.authConfig.ResourceManagerEndpoint = params.ResourceManagerEndpoint
    73  		config.authConfig.UseManagedIdentityExtension = false
    74  		config.LoadBalancerSku = "basic"
    75  		config.UseInstanceMetadata = false
    76  	}
    77  
    78  	buff := &bytes.Buffer{}
    79  	encoder := json.NewEncoder(buff)
    80  	encoder.SetIndent("", "\t")
    81  	if err := encoder.Encode(config); err != nil {
    82  		return "", err
    83  	}
    84  	return buff.String(), nil
    85  }