Skip to content

Commit

Permalink
Add Mock Async Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed May 13, 2019
1 parent 1f8f17e commit 5ea9413
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ jobs:
name: Run the end-to-end test suite
command: |
make e2e
- run:
name: Run the end-to-end test suite
command: |
make e2e NODE_NAME=vkubelet-mock-1 STATS_PORT=10256
- run:
name: Collect logs on failure from vkubelet-mock-0
command: |
kubectl logs vkubelet-mock-0
when: on_fail
- run:
name: Collect logs on failure from vkubelet-mock-1
command: |
kubectl logs vkubelet-mock-1
when: on_fail

workflows:
version: 2
Expand Down
7 changes: 4 additions & 3 deletions Makefile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ bin/e2e/virtual-kubelet: bin/e2e
.PHONY: e2e
e2e: KUBECONFIG ?= $(HOME)/.kube/config
e2e: NAMESPACE := default
e2e: NODE_NAME := vkubelet-mock-0
e2e: NODE_NAME ?= vkubelet-mock-0
e2e: TAINT_KEY := virtual-kubelet.io/provider
e2e: TAINT_VALUE := mock
e2e: TAINT_EFFECT := NoSchedule
e2e: STATS_PORT ?= 10255
e2e: export VK_BUILD_TAGS += mock_provider
e2e: e2e.clean bin/e2e/virtual-kubelet skaffold/run
@echo Running tests...
Expand All @@ -45,8 +46,8 @@ e2e: e2e.clean bin/e2e/virtual-kubelet skaffold/run
-node-name=$(NODE_NAME) \
-taint-key=$(TAINT_KEY) \
-taint-value=$(TAINT_VALUE) \
-taint-effect=$(TAINT_EFFECT)

-taint-effect=$(TAINT_EFFECT) \
-stats-port=$(STATS_PORT)
.PHONY: e2e.clean
e2e.clean: NODE_NAME ?= vkubelet-mock-0
e2e.clean: skaffold/delete
Expand Down
10 changes: 5 additions & 5 deletions hack/skaffold/virtual-kubelet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM gcr.io/distroless/base

ENV APISERVER_CERT_LOCATION /vkubelet-mock-0-crt.pem
ENV APISERVER_KEY_LOCATION /vkubelet-mock-0-key.pem
ENV APISERVER_CERT_LOCATION /vkubelet-mock-crt.pem
ENV APISERVER_KEY_LOCATION /vkubelet-mock-key.pem
ENV KUBELET_PORT 10250

# Use the pre-built binary in "bin/virtual-kubelet".
COPY bin/e2e/virtual-kubelet /virtual-kubelet
# Copy the configuration file for the mock provider.
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-0-cfg.json /vkubelet-mock-0-cfg.json
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-cfg.json /vkubelet-mock-cfg.json
# Copy the certificate for the HTTPS server.
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-0-crt.pem /vkubelet-mock-0-crt.pem
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-crt.pem /vkubelet-mock-crt.pem
# Copy the private key for the HTTPS server.
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-0-key.pem /vkubelet-mock-0-key.pem
COPY hack/skaffold/virtual-kubelet/vkubelet-mock-key.pem /vkubelet-mock-key.pem

