Skip to content

Commit

Permalink
Minimal deployment operator change (#117)
Browse files Browse the repository at this point in the history
* Minimal deployment operator change

Will help with usecases where pod labels need to be set explicitly

* add better values merge logic
  • Loading branch information
michaeljguarino authored Feb 7, 2024
1 parent 498ac9f commit 1fbbfc4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/deployment-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: deployment-operator
description: creates a new instance of the plural deployment operator
type: application
version: 0.4.5
version: 0.4.6
appVersion: "0.4.5"
maintainers:
- name: Plural
Expand Down
3 changes: 3 additions & 0 deletions charts/deployment-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
{{- end }}
labels:
{{- include "deployment-operator.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
1 change: 1 addition & 0 deletions charts/deployment-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ serviceAccount:
rbac:
clusterRole: cluster-admin

podLabels: {}
podAnnotations: {}
# prometheus.io/scrape: "true"
# prometheus.io/path: "/metrics"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/pluralsh/deployment-operator
go 1.21

require (
dario.cat/mergo v1.0.0
github.com/Masterminds/semver/v3 v3.2.1
github.com/Masterminds/sprig/v3 v3.2.3
github.com/Yamashou/gqlgenc v0.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
Expand Down
25 changes: 23 additions & 2 deletions pkg/manifests/template/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (h *helm) values(svc *console.ServiceDeploymentExtended) (map[string]interf
if err != nil {
return currentMap, err
}
currentMap = lo.Assign(currentMap, nextMap)
currentMap = merge(currentMap, nextMap)
}
}

Expand All @@ -166,7 +166,28 @@ func (h *helm) values(svc *console.ServiceDeploymentExtended) (map[string]interf
return currentMap, nil
}

return lo.Assign(currentMap, overrides), nil
return merge(currentMap, overrides), nil
}

func merge(m1, m2 map[string]interface{}) map[string]interface{} {
// lifted from helm's merge code
out := make(map[string]interface{}, len(m1))
for k, v := range m1 {
out[k] = v
}

for k, v := range m2 {
if v, ok := v.(map[string]interface{}); ok {
if bv, ok := out[k]; ok {
if bv, ok := bv.(map[string]interface{}); ok {
out[k] = merge(bv, v)
continue
}
}
}
out[k] = v
}
return out
}

func (h *helm) valuesFile(svc *console.ServiceDeploymentExtended, filename string) (map[string]interface{}, error) {
Expand Down

0 comments on commit 1fbbfc4

Please sign in to comment.