Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit 7419b78

Browse files
authored
Merge pull request #1026 from laverya/kustomize-state-storage
Kustomize state storage
2 parents d3c228d + d5406b4 commit 7419b78

39 files changed

+921
-26
lines changed

integration/init/grafana-preserve-state/metadata.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ upstream: "https://github.com/helm/charts/tree/353ba5ef6467fd64035b7d5446df426f8
22
args:
33
- --preserve-state
44
- --prefer-git
5+
- --files-in-state
6+
edit_args:
7+
- --files-in-state
58
skip_cleanup: false

integration/init/integration_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
type TestMetadata struct {
2424
Upstream string `yaml:"upstream"`
2525
Args []string `yaml:"args"`
26+
EditArgs []string `yaml:"edit_args"`
2627
MakeAbsolute bool `yaml:"make_absolute"`
2728
SkipEdit bool `yaml:"skip_edit"`
2829
// debugging
@@ -218,11 +219,11 @@ var _ = Describe("ship init with arbitrary upstream", func() {
218219
editCmd := cli.RootCmd()
219220
editBuf := new(bytes.Buffer)
220221
editCmd.SetOutput(editBuf)
221-
editCmd.SetArgs([]string{
222+
editCmd.SetArgs(append([]string{
222223
"edit",
223224
"--headless",
224225
"--log-level=off",
225-
})
226+
}, testMetadata.EditArgs...))
226227

227228
err = editCmd.Execute()
228229
Expect(err).NotTo(HaveOccurred())
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
args: []
1+
args:
2+
- --files-in-state
23

34
skip_cleanup: false
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
args: ["--prefer-git"]
1+
args:
2+
- "--prefer-git"
3+
- --files-in-state
24
skip_cleanup: false

integration/update/integration_test.go

+22-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"os"
99
"path"
10+
"path/filepath"
1011
"testing"
1112

1213
"github.com/docker/docker/client"
@@ -65,24 +66,14 @@ var _ = Describe("ship update", func() {
6566
testOutputPath, err = ioutil.TempDir(testPath, "_test_")
6667
Expect(err).NotTo(HaveOccurred())
6768

68-
// create `/test/.ship/state.json` and copy in the input state file before the test runs
69-
err := os.Mkdir(path.Join(testOutputPath, ".ship"), 0777)
70-
Expect(err).NotTo(HaveOccurred())
71-
outputStateFile := path.Join(testOutputPath, ".ship/state.json")
72-
73-
// read .ship/state.json from input state file
74-
stateFile, err := ioutil.ReadFile(path.Join(testInputPath, ".ship/state.json"))
75-
Expect(err).NotTo(HaveOccurred())
69+
recursiveCopy(testInputPath, testOutputPath)
7670

7771
// the test needs to execute in the same directory throughout the lifecycle of `ship update`
7872
testInputPath = testOutputPath
7973

80-
// copy .ship/state.json from testInputPath to testOutputPath
81-
err = ioutil.WriteFile(outputStateFile, stateFile, 0777)
74+
err = os.Chdir(testOutputPath)
8275
Expect(err).NotTo(HaveOccurred())
8376

84-
os.Chdir(testOutputPath)
85-
8677
// read the test metadata
8778
testMetadata = readMetadata(testPath)
8879
}, 20)
@@ -151,3 +142,22 @@ func readMetadata(testPath string) TestMetadata {
151142

152143
return testMetadata
153144
}
145+
146+
func recursiveCopy(sourceDir, destDir string) {
147+
err := os.MkdirAll(destDir, os.ModePerm)
148+
Expect(err).NotTo(HaveOccurred())
149+
srcFiles, err := ioutil.ReadDir(sourceDir)
150+
Expect(err).NotTo(HaveOccurred())
151+
for _, file := range srcFiles {
152+
if file.IsDir() {
153+
recursiveCopy(filepath.Join(sourceDir, file.Name()), filepath.Join(destDir, file.Name()))
154+
} else {
155+
// is file
156+
contents, err := ioutil.ReadFile(filepath.Join(sourceDir, file.Name()))
157+
Expect(err).NotTo(HaveOccurred())
158+
159+
err = ioutil.WriteFile(filepath.Join(destDir, file.Name()), contents, file.Mode())
160+
Expect(err).NotTo(HaveOccurred())
161+
}
162+
}
163+
}

integration/update/jenkins-deployment-labels/metadata.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
args: ["--prefer-git"]
1+
args:
2+
- "--prefer-git"
3+
- --files-in-state
24

35
skip_cleanup: false
46
ignoredFiles:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"v1": {
3+
"config": {},
4+
"releaseName": "ship",
5+
"upstream": "https://github.com/replicatedhq/test-charts/tree/960955cdcf61891c3b5ff27c25dcde0184926add/plain-k8s-no-trailing-newline",
6+
"upstreamContents": {
7+
"upstreamFiles": [
8+
{
9+
"filePath": "frontend-deployment.yaml",
10+
"fileContents": "YXBpVmVyc2lvbjogYXBwcy92MSAjICBmb3IgazhzIHZlcnNpb25zIGJlZm9yZSAxLjkuMCB1c2UgYXBwcy92MWJldGEyICBhbmQgYmVmb3JlIDEuOC4wIHVzZSBleHRlbnNpb25zL3YxYmV0YTEKa2luZDogRGVwbG95bWVudAptZXRhZGF0YToKICBuYW1lOiBmcm9udGVuZApzcGVjOgogIHNlbGVjdG9yOgogICAgbWF0Y2hMYWJlbHM6CiAgICAgIGFwcDogZ3Vlc3Rib29rCiAgICAgIHRpZXI6IGZyb250ZW5kCiAgcmVwbGljYXM6IDMKICB0ZW1wbGF0ZToKICAgIG1ldGFkYXRhOgogICAgICBsYWJlbHM6CiAgICAgICAgYXBwOiBndWVzdGJvb2sKICAgICAgICB0aWVyOiBmcm9udGVuZAogICAgc3BlYzoKICAgICAgY29udGFpbmVyczoKICAgICAgLSBuYW1lOiBwaHAtcmVkaXMKICAgICAgICBpbWFnZTogZ2NyLmlvL2dvb2dsZS1zYW1wbGVzL2diLWZyb250ZW5kOnY0CiAgICAgICAgcmVzb3VyY2VzOgogICAgICAgICAgcmVxdWVzdHM6CiAgICAgICAgICAgIGNwdTogMTAwbQogICAgICAgICAgICBtZW1vcnk6IDEwME1pCiAgICAgICAgZW52OgogICAgICAgIC0gbmFtZTogR0VUX0hPU1RTX0ZST00KICAgICAgICAgIHZhbHVlOiBkbnMKICAgICAgICAgICMgSWYgeW91ciBjbHVzdGVyIGNvbmZpZyBkb2VzIG5vdCBpbmNsdWRlIGEgZG5zIHNlcnZpY2UsIHRoZW4gdG8KICAgICAgICAgICMgaW5zdGVhZCBhY2Nlc3MgZW52aXJvbm1lbnQgdmFyaWFibGVzIHRvIGZpbmQgc2VydmljZSBob3N0CiAgICAgICAgICAjIGluZm8sIGNvbW1lbnQgb3V0IHRoZSAndmFsdWU6IGRucycgbGluZSBhYm92ZSwgYW5kIHVuY29tbWVudCB0aGUKICAgICAgICAgICMgbGluZSBiZWxvdzoKICAgICAgICAgICMgdmFsdWU6IGVudgogICAgICAgIHBvcnRzOgogICAgICAgIC0gY29udGFpbmVyUG9ydDogODA="
11+
},
12+
{
13+
"filePath": "frontend-service.yaml",
14+
"fileContents": "YXBpVmVyc2lvbjogdjEKa2luZDogU2VydmljZQptZXRhZGF0YToKICBuYW1lOiBmcm9udGVuZAogIGxhYmVsczoKICAgIGFwcDogZ3Vlc3Rib29rCiAgICB0aWVyOiBmcm9udGVuZApzcGVjOgogICMgY29tbWVudCBvciBkZWxldGUgdGhlIGZvbGxvd2luZyBsaW5lIGlmIHlvdSB3YW50IHRvIHVzZSBhIExvYWRCYWxhbmNlcgogIHR5cGU6IE5vZGVQb3J0IAogICMgaWYgeW91ciBjbHVzdGVyIHN1cHBvcnRzIGl0LCB1bmNvbW1lbnQgdGhlIGZvbGxvd2luZyB0byBhdXRvbWF0aWNhbGx5IGNyZWF0ZQogICMgYW4gZXh0ZXJuYWwgbG9hZC1iYWxhbmNlZCBJUCBmb3IgdGhlIGZyb250ZW5kIHNlcnZpY2UuCiAgIyB0eXBlOiBMb2FkQmFsYW5jZXIKICBwb3J0czoKICAtIHBvcnQ6IDgwCiAgc2VsZWN0b3I6CiAgICBhcHA6IGd1ZXN0Ym9vawogICAgdGllcjogImZyb250ZW5kIg=="
15+
},
16+
{
17+
"filePath": "redis-master-deployment.yaml",
18+
"fileContents": "YXBpVmVyc2lvbjogYXBwcy92MSAjICBmb3IgazhzIHZlcnNpb25zIGJlZm9yZSAxLjkuMCB1c2UgYXBwcy92MWJldGEyICBhbmQgYmVmb3JlIDEuOC4wIHVzZSBleHRlbnNpb25zL3YxYmV0YTEKa2luZDogRGVwbG95bWVudAptZXRhZGF0YToKICBuYW1lOiByZWRpcy1tYXN0ZXIKc3BlYzoKICBzZWxlY3RvcjoKICAgIG1hdGNoTGFiZWxzOgogICAgICBhcHA6IHJlZGlzCiAgICAgIHJvbGU6IG1hc3RlcgogICAgICB0aWVyOiBiYWNrZW5kCiAgcmVwbGljYXM6IDEKICB0ZW1wbGF0ZToKICAgIG1ldGFkYXRhOgogICAgICBsYWJlbHM6CiAgICAgICAgYXBwOiByZWRpcwogICAgICAgIHJvbGU6IG1hc3RlcgogICAgICAgIHRpZXI6IGJhY2tlbmQKICAgIHNwZWM6CiAgICAgIGNvbnRhaW5lcnM6CiAgICAgIC0gbmFtZTogbWFzdGVyCiAgICAgICAgaW1hZ2U6IGs4cy5nY3IuaW8vcmVkaXM6ZTJlICAjIG9yIGp1c3QgaW1hZ2U6IHJlZGlzCiAgICAgICAgcmVzb3VyY2VzOgogICAgICAgICAgcmVxdWVzdHM6CiAgICAgICAgICAgIGNwdTogMTAwbQogICAgICAgICAgICBtZW1vcnk6IDEwME1pCiAgICAgICAgcG9ydHM6CiAgICAgICAgLSBjb250YWluZXJQb3J0OiA2Mzc5"
19+
},
20+
{
21+
"filePath": "redis-master-service.yaml",
22+
"fileContents": "YXBpVmVyc2lvbjogdjEKa2luZDogU2VydmljZQptZXRhZGF0YToKICBuYW1lOiByZWRpcy1tYXN0ZXIKICBsYWJlbHM6CiAgICBhcHA6IHJlZGlzCiAgICByb2xlOiBtYXN0ZXIKICAgIHRpZXI6IGJhY2tlbmQKc3BlYzoKICBwb3J0czoKICAtIHBvcnQ6IDYzNzkKICAgIHRhcmdldFBvcnQ6IDYzNzkKICBzZWxlY3RvcjoKICAgIGFwcDogcmVkaXMKICAgIHJvbGU6IG1hc3RlcgogICAgdGllcjogImJhY2tlbmQi"
23+
},
24+
{
25+
"filePath": "redis-slave-deployment.yaml",
26+
"fileContents": "YXBpVmVyc2lvbjogYXBwcy92MSAjICBmb3IgazhzIHZlcnNpb25zIGJlZm9yZSAxLjkuMCB1c2UgYXBwcy92MWJldGEyICBhbmQgYmVmb3JlIDEuOC4wIHVzZSBleHRlbnNpb25zL3YxYmV0YTEKa2luZDogRGVwbG95bWVudAptZXRhZGF0YToKICBuYW1lOiByZWRpcy1zbGF2ZQpzcGVjOgogIHNlbGVjdG9yOgogICAgbWF0Y2hMYWJlbHM6CiAgICAgIGFwcDogcmVkaXMKICAgICAgcm9sZTogc2xhdmUKICAgICAgdGllcjogYmFja2VuZAogIHJlcGxpY2FzOiAyCiAgdGVtcGxhdGU6CiAgICBtZXRhZGF0YToKICAgICAgbGFiZWxzOgogICAgICAgIGFwcDogcmVkaXMKICAgICAgICByb2xlOiBzbGF2ZQogICAgICAgIHRpZXI6IGJhY2tlbmQKICAgIHNwZWM6CiAgICAgIGNvbnRhaW5lcnM6CiAgICAgIC0gbmFtZTogc2xhdmUKICAgICAgICBpbWFnZTogZ2NyLmlvL2dvb2dsZV9zYW1wbGVzL2diLXJlZGlzc2xhdmU6djEKICAgICAgICByZXNvdXJjZXM6CiAgICAgICAgICByZXF1ZXN0czoKICAgICAgICAgICAgY3B1OiAxMDBtCiAgICAgICAgICAgIG1lbW9yeTogMTAwTWkKICAgICAgICBlbnY6CiAgICAgICAgLSBuYW1lOiBHRVRfSE9TVFNfRlJPTQogICAgICAgICAgdmFsdWU6IGRucwogICAgICAgICAgIyBJZiB5b3VyIGNsdXN0ZXIgY29uZmlnIGRvZXMgbm90IGluY2x1ZGUgYSBkbnMgc2VydmljZSwgdGhlbiB0bwogICAgICAgICAgIyBpbnN0ZWFkIGFjY2VzcyBhbiBlbnZpcm9ubWVudCB2YXJpYWJsZSB0byBmaW5kIHRoZSBtYXN0ZXIKICAgICAgICAgICMgc2VydmljZSdzIGhvc3QsIGNvbW1lbnQgb3V0IHRoZSAndmFsdWU6IGRucycgbGluZSBhYm92ZSwgYW5kCiAgICAgICAgICAjIHVuY29tbWVudCB0aGUgbGluZSBiZWxvdzoKICAgICAgICAgICMgdmFsdWU6IGVudgogICAgICAgIHBvcnRzOgogICAgICAgIC0gY29udGFpbmVyUG9ydDogNjM3OQ=="
27+
},
28+
{
29+
"filePath": "redis-slave-service.yaml",
30+
"fileContents": "YXBpVmVyc2lvbjogdjEKa2luZDogU2VydmljZQptZXRhZGF0YToKICBuYW1lOiByZWRpcy1zbGF2ZQogIGxhYmVsczoKICAgIGFwcDogcmVkaXMKICAgIHJvbGU6IHNsYXZlCiAgICB0aWVyOiBiYWNrZW5kCnNwZWM6CiAgcG9ydHM6CiAgLSBwb3J0OiA2Mzc5CiAgc2VsZWN0b3I6CiAgICBhcHA6IHJlZGlzCiAgICByb2xlOiBzbGF2ZQogICAgdGllcjogImJhY2tlbmQiCiAgICB6cXVvdGVudW06ICIxMjMi"
31+
}
32+
]
33+
},
34+
"contentSHA": "1e35b69d101d049068451671a9ef5407db239ecc0520913e93c219b29fb6810a"
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: frontend
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: guestbook
9+
tier: frontend
10+
replicas: 3
11+
template:
12+
metadata:
13+
labels:
14+
app: guestbook
15+
tier: frontend
16+
spec:
17+
containers:
18+
- name: php-redis
19+
image: gcr.io/google-samples/gb-frontend:v4
20+
resources:
21+
requests:
22+
cpu: 100m
23+
memory: 100Mi
24+
env:
25+
- name: GET_HOSTS_FROM
26+
value: dns
27+
# If your cluster config does not include a dns service, then to
28+
# instead access environment variables to find service host
29+
# info, comment out the 'value: dns' line above, and uncomment the
30+
# line below:
31+
# value: env
32+
ports:
33+
- containerPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: frontend
5+
labels:
6+
app: guestbook
7+
tier: frontend
8+
spec:
9+
# comment or delete the following line if you want to use a LoadBalancer
10+
type: NodePort
11+
# if your cluster supports it, uncomment the following to automatically create
12+
# an external load-balanced IP for the frontend service.
13+
# type: LoadBalancer
14+
ports:
15+
- port: 80
16+
selector:
17+
app: guestbook
18+
tier: "frontend"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: ""
2+
apiversion: ""
3+
resources:
4+
- frontend-deployment.yaml
5+
- frontend-service.yaml
6+
- redis-master-deployment.yaml
7+
- redis-master-service.yaml
8+
- redis-slave-deployment.yaml
9+
- redis-slave-service.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: redis-master
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: redis
9+
role: master
10+
tier: backend
11+
replicas: 1
12+
template:
13+
metadata:
14+
labels:
15+
app: redis
16+
role: master
17+
tier: backend
18+
spec:
19+
containers:
20+
- name: master
21+
image: k8s.gcr.io/redis:e2e # or just image: redis
22+
resources:
23+
requests:
24+
cpu: 100m
25+
memory: 100Mi
26+
ports:
27+
- containerPort: 6379
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: redis-master
5+
labels:
6+
app: redis
7+
role: master
8+
tier: backend
9+
spec:
10+
ports:
11+
- port: 6379
12+
targetPort: 6379
13+
selector:
14+
app: redis
15+
role: master
16+
tier: "backend"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: redis-slave
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: redis
9+
role: slave
10+
tier: backend
11+
replicas: 2
12+
template:
13+
metadata:
14+
labels:
15+
app: redis
16+
role: slave
17+
tier: backend
18+
spec:
19+
containers:
20+
- name: slave
21+
image: gcr.io/google_samples/gb-redisslave:v1
22+
resources:
23+
requests:
24+
cpu: 100m
25+
memory: 100Mi
26+
env:
27+
- name: GET_HOSTS_FROM
28+
value: dns
29+
# If your cluster config does not include a dns service, then to
30+
# instead access an environment variable to find the master
31+
# service's host, comment out the 'value: dns' line above, and
32+
# uncomment the line below:
33+
# value: env
34+
ports:
35+
- containerPort: 6379
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: redis-slave
5+
labels:
6+
app: redis
7+
role: slave
8+
tier: backend
9+
spec:
10+
ports:
11+
- port: 6379
12+
selector:
13+
app: redis
14+
role: slave
15+
tier: "backend"
16+
zquotenum: "123"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"op":"remove","path":"/metadata/labels/chart"}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"op":"remove","path":"/metadata/labels/heritage"}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kind: ""
2+
apiversion: ""
3+
bases:
4+
- ../../base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: ""
2+
apiversion: ""
3+
patchesStrategicMerge:
4+
- redis-master-service.yaml
5+
- redis-slave-service.yaml
6+
bases:
7+
- ../defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: redis
6+
role: master
7+
tier: backend
8+
name: redis-master
9+
spec:
10+
selector:
11+
zquotenum: "456"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: redis
6+
role: slave
7+
tier: backend
8+
name: redis-slave
9+
spec:
10+
selector:
11+
zquotenum: "987"

0 commit comments

Comments
 (0)