paraglider-project / paraglider

Streamlining cloud networking
https://paragliderproject.io
Apache License 2.0
62 stars 4 forks source link

[Azure] Failed to create vm resource #496

Open aviweit opened 5 days ago

aviweit commented 5 days ago

Creating the file azure_vm.json with the below contents:

{
    "location": "eastus",
    "properties": {
        "hardwareProfile": {
            "vmSize": "Standard_B1s"
        },
        "osProfile": {
            "computerName": "sample-compute",
            "adminUsername": "weit",
            "adminPassword": "pas43920$rejkfjsdklwe48i@@9023d"
        },
        "storageProfile": {
            "imageReference": {
                "offer": "0001-com-ubuntu-minimal-jammy",
                "publisher": "canonical",
                "sku": "minimal-22_04-lts-gen2",
                "version": "latest"
            }
        }
    }
}

and invoking:

glide resource create azure vm-1 azure_vm.json

produced the below error message:

failed to create resource: Put "http://localhost:8080/namespaces/default/clouds/azure/resources/vm-1": EOF

which seems to cause the orchestrator to crash:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x13f4ce9]

goroutine 118 [running]:
github.com/paraglider-project/paraglider/pkg/azure.(*AzureSDKHandler).GetAllVnetsAddressSpaces(0xc001229860, {0x30b0308, 0xc0013c26f0}, {0xc001307d60, 0x7})
        /home/weit/paraglider/pkg/azure/sdk_handler.go:310 +0x2c9
github.com/paraglider-project/paraglider/pkg/azure.(*azurePluginServer).GetUsedAddressSpaces(0xc0000905a0, {0x30b0308, 0xc0013c26f0}, 0xc001378800)
        /home/weit/paraglider/pkg/azure/plugin.go:383 +0x273
github.com/paraglider-project/paraglider/pkg/paragliderpb._CloudPlugin_GetUsedAddressSpaces_Handler({0x2bcdee0, 0xc0000905a0}, {0x30b0308, 0xc0013c26f0}, 0xc00092c880, 0x0)
        /home/weit/paraglider/pkg/paragliderpb/paraglider_grpc.pb.go:271 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000f18a00, {0x30b0308, 0xc0008f5a10}, {0x30bc460, 0xc000835680}, 0xc000e08900, 0xc000f0cbd0, 0x4ac9800, 0x0)
        /home/weit/go/pkg/mod/google.golang.org/grpc@v1.64.0/server.go:1379 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc000f18a00, {0x30bc460, 0xc000835680}, 0xc000e08900)
        /home/weit/go/pkg/mod/google.golang.org/grpc@v1.64.0/server.go:1790 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        /home/weit/go/pkg/mod/google.golang.org/grpc@v1.64.0/server.go:1029 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 117
        /home/weit/go/pkg/mod/google.golang.org/grpc@v1.64.0/server.go:1040 +0x125

It seems to me that the SIGSEGV is related to azure/sdk_handler.go (where v.Tags exists but set with an empty map) at:

if v.Tags != nil && *v.Tags[namespaceTagKey] == namespace {

After updating the code with key existence check:

if val, ok := v.Tags[namespaceTagKey]; ok

I was able to create an azure vm with glide resource create CLI:

~/paraglider$ glide resource create azure vm-1 azure_vm.json
Creating resource: vm-1
Resource Created.
tag: default.azure.vm-1
uri: /subscriptions/my-subscription-id/resourceGroups/my-resource-group-name/providers/Microsoft.Compute/virtualMachines/vm-1
ip: 10.1.0.5

I would like to ask whether I am missing something or perhaps a fix should be applied.

Thanks.

Cohen-J-Omer commented 2 days ago

I encountered the same bug after pulling the latest commit and building from source. Applying the change @aviweit suggested solved the bug.

Output of glide version:

Release: latest 
Version: a05976c-dirty
Commit: a05976c146d49a984c6b06f673efdd0a28ed4159
J-467 commented 2 days ago

Hi Avi, I pulled the latest commit on main and I tried replicating the error with the vm json you attached, and it works fine on my end (probably because the only vnet in my rg is the paraglider created vnet). It seems there's a vnet within your resource group doesn't have a paraglider tag attached to it. The fix you provided should solve the problem as they may be non-Paraglider vnets in the resource groups. I can push a fix for this. (Unless you'd prefer to do that). Thanks for pointing this out!

Also, if I may ask, is there an external vnet within your resource group (one that wasn't created by Paraglider - which would make sense if there's no tag)? If there isn't, that may be something to worry about. (Why a Paraglider created vnet would not have the paraglider tag)

aviweit commented 1 day ago

Hi @J-467 , please feel free to push the fix.

Yes, we have a few vnets not related to Paraglider with no tags. I think that may explain.

Thanks a lot.