Coder Social home page Coder Social logo

Comments (9)

jayunit100 avatar jayunit100 commented on August 30, 2024 2

https://gist.github.com/rosskirkpat/063416fdf5512adc99fab85a411f7947

from sig-windows-dev-tools.

sladyn98 avatar sladyn98 commented on August 30, 2024

@friedrichwilken Would we want to get this into the powershell script to see if it works or are we going down another route with this ?

from sig-windows-dev-tools.

friedrichwilken avatar friedrichwilken commented on August 30, 2024

@sladyn98 well, the k.ps1 causes two errors

Cannot index into a null array.
At C:\k\helper.psm1:179 char:5
+     $subnet = $hnsNetwork.Subnets[0].AddressPrefix
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

4
5
You cannot call a method on a null-valued expression.
At C:\sync\k.ps1:191 char:1
+ $sourceVip = $sourceVipJSON.ip4.ip.Split("/")[0]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Where the second seems to be caused by the first one. The first one points at C:\k\helper.psm1.
In helper.psm1 this function is causing the error:

function GetSourceVip($ipaddress, $NetworkName)
{
    $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower()
    $subnet = $hnsNetwork.Subnets[0].AddressPrefix

    $ipamConfig = @"
        {"cniVersion": "0.2.0", "name": "vxlan0", "ipam":{"type":"host-local","ranges":[[{"subnet":"$subnet"}]],"dataDir":"/var/lib/cni/networks"}}
"@

    $ipamConfig | Out-File "C:\k\sourceVipRequest.json"

    $env:CNI_COMMAND="ADD"
    $env:CNI_CONTAINERID="dummy"
    $env:CNI_NETNS="dummy"
    $env:CNI_IFNAME="dummy"
    $env:CNI_PATH="c:\k\cni" #path to host-local.exe

    If(!(Test-Path c:/k/sourceVip.json)){
        Get-Content sourceVipRequest.json | .\cni\host-local.exe | Out-File sourceVip.json
    }

    Remove-Item env:CNI_COMMAND
    Remove-Item env:CNI_CONTAINERID
    Remove-Item env:CNI_NETNS
    Remove-Item env:CNI_IFNAME
    Remove-Item env:CNI_PATH
}

So I would suggest that we throw a copy of the file @jayunit100 shared (without the Invoke-WebRequest ...) into the ./Win dir and call it in k.ps1 instead of

GetSourceVip -ipAddress 10.0.0.10 -NetworkName $NetworkName

from sig-windows-dev-tools.

friedrichwilken avatar friedrichwilken commented on August 30, 2024

@sladyn98 well, the k.ps1 causes two errors

Cannot index into a null array.
At C:\k\helper.psm1:179 char:5
+     $subnet = $hnsNetwork.Subnets[0].AddressPrefix
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

4
5
You cannot call a method on a null-valued expression.
At C:\sync\k.ps1:191 char:1
+ $sourceVip = $sourceVipJSON.ip4.ip.Split("/")[0]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Where the second seems to be caused by the first one. The first one points at C:\k\helper.psm1.
In helper.psm1 this function is causing the error:

function GetSourceVip($ipaddress, $NetworkName)
{
    $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower()
    $subnet = $hnsNetwork.Subnets[0].AddressPrefix

    $ipamConfig = @"
        {"cniVersion": "0.2.0", "name": "vxlan0", "ipam":{"type":"host-local","ranges":[[{"subnet":"$subnet"}]],"dataDir":"/var/lib/cni/networks"}}
"@

    $ipamConfig | Out-File "C:\k\sourceVipRequest.json"

    $env:CNI_COMMAND="ADD"
    $env:CNI_CONTAINERID="dummy"
    $env:CNI_NETNS="dummy"
    $env:CNI_IFNAME="dummy"
    $env:CNI_PATH="c:\k\cni" #path to host-local.exe

    If(!(Test-Path c:/k/sourceVip.json)){
        Get-Content sourceVipRequest.json | .\cni\host-local.exe | Out-File sourceVip.json
    }

    Remove-Item env:CNI_COMMAND
    Remove-Item env:CNI_CONTAINERID
    Remove-Item env:CNI_NETNS
    Remove-Item env:CNI_IFNAME
    Remove-Item env:CNI_PATH
}

So I would suggest that we throw a copy of the file @jayunit100 shared (without the Invoke-WebRequest ...) into the ./Win dir and call it in k.ps1 instead of

GetSourceVip -ipAddress 10.0.0.10 -NetworkName $NetworkName

