Skip to content

Commit

Permalink
Merge branch 'release/v0.14.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nhinze23 authored and cesmarvin committed Oct 30, 2024
2 parents 299b3a9 + 32e824e commit 6287498
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v0.14.3] - 2024-10-30
### Fixed
- [#47] map nginx dependencies to k8s equivalent dogus

## [v0.14.2] - 2024-10-18
### Fixed
- [#44] fix, that dogus with irrelevant optional dependencies were not included when sorting by dependency
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Set these to the desired values
ARTIFACT_ID=cesapp-lib
VERSION=0.14.2
VERSION=0.14.3

GOTAG?=1.18.6
MAKEFILES_VERSION=7.4.0
Expand Down
22 changes: 22 additions & 0 deletions core/dogu-sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"sort"
)

var (
nginxIngressDependency = Dependency{
Type: DependencyTypeDogu,
Name: "nginx-ingress",
}
k8sDependencyMapping = map[string]Dependency{
"nginx": nginxIngressDependency,
}
)

// SortDogusByDependency takes an unsorted slice of Dogu structs and returns a slice of Dogus ordered by the
// importance of their dependencies descending, that is: the most needed dogu will be the first element.
//
Expand Down Expand Up @@ -128,6 +138,9 @@ func toDoguSlice(dogus []interface{}) ([]*Dogu, error) {
func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Dogu {
var result []*Dogu

// we can just append all k8s mappings here, since not installed dogus will be removed in the next step
dependencies = appendK8sMappedDependencies(dependencies)

for _, dogu := range bd.dogus {
if contains(dependencies, dogu.GetSimpleName()) {
result = append(result, dogu)
Expand All @@ -137,6 +150,15 @@ func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Do
return result
}

func appendK8sMappedDependencies(dependencies []Dependency) []Dependency {
for _, dep := range dependencies {
if _, ok := k8sDependencyMapping[dep.Name]; ok {
dependencies = append(dependencies, k8sDependencyMapping[dep.Name])
}
}
return dependencies
}

func (bd *sortByDependency) sortDogusByInvertedDependency() ([]*Dogu, error) {
dependencyEdges := bd.getDependencyEdges()
sorted, err := toposort.ToposortR(dependencyEdges)
Expand Down
48 changes: 36 additions & 12 deletions core/dogu-sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ func TestSortDogusByDependencyWithError(t *testing.T) {
assert.Equal(t, "a", dogus[0].Name)
})

t.Run("should map k8s dependencies correctly and sort accordingly", func(t *testing.T) {
dogus := []*Dogu{}
dogus, _, err := ReadDogusFromFile("../resources/test/dogu-sort-005.json")
assert.Nil(t, err)
ordered, err := SortDogusByDependencyWithError(dogus)
require.NoError(t, err)

assert.Equal(t, "nginx-ingress", ordered[0].GetSimpleName())
assert.Equal(t, "nginx-static", ordered[1].GetSimpleName())
assert.Equal(t, "cas", ordered[2].GetSimpleName())
})

}

func stringSliceContains(slice []string, item string) bool {
Expand Down Expand Up @@ -265,6 +277,30 @@ func TestSortDogusByInvertedDependencyWithError(t *testing.T) {
assert.ErrorContains(t, err, "error in sorting dogus by inverted dependency")
assert.Nil(t, dogus)
})

t.Run("should return dogu if only irrelevant optional dependencies are set", func(t *testing.T) {
a := &Dogu{
Name: "a",
OptionalDependencies: []Dependency{{Type: DependencyTypeDogu, Name: "c"}},
}

dogus, err := SortDogusByInvertedDependencyWithError([]*Dogu{a})
assert.NoError(t, err)
assert.Len(t, dogus, 1)
assert.Equal(t, "a", dogus[0].Name)
})

t.Run("should map k8s dependencies correctly and sort accordingly", func(t *testing.T) {
dogus := []*Dogu{}
dogus, _, err := ReadDogusFromFile("../resources/test/dogu-sort-005.json")
assert.Nil(t, err)
ordered, err := SortDogusByInvertedDependencyWithError(dogus)
require.NoError(t, err)

assert.Equal(t, "cas", ordered[0].GetSimpleName())
assert.Equal(t, "nginx-static", ordered[1].GetSimpleName())
assert.Equal(t, "nginx-ingress", ordered[2].GetSimpleName())
})
}

func TestSortDogusByDependency(t *testing.T) {
Expand Down Expand Up @@ -322,18 +358,6 @@ func TestSortDogusByInvertedDependency(t *testing.T) {
dogus := SortDogusByInvertedDependency([]*Dogu{a, b, c})
assert.Nil(t, dogus)
})

t.Run("should return dogu if only irrelevant optional dependencies are set", func(t *testing.T) {
a := &Dogu{
Name: "a",
OptionalDependencies: []Dependency{{Type: DependencyTypeDogu, Name: "c"}},
}

dogus, err := SortDogusByInvertedDependencyWithError([]*Dogu{a})
assert.NoError(t, err)
assert.Len(t, dogus, 1)
assert.Equal(t, "a", dogus[0].Name)
})
}

func TestTransformsDependencyListToDoguList(t *testing.T) {
Expand Down
67 changes: 67 additions & 0 deletions resources/test/dogu-sort-005.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"Name": "official/cas",
"Version": "7.0.8-2",
"DisplayName": "Central Authentication Service",
"Dependencies": [
{
"type": "dogu",
"name": "nginx",
"version": ">=1.26.1-5"
}
],
"OptionalDependencies": [
{
"type": "dogu",
"name": "ldap",
"version": ""
}
]
},
{
"Name": "k8s/nginx-static",
"Version": "1.26.1-7",
"DisplayName": "Nginx Static",
"Dependencies": [
{
"type": "dogu",
"name": "nginx-ingress",
"version": ""
},
{
"type": "client",
"name": "k8s-dogu-operator",
"version": ""
},
{
"type": "client",
"name": "cesapp",
"version": "<0.0.0"
}
],
"OptionalDependencies": null
},
{
"Name": "k8s/nginx-ingress",
"Version": "1.11.1-3",
"DisplayName": "Nginx Ingress",
"Dependencies": [
{
"type": "client",
"name": "k8s-dogu-operator",
"version": ">=0.16.0"
},
{
"type": "client",
"name": "cesapp",
"version": "<0.0.0"
},
{
"type": "client",
"name": "ces-setup",
"version": "<0.0.0"
}
],
"OptionalDependencies": null
}
]

0 comments on commit 6287498

Please sign in to comment.