Skip to content

Commit

Permalink
Merge pull request #95 from ferryproxy/test/cloud
Browse files Browse the repository at this point in the history
Optimizing the handshake and test cloud
  • Loading branch information
wzshiming authored Aug 5, 2022
2 parents 002b532 + 9f50108 commit fe5f3dc
Show file tree
Hide file tree
Showing 85 changed files with 2,235 additions and 191 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/test-cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Test Cloud

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-ferrctl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- run: |
go build -o ferryctl ./cmd/ferryctl
- name: Upload ferryctl
uses: actions/upload-artifact@v2
with:
name: ferryctl
path: ferryctl

test-cloud:
continue-on-error: true
strategy:
matrix:
cloud:
- aliyun
- aws
- azure
- gcp
runs-on: ubuntu-latest
needs:
- build-ferrctl
steps:
- uses: actions/checkout@v3

- name: Download for ferryctl
uses: actions/download-artifact@v2
with:
name: ferryctl

- name: Set up ferryctl
run: |
cp ferryctl /usr/local/bin/ferryctl && chmod +x /usr/local/bin/ferryctl
- name: Set up eksctl
if: matrix.cloud == 'aws'
run: |
wget -O eksctl.tar.gc "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_linux_amd64.tar.gz"
tar -xzf eksctl.tar.gz -C /tmp/ && mv /tmp/eksctl /usr/local/bin/ && chmod +x /usr/local/bin/eksctl
- name: Set up gcloud
if: matrix.cloud == 'gcp'
uses: google-github-actions/setup-gcloud@v0
with:
install_components: 'gke-gcloud-auth-plugin'

