Skip to content

Commit 8e9cbf0

Browse files
Merge pull request #3927 from pmtk/delete-manifests
USHIFT-4115: Manifest deletion
2 parents c5482c9 + bdffb9b commit 8e9cbf0

File tree

12 files changed

+356
-146
lines changed

12 files changed

+356
-146
lines changed

docs/user/howto_config.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Setting the `memoryLimitMB` to a value greater than 0 will result in a soft memo
166166

167167
Please note that values close to the floor may be more likely to impact etcd performance - the memory limit is a trade-off of memory footprint and etcd performance. The lower the limit, the more time etcd will spend on paging memory to disk and will take longer to respond to queries or even timing requests out if the limit is low and the etcd usage is high.
168168

169-
# Auto-applying Manifests
169+
## Auto-applying Manifests
170170

171171
MicroShift leverages `kustomize` for Kubernetes-native templating and declarative management of resource objects. Upon start-up, it searches `/etc/microshift/manifests`, `/etc/microshift/manifests.d/*`, `/usr/lib/microshift/manifests`, and `/usr/lib/microshift/manifests.d/*` directories for a `kustomization.yaml`, `kustomization.yml`, or `Kustomization` file. If it finds one, it automatically runs `kubectl apply -k` command to apply that manifest.
172172

@@ -204,7 +204,7 @@ manifests:
204204
```
205205

206206

207-
## Manifest Example
207+
### Manifest Example
208208

209209
The example demonstrates automatic deployment of a `busybox` container using `kustomize` manifests in the `/etc/microshift/manifests` directory.
210210

@@ -262,6 +262,42 @@ sudo systemctl restart microshift
262262
oc get pods -n busybox
263263
```
264264

265+
### Deleting Manifests
266+
267+
MicroShift supports resource manifest deletion for data removal or upgrade scenarios.
268+
Upgrade scenarios include situations where some objects should be removed, but not all of them to keep the data.
269+
270+
MicroShift scans `delete` subdirectories of configured manifests directory.
271+
Given the default configuration, MicroShift will run `kubectl delete -k --ignore-not-found=true .` for any kustomization file found in following paths:
272+
- `/etc/microshift/manifests/delete`
273+
- `/etc/microshift/manifests.d/delete/*`
274+
- `/usr/lib/microshift/manifests/delete`
275+
- `/usr/lib/microshift/manifests.d/delete/*`
276+
277+
For delete scenarios, just move the existing manifest to one of the `delete` directories.
278+
279+
For resource removal in upgrade scenarios, is not necessary to include `spec`. Specify `group/version`, `kind`, `name`, and `namespace` of an object.
280+
```yaml
281+
# kustomization.yaml
282+
apiVersion: kustomize.config.k8s.io/v1beta1
283+
kind: Kustomization
284+
resources:
285+
- all_resources.yaml
286+
287+
# all_resources.yaml
288+
kind: DaemonSet
289+
apiVersion: apps/v1
290+
metadata:
291+
name: multus
292+
namespace: openshift-multus
293+
---
294+
apiVersion: apps/v1
295+
kind: DaemonSet
296+
metadata:
297+
name: dhcp-daemon
298+
namespace: openshift-multus
299+
```
300+
265301
## Storage Configuration
266302

267303
MicroShift's included CSI plugin manages LVM LogicalVolumes to provide persistent workload storage. For LVMS

etcd/vendor/github.com/openshift/microshift/pkg/config/manifests.go

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/manifests.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,33 @@ type Manifests struct {
3434
// are returned in the order given in the configuration file. The
3535
// results of any glob patterns are sorted lexicographically.
3636
func (m *Manifests) GetKustomizationPaths() ([]string, error) {
37+
return getKustomizationPaths(m.KustomizePaths)
38+
}
39+
40+
func (m *Manifests) GetKustomizationDeletePaths() ([]string, error) {
41+
deletePaths := make([]string, 0, len(m.KustomizePaths))
42+
for _, path := range m.KustomizePaths {
43+
// If kustomize path ends with "*": add "delete" dir before it.
44+
// Otherwise, just add it at the end.
45+
dir, file := filepath.Split(path)
46+
newPath := filepath.Join(dir, file, "delete")
47+
if file == "*" {
48+
newPath = filepath.Join(dir, "delete", file)
49+
}
50+
deletePaths = append(deletePaths, newPath)
51+
}
52+
return getKustomizationPaths(deletePaths)
53+
}
54+
55+
func getKustomizationPaths(kustomizePaths []string) ([]string, error) {
3756
kustomizationFileNames := konfig.RecognizedKustomizationFileNames()
3857
results := []string{}
39-
for _, path := range m.KustomizePaths {
58+
for _, path := range kustomizePaths {
4059
for _, filename := range kustomizationFileNames {
4160
pattern := filepath.Join(path, filename)
4261
matches, err := filepath.Glob(pattern)
4362
if err != nil {
44-
return nil, fmt.Errorf("Could not understand kustomizePath value %v: %w", path, err)
63+
return nil, fmt.Errorf("could not understand kustomizePath value %v: %w", path, err)
4564
}
4665
if len(matches) == 0 {
4766
klog.Infof("No kustomize path matches %v", pattern)

pkg/kustomize/apply.go

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)