Skip to content

Commit 6287498

Browse files
nhinze23cesmarvin
authored andcommitted
Merge branch 'release/v0.14.3' into main
2 parents 299b3a9 + 32e824e commit 6287498

File tree

5 files changed

+130
-13
lines changed

5 files changed

+130
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [v0.14.3] - 2024-10-30
11+
### Fixed
12+
- [#47] map nginx dependencies to k8s equivalent dogus
13+
1014
## [v0.14.2] - 2024-10-18
1115
### Fixed
1216
- [#44] fix, that dogus with irrelevant optional dependencies were not included when sorting by dependency

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Set these to the desired values
22
ARTIFACT_ID=cesapp-lib
3-
VERSION=0.14.2
3+
VERSION=0.14.3
44

55
GOTAG?=1.18.6
66
MAKEFILES_VERSION=7.4.0

core/dogu-sort.go

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import (
66
"sort"
77
)
88

9+
var (
10+
nginxIngressDependency = Dependency{
11+
Type: DependencyTypeDogu,
12+
Name: "nginx-ingress",
13+
}
14+
k8sDependencyMapping = map[string]Dependency{
15+
"nginx": nginxIngressDependency,
16+
}
17+
)
18+
919
// SortDogusByDependency takes an unsorted slice of Dogu structs and returns a slice of Dogus ordered by the
1020
// importance of their dependencies descending, that is: the most needed dogu will be the first element.
1121
//
@@ -128,6 +138,9 @@ func toDoguSlice(dogus []interface{}) ([]*Dogu, error) {
128138
func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Dogu {
129139
var result []*Dogu
130140

141+
// we can just append all k8s mappings here, since not installed dogus will be removed in the next step
142+
dependencies = appendK8sMappedDependencies(dependencies)
143+
131144
for _, dogu := range bd.dogus {
132145
if contains(dependencies, dogu.GetSimpleName()) {
133146
result = append(result, dogu)
@@ -137,6 +150,15 @@ func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Do
137150
return result
138151
}
139152

153+
func appendK8sMappedDependencies(dependencies []Dependency) []Dependency {
154+
for _, dep := range dependencies {
155+
if _, ok := k8sDependencyMapping[dep.Name]; ok {
156+
dependencies = append(dependencies, k8sDependencyMapping[dep.Name])
157+
}
158+
}
159+
return dependencies
160+
}
161+
140162
func (bd *sortByDependency) sortDogusByInvertedDependency() ([]*Dogu, error) {
141163
dependencyEdges := bd.getDependencyEdges()
142164
sorted, err := toposort.ToposortR(dependencyEdges)

core/dogu-sort_test.go

+36-12
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ func TestSortDogusByDependencyWithError(t *testing.T) {
155155
assert.Equal(t, "a", dogus[0].Name)
156156
})
157157

158+
t.Run("should map k8s dependencies correctly and sort accordingly", func(t *testing.T) {
159+
dogus := []*Dogu{}
160+
dogus, _, err := ReadDogusFromFile("../resources/test/dogu-sort-005.json")
161+
assert.Nil(t, err)
162+
ordered, err := SortDogusByDependencyWithError(dogus)
163+
require.NoError(t, err)
164+
165+
assert.Equal(t, "nginx-ingress", ordered[0].GetSimpleName())
166+
assert.Equal(t, "nginx-static", ordered[1].GetSimpleName())
167+
assert.Equal(t, "cas", ordered[2].GetSimpleName())
168+
})
169+
158170
}
159171

160172
func stringSliceContains(slice []string, item string) bool {
@@ -265,6 +277,30 @@ func TestSortDogusByInvertedDependencyWithError(t *testing.T) {
265277
assert.ErrorContains(t, err, "error in sorting dogus by inverted dependency")
266278
assert.Nil(t, dogus)
267279
})
280+
281+
t.Run("should return dogu if only irrelevant optional dependencies are set", func(t *testing.T) {
282+
a := &Dogu{
283+
Name: "a",
284+
OptionalDependencies: []Dependency{{Type: DependencyTypeDogu, Name: "c"}},
285+
}
286+
287+
dogus, err := SortDogusByInvertedDependencyWithError([]*Dogu{a})
288+
assert.NoError(t, err)
289+
assert.Len(t, dogus, 1)
290+
assert.Equal(t, "a", dogus[0].Name)
291+
})
292+
293+
t.Run("should map k8s dependencies correctly and sort accordingly", func(t *testing.T) {
294+
dogus := []*Dogu{}
295+
dogus, _, err := ReadDogusFromFile("../resources/test/dogu-sort-005.json")
296+
assert.Nil(t, err)
297+
ordered, err := SortDogusByInvertedDependencyWithError(dogus)
298+
require.NoError(t, err)
299+
300+
assert.Equal(t, "cas", ordered[0].GetSimpleName())
301+
assert.Equal(t, "nginx-static", ordered[1].GetSimpleName())
302+
assert.Equal(t, "nginx-ingress", ordered[2].GetSimpleName())
303+
})
268304
}
269305

270306
func TestSortDogusByDependency(t *testing.T) {
@@ -322,18 +358,6 @@ func TestSortDogusByInvertedDependency(t *testing.T) {
322358
dogus := SortDogusByInvertedDependency([]*Dogu{a, b, c})
323359
assert.Nil(t, dogus)
324360
})
325-
326-
t.Run("should return dogu if only irrelevant optional dependencies are set", func(t *testing.T) {
327-
a := &Dogu{
328-
Name: "a",
329-
OptionalDependencies: []Dependency{{Type: DependencyTypeDogu, Name: "c"}},
330-
}
331-
332-
dogus, err := SortDogusByInvertedDependencyWithError([]*Dogu{a})
333-
assert.NoError(t, err)
334-
assert.Len(t, dogus, 1)
335-
assert.Equal(t, "a", dogus[0].Name)
336-
})
337361
}
338362

339363
func TestTransformsDependencyListToDoguList(t *testing.T) {

resources/test/dogu-sort-005.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[
2+
{
3+
"Name": "official/cas",
4+
"Version": "7.0.8-2",
5+
"DisplayName": "Central Authentication Service",
6+
"Dependencies": [
7+
{
8+
"type": "dogu",
9+
"name": "nginx",
10+
"version": ">=1.26.1-5"
11+
}
12+
],
13+
"OptionalDependencies": [
14+
{
15+
"type": "dogu",
16+
"name": "ldap",
17+
"version": ""
18+
}
19+
]
20+
},
21+
{
22+
"Name": "k8s/nginx-static",
23+
"Version": "1.26.1-7",
24+
"DisplayName": "Nginx Static",
25+
"Dependencies": [
26+
{
27+
"type": "dogu",
28+
"name": "nginx-ingress",
29+
"version": ""
30+
},
31+
{
32+
"type": "client",
33+
"name": "k8s-dogu-operator",
34+
"version": ""
35+
},
36+
{
37+
"type": "client",
38+
"name": "cesapp",
39+
"version": "<0.0.0"
40+
}
41+
],
42+
"OptionalDependencies": null
43+
},
44+
{
45+
"Name": "k8s/nginx-ingress",
46+
"Version": "1.11.1-3",
47+
"DisplayName": "Nginx Ingress",
48+
"Dependencies": [
49+
{
50+
"type": "client",
51+
"name": "k8s-dogu-operator",
52+
"version": ">=0.16.0"
53+
},
54+
{
55+
"type": "client",
56+
"name": "cesapp",
57+
"version": "<0.0.0"
58+
},
59+
{
60+
"type": "client",
61+
"name": "ces-setup",
62+
"version": "<0.0.0"
63+
}
64+
],
65+
"OptionalDependencies": null
66+
}
67+
]

0 commit comments

Comments
 (0)