- name: Login ${{ matrix.cloud }}
run: |
./test/cloud/${{ matrix.cloud }}/login.sh
./test/cloud/${{ matrix.cloud }}/list.sh
env:
ALIYUN_ACCESS_KEY_ID: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
ALIYUN_ACCESS_KEY_SECRET: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
ALIYUN_REGION_ID: ${{ secrets.ALIYUN_REGION_ID }}
ALIYUN_ZONE_ID: ${{ secrets.ALIYUN_ZONE_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_ACCESS_KEY_SECRET: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
AWS_REGION_ID: ${{ secrets.AWS_REGION_ID }}
AWS_ZONE_ID: ${{ secrets.AWS_ZONE_ID }}
AZURE_APP_ID: ${{ secrets.AZURE_APP_ID }}
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
AZURE_TENANT: ${{ secrets.AZURE_TENANT }}
AZURE_REGION_ID: ${{ secrets.AZURE_REGION_ID }}
AZURE_ZONE_ID: ${{ secrets.AZURE_ZONE_ID }}
GCP_CRED_DATA: ${{ secrets.GCP_CRED_DATA }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION_ID: ${{ secrets.GCP_REGION_ID }}
GCP_ZONE_ID: ${{ secrets.GCP_ZONE_ID }}
- name: Start cluster
run: |
./test/hack/start-environment.sh cloud-${{ matrix.cloud }}
- name: Test control-plane and cluster-${{ matrix.cloud }}
run: ./test/test/test-in-both-easy.sh
env:
ROUTE_NAME: ferry-test
CONTROL_PLANE: control-plane
CLUSTER_1: cluster-${{ matrix.cloud }}
CLUSTER_2: control-plane
TARGET_1: web-${{ matrix.cloud }}
TARGET_2: web-0

- name: Clean cluster
run: |
./test/hack/clean-environment.sh cloud-${{ matrix.cloud }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
FERRY_TUNNEL_IMAGE: ferry-tunnel:test

concurrency:
group: ${{ github.head_ref || github.run_id }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ testbin/*


# Customs
!/test/bin
vendor
kubeconfigs
test/kubeconfigs
1 change: 0 additions & 1 deletion pkg/ferryctl/cmd/ferryctl/control_plane/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func NewCommand(logger log.Logger) *cobra.Command {

utils.Prompt(
fmt.Sprintf("join the %s data cluster", dataPlaneName),
"ferryctl data-plane init",
next,
)

Expand Down
1 change: 0 additions & 1 deletion pkg/ferryctl/cmd/ferryctl/local/manual/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func NewCommand(logger log.Logger) *cobra.Command {

utils.Prompt(
"peer tunnel",
"ferryctl data-plane init",
second,
)
return nil
Expand Down
1 change: 0 additions & 1 deletion pkg/ferryctl/cmd/ferryctl/local/manual/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func NewCommand(logger log.Logger) *cobra.Command {

utils.Prompt(
"peer tunnel",
"ferryctl data-plane init",
second,
)
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/ferryctl/cmd/ferryctl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewCommand(logger log.Logger) *cobra.Command {

persistentFlags := cmd.PersistentFlags()
persistentFlags.StringVar(&vars.KubeconfigPath, "kubeconfig", vars.KubeconfigPath, "override the default kubeconfig path")
persistentFlags.StringVar(&vars.PeerKubeconfigPath, "peer-kubeconfig", vars.PeerKubeconfigPath, "this Kubeconfig specifies the handshake peer for operations that require handshaking")
persistentFlags.StringVar(&vars.FerryControllerImage, "ferry-controller-image", vars.FerryControllerImage, "default ferry controller image")
persistentFlags.StringVar(&vars.FerryTunnelImage, "ferry-tunnel-image", vars.FerryTunnelImage, "default ferry tunnel image")
persistentFlags.StringVar(&vars.ControlPlaneName, "control-plane-name", vars.ControlPlaneName, "default control plane name")
Expand Down
31 changes: 26 additions & 5 deletions pkg/ferryctl/utils/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,34 @@ package utils

import (
"fmt"
"github.com/ferryproxy/ferry/pkg/ferryctl/vars"
"os"
"os/exec"
)

func Prompt(want string, lines ...string) {
fmt.Printf("# ++++ Please run the following command to %s:\n", want)
fmt.Printf("# =============================================\n")
defer fmt.Printf("# =============================================\n")
for _, line := range lines {
fmt.Printf("%s\n", line)
if vars.PeerKubeconfigPath != "" {
fmt.Printf("# Run command to %s:\n", want)
for _, line := range lines {
cmd := exec.Command("sh", "-c", line)
cmd.Env = append(os.Environ(),
"KUBECONFIG="+vars.PeerKubeconfigPath,
"FERRY_PEER_KUBECONFIG="+vars.KubeconfigPath,
)
fmt.Printf("> %s\n", line)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println(cmd)
}
}
} else {
fmt.Printf("# ++++ Please run the following command to %s:\n", want)
fmt.Printf("# =============================================\n")
defer fmt.Printf("# =============================================\n")
for _, line := range lines {
fmt.Printf("%s\n", line)
}
}
}
7 changes: 4 additions & 3 deletions pkg/ferryctl/vars/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
)

var (
ControlPlaneName = "control-plane"
home, _ = os.UserHomeDir()
KubeconfigPath = env.GetEnv("KUBECONFIG", filepath.Join(home, ".kube/config"))
ControlPlaneName = "control-plane"
home, _ = os.UserHomeDir()
KubeconfigPath = env.GetEnv("KUBECONFIG", filepath.Join(home, ".kube/config"))
PeerKubeconfigPath = env.GetEnv("FERRY_PEER_KUBECONFIG", "")

FerryImagePrefix = env.GetEnv("FERRY_IMAGE_PREFIX", "ghcr.io/ferryproxy/ferry")

Expand Down
47 changes: 47 additions & 0 deletions test/cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Cloud

The following are the Kubernetes services for various public cloud platforms
that Ferry has tested and validated. If there are multiple Kubernetes services
on the same platform, we prefer to choose the one that does not require a management server.

- Aliyun (Alibaba Cloud)
[ ] ACK (Managed Kubernetes Cluster Service)
[x] ASK (Serverless Kubernetes Cluster Service)
- AWS (Amazon Web Services)
[x] EKS (Elastic Kubernetes Engine)
- GCP (Google Cloud Platform)
[ ] GKE Standard (Google Kubernetes Engine Standard)
[x] GKE Autopilot (Google Kubernetes Engine Autopilot)
- Azure (Microsoft Azure)
[x] AKS (Azure Kubernets Service)

The following scripts are included in each platform's directory
- login.sh `[This requires special handling, as each platform has a different login method]`
- create.sh `<cluster-name>`
- get_kubeconfig.sh` <cluster-name>`
- list.sh
- delete.sh `<cluster-name>`

## Login

### Aliyun
ALIYUN_ACCESS_KEY_ID=
ALIYUN_ACCESS_KEY_SECRET=
ALIYUN_REGION_ID=
ALIYUN_ZONE_ID=

### AWS
AWS_ACCESS_KEY_ID=
AWS_ACCESS_KEY_SECRET=
AWS_REGION_ID=

### GCP
GCP_PROJECT_ID=
GCP_CRED_DATA=
GCP_REGION_ID=

### Azure
AZURE_APP_ID=
AZURE_PASSWORD=
AZURE_TENANT=
AZURE_REGION_ID=
15 changes: 15 additions & 0 deletions test/cloud/aliyun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Aliyun

## Login

https://www.alibabacloud.com/help/en/alibaba-cloud-cli/latest/overview#section-vfn-jja-bsk

## Regions

https://www.alibabacloud.com/help/en/elastic-container-instance/latest/regions-and-zones

## aliyun tool

Used to create and manage Kubernetes clusters.

https://www.alibabacloud.com/help/en/resource-orchestration-service/latest/install-alibaba-cloud-cli
84 changes: 84 additions & 0 deletions test/cloud/aliyun/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# Copyright 2022 FerryProxy Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CURRENT_DIR="$(dirname "${BASH_SOURCE[0]}")"

CLUSTER_NAME=$1

REGION_ID=$2

ZONE_ID=$3

if [ "${REGION_ID}" == "" ] && [ "${ALIYUN_REGION_ID}" != "" ]; then
REGION_ID="${ALIYUN_REGION_ID}"
fi

if [ "${REGION_ID}" == "" ]; then
REGION_ID="cn-hongkong"
fi

if [ "${ZONE_ID}" == "" ] && [ "${ALIYUN_ZONE_ID}" != "" ]; then
ZONE_ID="${ALIYUN_ZONE_ID}"
fi

if [ "${ZONE_ID}" == "" ]; then
ZONE_ID="${REGION_ID}-b"
fi

if [ "${CLUSTER_NAME}" == "" ] || [ "${REGION_ID}" == "" ]; then
echo "Usage: ${0} <cluster-name> <region-id>"
exit 1
fi

body=$(
cat <<EOF
{
"cluster_type": "ManagedKubernetes",
"name": "${CLUSTER_NAME}",
"kubernetes_version": "1.22.10-aliyun.1",
"region_id": "${REGION_ID}",
"endpoint_public_access": true,
"service_discovery_types": [
"CoreDNS"
],
"tags": [],
"deletion_protection": false,
"service_cidr": "172.21.0.0/20",
"timezone": "UTC",
"addons": [],
"profile": "Serverless",
"snat_entry": true,
"zoneid": "${ZONE_ID}",
"cluster_spec": "ack.pro.small",
"load_balancer_spec": "slb.s1.small"
}
EOF
)

aliyun cs CreateCluster \
--header "Content-Type=application/json" \
--body "${body}"

while true; do
state=$(aliyun cs DescribeClusters --name "${CLUSTER_NAME}" |
jq -r '.[0].state')
if [ "${state}" == "running" ]; then
break
fi
echo "$(date) Waiting for cluster to be running... (state: ${state})"
sleep 10
done

echo "$(date) Cluster ${CLUSTER_NAME} is running!"
Loading

0 comments on commit fe5f3dc

Please sign in to comment.