Skip to content

Commit 7fd1cb2

Browse files
authored
CLOUDP-58180: Create Kind Cluster in Evergreen (#16)
1 parent 25e9b7e commit 7fd1cb2

File tree

5 files changed

+125
-21
lines changed

5 files changed

+125
-21
lines changed

.evergreen.yml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,55 @@ functions:
2222
command: "go test ./..."
2323

2424
setup_operator_sdk:
25+
- command: subprocess.exec
26+
type: setup
27+
params:
28+
working_dir: mongodb-kubernetes-operator/scripts/ci
29+
command: go run download.go
30+
env:
31+
URL: https://github.com/operator-framework/operator-sdk/releases/download/v0.15.1/operator-sdk-v0.15.1-x86_64-linux-gnu
32+
FILENAME: operator-sdk
33+
BINDIR: ${workdir}/bin
34+
35+
generate_k8s:
2536
- command: subprocess.exec
2637
type: setup
2738
params:
2839
add_to_path:
2940
- ${workdir}/bin
3041
working_dir: mongodb-kubernetes-operator
31-
include_expansions_in_env:
32-
- workdir
33-
binary: scripts/ci/setup_operator_sdk.sh
42+
binary: scripts/ci/generate_k8.sh
43+
44+
setup_kubernetes_environment:
45+
- command: subprocess.exec
46+
type: setup
47+
params:
48+
working_dir: mongodb-kubernetes-operator/scripts/ci
49+
command: go run download.go
50+
env:
51+
URL: https://storage.googleapis.com/kubernetes-release/release/v1.15.4/bin/linux/amd64/kubectl
52+
FILENAME: kubectl
53+
BINDIR: ${workdir}/bin
54+
55+
- command: subprocess.exec
56+
type: setup
57+
params:
58+
working_dir: mongodb-kubernetes-operator/scripts/ci
59+
command: go run download.go
60+
env:
61+
URL: https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-linux-amd64
62+
FILENAME: kind
63+
BINDIR: ${workdir}/bin
3464

35-
generate_k8s:
3665
- command: subprocess.exec
3766
type: setup
3867
params:
3968
add_to_path:
4069
- ${workdir}/bin
4170
working_dir: mongodb-kubernetes-operator
42-
binary: scripts/ci/generate_k8.sh
71+
binary: scripts/ci/create_kind_cluster.sh
72+
env:
73+
KUBECONFIG: ${workdir}/kube_config
4374

4475
tasks:
4576
- name: unit_tests
@@ -49,11 +80,23 @@ tasks:
4980
- func: generate_k8s
5081
- func: go_test
5182

83+
- name: e2e_test
84+
commands:
85+
- func: clone
86+
- func: setup_kubernetes_environment
87+
# deploy operator and run test
88+
5289
buildvariants:
5390
- name: go_unit_tests
5491
display_name: go_unit_tests
5592
run_on:
5693
- archlinux-test
57-
stepback: false
5894
tasks:
5995
- name: unit_tests
96+
97+
- name: e2e_tests
98+
display_name: e2e_tests
99+
run_on:
100+
- ubuntu1604-build
101+
tasks:
102+
- name: e2e_test

scripts/ci/create_kind_cluster.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
kind create cluster --kubeconfig ${KUBECONFIG}

scripts/ci/download.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"net/http"
7+
"os"
8+
"path"
9+
)
10+
11+
// download.go uses the following environment variables:
12+
// URL: The url of the file to download
13+
// BINDIR: The directory which the newly downloaded file will be placed
14+
// FILENAME: The name the file should have after being downloaded
15+
16+
func main() {
17+
if err := downloadFile(mustMakeOptions()); err != nil {
18+
panic(fmt.Errorf("error downloading file: %s", err))
19+
}
20+
}
21+
22+
type downloadOptions struct {
23+
url, fileName, bindir string
24+
perms os.FileMode
25+
}
26+
27+
func mustMakeOptions() downloadOptions {
28+
return downloadOptions{
29+
url: os.Getenv("URL"),
30+
fileName: os.Getenv("FILENAME"),
31+
perms: os.FileMode(755),
32+
bindir: os.Getenv("BINDIR"),
33+
}
34+
}
35+
36+
func downloadFile(opts downloadOptions) error {
37+
fmt.Printf("Using download options: %+v\n", opts)
38+
fullPath := path.Join(opts.bindir, opts.fileName)
39+
fmt.Printf("full path to directory: %s\n", fullPath)
40+
if err := os.MkdirAll(opts.bindir, opts.perms); err != nil {
41+
return fmt.Errorf("error making directory %s with permissions %d: %s", opts.bindir, opts.perms, err)
42+
}
43+
if err := fetchFile(fullPath, opts.url); err != nil {
44+
return fmt.Errorf("error fetching file: %s", err)
45+
}
46+
fmt.Printf("successfully downloaded file from %s to %s\n", opts.url, fullPath)
47+
if err := os.Chmod(fullPath, opts.perms); err != nil {
48+
return fmt.Errorf("error changing file permissions: %s", err)
49+
}
50+
return nil
51+
}
52+
53+
func fetchFile(filePath, url string) error {
54+
resp, err := http.Get(url)
55+
if err != nil {
56+
return fmt.Errorf("error getting url: %s", err)
57+
}
58+
defer resp.Body.Close()
59+
60+
if resp.StatusCode != http.StatusOK {
61+
return fmt.Errorf("bad status: %s", resp.Status)
62+
}
63+
64+
out, err := os.Create(filePath)
65+
if err != nil {
66+
return fmt.Errorf("error creating file: %s", err)
67+
}
68+
defer out.Close()
69+
70+
_, err = io.Copy(out, resp.Body)
71+
return err
72+
}

scripts/ci/generate_k8.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
set -o nounset
44
set -xeo pipefail

scripts/ci/setup_operator_sdk.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)