From fad8dcd6276c8d0641f4aba31eb24baf21284c16 Mon Sep 17 00:00:00 2001 From: meiserloh Date: Tue, 29 Oct 2024 16:12:28 +0100 Subject: [PATCH 1/6] map nginx dependencies to k8s equivalent dogus --- CHANGELOG.md | 2 + core/dogu-sort.go | 25 ++++++++++++ core/dogu-sort_test.go | 24 +++++++++++ resources/test/dogu-sort-005.json | 67 +++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 resources/test/dogu-sort-005.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0869892..2cd77ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- map nginx dependencies to k8s equivalent dogus ## [v0.14.1] - 2024-10-17 ### Changed diff --git a/core/dogu-sort.go b/core/dogu-sort.go index 0968f41..9f1e4ad 100644 --- a/core/dogu-sort.go +++ b/core/dogu-sort.go @@ -6,6 +6,20 @@ import ( "sort" ) +var ( + nginxIngressDependency = Dependency{ + Type: DependencyTypeDogu, + Name: "nginx-ingress", + } + nginxStaticDependency = Dependency{ + Type: DependencyTypeDogu, + Name: "nginx-static", + } + K8sDependencyMapping = map[string][]Dependency{ + "nginx": {nginxIngressDependency, nginxStaticDependency}, + } +) + // 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. // @@ -128,6 +142,8 @@ func toDoguSlice(dogus []interface{}) ([]*Dogu, error) { func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Dogu { var result []*Dogu + dependencies = appendK8sMappedDependencies(dependencies) + for _, dogu := range bd.dogus { if contains(dependencies, dogu.GetSimpleName()) { result = append(result, dogu) @@ -137,6 +153,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) diff --git a/core/dogu-sort_test.go b/core/dogu-sort_test.go index 7bbdefa..225dbc1 100644 --- a/core/dogu-sort_test.go +++ b/core/dogu-sort_test.go @@ -143,6 +143,18 @@ func TestSortDogusByDependencyWithError(t *testing.T) { assert.Nil(t, dogus) }) + 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 { @@ -253,6 +265,18 @@ func TestSortDogusByInvertedDependencyWithError(t *testing.T) { assert.ErrorContains(t, err, "error in sorting dogus by inverted dependency") assert.Nil(t, dogus) }) + + 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) { diff --git a/resources/test/dogu-sort-005.json b/resources/test/dogu-sort-005.json new file mode 100644 index 0000000..7e92089 --- /dev/null +++ b/resources/test/dogu-sort-005.json @@ -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 + } +] From fce36dc86ec21ea6f0475c8ea17c7b22f8ef6998 Mon Sep 17 00:00:00 2001 From: meiserloh Date: Wed, 30 Oct 2024 08:34:31 +0100 Subject: [PATCH 2/6] remove nginx-static from mappings, since unnecessary --- core/dogu-sort.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/dogu-sort.go b/core/dogu-sort.go index a07edbd..5eb57dd 100644 --- a/core/dogu-sort.go +++ b/core/dogu-sort.go @@ -11,12 +11,8 @@ var ( Type: DependencyTypeDogu, Name: "nginx-ingress", } - nginxStaticDependency = Dependency{ - Type: DependencyTypeDogu, - Name: "nginx-static", - } - K8sDependencyMapping = map[string][]Dependency{ - "nginx": {nginxIngressDependency, nginxStaticDependency}, + K8sDependencyMapping = map[string]Dependency{ + "nginx": nginxIngressDependency, } ) @@ -142,6 +138,7 @@ 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 { @@ -156,7 +153,7 @@ func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Do func appendK8sMappedDependencies(dependencies []Dependency) []Dependency { for _, dep := range dependencies { if _, ok := K8sDependencyMapping[dep.Name]; ok { - dependencies = append(dependencies, K8sDependencyMapping[dep.Name]...) + dependencies = append(dependencies, K8sDependencyMapping[dep.Name]) } } return dependencies From 80cd7cc698aeb9d4ff01ed692f048114f46a63be Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 30 Oct 2024 11:21:23 +0100 Subject: [PATCH 3/6] #47 Add issue nr to changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1b807a..a2713da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ### Fixed -- map nginx dependencies to k8s equivalent dogus +- [#47] map nginx dependencies to k8s equivalent dogus ## [v0.14.2] - 2024-10-18 ### Fixed From afa955b6ef8cb4da762a665c6647652f5d998b34 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 30 Oct 2024 11:26:41 +0100 Subject: [PATCH 4/6] #47 Make dependency map private --- core/dogu-sort.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/dogu-sort.go b/core/dogu-sort.go index 5eb57dd..55e5149 100644 --- a/core/dogu-sort.go +++ b/core/dogu-sort.go @@ -11,7 +11,7 @@ var ( Type: DependencyTypeDogu, Name: "nginx-ingress", } - K8sDependencyMapping = map[string]Dependency{ + k8sDependencyMapping = map[string]Dependency{ "nginx": nginxIngressDependency, } ) @@ -152,8 +152,8 @@ func (bd *sortByDependency) dependenciesToDogus(dependencies []Dependency) []*Do func appendK8sMappedDependencies(dependencies []Dependency) []Dependency { for _, dep := range dependencies { - if _, ok := K8sDependencyMapping[dep.Name]; ok { - dependencies = append(dependencies, K8sDependencyMapping[dep.Name]) + if _, ok := k8sDependencyMapping[dep.Name]; ok { + dependencies = append(dependencies, k8sDependencyMapping[dep.Name]) } } return dependencies From c490389804d8edb9ffef6bd91ba58dc9d5f0a8fc Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 30 Oct 2024 11:35:24 +0100 Subject: [PATCH 5/6] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36d0eb6..c08ba09 100644 --- a/Makefile +++ b/Makefile @@ -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 From 32e824eb9d320b223e73f41122b636bfa2585506 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 30 Oct 2024 11:35:27 +0100 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2713da..549f0b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 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