Browse Source
			
			
			Add Pre/PostSync job example
			
			
				pull/2/head
			
			
				pre-post-sync-v0.1
			
		 
		
			
				
					
						 Jesse Suen
					
					7 years ago
						Jesse Suen
					
					7 years ago
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 90C911E8A6106562
						
					
				
			
		
		
		
	
		
			
				 10 changed files with 
162 additions and 
0 deletions
			 
			
		 
		
			
				- 
					
					
					 
					pre-post-sync/.gitignore
				
- 
					
					
					 
					pre-post-sync/app.yaml
				
- 
					
					
					 
					pre-post-sync/components/guestbook-ui.jsonnet
				
- 
					
					
					 
					pre-post-sync/components/params.libsonnet
				
- 
					
					
					 
					pre-post-sync/components/post-sync-job.yaml
				
- 
					
					
					 
					pre-post-sync/components/pre-sync-job.yaml
				
- 
					
					
					 
					pre-post-sync/environments/base.libsonnet
				
- 
					
					
					 
					pre-post-sync/environments/default/globals.libsonnet
				
- 
					
					
					 
					pre-post-sync/environments/default/main.jsonnet
				
- 
					
					
					 
					pre-post-sync/environments/default/params.libsonnet
				
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,4 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | /lib | 
			
		
	
		
		
			
				
					|  |  |  |  |  | /.ksonnet/registries | 
			
		
	
		
		
			
				
					|  |  |  |  |  | /app.override.yaml | 
			
		
	
		
		
			
				
					|  |  |  |  |  | /.ks_environment | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,11 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | apiVersion: 0.1.0 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | environments: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   default: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     destination: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       namespace: default | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       server: https://kubernetes.default.svc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     k8sVersion: v1.10.0 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     path: default | 
			
		
	
		
		
			
				
					|  |  |  |  |  | kind: ksonnet.io/app | 
			
		
	
		
		
			
				
					|  |  |  |  |  | name: pre-post-sync | 
			
		
	
		
		
			
				
					|  |  |  |  |  | version: 0.0.1 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,66 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local env = std.extVar("__ksonnet/environments"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local params = std.extVar("__ksonnet/params").components["guestbook-ui"]; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | [ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "apiVersion": "v1", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "kind": "Service", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "metadata": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "name": params.name | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "spec": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "ports": [ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                "port": params.servicePort, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                "targetPort": params.containerPort | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          ], | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "selector": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             "app": params.name | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "type": params.type | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "apiVersion": "apps/v1beta2", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "kind": "Deployment", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "metadata": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "name": params.name | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       "spec": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "replicas": params.replicas, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "selector": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             "matchLabels": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                "app": params.name | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          "template": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             "metadata": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                "labels": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   "app": params.name | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             "spec": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                "containers": [ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     "image": params.image, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     "name": params.name, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     "ports": [ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             "containerPort": params.containerPort | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     ], | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     // dummy readiness probe to slow down the rollout for demo/testing | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     "readinessProbe": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         "exec": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             "command": [ "sh", "-c", "exit 0" ], | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         "initialDelaySeconds": 30, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         "periodSeconds": 120, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                ] | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | ] | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,20 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   global: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // User-defined global parameters; accessible to all component and environments, Ex: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // replicas: 4, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   components: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // Component-level parameters, defined initially from 'ks prototype use ...' | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // Each object below should correspond to a component in the components/ directory | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     "guestbook-ui": { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       containerPort: 80, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       image: "gcr.io/heptio-images/ks-guestbook-demo:0.1", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       name: "pre-post-sync", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       replicas: 1, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       servicePort: 80, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       type: "LoadBalancer", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     "pre-sync-job": {}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     "post-sync-job": {}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,15 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | apiVersion: batch/v1 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | kind: Job | 
			
		
	
		
		
			
				
					|  |  |  |  |  | metadata: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   generateName: after- | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   annotations: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     argocd.argoproj.io/hook: PostSync | 
			
		
	
		
		
			
				
					|  |  |  |  |  | spec: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   template: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     spec: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       containers: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       - name: sleep | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         image: alpine:latest | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         command: ["sleep", "30"] | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       restartPolicy: Never | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   backoffLimit: 4 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,15 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | apiVersion: batch/v1 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | kind: Job | 
			
		
	
		
		
			
				
					|  |  |  |  |  | metadata: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   generateName: before- | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   annotations: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     argocd.argoproj.io/hook: PreSync | 
			
		
	
		
		
			
				
					|  |  |  |  |  | spec: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   template: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     spec: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       containers: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       - name: sleep | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         image: alpine:latest | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         command: ["sleep", "30"] | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       restartPolicy: Never | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   backoffLimit: 4 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,4 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local components = std.extVar("__ksonnet/components"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | components + { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   // Insert user-specified overrides here. | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,8 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local base = import "base.libsonnet"; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | // uncomment if you reference ksonnet-lib | 
			
		
	
		
		
			
				
					|  |  |  |  |  | // local k = import "k.libsonnet"; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | base + { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   // Insert user-specified overrides here. For example if a component is named \"nginx-deployment\", you might have something like:\n") | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   // "nginx-deployment"+: k.deployment.mixin.metadata.labels({foo: "bar"}) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -0,0 +1,17 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local params = std.extVar("__ksonnet/params"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local globals = import "globals.libsonnet"; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | local envParams = params + { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   components +: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // Insert component parameter overrides here. Ex: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // guestbook +: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     //   name: "guestbook-dev", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     //   replicas: params.global.replicas, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     // }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | }; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   components: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     [x]: envParams.components[x] + globals, for x in std.objectFields(envParams.components) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } |