npc: Add ruleHost interface
The idea for the interface is taken from the kitt1987/ipblock work. The interface is going to be implemented by selectorSpec and ipBlockSpec.
This commit is contained in:
1 parent
affdc6f5af
commit
2e85018c26
2 files changed
+34
-9
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package npc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@@ -37,6 +39,23 @@ func newSelectorSpec(json *metav1.LabelSelector, policyType []policyType, nsName
|
||||
nsName: nsName}, nil
|
||||
}
|
||||
|
||||
func (spec *selectorSpec) getRuleSpec(src bool) ([]string, string) {
|
||||
dir := "dst"
|
||||
if src {
|
||||
dir = "src"
|
||||
}
|
||||
rule := []string{"-m", "set", "--match-set", string(spec.ipsetName), dir}
|
||||
|
||||
comment := "anywhere"
|
||||
if spec.nsName != "" {
|
||||
comment = fmt.Sprintf("pods: namespace: %s, selector: %s", spec.nsName, spec.key)
|
||||
} else {
|
||||
comment = fmt.Sprintf("namespaces: selector: %s", spec.key)
|
||||
}
|
||||
|
||||
return rule, comment
|
||||
}
|
||||
|
||||
type selector struct {
|
||||
ips ipset.Interface
|
||||
spec *selectorSpec
|
||||
|
||||
Reference in new issue
Block a user