Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <[email protected]>
  • Loading branch information
kfirtoledo committed Jul 24, 2024
1 parent 520f771 commit ab77425
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 161 deletions.
15 changes: 8 additions & 7 deletions demos/frp/kind/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
# limitations under the License.

################################################################
# Name: Simple iperf3 test
# Desc: create 2 kind clusters :
# 1) GW and iperf3 client
# 2) GW and iperf3 server
# Name: FRP demo that connect 3 Kind clusters using FRP:
# Desc: create 3 kind clusters :
# 1) GW, iPerf3 client, FRP client, and FRP server
# 2) GW, iPerf3 server, and FRP client
# 3) GW, iPerf3 client, and FRP client
###############################################################
import os
import sys
Expand All @@ -27,9 +28,9 @@
from demos.utils.common import printHeader
from demos.utils.kind import Cluster
from demos.iperf3.kind.iperf3_client_start import directTestIperf3,testIperf3Client
from demos.frp.test import iperf3Test
from demos.frp.test import frpTest

testOutputFolder = f"{projDir}/bin/tests/iperf3"
testOutputFolder = f"{projDir}/bin/tests/frp"

############################### MAIN ##########################
if __name__ == "__main__":
Expand All @@ -46,7 +47,7 @@
iperf3DirectPort = "30001"

# Setup
iperf3Test(cl1, cl2, cl3, testOutputFolder)
frpTest(cl1, cl2, cl3, testOutputFolder)
#Testing
printHeader("\n\nStart Iperf3 testing")
cl2.useCluster()
Expand Down
51 changes: 28 additions & 23 deletions demos/frp/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
# limitations under the License.

################################################################
# Name: Simple iperf3 test
# Desc: create 2 kind clusters :
# 1) GW and iPerf3 client
# 2) GW and iPerf3 server
# Name: FRP demo that connect 3 clusters using FRP:
# Desc: create 3 kind clusters :
# 1) GW, iPerf3 client, FRP client, and FRP server
# 2) GW, iPerf3 server, and FRP client
# 3) GW, iPerf3 client, and FRP client
###############################################################
import os
import sys
import time
import hashlib
projDir = os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))

sys.path.insert(0,f'{projDir}')
Expand All @@ -28,24 +31,23 @@
from demos.utils.kind import Cluster as KindCluster
from demos.utils.common import printHeader

testOutputFolder = f"{projDir}/bin/tests/iperf3"

# Folders
folCl=f"{projDir}/demos/iperf3/testdata/manifests/iperf3-client"
folSv=f"{projDir}/demos/iperf3/testdata/manifests/iperf3-server"
folFrp=f"{projDir}/demos/frp/testdata/manifests/"
#services

# Services
srcSvc = "iperf3-client"
destSvc = "iperf3-server"
destPort = 5000
namespace = "default"
frpNamespace= "frp"

# iperf3Test setup two cluster for creating iPerf3 test.
def iperf3Test(cl1:KindCluster, cl2:KindCluster,cl3:KindCluster, testOutputFolder):
def frpTest(cl1:KindCluster, cl2:KindCluster,cl3:KindCluster, testOutputFolder):
print(f'Working directory {projDir}')
os.chdir(projDir)

