Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipam: deepcopy interface resource correctly. #26998

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/alibabacloud/eni/types/types.go
Expand Up @@ -126,6 +126,10 @@ type ENI struct {
Tags map[string]string `json:"tags,omitempty"`
}

func (e *ENI) DeepCopyInterface() types.Interface {
return e.DeepCopy()
}

// InterfaceID returns the identifier of the interface
func (e *ENI) InterfaceID() string {
return e.NetworkInterfaceID
Expand Down
4 changes: 4 additions & 0 deletions pkg/aws/eni/types/types.go
Expand Up @@ -208,6 +208,10 @@ type ENI struct {
Tags map[string]string `json:"tags,omitempty"`
}

func (e *ENI) DeepCopyInterface() types.Interface {
return e.DeepCopy()
}

// InterfaceID returns the identifier of the interface
func (e *ENI) InterfaceID() string {
return e.ID
Expand Down
4 changes: 4 additions & 0 deletions pkg/azure/types/types.go
Expand Up @@ -126,6 +126,10 @@ type AzureInterface struct {
resourceGroup string `json:"-"`
}

func (a *AzureInterface) DeepCopyInterface() types.Interface {
return a.DeepCopy()
}

// SetID sets the Azure interface ID, as well as extracting other fields from
// the ID itself.
func (a *AzureInterface) SetID(id string) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/ipam/types/types.go
Expand Up @@ -361,6 +361,9 @@ type Interface interface {
// ForeachAddress must iterate over all addresses of the interface and
// call fn for each address
ForeachAddress(instanceID string, fn AddressIterator) error

// DeepCopyInterface returns a deep copy of the underlying interface type.
DeepCopyInterface() Interface
}

// InterfaceRevision is the configurationr revision of a network interface. It
Expand Down Expand Up @@ -542,6 +545,7 @@ func (m *InstanceMap) DeepCopy() *InstanceMap {
c := NewInstanceMap()
m.ForeachInterface("", func(instanceID, interfaceID string, rev InterfaceRevision) error {
// c is not exposed yet, we can access it without locking it
rev.Resource = rev.Resource.DeepCopyInterface()
c.updateLocked(instanceID, rev)
return nil
})
Expand Down
17 changes: 17 additions & 0 deletions pkg/ipam/types/types_test.go
Expand Up @@ -31,6 +31,23 @@ type mockInterface struct {
pools map[string][]net.IP
}

func (m *mockInterface) DeepCopyInterface() Interface {
mc := &mockInterface{
id: m.id,
pools: map[string][]net.IP{},
}
for id, pool := range m.pools {
pc := make([]net.IP, 0, len(pool))
for _, ip := range pool {
ipc := net.IP{}
copy(ipc, ip)
pc = append(pc, ipc)
}
mc.pools[id] = pc
}
return mc
}

func (m *mockInterface) InterfaceID() string {
return m.id
}
Expand Down