Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search index to generated configmap #205

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add service tiles entry to generated config map.
Hyperkid123 committed Oct 22, 2024
commit 683f9034ea8235390ba7d84e574a3e45d04b1e73
15 changes: 8 additions & 7 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
@@ -49,13 +49,14 @@ type SearchEntry struct {
}

type ServiceTile struct {
Section string `json:"section" yaml:"section"`
Group string `json:"group" yaml:"group"`
ID string `json:"id" yaml:"id"`
Href string `json:"href" yaml:"href"`
Title string `json:"title" yaml:"title"`
Icon string `json:"icon" yaml:"icon"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
Section string `json:"section" yaml:"section"`
Group string `json:"group" yaml:"group"`
ID string `json:"id" yaml:"id"`
Href string `json:"href" yaml:"href"`
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Icon string `json:"icon" yaml:"icon"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
}

type WidgetHeaderLink struct {
29 changes: 29 additions & 0 deletions api/v1alpha1/frontendenvironment_types.go
Original file line number Diff line number Diff line change
@@ -24,6 +24,33 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

type FrontendServiceCategoryGroup struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
}

// FrontendServiceCategory defines the category to which service can inject ServiceTiles
// Chroming UI will use this to render the service dropdown component
type FrontendServiceCategory struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
// +kubebuilder:validation:items:MinItems:=1
Groups []FrontendServiceCategoryGroup `json:"groups" yaml:"groups"`
}

type FrontendServiceCategoryGroupGenerated struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
Tiles *[]ServiceTile `json:"tiles" yaml:"tiles"`
}

// The categories but with the groups filled with service tiles
type FrontendServiceCategoryGenerated struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
Groups []FrontendServiceCategoryGroupGenerated `json:"groups" yaml:"groups"`
}

// FrontendEnvironmentSpec defines the desired state of FrontendEnvironment
type FrontendEnvironmentSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
@@ -65,6 +92,8 @@ type FrontendEnvironmentSpec struct {
// List of namespaces that should receive a copy of the frontend configuration as a config map
// By configurations we mean the fed-modules.json, navigation files, etc.
TargetNamespaces []string `json:"targetNamespaces,omitempty" yaml:"targetNamespaces,omitempty"`
// For the ChromeUI to render additional global components
ServiceCategories *[]FrontendServiceCategory `json:"serviceCategories,omitempty" yaml:"serviceCategories,omitempty"`
}

type MonitoringConfig struct {
92 changes: 92 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontendenvironments.yaml
Original file line number Diff line number Diff line change
@@ -92,6 +92,35 @@ spec:
- disabled
- mode
type: object
serviceCategories:
description: For the ChromeUI to render additional global components
items:
description: |-
FrontendServiceCategory defines the category to which service can inject ServiceTiles
Chroming UI will use this to render the service dropdown component
properties:
groups:
items:
properties:
id:
type: string
title:
type: string
required:
- id
- title
type: object
type: array
id:
type: string
title:
type: string
required:
- groups
- id
- title
type: object
type: array
ssl:
description: |-
SSL mode requests SSL from the services in openshift and k8s and then applies them to the
3 changes: 3 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontends.yaml
Original file line number Diff line number Diff line change
@@ -343,6 +343,8 @@ spec:
description: Data for the all services dropdown
items:
properties:
description:
type: string
group:
type: string
href:
@@ -358,6 +360,7 @@ spec:
title:
type: string
required:
- description
- group
- href
- icon
162 changes: 162 additions & 0 deletions controllers/frontend_controller_suite_test.go
Original file line number Diff line number Diff line change
@@ -1291,3 +1291,165 @@ var _ = ginkgo.Describe("Widget registry", func() {
})
})
})

type ServiceTileTestEntry struct {
ServiceTiles []*crd.ServiceTile
FrontendName string
}

type ServiceTileCase struct {
ServiceTiles []*ServiceTileTestEntry
Namespace string
Environment string
ExpectedConfigMapEntry string
}

func frontendFromServiceTile(sct ServiceTileCase, ste ServiceTileTestEntry) *crd.Frontend {
frontend := &crd.Frontend{
TypeMeta: metav1.TypeMeta{
APIVersion: "cloud.redhat.com/v1",
Kind: "Frontend",
},
ObjectMeta: metav1.ObjectMeta{
Name: ste.FrontendName,
Namespace: sct.Namespace,
},
Spec: crd.FrontendSpec{
EnvName: sct.Environment,
Title: "",
DeploymentRepo: "",
Frontend: crd.FrontendInfo{
Paths: []string{""},
},
Image: "my-image:version",
Module: &crd.FedModule{
ManifestLocation: "",
Modules: []crd.Module{},
},
ServiceTiles: ste.ServiceTiles,
},
}
return frontend
}

