Skip to content

Commit

Permalink
Add service tiles entry to generated config map.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Oct 22, 2024
1 parent 865f1c6 commit 5af6346
Show file tree
Hide file tree
Showing 14 changed files with 552 additions and 8 deletions.
15 changes: 8 additions & 7 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions api/v1alpha1/frontendenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
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
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ spec:
description: Data for the all services dropdown
items:
properties:
description:
type: string
group:
type: string
href:
Expand All @@ -358,6 +360,7 @@ spec:
title:
type: string
required:
- description
- group
- href
- icon
Expand Down
146 changes: 146 additions & 0 deletions controllers/frontend_controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,149 @@ 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, st []*crd.ServiceTile) *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: st,
},
}
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, sc.ServiceTiles)
gomega.Expect(k8sClient.Create(ctx, frontend)).Should(gomega.Succeed())
}

frontendEnvironment := mockFrontendEnv(serviceCase.Environment, serviceCase.Namespace)
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())

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

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

0 comments on commit 5af6346

Please sign in to comment.