Skip to content

Commit 0489778

Browse files
authored
Add sync seconds for informer (#19)
1 parent cd4039c commit 0489778

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
func parserFlags() {
4545
flag.StringVarP(&kubeconfig, "kubeconfig", "", "", "Absolute path to the kubeconfig file.")
4646
flag.IntVarP(&cfg.Threads, "threads", "", 2, "Number of worker threads used by the controller.")
47+
flag.IntVarP(&cfg.SyncSec, "sync-seconds", "", 30, "Seconds for syncing and retrying objects.")
4748
flag.StringSliceVarP(&cfg.IgnoreNamespaces, "ignore-namespaces", "", nil, "Ignore namespaces for syncing objects.")
4849
flag.StringSliceVarP(&cfg.Services, "services", "", []string{"k8s-tcp", "k8s-udp"}, "The service objects of security policy.")
4950
flag.StringSliceVarP(&cfg.SourceZones, "source-zones", "", []string{"untrust"}, "The source zones of security policy.")

pkg/config/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package config
1818

1919
// Config contains the operator config
2020
type Config struct {
21-
Threads int
22-
21+
Threads int
22+
SyncSec int
2323
SourceZones []string
2424
SourceUsers []string
2525
HipProfiles []string

pkg/operator/operator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ func New(cfg *config.Config, clientset kubernetes.Interface, blendedset blended.
5050
clientset: clientset,
5151
blendedset: blendedset,
5252
}
53-
54-
o.informer = informers.NewSharedInformerFactory(clientset, defaultSyncTime)
53+
t := defaultSyncTime
54+
if cfg.SyncSec > 30 {
55+
t = time.Second * time.Duration(cfg.SyncSec)
56+
}
57+
o.informer = informers.NewSharedInformerFactory(clientset, t)
5558
o.service = service.NewController(cfg, clientset, blendedset, o.informer.Core().V1().Services())
5659
o.namespace = namespace.NewController(cfg, clientset, blendedset, o.informer.Core().V1().Namespaces())
5760
return o

0 commit comments

Comments
 (0)