# build docker environment
# Build docker environment
printHeader("Build docker image")
os.system("make docker-build")
os.system("make install")
Expand All @@ -62,40 +64,43 @@ def iperf3Test(cl1:KindCluster, cl2:KindCluster,cl3:KindCluster, testOutputFolde
cl3.startCluster(testOutputFolder)

# Create iPerf3 micro-services
cl1.loadService(srcSvc, "mlabbe/iperf3",f"{folCl}/iperf3-client.yaml" )
cl2.loadService(destSvc, "mlabbe/iperf3",f"{folSv}/iperf3.yaml" )
cl3.loadService(srcSvc, "mlabbe/iperf3",f"{folCl}/iperf3-client.yaml" )
cl1.loadService(srcSvc, "taoyou/iperf3-alpine",f"{folCl}/iperf3-client.yaml" )
cl2.loadService(destSvc, "taoyou/iperf3-alpine",f"{folSv}/iperf3.yaml" )
cl3.loadService(srcSvc, "taoyou/iperf3-alpine",f"{folCl}/iperf3-client.yaml" )
os.environ['FRP_SERVER_IP'] = cl1.ip

os.environ['FRP_SECRET_KEY'] = hashlib.sha256(str(time.time_ns()).encode()).hexdigest()[:10]
# Use envsubst to replace the placeholder and apply the ConfigMap
runcmd(f"envsubst < {folFrp}/server/frps-configmap.yaml | kubectl apply -f -")
# Create peers
printHeader("Create peers")
cl1.useCluster()
runcmd(f"kubectl apply -f {folFrp}/server/frps-configmap.yaml")
runcmd(f"kubectl apply -f {folFrp}/server/frps.yaml")
runcmd(f"kubectl apply -f {folFrp}/frp-ns.yaml")
runcmd(f"kubectl apply -f {folFrp}/server/frps-configmap.yaml")
cl1.loadService("frps", "snowdreamtech/frps",f"{folFrp}/server/frps.yaml", frpNamespace)

# Create peers
printHeader("Create peers")
cl1.useCluster()
runcmd(f"envsubst < {folFrp}/client/peer1/frpc-configmap.yaml| kubectl apply -f -")
runcmd(f"kubectl apply -f {folFrp}/client/frpc.yaml")
cl1.loadService("frpc", "snowdreamtech/frpc",f"{folFrp}/client/frpc.yaml",frpNamespace )
runcmd(f"kubectl apply -f {folFrp}/client/peer1/peer.yaml")
cl2.useCluster()
runcmd(f"kubectl apply -f {folFrp}/frp-ns.yaml")
runcmd(f"envsubst < {folFrp}/client/peer2/frpc-configmap.yaml| kubectl apply -f -")
cl2.loadService("frpc", "snowdreamtech/frpc",f"{folFrp}/client/frpc.yaml",frpNamespace )
runcmd(f"kubectl apply -f {folFrp}/client/frpc.yaml")
runcmd(f"kubectl apply -f {folFrp}/client/peer2/peer.yaml")
cl3.useCluster()
runcmd(f"kubectl apply -f {folFrp}/frp-ns.yaml")
runcmd(f"envsubst < {folFrp}/client/peer3/frpc-configmap.yaml| kubectl apply -f -")
runcmd(f"kubectl apply -f {folFrp}/client/frpc.yaml")
cl3.loadService("frpc", "snowdreamtech/frpc",f"{folFrp}/client/frpc.yaml" ,frpNamespace)
runcmd(f"kubectl apply -f {folFrp}/client/peer3/peer.yaml")
# Create exports
cl2.exports.create(destSvc, namespace, destPort)

#Import destination service
# Import destination service
printHeader(f"\n\nStart Importing {destSvc} service to {cl1.name}")
cl1.imports.create(destSvc,namespace,destPort,cl2.name,destSvc,namespace)
cl3.imports.create(destSvc,namespace,destPort,cl2.name,destSvc,namespace)

#Add policy
# Add policy
printHeader("Applying policies")
cl1.policies.create(name="allow-all",namespace=namespace, action="allow", from_attribute=[{"workloadSelector": {}}],to_attribute=[{"workloadSelector": {}}])
cl2.policies.create(name="allow-all",namespace=namespace, action="allow", from_attribute=[{"workloadSelector": {}}],to_attribute=[{"workloadSelector": {}}])
Expand Down
4 changes: 2 additions & 2 deletions demos/frp/testdata/manifests/client/frpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: frpc
namespace: clusterlink-system
namespace: frp
spec:
replicas: 1
selector:
Expand All @@ -17,11 +17,11 @@ spec:
containers:
- name: frpc
image: snowdreamtech/frpc
imagePullPolicy: IfNotPresent
volumeMounts:
- name: frpc-config-volume
mountPath: /etc/frp
volumes:
- name: frpc-config-volume
configMap:
name: frpc-config
restartPolicy: Always
8 changes: 4 additions & 4 deletions demos/frp/testdata/manifests/client/peer1/frpc-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: frpc-config
namespace: clusterlink-system
namespace: frp
data:
frpc.toml: |
# Set server address
Expand All @@ -14,20 +14,20 @@ data:
type = "stcp"
localIP = "clusterlink.clusterlink-system.svc.cluster.local"
localPort = 443
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
[[visitors]]
name = "clusterlink-peer1-to-peer2-visitor"
type = "stcp"
serverName = "clusterlink-peer2"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6002
[[visitors]]
name = "clusterlink-peer1-to-peer3-visitor"
type = "stcp"
serverName = "clusterlink-peer3"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6003
10 changes: 5 additions & 5 deletions demos/frp/testdata/manifests/client/peer1/peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer2-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer2-clusterlink.frp.svc.cluster.local
port: 6002

---
apiVersion: v1
kind: Service
metadata:
name: frp-peer2-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
Expand All @@ -29,19 +29,19 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer3-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer3-clusterlink.frp.svc.cluster.local
port: 6003

---
apiVersion: v1
kind: Service
metadata:
name: frp-peer3-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
app: frpc
ports:
- port: 6003
targetPort: 6003
targetPort: 6003
8 changes: 4 additions & 4 deletions demos/frp/testdata/manifests/client/peer2/frpc-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: frpc-config
namespace: clusterlink-system
namespace: frp
data:
frpc.toml: |
# Set server address
Expand All @@ -14,20 +14,20 @@ data:
type = "stcp"
localIP = "clusterlink.clusterlink-system.svc.cluster.local"
localPort = 443
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
[[visitors]]
name = "clusterlink-peer2-to-peer1-visitor"
type = "stcp"
serverName = "clusterlink-peer1"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6001
[[visitors]]
name = "clusterlink-peer2-to-peer3-visitor"
type = "stcp"
serverName = "clusterlink-peer3"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6003
10 changes: 5 additions & 5 deletions demos/frp/testdata/manifests/client/peer2/peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer1-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer1-clusterlink.frp.svc.cluster.local
port: 6001
---
apiVersion: v1
kind: Service
metadata:
name: frp-peer1-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
Expand All @@ -28,18 +28,18 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer3-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer3-clusterlink.frp.svc.cluster.local
port: 6003
---
apiVersion: v1
kind: Service
metadata:
name: frp-peer3-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
app: frpc
ports:
- port: 6003
targetPort: 6003
targetPort: 6003
10 changes: 5 additions & 5 deletions demos/frp/testdata/manifests/client/peer3/frpc-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: frpc-config
namespace: clusterlink-system
namespace: frp
data:
frpc.toml: |
# Set server address
Expand All @@ -14,20 +14,20 @@ data:
type = "stcp"
localIP = "clusterlink.clusterlink-system.svc.cluster.local"
localPort = 443
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
[[visitors]]
name = "clusterlink-peer3-to-peer1-visitor"
type = "stcp"
serverName = "clusterlink-peer1"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6001
[[visitors]]
name = "clusterlink-peer3-to-peer2-visitor"
type = "stcp"
serverName = "clusterlink-peer2"
secretKey = "abcdefg"
secretKey = "${FRP_SECRET_KEY}"
bindAddr = "::"
bindPort = 6002
bindPort = 6002
8 changes: 4 additions & 4 deletions demos/frp/testdata/manifests/client/peer3/peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer1-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer1-clusterlink.frp.svc.cluster.local
port: 6001

---
apiVersion: v1
kind: Service
metadata:
name: frp-peer1-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
Expand All @@ -29,15 +29,15 @@ metadata:
namespace: clusterlink-system
spec:
gateways:
- host: frp-peer2-clusterlink.clusterlink-system.svc.cluster.local
- host: frp-peer2-clusterlink.frp.svc.cluster.local
port: 6002

---
apiVersion: v1
kind: Service
metadata:
name: frp-peer2-clusterlink
namespace: clusterlink-system
namespace: frp
spec:
type: ClusterIP
selector:
Expand Down
4 changes: 4 additions & 0 deletions demos/frp/testdata/manifests/frp-ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: frp
Loading

0 comments on commit ab77425

Please sign in to comment.