-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate manifest of pod with certain # PVs Add to --node-affinity flag to generate_example_manifest.go
- Loading branch information
1 parent
551b59a
commit 76ae6be
Showing
2 changed files
with
106 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: device-limit-tester-{{ len .Volumes }}-volumes | ||
spec: | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: {{ .NodeAffinityKey }} | ||
operator: In | ||
values: | ||
- {{ .NodeAffinityValue }} | ||
containers: | ||
- name: device-limit-tester-{{ len .Volumes }}-volumes | ||
image: centos | ||
command: ["/bin/sh"] | ||
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"] | ||
volumeMounts: | ||
{{- range $index, $value := .Volumes }} | ||
- name: persistent-storage-{{ $index }} | ||
mountPath: /data-{{ $index }} | ||
{{- end }} | ||
volumes: | ||
{{- range $index, $value := .Volumes }} | ||
- name: persistent-storage-{{ $index }} | ||
persistentVolumeClaim: | ||
claimName: ebs-claim-{{ $index }} | ||
{{- end }} | ||
--- | ||
{{- range $index, $value := .Volumes }} | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: ebs-claim-{{ $index }} | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
storageClassName: ebs-sc | ||
resources: | ||
requests: | ||
storage: 4Gi | ||
--- | ||
{{- end }} | ||
apiVersion: storage.k8s.io/v1 | ||
kind: StorageClass | ||
metadata: | ||
name: ebs-sc | ||
provisioner: ebs.csi.aws.com | ||
volumeBindingMode: WaitForFirstConsumer |
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,55 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type Manifest struct { | ||
NodeAffinityKey string | ||
NodeAffinityValue string | ||
Volumes []int | ||
} | ||
|
||
func main() { | ||
// Parse Command-Line args & flags | ||
nodeAffinityPtr := flag.String("node-affinity", "", "node affinity for pod in form of 'key:value'") | ||
volumeCountPtr := flag.Int("volume-count", 2, "amount of Volumes to provision") | ||
flag.Parse() | ||
|
||
nodeAffinityKey, nodeAffinityValue := parseNodeAffinityFlag(nodeAffinityPtr) | ||
|
||
manifest := Manifest{ | ||
NodeAffinityKey: nodeAffinityKey, | ||
NodeAffinityValue: nodeAffinityValue, | ||
Volumes: make([]int, *volumeCountPtr), | ||
} | ||
|
||
// Generate manifest to stdout from template file | ||
var tmplFile = "device_slot_test.tmpl" | ||
tmpl, err := template.New(tmplFile).ParseFiles(tmplFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = tmpl.Execute(os.Stdout, manifest) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func parseNodeAffinityFlag(nodeAffinityPtr *string) (string, string) { | ||
nodeAffinityKey := "" | ||
nodeAffinityValue := "" | ||
if len(*nodeAffinityPtr) > 0 { | ||
nodeAffinity := strings.Split(*nodeAffinityPtr, ":") | ||
if len(nodeAffinity) != 2 { | ||
panic(fmt.Errorf("flag '--node-affinity' must take the form 'key:value'")) | ||
} | ||
nodeAffinityKey = nodeAffinity[0] | ||
nodeAffinityValue = nodeAffinity[1] | ||
} | ||
return nodeAffinityKey, nodeAffinityValue | ||
} |