Skip to content

Commit

Permalink
"remove check for duplicate names as it can not correctly assess disa…
Browse files Browse the repository at this point in the history
…bled networks from there #308"
  • Loading branch information
eveld committed Oct 10, 2024
1 parent 45b93eb commit 876ce02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
18 changes: 9 additions & 9 deletions pkg/config/resources/network/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var bridgeNetwork = dtypes.NetworkResource{
ID: "bridge",
Name: "bridge",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.8.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.8.2.0/24"}},
},
}

Expand All @@ -45,10 +45,10 @@ func TestLookupReturnsID(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.2.0/24"}},
},
},
bridgeNetwork,
Expand Down Expand Up @@ -128,10 +128,10 @@ func TestNetworkDoesNOTCreateWhenExists(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.2.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand All @@ -150,10 +150,10 @@ func TestCreateWithCorrectNameAndDifferentSubnetReturnsError(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.1.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.1.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand All @@ -171,10 +171,10 @@ func TestCreateWithOverlappingSubnetReturnsError(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "abc",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.2.0.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.2.0.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand Down
22 changes: 0 additions & 22 deletions pkg/config/resources/network/resource.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package network

import (
"fmt"

"github.com/jumppad-labs/hclconfig/types"
)

Expand All @@ -17,23 +15,3 @@ type Network struct {
Subnet string `hcl:"subnet" json:"subnet"`
EnableIPv6 bool `hcl:"enable_ipv6,optional" json:"enable_ipv6"`
}

func (c *Network) Parse(conf types.Findable) error {
// do any other networks with this name exist?
nets, err := conf.FindResourcesByType(TypeNetwork)
if err != nil {
return err
}

for _, n := range nets {
if n.Metadata().Name == c.Meta.Name && n.Metadata().ID != c.Meta.ID {
return fmt.Errorf("a network named '%s' is already defined by the resource '%s'", c.Meta.Name, n.Metadata().ID)
}
}

return nil
}

func (c *Network) Process() error {
return nil
}

0 comments on commit 876ce02

Please sign in to comment.