GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update_test.go 24KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. package kubernetes
  2. import (
  3. "testing"
  4. kresource "github.com/fluxcd/flux/cluster/kubernetes/resource"
  5. "github.com/fluxcd/flux/image"
  6. "github.com/fluxcd/flux/resource"
  7. )
  8. type update struct {
  9. name string
  10. resourceID string
  11. containers []string
  12. updatedImage string
  13. caseIn, caseOut string
  14. imageAnnotations kresource.ContainerImageMap
  15. }
  16. func testUpdateWorkloadContainer(t *testing.T, u update) {
  17. id, err := image.ParseRef(u.updatedImage)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. manifest := u.caseIn
  22. for _, container := range u.containers {
  23. var out []byte
  24. var err error
  25. if out, err = updateWorkloadContainer([]byte(manifest), resource.MustParseID(u.resourceID), container, id); err != nil {
  26. t.Errorf("Failed: %s", err.Error())
  27. return
  28. }
  29. manifest = string(out)
  30. }
  31. if manifest != u.caseOut {
  32. t.Errorf("id not get expected result:\n\n%s\n\nInstead got:\n\n%s", u.caseOut, manifest)
  33. }
  34. }
  35. func testUpdateWorkloadImagePath(t *testing.T, u update) {
  36. id, err := image.ParseRef(u.updatedImage)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. manifest := u.caseIn
  41. var out []byte
  42. if out, err = updateWorkloadImagePaths([]byte(manifest), resource.MustParseID(u.resourceID), u.imageAnnotations, id); err != nil {
  43. t.Errorf("Failed: %s", err.Error())
  44. return
  45. }
  46. manifest = string(out)
  47. if manifest != u.caseOut {
  48. t.Errorf("it did not get expected result:\n\n%s\n\nInstead got:\n\n%s", u.caseOut, manifest)
  49. }
  50. }
  51. func TestWorkloadContainerUpdates(t *testing.T) {
  52. for _, c := range []update{
  53. {"common case", case1resource, case1container, case1image, case1, case1out, emptyContainerImageMap},
  54. {"new version like number", case2resource, case2container, case2image, case2, case2out, emptyContainerImageMap},
  55. {"old version like number", case2resource, case2container, case2reverseImage, case2out, case2, emptyContainerImageMap},
  56. {"name label out of order", case3resource, case3container, case3image, case3, case3out, emptyContainerImageMap},
  57. {"version (tag) with dots", case4resource, case4container, case4image, case4, case4out, emptyContainerImageMap},
  58. {"minimal dockerhub image name", case5resource, case5container, case5image, case5, case5out, emptyContainerImageMap},
  59. {"reordered keys", case6resource, case6containers, case6image, case6, case6out, emptyContainerImageMap},
  60. {"from prod", case7resource, case7containers, case7image, case7, case7out, emptyContainerImageMap},
  61. {"single quotes", case8resource, case8containers, case8image, case8, case8out, emptyContainerImageMap},
  62. {"in multidoc", case9resource, case9containers, case9image, case9, case9out, emptyContainerImageMap},
  63. {"in kubernetes List resource", case10resource, case10containers, case10image, case10, case10out, emptyContainerImageMap},
  64. {"FluxHelmRelease (v1alpha2; simple image encoding)", case11resource, case11containers, case11image, case11, case11out, emptyContainerImageMap},
  65. {"FluxHelmRelease (v1alpha2; multi image encoding)", case12resource, case12containers, case12image, case12, case12out, emptyContainerImageMap},
  66. {"HelmRelease (v1beta1; image with port number)", case13resource, case13containers, case13image, case13, case13out, emptyContainerImageMap},
  67. {"HelmRelease (v1; with image map)", case14resource, make([]string, 0), case14image, case14, case14out, case14ImageMap},
  68. {"initContainer", case15resource, case15containers, case15image, case15, case15out, emptyContainerImageMap},
  69. } {
  70. t.Run(c.name, func(t *testing.T) {
  71. switch c.imageAnnotations {
  72. case emptyContainerImageMap:
  73. testUpdateWorkloadContainer(t, c)
  74. default:
  75. testUpdateWorkloadImagePath(t, c)
  76. }
  77. t.Parallel()
  78. })
  79. }
  80. }
  81. var emptyContainerImageMap = kresource.ContainerImageMap{}
  82. // Unusual but still valid indentation between containers: and the
  83. // next line
  84. const case1 = `---
  85. apiVersion: extensions/v1beta1
  86. kind: Deployment
  87. metadata:
  88. name: pr-assigner
  89. namespace: extra
  90. spec:
  91. replicas: 1
  92. template:
  93. metadata:
  94. labels:
  95. name: pr-assigner
  96. spec:
  97. imagePullSecrets:
  98. - name: quay-secret
  99. containers:
  100. - name: pr-assigner
  101. image: quay.io/weaveworks/pr-assigner:master-6f5e816
  102. imagePullPolicy: IfNotPresent
  103. args:
  104. - --conf_path=/config/pr-assigner.json
  105. env:
  106. - name: GITHUB_TOKEN
  107. valueFrom:
  108. secretKeyRef:
  109. name: pr-assigner
  110. key: githubtoken
  111. volumeMounts:
  112. - name: config-volume
  113. mountPath: /config
  114. volumes:
  115. - name: config-volume
  116. configMap:
  117. name: pr-assigner
  118. items:
  119. - key: conffile
  120. path: pr-assigner.json
  121. `
  122. const case1resource = "extra:deployment/pr-assigner"
  123. const case1image = "quay.io/weaveworks/pr-assigner:master-1234567"
  124. var case1container = []string{"pr-assigner"}
  125. const case1out = `---
  126. apiVersion: extensions/v1beta1
  127. kind: Deployment
  128. metadata:
  129. name: pr-assigner
  130. namespace: extra
  131. spec:
  132. replicas: 1
  133. template:
  134. metadata:
  135. labels:
  136. name: pr-assigner
  137. spec:
  138. imagePullSecrets:
  139. - name: quay-secret
  140. containers:
  141. - name: pr-assigner
  142. image: quay.io/weaveworks/pr-assigner:master-1234567
  143. imagePullPolicy: IfNotPresent
  144. args:
  145. - --conf_path=/config/pr-assigner.json
  146. env:
  147. - name: GITHUB_TOKEN
  148. valueFrom:
  149. secretKeyRef:
  150. name: pr-assigner
  151. key: githubtoken
  152. volumeMounts:
  153. - name: config-volume
  154. mountPath: /config
  155. volumes:
  156. - name: config-volume
  157. configMap:
  158. name: pr-assigner
  159. items:
  160. - key: conffile
  161. path: pr-assigner.json
  162. `
  163. // Version looks like a number
  164. const case2 = `---
  165. apiVersion: extensions/v1beta1
  166. kind: Deployment
  167. metadata:
  168. name: fluxy
  169. spec:
  170. replicas: 1
  171. template:
  172. metadata:
  173. labels:
  174. name: fluxy
  175. spec:
  176. volumes:
  177. - name: key
  178. secret:
  179. secretName: fluxy-repo-key
  180. containers:
  181. - name: fluxy
  182. image: weaveworks/fluxy:master-a000001
  183. imagePullPolicy: Never # must build manually
  184. ports:
  185. - containerPort: 3030
  186. volumeMounts:
  187. - name: key
  188. mountPath: /var/run/secrets/fluxy/key
  189. readOnly: true
  190. args:
  191. - /home/flux/fluxd
  192. - --kubernetes-kubectl=/home/flux/kubectl
  193. - --kubernetes-host=https://kubernetes
  194. - --kubernetes-certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  195. - --kubernetes-bearer-token-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  196. - --database-driver=ql
  197. - --database-source=file://history.db
  198. - --repo-url=git@github.com:squaremo/fluxy-testdata
  199. - --repo-key=/var/run/secrets/fluxy/key/id-rsa
  200. - --repo-path=testdata
  201. `
  202. const case2resource = "default:deployment/fluxy"
  203. const case2image = "weaveworks/fluxy:1234567"
  204. var case2container = []string{"fluxy"}
  205. const case2out = `---
  206. apiVersion: extensions/v1beta1
  207. kind: Deployment
  208. metadata:
  209. name: fluxy
  210. spec:
  211. replicas: 1
  212. template:
  213. metadata:
  214. labels:
  215. name: fluxy
  216. spec:
  217. volumes:
  218. - name: key
  219. secret:
  220. secretName: fluxy-repo-key
  221. containers:
  222. - name: fluxy
  223. image: weaveworks/fluxy:1234567
  224. imagePullPolicy: Never # must build manually
  225. ports:
  226. - containerPort: 3030
  227. volumeMounts:
  228. - name: key
  229. mountPath: /var/run/secrets/fluxy/key
  230. readOnly: true
  231. args:
  232. - /home/flux/fluxd
  233. - --kubernetes-kubectl=/home/flux/kubectl
  234. - --kubernetes-host=https://kubernetes
  235. - --kubernetes-certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  236. - --kubernetes-bearer-token-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  237. - --database-driver=ql
  238. - --database-source=file://history.db
  239. - --repo-url=git@github.com:squaremo/fluxy-testdata
  240. - --repo-key=/var/run/secrets/fluxy/key/id-rsa
  241. - --repo-path=testdata
  242. `
  243. const case2reverseImage = `weaveworks/fluxy:master-a000001`
  244. const case3 = `---
  245. apiVersion: extensions/v1beta1
  246. kind: Deployment
  247. metadata:
  248. namespace: monitoring
  249. name: grafana # comment, and only one space indent
  250. spec:
  251. replicas: 1
  252. template:
  253. metadata:
  254. labels:
  255. name: grafana
  256. spec:
  257. imagePullSecrets:
  258. - name: quay-secret
  259. containers:
  260. - name: grafana
  261. image: quay.io/weaveworks/grafana:master-ac5658a
  262. imagePullPolicy: IfNotPresent
  263. ports:
  264. - containerPort: 80
  265. - name: gfdatasource
  266. image: quay.io/weaveworks/gfdatasource:master-e50ecf2
  267. imagePullPolicy: IfNotPresent
  268. args:
  269. - http://prometheus.monitoring.svc.cluster.local/admin/prometheus
  270. `
  271. const case3resource = "monitoring:deployment/grafana"
  272. const case3image = "quay.io/weaveworks/grafana:master-37aaf67"
  273. var case3container = []string{"grafana"}
  274. const case3out = `---
  275. apiVersion: extensions/v1beta1
  276. kind: Deployment
  277. metadata:
  278. namespace: monitoring
  279. name: grafana # comment, and only one space indent
  280. spec:
  281. replicas: 1
  282. template:
  283. metadata:
  284. labels:
  285. name: grafana
  286. spec:
  287. imagePullSecrets:
  288. - name: quay-secret
  289. containers:
  290. - name: grafana
  291. image: quay.io/weaveworks/grafana:master-37aaf67
  292. imagePullPolicy: IfNotPresent
  293. ports:
  294. - containerPort: 80
  295. - name: gfdatasource
  296. image: quay.io/weaveworks/gfdatasource:master-e50ecf2
  297. imagePullPolicy: IfNotPresent
  298. args:
  299. - http://prometheus.monitoring.svc.cluster.local/admin/prometheus
  300. `
  301. const case4 = `---
  302. apiVersion: extensions/v1beta1
  303. kind: Deployment
  304. metadata:
  305. name: front-end
  306. namespace: sock-shop
  307. spec:
  308. replicas: 1
  309. template:
  310. metadata:
  311. labels:
  312. name: front-end
  313. spec:
  314. containers:
  315. - name: front-end
  316. image: weaveworksdemos/front-end:v_0.2.0
  317. resources:
  318. requests:
  319. cpu: 100m
  320. memory: 100Mi
  321. ports:
  322. - containerPort: 8079
  323. securityContext:
  324. runAsNonRoot: true
  325. runAsUser: 10001
  326. capabilities:
  327. drop:
  328. - all
  329. readOnlyRootFilesystem: true
  330. `
  331. const case4resource = "sock-shop:deployment/front-end"
  332. const case4image = "weaveworksdemos/front-end:7f511af2d21fd601b86b3bed7baa6adfa9c8c669"
  333. var case4container = []string{"front-end"}
  334. const case4out = `---
  335. apiVersion: extensions/v1beta1
  336. kind: Deployment
  337. metadata:
  338. name: front-end
  339. namespace: sock-shop
  340. spec:
  341. replicas: 1
  342. template:
  343. metadata:
  344. labels:
  345. name: front-end
  346. spec:
  347. containers:
  348. - name: front-end
  349. image: weaveworksdemos/front-end:7f511af2d21fd601b86b3bed7baa6adfa9c8c669
  350. resources:
  351. requests:
  352. cpu: 100m
  353. memory: 100Mi
  354. ports:
  355. - containerPort: 8079
  356. securityContext:
  357. runAsNonRoot: true
  358. runAsUser: 10001
  359. capabilities:
  360. drop:
  361. - all
  362. readOnlyRootFilesystem: true
  363. `
  364. const case5 = `---
  365. apiVersion: extensions/v1beta1
  366. kind: Deployment
  367. metadata:
  368. name: nginx
  369. spec:
  370. replicas: 1
  371. template:
  372. metadata:
  373. labels:
  374. name: nginx
  375. spec:
  376. containers:
  377. - name: nginx
  378. image: nginx
  379. ports:
  380. - containerPort: 80
  381. `
  382. const case5resource = "default:deployment/nginx"
  383. const case5image = "nginx:1.10-alpine"
  384. var case5container = []string{"nginx"}
  385. const case5out = `---
  386. apiVersion: extensions/v1beta1
  387. kind: Deployment
  388. metadata:
  389. name: nginx
  390. spec:
  391. replicas: 1
  392. template:
  393. metadata:
  394. labels:
  395. name: nginx
  396. spec:
  397. containers:
  398. - name: nginx
  399. image: nginx:1.10-alpine
  400. ports:
  401. - containerPort: 80
  402. `
  403. const case6 = `---
  404. apiVersion: extensions/v1beta1
  405. kind: Deployment
  406. metadata:
  407. name: nginx
  408. spec:
  409. replicas: 1
  410. template:
  411. metadata:
  412. labels:
  413. name: nginx
  414. spec:
  415. containers:
  416. - ports:
  417. - containerPort: 80
  418. image: nginx
  419. name: nginx
  420. - image: nginx:some-other-tag # testing comments, and this image is on the first line.
  421. name: nginx2
  422. `
  423. const case6resource = "default:deployment/nginx"
  424. const case6image = "nginx:1.10-alpine"
  425. var case6containers = []string{"nginx", "nginx2"}
  426. const case6out = `---
  427. apiVersion: extensions/v1beta1
  428. kind: Deployment
  429. metadata:
  430. name: nginx
  431. spec:
  432. replicas: 1
  433. template:
  434. metadata:
  435. labels:
  436. name: nginx
  437. spec:
  438. containers:
  439. - ports:
  440. - containerPort: 80
  441. image: nginx:1.10-alpine
  442. name: nginx
  443. - image: nginx:1.10-alpine # testing comments, and this image is on the first line.
  444. name: nginx2
  445. `
  446. const case7 = `---
  447. apiVersion: extensions/v1beta1
  448. kind: Deployment
  449. metadata:
  450. name: authfe
  451. spec:
  452. # A couple of comment lines after a blank line
  453. # since that's essentially what we have elsewhere
  454. minReadySeconds: 30
  455. strategy:
  456. rollingUpdate:
  457. maxUnavailable: 0
  458. maxSurge: 1
  459. replicas: 5
  460. template:
  461. metadata:
  462. labels:
  463. name: authfe
  464. annotations:
  465. prometheus.io/port: "8080"
  466. spec:
  467. # blank comment spacers in the following
  468. containers:
  469. - name: authfe
  470. image: quay.io/weaveworks/authfe:master-71a4ede
  471. args:
  472. - -log.level=info
  473. #
  474. # Can have a comment here
  475. - -log.blargle=false
  476. #
  477. ports:
  478. - containerPort: 80
  479. name: http
  480. - containerPort: 8080
  481. name: private
  482. #
  483. - name: logging
  484. image: quay.io/weaveworks/logging:master-ccfa2af
  485. env:
  486. - name: FLUENTD_CONF
  487. value: fluent.conf
  488. `
  489. const case7resource = "default:deployment/authfe"
  490. const case7image = "quay.io/weaveworks/logging:master-123456"
  491. var case7containers = []string{"logging"}
  492. const case7out = `---
  493. apiVersion: extensions/v1beta1
  494. kind: Deployment
  495. metadata:
  496. name: authfe
  497. spec:
  498. # A couple of comment lines after a blank line
  499. # since that's essentially what we have elsewhere
  500. minReadySeconds: 30
  501. strategy:
  502. rollingUpdate:
  503. maxUnavailable: 0
  504. maxSurge: 1
  505. replicas: 5
  506. template:
  507. metadata:
  508. labels:
  509. name: authfe
  510. annotations:
  511. prometheus.io/port: "8080"
  512. spec:
  513. # blank comment spacers in the following
  514. containers:
  515. - name: authfe
  516. image: quay.io/weaveworks/authfe:master-71a4ede
  517. args:
  518. - -log.level=info
  519. #
  520. # Can have a comment here
  521. - -log.blargle=false
  522. #
  523. ports:
  524. - containerPort: 80
  525. name: http
  526. - containerPort: 8080
  527. name: private
  528. #
  529. - name: logging
  530. image: quay.io/weaveworks/logging:master-123456
  531. env:
  532. - name: FLUENTD_CONF
  533. value: fluent.conf
  534. `
  535. const case8 = `---
  536. apiVersion: extensions/v1beta1
  537. kind: Deployment
  538. metadata:
  539. name: weave
  540. spec:
  541. replicas: 1
  542. template:
  543. metadata:
  544. labels:
  545. name: weave
  546. spec:
  547. containers:
  548. - name: weave
  549. image: 'weaveworks/weave-kube:2.2.0'
  550. `
  551. const case8resource = "default:deployment/weave"
  552. const case8image = "weaveworks/weave-kube:2.2.1"
  553. var case8containers = []string{"weave"}
  554. const case8out = `---
  555. apiVersion: extensions/v1beta1
  556. kind: Deployment
  557. metadata:
  558. name: weave
  559. spec:
  560. replicas: 1
  561. template:
  562. metadata:
  563. labels:
  564. name: weave
  565. spec:
  566. containers:
  567. - name: weave
  568. image: 'weaveworks/weave-kube:2.2.1'
  569. `
  570. const case9 = `---
  571. apiVersion: v1
  572. kind: Namespace
  573. metadata:
  574. name: hello
  575. ---
  576. apiVersion: extensions/v1beta1
  577. kind: Deployment
  578. metadata:
  579. annotations:
  580. some.other.com/foo: bar
  581. name: helloworld
  582. namespace: hello
  583. spec:
  584. minReadySeconds: 1
  585. replicas: 5
  586. template:
  587. metadata:
  588. labels:
  589. name: helloworld
  590. spec:
  591. containers:
  592. - name: helloworld
  593. image: quay.io/weaveworks/helloworld:master-07a1b6b
  594. args:
  595. - -msg=Bilbo Baggins
  596. ports:
  597. - containerPort: 80
  598. - name: sidecar
  599. image: quay.io/weaveworks/sidecar:master-a000002
  600. args:
  601. - -addr=:8080
  602. ports:
  603. - containerPort: 8080
  604. restartPolicy: Always
  605. ---
  606. apiVersion: v1
  607. kind: Service
  608. metadata:
  609. name: helloworld
  610. namespace: hello
  611. spec:
  612. ports:
  613. - port: 80
  614. selector:
  615. name: helloworld
  616. `
  617. const case9resource = "hello:deployment/helloworld"
  618. const case9image = "quay.io/weaveworks/helloworld:master-a000001"
  619. var case9containers = []string{"helloworld"}
  620. const case9out = `---
  621. apiVersion: v1
  622. kind: Namespace
  623. metadata:
  624. name: hello
  625. ---
  626. apiVersion: extensions/v1beta1
  627. kind: Deployment
  628. metadata:
  629. annotations:
  630. some.other.com/foo: bar
  631. name: helloworld
  632. namespace: hello
  633. spec:
  634. minReadySeconds: 1
  635. replicas: 5
  636. template:
  637. metadata:
  638. labels:
  639. name: helloworld
  640. spec:
  641. containers:
  642. - name: helloworld
  643. image: quay.io/weaveworks/helloworld:master-a000001
  644. args:
  645. - -msg=Bilbo Baggins
  646. ports:
  647. - containerPort: 80
  648. - name: sidecar
  649. image: quay.io/weaveworks/sidecar:master-a000002
  650. args:
  651. - -addr=:8080
  652. ports:
  653. - containerPort: 8080
  654. restartPolicy: Always
  655. ---
  656. apiVersion: v1
  657. kind: Service
  658. metadata:
  659. name: helloworld
  660. namespace: hello
  661. spec:
  662. ports:
  663. - port: 80
  664. selector:
  665. name: helloworld
  666. `
  667. const case10 = `---
  668. apiVersion: v1
  669. kind: List
  670. items:
  671. - apiVersion: v1
  672. kind: Namespace
  673. metadata:
  674. name: hello
  675. - apiVersion: extensions/v1beta1
  676. kind: Deployment
  677. metadata:
  678. annotations:
  679. some.other.com/foo: bar
  680. name: helloworld
  681. namespace: hello
  682. spec:
  683. minReadySeconds: 1
  684. replicas: 5
  685. template:
  686. metadata:
  687. labels:
  688. name: helloworld
  689. spec:
  690. containers:
  691. - name: helloworld
  692. image: quay.io/weaveworks/helloworld:master-07a1b6b
  693. args:
  694. - -msg=Bilbo Baggins
  695. ports:
  696. - containerPort: 80
  697. - name: sidecar
  698. image: quay.io/weaveworks/sidecar:master-a000002
  699. args:
  700. - -addr=:8080
  701. ports:
  702. - containerPort: 8080
  703. restartPolicy: Always
  704. - apiVersion: v1
  705. kind: Service
  706. metadata:
  707. name: helloworld
  708. namespace: hello
  709. spec:
  710. ports:
  711. - port: 80
  712. selector:
  713. name: helloworld
  714. `
  715. const case10resource = "hello:deployment/helloworld"
  716. const case10image = "quay.io/weaveworks/helloworld:master-a000001"
  717. var case10containers = []string{"helloworld"}
  718. const case10out = `---
  719. apiVersion: v1
  720. kind: List
  721. items:
  722. - apiVersion: v1
  723. kind: Namespace
  724. metadata:
  725. name: hello
  726. - apiVersion: extensions/v1beta1
  727. kind: Deployment
  728. metadata:
  729. annotations:
  730. some.other.com/foo: bar
  731. name: helloworld
  732. namespace: hello
  733. spec:
  734. minReadySeconds: 1
  735. replicas: 5
  736. template:
  737. metadata:
  738. labels:
  739. name: helloworld
  740. spec:
  741. containers:
  742. - name: helloworld
  743. image: quay.io/weaveworks/helloworld:master-a000001
  744. args:
  745. - -msg=Bilbo Baggins
  746. ports:
  747. - containerPort: 80
  748. - name: sidecar
  749. image: quay.io/weaveworks/sidecar:master-a000002
  750. args:
  751. - -addr=:8080
  752. ports:
  753. - containerPort: 8080
  754. restartPolicy: Always
  755. - apiVersion: v1
  756. kind: Service
  757. metadata:
  758. name: helloworld
  759. namespace: hello
  760. spec:
  761. ports:
  762. - port: 80
  763. selector:
  764. name: helloworld
  765. `
  766. const case11 = `---
  767. apiVersion: helm.integrations.flux.weave.works/v1alpha2
  768. kind: FluxHelmRelease
  769. metadata:
  770. name: mariadb
  771. namespace: maria
  772. labels:
  773. chart: mariadb
  774. spec:
  775. chartGitPath: mariadb
  776. values:
  777. image: bitnami/mariadb:10.1.30-r1
  778. persistence:
  779. enabled: false
  780. `
  781. const case11resource = "maria:fluxhelmrelease/mariadb"
  782. const case11image = "bitnami/mariadb:10.1.33"
  783. var case11containers = []string{"chart-image"}
  784. const case11out = `---
  785. apiVersion: helm.integrations.flux.weave.works/v1alpha2
  786. kind: FluxHelmRelease
  787. metadata:
  788. name: mariadb
  789. namespace: maria
  790. labels:
  791. chart: mariadb
  792. spec:
  793. chartGitPath: mariadb
  794. values:
  795. image: bitnami/mariadb:10.1.33
  796. persistence:
  797. enabled: false
  798. `
  799. const case12 = `---
  800. apiVersion: helm.integrations.flux.weave.works/v1alpha2
  801. kind: FluxHelmRelease
  802. metadata:
  803. name: mariadb
  804. namespace: maria
  805. labels:
  806. chart: mariadb
  807. spec:
  808. chartGitPath: mariadb
  809. values:
  810. mariadb:
  811. image: bitnami/mariadb:10.1.30-r1
  812. persistence:
  813. enabled: false
  814. workProperly: true
  815. sidecar:
  816. image: sidecar:v1
  817. `
  818. const case12resource = "maria:fluxhelmrelease/mariadb"
  819. const case12image = "bitnami/mariadb:10.1.33"
  820. var case12containers = []string{"mariadb"}
  821. const case12out = `---
  822. apiVersion: helm.integrations.flux.weave.works/v1alpha2
  823. kind: FluxHelmRelease
  824. metadata:
  825. name: mariadb
  826. namespace: maria
  827. labels:
  828. chart: mariadb
  829. spec:
  830. chartGitPath: mariadb
  831. values:
  832. mariadb:
  833. image: bitnami/mariadb:10.1.33
  834. persistence:
  835. enabled: false
  836. workProperly: true
  837. sidecar:
  838. image: sidecar:v1
  839. `
  840. const case13 = `---
  841. apiVersion: flux.weave.works/v1beta1
  842. kind: HelmRelease
  843. metadata:
  844. name: mariadb
  845. namespace: maria
  846. spec:
  847. chart:
  848. repository: https://example.com/charts
  849. name: mariadb
  850. version: 1.1.2
  851. values:
  852. mariadb:
  853. image: localhost:5000/mariadb
  854. tag: 10.1.30-r1
  855. persistence:
  856. enabled: false
  857. workProperly: true
  858. sidecar:
  859. image: sidecar:v1
  860. `
  861. const case13resource = "maria:helmrelease/mariadb"
  862. const case13image = "localhost:5000/mariadb:10.1.33"
  863. var case13containers = []string{"mariadb"}
  864. const case13out = `---
  865. apiVersion: flux.weave.works/v1beta1
  866. kind: HelmRelease
  867. metadata:
  868. name: mariadb
  869. namespace: maria
  870. spec:
  871. chart:
  872. repository: https://example.com/charts
  873. name: mariadb
  874. version: 1.1.2
  875. values:
  876. mariadb:
  877. image: localhost:5000/mariadb
  878. tag: 10.1.33
  879. persistence:
  880. enabled: false
  881. workProperly: true
  882. sidecar:
  883. image: sidecar:v1
  884. `
  885. const case14 = `---
  886. apiVersion: helm.fluxcd.io/v1
  887. kind: HelmRelease
  888. metadata:
  889. name: mariadb
  890. namespace: maria
  891. annotations:
  892. repository.fluxcd.io/custom: mariadb.customImage
  893. tag.fluxcd.io/custom: mariadb.customTag
  894. spec:
  895. chart:
  896. repository: https://example.com/charts
  897. name: mariadb
  898. version: 1.1.2
  899. values:
  900. mariadb:
  901. customImage: localhost:5000/mariadb
  902. customTag: 10.1.30-r1
  903. persistence:
  904. enabled: false
  905. workProperly: true
  906. sidecar:
  907. image: sidecar:v1
  908. `
  909. const case14resource = "maria:helmrelease/mariadb"
  910. var case14ImageMap = kresource.ContainerImageMap{
  911. BasePath: kresource.ImageBasePath,
  912. Repository: "mariadb.customImage",
  913. Tag: "mariadb.customTag",
  914. }
  915. const case14image = "localhost:5000/mariadb:10.1.33"
  916. const case14out = `---
  917. apiVersion: helm.fluxcd.io/v1
  918. kind: HelmRelease
  919. metadata:
  920. name: mariadb
  921. namespace: maria
  922. annotations:
  923. repository.fluxcd.io/custom: mariadb.customImage
  924. tag.fluxcd.io/custom: mariadb.customTag
  925. spec:
  926. chart:
  927. repository: https://example.com/charts
  928. name: mariadb
  929. version: 1.1.2
  930. values:
  931. mariadb:
  932. customImage: localhost:5000/mariadb
  933. customTag: 10.1.33
  934. persistence:
  935. enabled: false
  936. workProperly: true
  937. sidecar:
  938. image: sidecar:v1
  939. `
  940. const case15 = `---
  941. apiVersion: extensions/v1beta1
  942. kind: Deployment
  943. metadata:
  944. name: weave
  945. spec:
  946. replicas: 1
  947. template:
  948. metadata:
  949. labels:
  950. name: weave
  951. spec:
  952. initContainers:
  953. - name: weave
  954. image: 'weaveworks/weave-kube:2.2.0'
  955. `
  956. const case15resource = "default:deployment/weave"
  957. const case15image = "weaveworks/weave-kube:2.2.1"
  958. var case15containers = []string{"weave"}
  959. const case15out = `---
  960. apiVersion: extensions/v1beta1
  961. kind: Deployment
  962. metadata:
  963. name: weave
  964. spec:
  965. replicas: 1
  966. template:
  967. metadata:
  968. labels:
  969. name: weave
  970. spec:
  971. initContainers:
  972. - name: weave
  973. image: 'weaveworks/weave-kube:2.2.1'
  974. `