CMD ["/virtual-kubelet"]
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ spec:
- --nodename
- vkubelet-mock-0
- --provider
- mock
- mocklegacy
- --provider-config
- /vkubelet-mock-0-cfg.json
- /vkubelet-mock-cfg.json
- --startup-timeout
- 10s
- --klog.v
Expand Down
38 changes: 38 additions & 0 deletions hack/skaffold/virtual-kubelet/pod2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Pod
metadata:
name: vkubelet-mock-1
spec:
containers:
- name: vkubelet-mock-1
image: virtual-kubelet
# "IfNotPresent" is used to prevent Minikube from trying to pull from the registry (and failing) in the first place.
imagePullPolicy: IfNotPresent
args:
- /virtual-kubelet
- --nodename
- vkubelet-mock-1
- --provider
- mock
- --provider-config
- /vkubelet-mock-cfg.json
- --startup-timeout
- 10s
- --klog.v
- "2"
- --klog.logtostderr
- --log-level
- debug
- --metrics-addr
- :10256
env:
- name: KUBELET_PORT
value: "10251"
ports:
- name: metrics
containerPort: 10256
readinessProbe:
httpGet:
path: /stats/summary
port: metrics
serviceAccountName: virtual-kubelet
2 changes: 1 addition & 1 deletion hack/skaffold/virtual-kubelet/skaffold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deploy:
kubectl:
manifests:
- hack/skaffold/virtual-kubelet/base.yml
- hack/skaffold/virtual-kubelet/pod.yml
- hack/skaffold/virtual-kubelet/pod1.yml
profiles:
- name: local
build:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"vkubelet-mock-0": {
"cpu": "2",
"memory": "32Gi",
"pods": "128"
},
"vkubelet-mock-0": {
"cpu": "2",
"memory": "32Gi",
"pods": "128"
}
}
}
4 changes: 3 additions & 1 deletion test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ type Framework struct {
TaintKey string
TaintValue string
TaintEffect string
StatsPort int
}

// NewTestingFramework returns a new instance of the testing framework.
func NewTestingFramework(kubeconfig, namespace, nodeName, taintKey, taintValue, taintEffect string) *Framework {
func NewTestingFramework(kubeconfig, namespace, nodeName, taintKey, taintValue, taintEffect string, statsPort int) *Framework {
return &Framework{
KubeClient: createKubeClient(kubeconfig),
Namespace: namespace,
NodeName: nodeName,
TaintKey: taintKey,
TaintValue: taintValue,
TaintEffect: taintEffect,
StatsPort: statsPort,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (f *Framework) GetStatsSummary() (*stats.Summary, error) {
Namespace(f.Namespace).
Resource("pods").
SubResource("proxy").
Name(net.JoinSchemeNamePort("http", f.NodeName, strconv.Itoa(10255))).
Name(net.JoinSchemeNamePort("http", f.NodeName, strconv.Itoa(f.StatsPort))).
Suffix("/stats/summary").DoRaw()
if err != nil {
return nil, err
Expand Down
15 changes: 9 additions & 6 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
defaultTaintKey = "virtual-kubelet.io/provider"
defaultTaintValue = "mock"
defaultTaintEffect = string(v1.TaintEffectNoSchedule)
defaultStatsPort = 10255
)

var (
Expand All @@ -36,6 +37,8 @@ var (
taintValue string
// taintEffect is the effect of the taint that is expected to be associated with the virtual-kubelet node to test.
taintEffect string
// Port that the statistics daemon is running on on the kubelet
statsPort int
)

func init() {
Expand All @@ -45,18 +48,15 @@ func init() {
flag.StringVar(&taintKey, "taint-key", defaultTaintKey, "the key of the taint that is expected to be associated with the virtual-kubelet node to test")
flag.StringVar(&taintValue, "taint-value", defaultTaintValue, "the value of the taint that is expected to be associated with the virtual-kubelet node to test")
flag.StringVar(&taintEffect, "taint-effect", defaultTaintEffect, "the effect of the taint that is expected to be associated with the virtual-kubelet node to test")
flag.Parse()
flag.IntVar(&statsPort, "stats-port", defaultStatsPort, "Port that the statistics daemon is running on on the kubelet")
}

func TestMain(m *testing.M) {
flag.Parse()
// Set sane defaults in case no values (or empty ones) have been provided.
setDefaults()
// Create a new instance of the test framework targeting the specified node.
f = framework.NewTestingFramework(kubeconfig, namespace, nodeName, taintKey, taintValue, taintEffect)
// Wait for the virtual-kubelet pod to be ready.
if err := f.WaitUntilPodReady(namespace, nodeName); err != nil {
panic(err)
}
f = framework.NewTestingFramework(kubeconfig, namespace, nodeName, taintKey, taintValue, taintEffect, statsPort)
// Run the test suite.
os.Exit(m.Run())
}
Expand All @@ -78,4 +78,7 @@ func setDefaults() {
if taintEffect == "" {
taintEffect = defaultTaintEffect
}
if statsPort == 0 {
statsPort = defaultStatsPort
}
}

0 comments on commit 5ea9413

Please sign in to comment.