That did not fix the problem, so I am trying to really understand what is going on here. Unfortunately I have zero experience with powershell and I have to admit that until now I was only copy/pasting stuff I found on Google. But I will try my best:

The error says simply, that you can't index into an empty array, and even I understand that:

Cannot index into a null array.
At C:\k\helper.psm1:179 char:5
+     $subnet = $hnsNetwork.Subnets[0].AddressPrefix
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

So let's look why it is empty. This function causes the error:

function GetSourceVip($ipaddress, $NetworkName)
{
...
    $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower()
    $subnet = $hnsNetwork.Subnets[0].AddressPrefix
...
}

Where Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower() is supposed to put values into $hnsNetwork which then contains an array called Subnets. The command translates to "Get the HnsNetwork that has the name that is equal to $NetworkName". $NetworkName is set in line 45 of k.ps1:

...
$NetworkName = "vxlan0"
...

And indeed if I run Get-HnsNetwork (after running k.ps1) there are networks, but there is no one named vxlan0.

$NetworkName is set up before the install.ps1 is called, but (against my expectations) it is actually not passed as an argument:

powershell $install -NetworkMode "$NetworkMode" -clusterCIDR "$ClusterCIDR" -KubeDnsServiceIP "$KubeDnsServiceIP" -serviceCIDR "$ServiceCIDR" -InterfaceName "'$InterfaceName'" -LogDir "$LogDir"

(by the way, I have no idea if the PowerShell keyword is needed in an actual script. But since it seemingly does no harm I will leave it for now. Feel free to remove it.`)

But in install.ps1 it is actually set to "vxlan0" if the $NetworkMode is set to "overlay".

$NetworkName = "cbr0"
if ($NetworkMode -eq "overlay")
{
    $NetworkName = "vxlan0"
}

And indeed, in k.ps1 you find the line

$NetworkMode="overlay"

And is passed as an argument when install.ps1 is called, see above. So why is there no network with the name "vxlan0"? Further down at line 98 of install.ps1 there are these lines:

# Prepare Network
ipmo C:\k\hns.psm1
CleanupOldNetwork $NetworkName
CreateExternalNetwork $NetworkMode

And CleanupOldNetwork seems to remove the network vxlan0-network. In the next line CreateExternalNetwork is called and when I tried out the Get-HnsNetwork command earlier, a network with the name external came up. So maybe this is just the network to be used.
Back to k.ps1 I changed the $NetworkName

$NetworkName = "external"

Now, when I run k.ps1 (from a fresh new virtual machine) it runs without any errors.

Status      : Running
Name        : kubelet
DisplayName : kubelet

Status      : Running
Name        : kube-proxy
DisplayName : kube-proxy

And if I ssh into master I get:

vagrant@master:~$ kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   42m   v1.20.4
winw1    Ready    <none>                 33m   v1.20.4

It looks fine, but now I wonder if the vxlan0-network is actually important, and really what I just did I just obscured the error (for now). I will try to get some pods running later. Maybe now is a good time to try to execute k.ps1 from the makefile.

from sig-windows-dev-tools.

sladyn98 avatar sladyn98 commented on August 30, 2024

@friedrichwilken Did you push this code to the k.ps1 ?

from sig-windows-dev-tools.

friedrichwilken avatar friedrichwilken commented on August 30, 2024

@friedrichwilken Did you push this code to the k.ps1 ?

now, sorry cleaned everything up first.

from sig-windows-dev-tools.

friedrichwilken avatar friedrichwilken commented on August 30, 2024

@sladyn98 let me know if this now works for you as well so I could close this issue.

from sig-windows-dev-tools.

sladyn98 avatar sladyn98 commented on August 30, 2024

@friedrichwilken I tried it out but hitting this error

vagrant winrm -c "Restart-Computer" winw1
Failed to restart the computer vagrant with the following error message: The system shutdown cannot be initiated because there are other users logged on to the computer.
At line:1 char:1

  • Restart-Computer
  •   + CategoryInfo          : OperationStopped: (vagrant:String) [Restart-Computer], InvalidOperationException
      + FullyQualifiedErrorId : RestartcomputerFailed,Microsoft.PowerShell.Commands.RestartComputerCommand
    

Makefile:2: recipe for target 'run' failed
make: *** [run] Error 1

from sig-windows-dev-tools.

friedrichwilken avatar friedrichwilken commented on August 30, 2024

Looks like you are legged in the vm. This will prevent it from rebooting.

from sig-windows-dev-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.