-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from pablochacin/generic-k8s-interface
Generic k8s interface
- Loading branch information
Showing
7 changed files
with
693 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Kubernetes } from 'k6/x/kubernetes' | ||
import { sleep } from 'k6' | ||
|
||
const k8s = new Kubernetes() | ||
|
||
const podSpec = { | ||
apiVersion: "v1", | ||
kind: "Pod", | ||
metadata: { | ||
name: "busybox", | ||
namespace: "default" | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: "busybox", | ||
image: "busybox", | ||
command: ["sh", "-c", "sleep 30"] | ||
} | ||
] | ||
} | ||
} | ||
|
||
export default function(){ | ||
var created = k8s.create(podSpec) | ||
console.log("pod '" + created.metadata.name +"' created") | ||
|
||
var pod = k8s.get(podSpec.kind, podSpec.metadata.name, podSpec.metadata.namespace) | ||
if (podSpec.metadata.name != pod.metadata.name) { | ||
throw new Error("fetch by name did not return the Pod. Expected: " + podSpec.metadata.name + " but got: " + fetched.name) | ||
} | ||
|
||
const pods = k8s.list(podSpec.kind, podSpec.metadata.namespace) | ||
if (pods === undefined || pods.length < 1) { | ||
throw new Error("expected listing with 1 Pod") | ||
} | ||
|
||
k8s.delete(podSpec.kind, podSpec.metadata.name, podSpec.metadata.namespace) | ||
|
||
// give time for the pod to be deleted | ||
sleep(5) | ||
|
||
if (k8s.list(podSpec.kind, podSpec.metadata.namespace).length != 0) { | ||
throw new Error("deletion failed to remove pod") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package testutils | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
dynamicfake "k8s.io/client-go/dynamic/fake" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
// NewFakeDynamic creates a new instance of a fake dynamic client with a default scheme | ||
func NewFakeDynamic() (*dynamicfake.FakeDynamicClient, error) { | ||
scheme := runtime.NewScheme() | ||
err := fake.AddToScheme(scheme) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return dynamicfake.NewSimpleDynamicClient(scheme), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.