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

Commit a7858a2

Browse files
authored
Merge pull request #1018 from laverya/exclude-kubernetes-patches-with-resources
Exclude kubernetes patches with resources
2 parents 4f2461e + cefaab2 commit a7858a2

File tree

7 files changed

+726
-107
lines changed

7 files changed

+726
-107
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
bases:
2-
- ../../base
1+
kind: ""
2+
apiversion: ""
33
patchesJson6902:
4-
- path: chart-patch.json
5-
target:
4+
- target:
65
group: apps
6+
version: v1beta2
77
kind: Deployment
88
name: basic
9-
version: v1beta2
10-
- path: heritage-patch.json
11-
target:
9+
path: chart-patch.json
10+
- target:
1211
group: apps
12+
version: v1beta2
1313
kind: Deployment
1414
name: basic
15-
version: v1beta2
15+
path: heritage-patch.json
16+
bases:
17+
- ../../base
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
bases:
2-
- ../../base
1+
kind: ""
2+
apiversion: ""
33
patchesJson6902:
4-
- path: chart-patch.json
5-
target:
4+
- target:
5+
version: v1
66
kind: PersistentVolumeClaim
77
name: jenkins
8+
path: chart-patch.json
9+
- target:
810
version: v1
9-
- path: heritage-patch.json
10-
target:
1111
kind: PersistentVolumeClaim
1212
name: jenkins
13+
path: heritage-patch.json
14+
- target:
1315
version: v1
14-
- path: chart-patch.json
15-
target:
1616
kind: Service
1717
name: jenkins-agent
18-
version: v1
19-
- path: chart-patch.json
20-
target:
18+
path: chart-patch.json
19+
- target:
2120
group: apps
21+
version: v1beta1
2222
kind: Deployment
2323
name: jenkins
24-
version: v1beta1
25-
- path: heritage-patch.json
26-
target:
24+
path: chart-patch.json
25+
- target:
2726
group: apps
27+
version: v1beta1
2828
kind: Deployment
2929
name: jenkins
30-
version: v1beta1
31-
- path: chart-patch.json
32-
target:
30+
path: heritage-patch.json
31+
- target:
32+
version: v1
3333
kind: Service
3434
name: jenkins
35+
path: chart-patch.json
36+
- target:
3537
version: v1
36-
- path: heritage-patch.json
37-
target:
3838
kind: Service
3939
name: jenkins
40+
path: heritage-patch.json
41+
- target:
4042
version: v1
41-
- path: chart-patch.json
42-
target:
4343
kind: Secret
4444
name: jenkins
45+
path: chart-patch.json
46+
- target:
4547
version: v1
46-
- path: heritage-patch.json
47-
target:
4848
kind: Secret
4949
name: jenkins
50-
version: v1
50+
path: heritage-patch.json
51+
bases:
52+
- ../../base

pkg/lifecycle/kustomize/daemonless.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kustomize
22

33
import (
44
"context"
5+
"path/filepath"
56
"strings"
67

78
"github.com/go-kit/kit/log"
@@ -11,6 +12,7 @@ import (
1112
yaml "gopkg.in/yaml.v2"
1213

1314
"github.com/replicatedhq/ship/pkg/api"
15+
"github.com/replicatedhq/ship/pkg/constants"
1416
"github.com/replicatedhq/ship/pkg/lifecycle"
1517
"github.com/replicatedhq/ship/pkg/patch"
1618
"github.com/replicatedhq/ship/pkg/state"
@@ -40,12 +42,6 @@ func NewDaemonlessKustomizer(
4042
func (l *Kustomizer) Execute(ctx context.Context, release *api.Release, step api.Kustomize) error {
4143
debug := level.Debug(log.With(l.Logger, "struct", "daemonless.kustomizer", "method", "execute"))
4244

43-
debug.Log("event", "write.base.kustomization.yaml")
44-
err := l.writeBase(step.Base)
45-
if err != nil {
46-
return errors.Wrap(err, "write base kustomization")
47-
}
48-
4945
current, err := l.State.CachedState()
5046
if err != nil {
5147
return errors.Wrap(err, "load state")
@@ -61,6 +57,27 @@ func (l *Kustomizer) Execute(ctx context.Context, release *api.Release, step api
6157
shipOverlay = kustomizeState.Ship()
6258
}
6359

60+
debug.Log("event", "base.kustomization.check")
61+
existingKustomize, err := l.FS.Exists(filepath.Join(step.Base, "kustomization.yaml"))
62+
if err != nil {
63+
return errors.Wrapf(err, "check for kustomization in %s", step.Base)
64+
}
65+
if existingKustomize {
66+
// no need to write base, kustomization already exists
67+
// but we do need to remove excluded bases
68+
debug.Log("event", "exclude.kustomize.resources")
69+
err = util.ExcludeKubernetesResources(l.FS, step.Base, constants.DefaultOverlaysPath, shipOverlay.ExcludedBases)
70+
if err != nil {
71+
return errors.Wrapf(err, "write base %s", step.Base)
72+
}
73+
} else {
74+
debug.Log("event", "write.base.kustomization.yaml")
75+
err = l.writeBase(step.Base)
76+
if err != nil {
77+
return errors.Wrap(err, "write base kustomization")
78+
}
79+
}
80+
6481
fs, err := l.getPotentiallyChrootedFs(release)
6582
if err != nil {
6683
debug.Log("event", "getFs.fail")

pkg/lifecycle/kustomize/kustomizer.go

-10
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,6 @@ func (l *Kustomizer) writeBase(base string) error {
214214
}
215215
shipOverlay := currentKustomize.Ship()
216216

217-
existingKustomize, err := l.FS.Exists(filepath.Join(base, "kustomization.yaml"))
218-
if err != nil {
219-
return errors.Wrapf(err, "check for kustomization in %s", base)
220-
}
221-
if existingKustomize {
222-
// no need to write base, kustomization already exists
223-
// but we do need to remove excluded bases
224-
return errors.Wrapf(util.ExcludeKubernetesResources(l.FS, base, shipOverlay.ExcludedBases), "write base %s", base)
225-
}
226-
227217
baseKustomization := ktypes.Kustomization{}
228218
if err := l.FS.Walk(
229219
base,

0 commit comments

Comments
 (0)