Skip to content

Commit

Permalink
changed: tidy up the main example
Browse files Browse the repository at this point in the history
  • Loading branch information
aabouzaid committed Sep 10, 2023
1 parent 77df539 commit 70c84b8
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 36 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ apiVersion: generators.kustomize.aabouzaid.com/v1alpha1
kind: Merger
metadata:
name: merge
annotations:
# Containerized KRM function.
config.kubernetes.io/function: |
container:
image: ghcr.io/aabouzaid/kustomize-generator-merger
mounts:
- type: bind
src: ./
dst: /mnt
# Exec KRM functions.
# config.kubernetes.io/function: |
# exec:
# path: ./kustomize-plugin-merger
spec:
resources:
- name: example
Expand All @@ -66,6 +79,8 @@ spec:
# - Patch: Produce a single output by merging all sources together then with the destination.
method: overlay
files:
# The same as in the KRM container above.
root: /mnt
sources:
- src01.yaml
- src02.yaml
Expand Down
8 changes: 8 additions & 0 deletions examples/krm-and-kustomize/input/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: base
spec:
containers:
- name: sidecar
image: sidecar
8 changes: 8 additions & 0 deletions examples/krm-and-kustomize/input/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
metadata:
name: dev
spec:
containers:
- name: dev
image: dev:1.0.0
ports:
- containerPort: 80
8 changes: 8 additions & 0 deletions examples/krm-and-kustomize/input/stage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
metadata:
name: stage
spec:
containers:
- name: stage
image: stage:1.0.0
ports:
- containerPort: 80
5 changes: 5 additions & 0 deletions examples/krm-and-kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

generators:
- merger.yaml
34 changes: 34 additions & 0 deletions examples/krm-and-kustomize/merger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
apiVersion: generators.kustomize.aabouzaid.com/v1alpha1
kind: Merger
metadata:
name: merge
annotations:
# Containerized KRM function.
config.kubernetes.io/function: |
container:
image: ghcr.io/aabouzaid/kustomize-generator-merger
mounts:
- type: bind
src: ./
dst: /mnt
# Exec KRM functions.
# config.kubernetes.io/function: |
# exec:
# path: ./kustomize-plugin-merger
spec:
resources:
- name: my-envs
input:
method: overlay
files:
# The same as in the KRM container above.
root: /mnt
sources:
- input/dev.yaml
- input/stage.yaml
destination: input/base.yaml
merge:
strategy: append
output:
format: raw
39 changes: 39 additions & 0 deletions examples/krm-and-kustomize/resourcelist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: config.kubernetes.io/v1
kind: ResourceList
metadata:
name: krm-function-input
functionConfig:
apiVersion: generators.kustomize.aabouzaid.com/v1alpha1
kind: Merger
metadata:
name: merge
annotations:
# Containerized KRM function.
config.kubernetes.io/function: |
container:
image: ghcr.io/aabouzaid/kustomize-generator-merger
mounts:
- type: bind
src: ./
dst: /mnt
# Exec KRM functions.
# config.kubernetes.io/function: |
# exec:
# path: ./kustomize-plugin-merger
spec:
resources:
- name: my-envs
input:
method: overlay
files:
# The same as in the KRM container above.
root: /mnt
sources:
- input/dev.yaml
- input/stage.yaml
destination: input/base.yaml
merge:
strategy: append
output:
format: raw
3 changes: 0 additions & 3 deletions examples/krm-without-kustomize/input/common.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/krm-without-kustomize/input/dev.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/krm-without-kustomize/input/stage.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions examples/krm-without-kustomize/resourcelist.yaml

This file was deleted.

7 changes: 5 additions & 2 deletions pkg/merger/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ func (r *mergerResource) setInputFilesOverlay() {
for _, inputFileSource := range r.Input.Files.Sources {
r.Input.items = append(r.Input.items,
resourceInputFiles{
Sources: []string{inputFileSource},
Destination: r.Input.Files.Destination,
Sources: []string{r.Input.Files.Root + inputFileSource},
Destination: r.Input.Files.Root + r.Input.Files.Destination,
})
}
}

func (r *mergerResource) setInputFilesPatch() {
for index, inputFileSource := range r.Input.Files.Sources {
r.Input.Files.Sources[index] = r.Input.Files.Root + inputFileSource
}
r.Input.items = append(r.Input.items, r.Input.Files)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Merger manifest.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -44,6 +45,8 @@ spec:
properties:
destination:
type: string
root:
type: string
sources:
items:
type: string
Expand Down
4 changes: 3 additions & 1 deletion pkg/merger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
ResourceKind string = "Merger"
)

// Merger manifest body.
// Merger manifest.
type Merger struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Expand Down Expand Up @@ -49,6 +49,8 @@ type mergerResource struct {
//

type resourceInputFiles struct {
// +optional
Root string `yaml:"root" json:"root"`
Sources []string `yaml:"sources" json:"sources"`
Destination string `yaml:"destination" json:"destination"`
}
Expand Down

0 comments on commit 70c84b8

Please sign in to comment.