| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,116 @@ |
| 0 |
+apiVersion: v1 |
|
| 1 |
+items: |
|
| 2 |
+- apiVersion: v1 |
|
| 3 |
+ kind: ImageStream |
|
| 4 |
+ metadata: |
|
| 5 |
+ creationTimestamp: null |
|
| 6 |
+ name: ubuntu-debootstrap |
|
| 7 |
+ spec: |
|
| 8 |
+ dockerImageRepository: library/ubuntu-debootstrap:14.04 |
|
| 9 |
+ status: |
|
| 10 |
+ dockerImageRepository: "" |
|
| 11 |
+- apiVersion: v1 |
|
| 12 |
+ kind: ImageStream |
|
| 13 |
+ metadata: |
|
| 14 |
+ creationTimestamp: null |
|
| 15 |
+ name: docker-nfs-server |
|
| 16 |
+ spec: |
|
| 17 |
+ tags: |
|
| 18 |
+ - from: |
|
| 19 |
+ kind: DockerImage |
|
| 20 |
+ name: library/docker-nfs-server:latest |
|
| 21 |
+ name: latest |
|
| 22 |
+ status: |
|
| 23 |
+ dockerImageRepository: "" |
|
| 24 |
+- apiVersion: v1 |
|
| 25 |
+ kind: BuildConfig |
|
| 26 |
+ metadata: |
|
| 27 |
+ creationTimestamp: null |
|
| 28 |
+ name: docker-nfs-server |
|
| 29 |
+ spec: |
|
| 30 |
+ output: |
|
| 31 |
+ to: |
|
| 32 |
+ kind: ImageStreamTag |
|
| 33 |
+ name: docker-nfs-server:latest |
|
| 34 |
+ resources: {}
|
|
| 35 |
+ source: |
|
| 36 |
+ git: |
|
| 37 |
+ uri: https://github.com/deads2k/docker-nfs-server |
|
| 38 |
+ type: Git |
|
| 39 |
+ strategy: |
|
| 40 |
+ dockerStrategy: |
|
| 41 |
+ from: |
|
| 42 |
+ kind: ImageStreamTag |
|
| 43 |
+ name: ubuntu-debootstrap:14.04 |
|
| 44 |
+ type: Docker |
|
| 45 |
+ triggers: |
|
| 46 |
+ - github: |
|
| 47 |
+ secret: wAWBuMZdIVbWLscgzxUn |
|
| 48 |
+ type: GitHub |
|
| 49 |
+ - generic: |
|
| 50 |
+ secret: _XRLouIDQsz0ARuFnEo0 |
|
| 51 |
+ type: Generic |
|
| 52 |
+ - imageChange: {}
|
|
| 53 |
+ type: ImageChange |
|
| 54 |
+ status: |
|
| 55 |
+ lastVersion: 0 |
|
| 56 |
+- apiVersion: v1 |
|
| 57 |
+ kind: Secret |
|
| 58 |
+ metadata: |
|
| 59 |
+ creationTimestamp: null |
|
| 60 |
+ name: unmountable-secret |
|
| 61 |
+- apiVersion: v1 |
|
| 62 |
+ kind: DeploymentConfig |
|
| 63 |
+ metadata: |
|
| 64 |
+ creationTimestamp: null |
|
| 65 |
+ name: docker-nfs-server |
|
| 66 |
+ spec: |
|
| 67 |
+ replicas: 1 |
|
| 68 |
+ selector: |
|
| 69 |
+ deploymentconfig: docker-nfs-server |
|
| 70 |
+ strategy: |
|
| 71 |
+ resources: {}
|
|
| 72 |
+ type: Recreate |
|
| 73 |
+ template: |
|
| 74 |
+ metadata: |
|
| 75 |
+ creationTimestamp: null |
|
| 76 |
+ labels: |
|
| 77 |
+ deploymentconfig: docker-nfs-server |
|
| 78 |
+ spec: |
|
| 79 |
+ containers: |
|
| 80 |
+ - image: library/docker-nfs-server:latest |
|
| 81 |
+ name: docker-nfs-server |
|
| 82 |
+ ports: |
|
| 83 |
+ - containerPort: 111 |
|
| 84 |
+ name: docker-nfs-server-udp-111 |
|
| 85 |
+ protocol: UDP |
|
| 86 |
+ - containerPort: 111 |
|
| 87 |
+ name: docker-nfs-server-tcp-111 |
|
| 88 |
+ protocol: TCP |
|
| 89 |
+ - containerPort: 2049 |
|
| 90 |
+ name: docker-nfs-server-tcp-2049 |
|
| 91 |
+ protocol: TCP |
|
| 92 |
+ - containerPort: 2049 |
|
| 93 |
+ name: docker-nfs-server-udp-2049 |
|
| 94 |
+ protocol: UDP |
|
| 95 |
+ resources: {}
|
|
| 96 |
+ volumes: |
|
| 97 |
+ - name: missing-secret-volume |
|
| 98 |
+ secret: |
|
| 99 |
+ secretName: missing-secret |
|
| 100 |
+ - name: unmountable-secret-volume |
|
| 101 |
+ secret: |
|
| 102 |
+ secretName: unmountable-secret |
|
| 103 |
+ triggers: |
|
| 104 |
+ - type: ConfigChange |
|
| 105 |
+ - imageChangeParams: |
|
| 106 |
+ automatic: true |
|
| 107 |
+ containerNames: |
|
| 108 |
+ - docker-nfs-server |
|
| 109 |
+ from: |
|
| 110 |
+ kind: ImageStreamTag |
|
| 111 |
+ name: docker-nfs-server:latest |
|
| 112 |
+ type: ImageChange |
|
| 113 |
+ status: {}
|
|
| 114 |
+kind: List |
|
| 115 |
+metadata: {}
|
| 0 | 116 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,101 @@ |
| 0 |
+package test |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "reflect" |
|
| 5 |
+ |
|
| 6 |
+ kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 7 |
+ |
|
| 8 |
+ osgraph "github.com/openshift/origin/pkg/api/graph" |
|
| 9 |
+ kubegraph "github.com/openshift/origin/pkg/api/kubegraph/nodes" |
|
| 10 |
+ buildapi "github.com/openshift/origin/pkg/build/api" |
|
| 11 |
+ buildgraph "github.com/openshift/origin/pkg/build/graph/nodes" |
|
| 12 |
+ deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 13 |
+ deploygraph "github.com/openshift/origin/pkg/deploy/graph/nodes" |
|
| 14 |
+ imageapi "github.com/openshift/origin/pkg/image/api" |
|
| 15 |
+ imagegraph "github.com/openshift/origin/pkg/image/graph/nodes" |
|
| 16 |
+) |
|
| 17 |
+ |
|
| 18 |
+// typeToEnsureMethod stores types to Ensure*Node methods |
|
| 19 |
+var typeToEnsureMethod = map[reflect.Type]reflect.Value{}
|
|
| 20 |
+ |
|
| 21 |
+func init() {
|
|
| 22 |
+ if err := RegisterEnsureNode(&imageapi.Image{}, imagegraph.EnsureImageNode); err != nil {
|
|
| 23 |
+ panic(err) |
|
| 24 |
+ } |
|
| 25 |
+ if err := RegisterEnsureNode(&imageapi.ImageStream{}, imagegraph.EnsureImageStreamNode); err != nil {
|
|
| 26 |
+ panic(err) |
|
| 27 |
+ } |
|
| 28 |
+ if err := RegisterEnsureNode(&deployapi.DeploymentConfig{}, deploygraph.EnsureDeploymentConfigNode); err != nil {
|
|
| 29 |
+ panic(err) |
|
| 30 |
+ } |
|
| 31 |
+ if err := RegisterEnsureNode(&buildapi.BuildConfig{}, buildgraph.EnsureBuildConfigNode); err != nil {
|
|
| 32 |
+ panic(err) |
|
| 33 |
+ } |
|
| 34 |
+ if err := RegisterEnsureNode(&buildapi.Build{}, buildgraph.EnsureBuildNode); err != nil {
|
|
| 35 |
+ panic(err) |
|
| 36 |
+ } |
|
| 37 |
+ if err := RegisterEnsureNode(&kapi.Pod{}, kubegraph.EnsurePodNode); err != nil {
|
|
| 38 |
+ panic(err) |
|
| 39 |
+ } |
|
| 40 |
+ if err := RegisterEnsureNode(&kapi.Secret{}, kubegraph.EnsureSecretNode); err != nil {
|
|
| 41 |
+ panic(err) |
|
| 42 |
+ } |
|
| 43 |
+ if err := RegisterEnsureNode(&kapi.Service{}, kubegraph.EnsureServiceNode); err != nil {
|
|
| 44 |
+ panic(err) |
|
| 45 |
+ } |
|
| 46 |
+ if err := RegisterEnsureNode(&kapi.ReplicationController{}, kubegraph.EnsureReplicationControllerNode); err != nil {
|
|
| 47 |
+ panic(err) |
|
| 48 |
+ } |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+func RegisterEnsureNode(containedType, ensureFunction interface{}) error {
|
|
| 52 |
+ ensureFunctionValue := reflect.ValueOf(ensureFunction) |
|
| 53 |
+ ensureType := ensureFunctionValue.Type() |
|
| 54 |
+ if err := verifyEnsureFunctionSignature(ensureType); err != nil {
|
|
| 55 |
+ return err |
|
| 56 |
+ } |
|
| 57 |
+ |
|
| 58 |
+ reflectedContainedType := reflect.TypeOf(containedType) |
|
| 59 |
+ if _, exists := typeToEnsureMethod[reflectedContainedType]; exists {
|
|
| 60 |
+ return fmt.Errorf("%v is already registered", reflectedContainedType)
|
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ typeToEnsureMethod[reflectedContainedType] = reflect.ValueOf(ensureFunction) |
|
| 64 |
+ |
|
| 65 |
+ return nil |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+func EnsureNode(g osgraph.Graph, obj interface{}) error {
|
|
| 69 |
+ reflectedContainedType := reflect.TypeOf(obj) |
|
| 70 |
+ |
|
| 71 |
+ ensureMethod, exists := typeToEnsureMethod[reflectedContainedType] |
|
| 72 |
+ if !exists {
|
|
| 73 |
+ return fmt.Errorf("%v is not registered", reflectedContainedType)
|
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 76 |
+ callEnsureNode(g, reflect.ValueOf(obj), ensureMethod) |
|
| 77 |
+ return nil |
|
| 78 |
+} |
|
| 79 |
+ |
|
| 80 |
+func verifyEnsureFunctionSignature(ft reflect.Type) error {
|
|
| 81 |
+ if ft.Kind() != reflect.Func {
|
|
| 82 |
+ return fmt.Errorf("expected func, got: %v", ft)
|
|
| 83 |
+ } |
|
| 84 |
+ if ft.NumIn() != 2 {
|
|
| 85 |
+ return fmt.Errorf("expected two 'in' param, got: %v", ft)
|
|
| 86 |
+ } |
|
| 87 |
+ if ft.NumOut() != 1 {
|
|
| 88 |
+ return fmt.Errorf("expected one 'out' param, got: %v", ft)
|
|
| 89 |
+ } |
|
| 90 |
+ if ft.In(1).Kind() != reflect.Ptr {
|
|
| 91 |
+ return fmt.Errorf("expected pointer arg for 'in' param 1, got: %v", ft)
|
|
| 92 |
+ } |
|
| 93 |
+ return nil |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 96 |
+// callEnsureNode calls 'custom' with sv & dv. custom must be a conversion function. |
|
| 97 |
+func callEnsureNode(g osgraph.Graph, obj, ensureMethod reflect.Value) {
|
|
| 98 |
+ args := []reflect.Value{reflect.ValueOf(g), obj}
|
|
| 99 |
+ ensureMethod.Call(args)[0].Interface() |
|
| 100 |
+} |