mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Generic sets in ipset.go
This commit is contained in:
parent
fbe671d3f0
commit
3325c7031d
@ -93,7 +93,7 @@ type IPSetVersioner interface {
|
|||||||
type IPSet struct {
|
type IPSet struct {
|
||||||
utilipset.IPSet
|
utilipset.IPSet
|
||||||
// activeEntries is the current active entries of the ipset.
|
// activeEntries is the current active entries of the ipset.
|
||||||
activeEntries sets.String
|
activeEntries sets.Set[string]
|
||||||
// handle is the util ipset interface handle.
|
// handle is the util ipset interface handle.
|
||||||
handle utilipset.Interface
|
handle utilipset.Interface
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func NewIPSet(handle utilipset.Interface, name string, setType utilipset.Type, i
|
|||||||
HashFamily: hashFamily,
|
HashFamily: hashFamily,
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
},
|
},
|
||||||
activeEntries: sets.NewString(),
|
activeEntries: sets.New[string](),
|
||||||
handle: handle,
|
handle: handle,
|
||||||
}
|
}
|
||||||
return set
|
return set
|
||||||
@ -144,7 +144,7 @@ func (set *IPSet) getComment() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (set *IPSet) resetEntries() {
|
func (set *IPSet) resetEntries() {
|
||||||
set.activeEntries = sets.NewString()
|
set.activeEntries = sets.New[string]()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (set *IPSet) syncIPSetEntries() {
|
func (set *IPSet) syncIPSetEntries() {
|
||||||
@ -155,14 +155,14 @@ func (set *IPSet) syncIPSetEntries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// currentIPSetEntries represents Endpoints watched from API Server.
|
// currentIPSetEntries represents Endpoints watched from API Server.
|
||||||
currentIPSetEntries := sets.NewString()
|
currentIPSetEntries := sets.New[string]()
|
||||||
for _, appliedEntry := range appliedEntries {
|
for _, appliedEntry := range appliedEntries {
|
||||||
currentIPSetEntries.Insert(appliedEntry)
|
currentIPSetEntries.Insert(appliedEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !set.activeEntries.Equal(currentIPSetEntries) {
|
if !set.activeEntries.Equal(currentIPSetEntries) {
|
||||||
// Clean legacy entries
|
// Clean legacy entries
|
||||||
for _, entry := range currentIPSetEntries.Difference(set.activeEntries).List() {
|
for _, entry := range currentIPSetEntries.Difference(set.activeEntries).UnsortedList() {
|
||||||
if err := set.handle.DelEntry(entry, set.Name); err != nil {
|
if err := set.handle.DelEntry(entry, set.Name); err != nil {
|
||||||
if !utilipset.IsNotFoundError(err) {
|
if !utilipset.IsNotFoundError(err) {
|
||||||
klog.ErrorS(err, "Failed to delete ip set entry from ip set", "ipSetEntry", entry, "ipSet", set.Name)
|
klog.ErrorS(err, "Failed to delete ip set entry from ip set", "ipSetEntry", entry, "ipSet", set.Name)
|
||||||
@ -172,7 +172,7 @@ func (set *IPSet) syncIPSetEntries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create active entries
|
// Create active entries
|
||||||
for _, entry := range set.activeEntries.Difference(currentIPSetEntries).List() {
|
for _, entry := range set.activeEntries.Difference(currentIPSetEntries).UnsortedList() {
|
||||||
if err := set.handle.AddEntry(entry, &set.IPSet, true); err != nil {
|
if err := set.handle.AddEntry(entry, &set.IPSet, true); err != nil {
|
||||||
klog.ErrorS(err, "Failed to add ip set entry to ip set", "ipSetEntry", entry, "ipSet", set.Name)
|
klog.ErrorS(err, "Failed to add ip set entry to ip set", "ipSetEntry", entry, "ipSet", set.Name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1501,7 +1501,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the KUBE-IPVS-IPS set to the "activeBindAddrs"
|
// Set the KUBE-IPVS-IPS set to the "activeBindAddrs"
|
||||||
proxier.ipsetList[kubeIPVSSet].activeEntries = sets.StringKeySet(activeBindAddrs)
|
proxier.ipsetList[kubeIPVSSet].activeEntries = activeBindAddrs
|
||||||
|
|
||||||
// sync ipset entries
|
// sync ipset entries
|
||||||
for _, set := range proxier.ipsetList {
|
for _, set := range proxier.ipsetList {
|
||||||
|
Loading…
Reference in New Issue
Block a user