-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ use iptables to let traffic in (#66)
- Loading branch information
Showing
17 changed files
with
288 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace: porter-test-cea56a86 | ||
namespace: porter-test-bc7c58a5 | ||
|
||
bases: | ||
- ../default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,63 @@ | ||
package eip | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
networkv1alpha1 "github.com/kubesphere/porter/api/v1alpha1" | ||
"github.com/kubesphere/porter/pkg/nettool" | ||
) | ||
|
||
func (r *EipReconciler) AddRule(instance *networkv1alpha1.Eip) error { | ||
if instance.Spec.Address != "" { | ||
rule, err := nettool.NewEIPRule(instance.Spec.Address) | ||
if err != nil { | ||
r.Log.Info("Failed to initialize ip rule", "eip", instance.Spec.Address) | ||
return err | ||
} | ||
nodeName := os.Getenv("MY_NODE_NAME") | ||
if ok, err := rule.IsExist(); err != nil { | ||
return err | ||
} else { | ||
if !ok { | ||
err = rule.Add() | ||
if err != nil { | ||
return err | ||
} | ||
r.Event(instance, "Normal", "Rule Created", fmt.Sprintf("Created ip rule for EIP %s in agent %s", instance.Spec.Address, nodeName)) | ||
} else { | ||
r.Log.Info("Detect rule in node") | ||
r.Event(instance, "Normal", "Detect rule in node", fmt.Sprintf("Skipped Creating ip rule for EIP %s in agent %s", instance.Spec.Address, nodeName)) | ||
} | ||
} | ||
} | ||
return nil | ||
// func (r *EipReconciler) AddRule(instance *networkv1alpha1.Eip) error { | ||
// if instance.Spec.Address != "" { | ||
// rule, err := nettool.NewEIPRule(instance.Spec.Address) | ||
// if err != nil { | ||
// r.Log.Info("Failed to initialize ip rule", "eip", instance.Spec.Address) | ||
// return err | ||
// } | ||
// nodeName := os.Getenv("MY_NODE_NAME") | ||
// if ok, err := rule.IsExist(); err != nil { | ||
// return err | ||
// } else { | ||
// if !ok { | ||
// err = rule.Add() | ||
// if err != nil { | ||
// return err | ||
// } | ||
// r.Event(instance, "Normal", "Rule Created", fmt.Sprintf("Created ip rule for EIP %s in agent %s", instance.Spec.Address, nodeName)) | ||
// } else { | ||
// r.Log.Info("Detect rule in node") | ||
// r.Event(instance, "Normal", "Detect rule in node", fmt.Sprintf("Skipped Creating ip rule for EIP %s in agent %s", instance.Spec.Address, nodeName)) | ||
// } | ||
// } | ||
// } | ||
// return nil | ||
// } | ||
|
||
// func (r *EipReconciler) DeleteRule(instance *networkv1alpha1.Eip) error { | ||
// if instance.Spec.Address != "" { | ||
// rule, err := nettool.NewEIPRule(instance.Spec.Address) | ||
// if err != nil { | ||
// r.Log.Info("Failed to initialize ip rule", "eip", instance.Spec.Address) | ||
// return err | ||
// } | ||
// if ok, err := rule.IsExist(); err != nil { | ||
// return err | ||
// } else { | ||
// if ok { | ||
// err = rule.Delete() | ||
// if err != nil { | ||
// return err | ||
// } | ||
// r.Log.Info("Rule is deleted successfully", "rule", rule.ToAgentRule().String()) | ||
// } else { | ||
// r.Log.Info("Try to delete a non-exist rule", "rule", rule.ToAgentRule().String()) | ||
// } | ||
// } | ||
// } | ||
// return nil | ||
// } | ||
|
||
func (r *EipReconciler) OpenEIPForward(eip string) error { | ||
return nettool.OpenForwardForEIP(r.iptableExec, eip) | ||
} | ||
|
||
func (r *EipReconciler) DeleteRule(instance *networkv1alpha1.Eip) error { | ||
if instance.Spec.Address != "" { | ||
rule, err := nettool.NewEIPRule(instance.Spec.Address) | ||
if err != nil { | ||
r.Log.Info("Failed to initialize ip rule", "eip", instance.Spec.Address) | ||
return err | ||
} | ||
if ok, err := rule.IsExist(); err != nil { | ||
return err | ||
} else { | ||
if ok { | ||
err = rule.Delete() | ||
if err != nil { | ||
return err | ||
} | ||
r.Log.Info("Rule is deleted successfully", "rule", rule.ToAgentRule().String()) | ||
} else { | ||
r.Log.Info("Try to delete a non-exist rule", "rule", rule.ToAgentRule().String()) | ||
} | ||
} | ||
} | ||
return nil | ||
func (r *EipReconciler) CloseEIPForward(eip string) error { | ||
return nettool.CloseForwardForEIP(r.iptableExec, eip) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM alpine | ||
WORKDIR / | ||
RUN apk add iptables | ||
COPY agent . | ||
ENTRYPOINT ["/agent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.