2020-02-22 18:39:33 +00:00
|
|
|
// +build !windows
|
|
|
|
|
2019-10-17 21:46:15 +00:00
|
|
|
package netpol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rancher/k3s/pkg/daemons/config"
|
2020-01-14 19:53:51 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-10-17 21:46:15 +00:00
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Run(ctx context.Context, nodeConfig *config.Node) error {
|
2020-01-14 19:53:51 +00:00
|
|
|
if _, err := NewSavedIPSet(false); err != nil {
|
|
|
|
logrus.Warnf("Skipping network policy controller start, ipset unavailable: %v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-27 05:53:25 +00:00
|
|
|
restConfig, err := clientcmd.BuildConfigFromFlags("", nodeConfig.AgentConfig.KubeConfigK3sController)
|
2019-10-17 21:46:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := kubernetes.NewForConfig(restConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
npc, err := NewNetworkPolicyController(ctx.Done(), client, time.Minute, nodeConfig.AgentConfig.NodeName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
go npc.Run(ctx.Done())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|