Skip to content

Commit

Permalink
Stop generating deprecated bundle data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Oct 25, 2024
1 parent 7d5e165 commit 22f5f10
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 85 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions controllers/frontend_controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ 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
}, 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": "{\"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))

Expand Down Expand Up @@ -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))

})
Expand Down Expand Up @@ -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))

Expand Down
61 changes: 2 additions & 59 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
6 changes: 0 additions & 6 deletions tests/e2e/bundles/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]}]}
12 changes: 0 additions & 12 deletions tests/e2e/propagate-config-map/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]}]}]}

0 comments on commit 22f5f10

Please sign in to comment.