Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
NeerajNagure committed Jul 4, 2024
1 parent 2561515 commit c64f5e8
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
./hack/e2e-test.sh kwokctl/kwokctl_with_dryrun
- name: Test e2e dry run
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.kwokctl-runtime == 'binary' }}
shell: bash
run: |
./hack/e2e-test.sh e2e/kwokctl/dryrun
Expand Down
45 changes: 17 additions & 28 deletions test/e2e/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/fs"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"testing"
Expand All @@ -32,52 +33,40 @@ import (
"sigs.k8s.io/kwok/pkg/utils/path"
)

func loadExpectedClusterDetails(filepath string) (string, error) {
data, err := os.ReadFile(filepath)
if err != nil {
return "", err
}
out := string(data)
out = strings.ReplaceAll(out, "\n", " ")
out = strings.Join(strings.Fields(out), " ")
return out, nil
}
var (
emptyLine = regexp.MustCompile("\n{2,}")
homeDir, _ = os.UserHomeDir()
)

func formatCmdOutput(output, clusterName, rootDir string) string {
got := output
extensions := map[string]string{
"windows": "zip",
"linux": "tar.gz",
"darwin": "tar.gz",
}
func formatCmdOutput(got, clusterName, rootDir string) string {
got = strings.ReplaceAll(got, clusterName, "<CLUSTER_NAME>")
got = strings.ReplaceAll(got, rootDir, "<ROOT_DIR>")
got = strings.ReplaceAll(got, runtime.GOOS, "<OS>")
got = strings.ReplaceAll(got, runtime.GOARCH, "<ARCH>")
got = strings.ReplaceAll(got, extensions[runtime.GOOS], "<TAR>")
got = strings.ReplaceAll(got, "\n", " ")
got = strings.Join(strings.Fields(got), " ")
got = strings.ReplaceAll(got, ".zip", ".<TAR>")
got = strings.ReplaceAll(got, ".tar.gz", ".<TAR>")
got = strings.ReplaceAll(got, homeDir, "~")
got = emptyLine.ReplaceAllLiteralString(got, "\n")
return got
}

func executeCommand(args []string, absPath string, clusterName string, kwokctlPath string, rootDir string, updateTestdata bool) (string, error) {
var expected string
var err error
expected, err = loadExpectedClusterDetails(path.Join(rootDir, absPath))
testdataPath := path.Join(rootDir, absPath)
expected, err := os.ReadFile(testdataPath)
if err != nil {
return "", err
}
cmd := exec.Command(kwokctlPath, args...) // #nosec G204
var output []byte
output, err = cmd.Output()
cmd := exec.Command(kwokctlPath, args...)
output, err := cmd.Output()
if err != nil {
return "", err
}
want := string(expected)
got := string(output)
got = formatCmdOutput(got, clusterName, rootDir)
if diff := cmp.Diff(strings.TrimSpace(got), strings.TrimSpace(expected)); diff != "" {
if diff := cmp.Diff(got, want); diff != "" {
if updateTestdata {
err = os.WriteFile(path.Join(rootDir, absPath), output, fs.FileMode(0644))
err = os.WriteFile(testdataPath, []byte(got), fs.FileMode(0644))
if err != nil {
return "", err
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/kwokctl/dryrun/testdata/binary/create_cluster.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ users:
user:
client-certificate: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt
client-key: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key

EOF
# Save cluster config to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kwok.yaml
# Add context kwok-<CLUSTER_NAME> to /home/runner/.kube/config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:32765
Expand All @@ -42,12 +41,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32764
Expand All @@ -57,12 +54,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32762
Expand All @@ -72,26 +67,22 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32761
- job_name: "kwok-controller-metrics-discovery"
http_sd_configs:
- url: http://127.0.0.1:32763/discovery/prometheus

- job_name: "kwok-controller"
scheme: http
honor_timestamps: true
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:32763
Expand All @@ -101,7 +92,6 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:9090
Expand All @@ -126,7 +116,6 @@ users:
user:
client-certificate: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt
client-key: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key

EOF
# Save cluster config to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kwok.yaml
# Add context kwok-<CLUSTER_NAME> to /home/runner/.kube/config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ apiVersion: apiserver.config.k8s.io/v1alpha1
kind: TracingConfiguration
endpoint: 127.0.0.1:32762
samplingRatePerMillion: 1000000

EOF
# Download https://dl.k8s.io/release/v1.30.0/bin/<OS>/<ARCH>/kube-controller-manager to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/bin/kube-controller-manager
# Download https://dl.k8s.io/release/v1.30.0/bin/<OS>/<ARCH>/kube-scheduler to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/bin/kube-scheduler
cp <ROOT_DIR>/test/kwokctl/scheduler-config.yaml <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/scheduler.yaml
cat <<EOF >><ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/scheduler.yaml

clientConnection:
kubeconfig: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kubeconfig.yaml"

EOF
# Download https://github.com/kubernetes-sigs/kwok/releases/download/v0.6.0/kwok-<OS>-<ARCH> to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/bin/kwok-controller
# Download https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.7.0/metrics-server-<OS>-<ARCH> to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/bin/metrics-server
Expand All @@ -50,7 +47,6 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:32765
Expand All @@ -60,12 +56,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32764
Expand All @@ -75,43 +69,35 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32761

- job_name: "kube-scheduler"
scheme: https
honor_timestamps: true
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32760
- job_name: "kwok-controller-metrics-discovery"
http_sd_configs:
- url: http://127.0.0.1:32763/discovery/prometheus


- job_name: "kwok-controller"
scheme: http
honor_timestamps: true
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:32763
Expand All @@ -121,12 +107,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt"
key_file: "<ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- 127.0.0.1:32759
Expand All @@ -136,11 +120,9 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:9090

EOF
cat <<EOF ><ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kubeconfig.yaml
apiVersion: v1
Expand All @@ -162,7 +144,6 @@ users:
user:
client-certificate: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt
client-key: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key

EOF
# Save cluster config to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kwok.yaml
# Add context kwok-<CLUSTER_NAME> to /home/runner/.kube/config
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/kwokctl/dryrun/testdata/docker/create_cluster.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ users:
user:
client-certificate: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt
client-key: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key

EOF
cat <<EOF ><ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kubeconfig
apiVersion: v1
Expand All @@ -50,7 +49,6 @@ users:
user:
client-certificate: /etc/kubernetes/pki/admin.crt
client-key: /etc/kubernetes/pki/admin.key

EOF
# Save cluster config to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kwok.yaml
docker network create kwok-<CLUSTER_NAME> --label=com.docker.compose.project=kwok-<CLUSTER_NAME>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- kwok-<CLUSTER_NAME>-etcd:2379
Expand All @@ -40,12 +39,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "/etc/kubernetes/pki/admin.crt"
key_file: "/etc/kubernetes/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- kwok-<CLUSTER_NAME>-kube-apiserver:6443
Expand All @@ -55,12 +52,10 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "/etc/kubernetes/pki/admin.crt"
key_file: "/etc/kubernetes/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- kwok-<CLUSTER_NAME>-kube-controller-manager:10257
Expand All @@ -70,27 +65,22 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

tls_config:
cert_file: "/etc/kubernetes/pki/admin.crt"
key_file: "/etc/kubernetes/pki/admin.key"
insecure_skip_verify: true

static_configs:
- targets:
- kwok-<CLUSTER_NAME>-kube-scheduler:10259
- job_name: "kwok-controller-metrics-discovery"
http_sd_configs:
- url: http://kwok-<CLUSTER_NAME>-kwok-controller:10247/discovery/prometheus


- job_name: "kwok-controller"
scheme: http
honor_timestamps: true
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- kwok-<CLUSTER_NAME>-kwok-controller:10247
Expand All @@ -100,7 +90,6 @@ scrape_configs:
metrics_path: /metrics
follow_redirects: true
enable_http2: true

static_configs:
- targets:
- 127.0.0.1:9090
Expand All @@ -126,7 +115,6 @@ users:
user:
client-certificate: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.crt
client-key: <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/pki/admin.key

EOF
cat <<EOF ><ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kubeconfig
apiVersion: v1
Expand All @@ -148,7 +136,6 @@ users:
user:
client-certificate: /etc/kubernetes/pki/admin.crt
client-key: /etc/kubernetes/pki/admin.key

EOF
# Save cluster config to <ROOT_DIR>/workdir/clusters/<CLUSTER_NAME>/kwok.yaml
docker network create kwok-<CLUSTER_NAME> --label=com.docker.compose.project=kwok-<CLUSTER_NAME>
Expand Down
Loading

0 comments on commit c64f5e8

Please sign in to comment.