Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davidefalcone1 committed Jun 28, 2021
1 parent 786c1ca commit e9369f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
6 changes: 3 additions & 3 deletions cmd/liqonet/main.go
Expand Up @@ -153,7 +153,7 @@ func main() {
os.Exit(1)
}
eventRecorder := mgr.GetEventRecorderFor(liqoconst.LiqoGatewayOperatorName + "." + podIP.String())
// This map is update by the tunnel operator after a successful tunnel creation
// This map is updated by the tunnel operator after a successful tunnel creation
// and is consumed by the natmapping operator to check whether the tunnel is ready or not.
var readyClustersMutex sync.Mutex
readyClusters := make(map[string]struct{})
Expand Down Expand Up @@ -181,12 +181,12 @@ func main() {
os.Exit(1)
}

nmo, err := tunneloperator.NewNatMappingController(mgr, &readyClustersMutex, readyClusters, gatewayNetns)
nmc, err := tunneloperator.NewNatMappingController(mgr.GetClient(), &readyClustersMutex, readyClusters, gatewayNetns)
if err != nil {
klog.Errorf("an error occurred while creating the natmapping controller: %v", err)
os.Exit(1)
}
if err = nmo.SetupWithManager(mgr); err != nil {
if err = nmc.SetupWithManager(mgr); err != nil {
klog.Errorf("unable to setup natmapping controller: %s", err)
os.Exit(1)
}
Expand Down
9 changes: 4 additions & 5 deletions internal/liqonet/tunnel-operator/natmapping-operator.go
Expand Up @@ -6,7 +6,6 @@ import (
"sync"

"github.com/containernetworking/plugins/pkg/ns"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -18,7 +17,6 @@ import (
// NatMappingController reconciles a NatMapping object.
type NatMappingController struct {
client.Client
Scheme *runtime.Scheme
iptables.IPTHandler
readyClustersMutex *sync.Mutex
readyClusters map[string]struct{}
Expand All @@ -27,7 +25,8 @@ type NatMappingController struct {

//+kubebuilder:rbac:groups=net.liqo.io,resources=natmappings,verbs=get;list;watch;create;update;patch;delete

// Reconcile NatMapping resource.
// Reconcile function handles requests made on NatMapping resource
// by guaranteeing the proper set of DNAT rules are updated.
func (npc *NatMappingController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var nm netv1alpha1.NatMapping

Expand Down Expand Up @@ -67,14 +66,14 @@ func (npc *NatMappingController) SetupWithManager(mgr ctrl.Manager) error {
}

// NewNatMappingController returns a NAT mapping controller istance.
func NewNatMappingController(mgr ctrl.Manager, readyClustersMutex *sync.Mutex,
func NewNatMappingController(client client.Client, readyClustersMutex *sync.Mutex,
readyClusters map[string]struct{}, gatewayNetns ns.NetNS) (*NatMappingController, error) {
iptablesHandler, err := iptables.NewIPTHandler()
if err != nil {
return nil, err
}
return &NatMappingController{
Client: mgr.GetClient(),
Client: client,
IPTHandler: iptablesHandler,
readyClustersMutex: readyClustersMutex,
readyClusters: readyClusters,
Expand Down
15 changes: 0 additions & 15 deletions internal/liqonet/tunnel-operator/natmapping_operator_test.go
Expand Up @@ -62,21 +62,6 @@ var _ = Describe("NatmappingOperator", func() {
})
Expect(err).To(BeNil())
})
Context("If a natmapping resource is deleted", func() {
It("the controller should return no errors", func() {
nm2.ObjectMeta.Name = "delete-resource"
request.Name = nm2.ObjectMeta.Name
Eventually(func() error {
err := k8sClient.Create(context.Background(), nm2, &client.CreateOptions{})
return err
}).Should(BeNil())
Eventually(func() error {
err := k8sClient.Delete(context.Background(), nm2, &client.DeleteOptions{})
return err
}).Should(BeNil())
Consistently(func() error { _, err := controller.Reconcile(context.TODO(), request); return err }).Should(BeNil())
})
})
Context("Reconcile on a resource that does not exist", func() {
It("the controller should return no errors", func() {
nm2.ObjectMeta.Name = "resource-not-exists"
Expand Down
Expand Up @@ -95,7 +95,6 @@ var _ = BeforeSuite(func() {

err = netv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).To(BeNil())
//+kubebuilder:scaffold:scheme
envTest = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "deployments", "liqo", "crds")},
}
Expand All @@ -106,7 +105,7 @@ var _ = BeforeSuite(func() {
MetricsBindAddress: "0",
})

controller, err = NewNatMappingController(mgr, &readyClustersMutex, readyClusters, iptNetns)
controller, err = NewNatMappingController(mgr.GetClient(), &readyClustersMutex, readyClusters, iptNetns)
Expect(err).To(BeNil())
go func() {
if err = mgr.Start(context.Background()); err != nil {
Expand Down

0 comments on commit e9369f7

Please sign in to comment.