mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #46940 from realfake/azure-cloud-controller-manager
Automatic merge from submit-queue Azure for cloud-controller-manager **What this PR does / why we need it**: This implements the NodeAddressesByProviderID and InstanceTypeByProviderID methods used by the cloud-controller-manager to the Azure provider. **Release note**: ```release-note NONE ``` Addresses #47257
This commit is contained in:
commit
67730881a6
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package azure
|
package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
@ -46,7 +45,12 @@ func (az *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
|
|||||||
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
||||||
// and other local methods cannot be used here
|
// and other local methods cannot be used here
|
||||||
func (az *Cloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
func (az *Cloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
||||||
return []v1.NodeAddress{}, errors.New("unimplemented")
|
name, err := splitProviderID(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return az.NodeAddresses(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
|
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
|
||||||
@ -83,7 +87,12 @@ func (az *Cloud) InstanceID(name types.NodeName) (string, error) {
|
|||||||
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
||||||
// and other local methods cannot be used here
|
// and other local methods cannot be used here
|
||||||
func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
||||||
return "", errors.New("unimplemented")
|
name, err := splitProviderID(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return az.InstanceID(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceType returns the type of the specified instance.
|
// InstanceType returns the type of the specified instance.
|
||||||
|
@ -750,3 +750,54 @@ func TestDecodeInstanceInfo(t *testing.T) {
|
|||||||
t.Error("got incorrect fault domain")
|
t.Error("got incorrect fault domain")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSplitProviderID(t *testing.T) {
|
||||||
|
providers := []struct {
|
||||||
|
providerID string
|
||||||
|
name types.NodeName
|
||||||
|
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
providerID: CloudProviderName + ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
|
||||||
|
name: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
|
||||||
|
fail: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
providerID: CloudProviderName + ":/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
|
||||||
|
name: "",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
providerID: CloudProviderName + "://",
|
||||||
|
name: "",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
providerID: ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
|
||||||
|
name: "",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
providerID: "aws:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
|
||||||
|
name: "",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range providers {
|
||||||
|
name, err := splitProviderID(test.providerID)
|
||||||
|
if (err != nil) != test.fail {
|
||||||
|
t.Errorf("Expected to failt=%t, with pattern %v", test.fail, test)
|
||||||
|
}
|
||||||
|
|
||||||
|
if test.fail {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if name != test.name {
|
||||||
|
t.Errorf("Expected %v, but got %v", test.name, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
|||||||
package azure
|
package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
@ -42,6 +44,8 @@ const (
|
|||||||
securityRuleIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s"
|
securityRuleIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var providerIDRE = regexp.MustCompile(`^` + CloudProviderName + `://(.+)$`)
|
||||||
|
|
||||||
// returns the full identifier of a machine
|
// returns the full identifier of a machine
|
||||||
func (az *Cloud) getMachineID(machineName string) string {
|
func (az *Cloud) getMachineID(machineName string) string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
@ -275,3 +279,12 @@ func (az *Cloud) getIPForMachine(nodeName types.NodeName) (string, error) {
|
|||||||
targetIP := *ipConfig.PrivateIPAddress
|
targetIP := *ipConfig.PrivateIPAddress
|
||||||
return targetIP, nil
|
return targetIP, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// splitProviderID converts a providerID to a NodeName.
|
||||||
|
func splitProviderID(providerID string) (types.NodeName, error) {
|
||||||
|
matches := providerIDRE.FindStringSubmatch(providerID)
|
||||||
|
if len(matches) != 2 {
|
||||||
|
return "", errors.New("error splitting providerID")
|
||||||
|
}
|
||||||
|
return types.NodeName(matches[1]), nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user