From 22f5f10434a863ff6f25ad3f444d977507db6d67 Mon Sep 17 00:00:00 2001 From: Martin Marosi Date: Mon, 21 Oct 2024 12:02:54 +0200 Subject: [PATCH] Stop generating deprecated bundle data. --- .golangci.yml | 5 ++ controllers/frontend_controller_suite_test.go | 14 ++--- controllers/reconcile.go | 61 +------------------ tests/e2e/bundles/02-assert.yaml | 6 -- tests/e2e/propagate-config-map/02-assert.yaml | 12 ---- 5 files changed, 13 insertions(+), 85 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3ff06e9f..7ab2759f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,11 @@ linters: - typecheck - bodyclose linters-settings: + staticcheck: + checks: + - all + # Ignore usage of deprecated things, will be removed after frontend resources are using new navigation + - '-SA1019' gosec: excludes: - G115 diff --git a/controllers/frontend_controller_suite_test.go b/controllers/frontend_controller_suite_test.go index 5d4ce538..fbf66e2f 100644 --- a/controllers/frontend_controller_suite_test.go +++ b/controllers/frontend_controller_suite_test.go @@ -202,7 +202,7 @@ var _ = ginkgo.Describe("Frontend controller with image", func() { if err != nil { return err == nil } - if len(createdConfigMap.Data) != 2 { + if len(createdConfigMap.Data) != 1 { return false } return true @@ -210,7 +210,6 @@ var _ = ginkgo.Describe("Frontend controller with image", func() { gomega.Expect(createdConfigMap.Name).Should(gomega.Equal(FrontendEnvName)) gomega.Expect(createdConfigMap.Data).Should(gomega.Equal(map[string]string{ "fed-modules.json": "{\"testFrontend\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"apple\":\"pie\"},\"fullProfile\":true},\"testFrontend2\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"cheese\":\"pasty\"},\"fullProfile\":false}}", - "test-env.json": "{\"id\":\"test-bundle\",\"title\":\"\",\"navItems\":[{\"title\":\"Test\",\"href\":\"/test/href\"},{\"title\":\"Test\",\"href\":\"/test/href\"}]}", })) gomega.Expect(createdConfigMap.ObjectMeta.OwnerReferences[0].Name).Should(gomega.Equal(FrontendEnvName)) @@ -590,15 +589,15 @@ var _ = ginkgo.Describe("Frontend controller with chrome", func() { if err != nil { return err == nil } - if len(createdConfigMap.Data) != 2 { + if len(createdConfigMap.Data) != 1 { return false } return true }, timeout, interval).Should(gomega.BeTrue()) gomega.Expect(createdConfigMap.Name).Should(gomega.Equal(FrontendEnvName)) gomega.Expect(createdConfigMap.Data).Should(gomega.Equal(map[string]string{ - "fed-modules.json": "{\"chrome\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"apple\":\"pie\",\"ssoUrl\":\"https://something-auth\"},\"fullProfile\":false},\"noConfig\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"fullProfile\":false},\"nonChrome\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"apple\":\"pie\"},\"fullProfile\":false}}", - "test-chrome-env.json": "{\"id\":\"test-chrome-bundle\",\"title\":\"\",\"navItems\":[{\"title\":\"Test\",\"href\":\"/test/href\"},{\"title\":\"Test\",\"href\":\"/test/href\"},{\"title\":\"Test\",\"href\":\"/test/href\"}]}"})) + "fed-modules.json": "{\"chrome\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"apple\":\"pie\",\"ssoUrl\":\"https://something-auth\"},\"fullProfile\":false},\"noConfig\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"fullProfile\":false},\"nonChrome\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"config\":{\"apple\":\"pie\"},\"fullProfile\":false}}", + })) gomega.Expect(createdConfigMap.ObjectMeta.OwnerReferences[0].Name).Should(gomega.Equal(FrontendEnvName)) }) @@ -909,15 +908,14 @@ var _ = ginkgo.Describe("Dependencies", func() { if err != nil { return err == nil } - if len(createdConfigMap.Data) != 2 { + if len(createdConfigMap.Data) != 1 { return false } return true }, timeout, interval).Should(gomega.BeTrue()) gomega.Expect(createdConfigMap.Name).Should(gomega.Equal(FrontendEnvName)) gomega.Expect(createdConfigMap.Data).Should(gomega.Equal(map[string]string{ - "test-dependencies-env.json": "{\"id\":\"test-dependencies-bundle\",\"title\":\"\",\"navItems\":[{\"title\":\"Test\",\"href\":\"/test/href\"},{\"title\":\"Test\",\"href\":\"/test/href\"},{\"title\":\"Test\",\"href\":\"/test/href\"}]}", - "fed-modules.json": "{\"testDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}],\"dependencies\":[\"depstring\"]}],\"fullProfile\":false},\"testNoDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"fullProfile\":false},\"testOptionalDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}],\"optionalDependencies\":[\"depstring-op\"]}],\"fullProfile\":false}}", + "fed-modules.json": "{\"testDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}],\"dependencies\":[\"depstring\"]}],\"fullProfile\":false},\"testNoDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}]}],\"fullProfile\":false},\"testOptionalDependencies\":{\"manifestLocation\":\"/apps/inventory/fed-mods.json\",\"modules\":[{\"id\":\"test\",\"module\":\"./RootApp\",\"routes\":[{\"pathname\":\"/test/href\"}],\"optionalDependencies\":[\"depstring-op\"]}],\"fullProfile\":false}}", })) gomega.Expect(createdConfigMap.ObjectMeta.OwnerReferences[0].Name).Should(gomega.Equal(FrontendEnvName)) diff --git a/controllers/reconcile.go b/controllers/reconcile.go index 284c83be..5d6ee0c7 100644 --- a/controllers/reconcile.go +++ b/controllers/reconcile.go @@ -757,52 +757,6 @@ func defaultNetSpec(ingressClass, host string, ingressPaths []networking.HTTPIng } } -func setupCustomNav(bundle *crd.Bundle, cfgMap *v1.ConfigMap) error { - newBundleObject := bundle.Spec.CustomNav - - jsonData, err := json.Marshal(newBundleObject) - if err != nil { - return err - } - - cfgMap.Data[fmt.Sprintf("%s.json", bundle.Name)] = string(jsonData) - return nil -} - -func setupNormalNav(bundle *crd.Bundle, cacheMap map[string]crd.Frontend, cfgMap *v1.ConfigMap) error { - newBundleObject := crd.ComputedBundle{ - ID: bundle.Spec.ID, - Title: bundle.Spec.Title, - NavItems: []crd.BundleNavItem{}, - } - - bundleCacheMap := make(map[string]crd.BundleNavItem) - for _, extraItem := range bundle.Spec.ExtraNavItems { - bundleCacheMap[extraItem.Name] = extraItem.NavItem - } - - for _, app := range bundle.Spec.AppList { - if retrievedFrontend, ok := cacheMap[app]; ok { - if retrievedFrontend.Spec.NavItems != nil { - for _, navItem := range retrievedFrontend.Spec.NavItems { - newBundleObject.NavItems = append(newBundleObject.NavItems, *navItem) - } - } - } - if bundleNavItem, ok := bundleCacheMap[app]; ok { - newBundleObject.NavItems = append(newBundleObject.NavItems, bundleNavItem) - } - } - - jsonData, err := json.Marshal(newBundleObject) - if err != nil { - return err - } - - cfgMap.Data[fmt.Sprintf("%s.json", bundle.Name)] = string(jsonData) - return nil -} - func setupFedModules(feEnv *crd.FrontendEnvironment, frontendList *crd.FrontendList, fedModules map[string]crd.FedModule) error { for _, frontend := range frontendList.Items { if frontend.Spec.Module != nil { @@ -956,7 +910,7 @@ func setupServiceTilesData(feList *crd.FrontendList, feEnvironment crd.FrontendE return categories, skippedTiles } -func (r *FrontendReconciliation) setupBundleData(cfgMap *v1.ConfigMap, cacheMap map[string]crd.Frontend) error { +func (r *FrontendReconciliation) setupBundleData(_ *v1.ConfigMap, _ map[string]crd.Frontend) error { bundleList := &crd.BundleList{} if err := r.FRE.Client.List(r.Ctx, bundleList, client.MatchingFields{"spec.envName": r.Frontend.Spec.EnvName}); err != nil { @@ -972,18 +926,7 @@ func (r *FrontendReconciliation) setupBundleData(cfgMap *v1.ConfigMap, cacheMap sort.Strings(keys) - for _, key := range keys { - bundle := nBundleMap[key] - if bundle.Spec.CustomNav != nil { - if err := setupCustomNav(&bundle, cfgMap); err != nil { - return err - } - } else { - if err := setupNormalNav(&bundle, cacheMap, cfgMap); err != nil { - return err - } - } - } + // TODO: Update reconcile to use the position based navigation for bundles return nil } diff --git a/tests/e2e/bundles/02-assert.yaml b/tests/e2e/bundles/02-assert.yaml index ce250ff5..7903438b 100644 --- a/tests/e2e/bundles/02-assert.yaml +++ b/tests/e2e/bundles/02-assert.yaml @@ -62,11 +62,5 @@ metadata: data: fed-modules.json: >- {"edge":{"manifestLocation":"/apps/edge/fed-mods.json","modules":[{"id":"edge","module":"./RootApp","routes":[{"pathname":"/edge"}]}],"moduleID":"edge","fullProfile":false}} - test-bundles-navigation.json: >- - {"id":"test","title":"FEO Test - Bundle","navItems":[{"title":"Inventory","permissions":[{"method":"withEmail","args":["@redhat.com"]}],"routes":[{"title":"Groups","appId":"edge","href":"/edge/fleet-management"},{"title":"Systems","appId":"edge","href":"/edge/inventory"}],"expandable":true},{"title":"Manage - Images","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}],"routes":[{"title":"Images","appId":"edge","href":"/edge/manage-images"},{"title":"Custom - Repositories","appId":"edge","href":"/edge/repositories"}],"expandable":true},{"title":"Learning - Resources","href":"/edge/learning-resources","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}]}]} diff --git a/tests/e2e/propagate-config-map/02-assert.yaml b/tests/e2e/propagate-config-map/02-assert.yaml index 695215ca..560d71c7 100644 --- a/tests/e2e/propagate-config-map/02-assert.yaml +++ b/tests/e2e/propagate-config-map/02-assert.yaml @@ -12,12 +12,6 @@ metadata: data: fed-modules.json: >- {"edge":{"manifestLocation":"/apps/edge/fed-mods.json","modules":[{"id":"edge","module":"./RootApp","routes":[{"pathname":"/edge"}]}],"moduleID":"edge","fullProfile":false}} - test-bundles-namespaces-navigation.json: >- - {"id":"test","title":"FEO Test - Bundle","navItems":[{"title":"Inventory","permissions":[{"method":"withEmail","args":["@redhat.com"]}],"routes":[{"title":"Groups","appId":"edge","href":"/edge/fleet-management"},{"title":"Systems","appId":"edge","href":"/edge/inventory"}],"expandable":true},{"title":"Manage - Images","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}],"routes":[{"title":"Images","appId":"edge","href":"/edge/manage-images"},{"title":"Custom - Repositories","appId":"edge","href":"/edge/repositories"}],"expandable":true},{"title":"Learning - Resources","href":"/edge/learning-resources","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}]}]} --- # Make sure the same exact config map ws propagated to the other namespace(s) kind: ConfigMap @@ -33,11 +27,5 @@ metadata: data: fed-modules.json: >- {"edge":{"manifestLocation":"/apps/edge/fed-mods.json","modules":[{"id":"edge","module":"./RootApp","routes":[{"pathname":"/edge"}]}],"moduleID":"edge","fullProfile":false}} - test-bundles-namespaces-navigation.json: >- - {"id":"test","title":"FEO Test - Bundle","navItems":[{"title":"Inventory","permissions":[{"method":"withEmail","args":["@redhat.com"]}],"routes":[{"title":"Groups","appId":"edge","href":"/edge/fleet-management"},{"title":"Systems","appId":"edge","href":"/edge/inventory"}],"expandable":true},{"title":"Manage - Images","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}],"routes":[{"title":"Images","appId":"edge","href":"/edge/manage-images"},{"title":"Custom - Repositories","appId":"edge","href":"/edge/repositories"}],"expandable":true},{"title":"Learning - Resources","href":"/edge/learning-resources","permissions":[{"method":"withEmail","args":["@redhat.com","@sbb.ch"]}]}]}