var _ = ginkgo.Describe("Service tiles", func() {
const (
FrontendName = "test-service-tile"
FrontendName2 = "test-service-tile2"
FrontendNamespace = "default"
FrontendEnvName = "test-service-tile-env"
ServiceSectionID = "test-service-section"
ServiceSectionGroupID1 = "test-service-section-group1"
ServiceSectionGroupID2 = "test-service-section-group2"

timeout = time.Second * 10
duration = time.Second * 10
interval = time.Millisecond * 250
)

var (
ServiceTile1 = &crd.ServiceTile{
Section: ServiceSectionID,
Group: ServiceSectionGroupID1,
ID: "test-service-tile1",
Href: "/foo",
Title: "bar",
Description: "",
Icon: "",
}
ServiceTile2 = &crd.ServiceTile{
Section: ServiceSectionID,
Group: ServiceSectionGroupID1,
ID: "test-service-tile2",
Href: "/bar",
Title: "bar",
Description: "",
Icon: "",
}
ServiceTile3 = &crd.ServiceTile{
Section: ServiceSectionID,
Group: ServiceSectionGroupID2,
ID: "test-service-tile3",
Href: "/baz",
Title: "baz",
Description: "",
Icon: "",
}
ExpectedServiceTiles1 = []crd.FrontendServiceCategoryGenerated{
{
ID: ServiceSectionID,
Title: "Service Section",
Groups: []crd.FrontendServiceCategoryGroupGenerated{{
ID: ServiceSectionGroupID1,
Title: "Service Section Group 1",
Tiles: &[]crd.ServiceTile{*ServiceTile1, *ServiceTile2},
}, {
ID: ServiceSectionGroupID2,
Title: "Service Section Group 2",
Tiles: &[]crd.ServiceTile{*ServiceTile3},
}},
},
}
)

ginkgo.It("Should create service tiles", func() {
ginkgo.By("collection entries from Frontend resources", func() {
expectedResult, err := json.Marshal(ExpectedServiceTiles1)
gomega.Expect(err).Should(gomega.BeNil())
serviceTileCases := []ServiceTileCase{{
Namespace: FrontendNamespace,
Environment: FrontendEnvName,
ExpectedConfigMapEntry: string(expectedResult),
ServiceTiles: []*ServiceTileTestEntry{{
ServiceTiles: []*crd.ServiceTile{ServiceTile1, ServiceTile2, ServiceTile3},
FrontendName: FrontendName,
}},
}}

for _, serviceCase := range serviceTileCases {
ctx := context.Background()
configMapLookupKey := types.NamespacedName{Name: serviceCase.Environment, Namespace: serviceCase.Namespace}
for _, sc := range serviceCase.ServiceTiles {
frontend := frontendFromServiceTile(serviceCase, *sc)
gomega.Expect(k8sClient.Create(ctx, frontend)).Should(gomega.Succeed())
}

frontendEnvironment := mockFrontendEnv(serviceCase.Environment, serviceCase.Namespace)
frontendEnvironment.Spec.ServiceCategories = &[]crd.FrontendServiceCategory{
{
ID: ServiceSectionID,
Title: "Service Section",
Groups: []crd.FrontendServiceCategoryGroup{
{
ID: ServiceSectionGroupID1,
Title: "Service Section Group 1",
},
{
ID: ServiceSectionGroupID2,
Title: "Service Section Group 2",
},
},
},
}
gomega.Expect(k8sClient.Create(ctx, frontendEnvironment)).Should(gomega.Succeed())
createdConfigMap := &v1.ConfigMap{}
gomega.Eventually(func() bool {
err := k8sClient.Get(ctx, configMapLookupKey, createdConfigMap)
if err != nil {
return err == nil
}
if len(createdConfigMap.Data) != 2 {
return false
}
return true
}, timeout, interval).Should(gomega.BeTrue())

serviceTileRegistryMap := createdConfigMap.Data["service-tiles.json"]

gomega.Expect(createdConfigMap.Name).Should(gomega.Equal(serviceCase.Environment))
gomega.Expect(serviceTileRegistryMap).Should(gomega.Equal(serviceCase.ExpectedConfigMapEntry))
gomega.Expect(createdConfigMap.ObjectMeta.OwnerReferences[0].Name).Should(gomega.Equal(serviceCase.Environment))
}
})
})
})
Loading