Skip to content

Commit f8114a7

Browse files
committed
updated deploygrid version
1 parent 653c65f commit f8114a7

File tree

8 files changed

+111
-62
lines changed

8 files changed

+111
-62
lines changed

api/e2e/testdata/config-default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
logging:
33
devMode: true
44
clusters:
5+
environments:
6+
- Dev
7+
- QA
8+
- Stage
59
clusters:
610
- name: kind-ops-cluster-1
711
address: https://127.0.0.1:6443

api/kind/applications.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kind: Application
1111
metadata:
1212
name: dev-app-a
1313
namespace: argocd
14-
labels:
14+
annotations:
1515
deploygrid/name: app-a
1616
deploygrid/environment: Dev
1717
deploygrid/group: Apps
@@ -30,7 +30,7 @@ kind: Application
3030
metadata:
3131
name: dev-app-b
3232
namespace: argocd
33-
labels:
33+
annotations:
3434
deploygrid/name: app-b
3535
deploygrid/environment: Dev
3636
deploygrid/group: Apps
@@ -49,7 +49,7 @@ kind: Application
4949
metadata:
5050
name: qa-app-a
5151
namespace: argocd
52-
labels:
52+
annotations:
5353
deploygrid/name: app-a
5454
deploygrid/environment: QA
5555
deploygrid/group: Apps
@@ -68,7 +68,7 @@ kind: Application
6868
metadata:
6969
name: qa-app-b
7070
namespace: argocd
71-
labels:
71+
annotations:
7272
deploygrid/name: app-b
7373
deploygrid/environment: QA
7474
deploygrid/group: Apps
@@ -87,7 +87,7 @@ kind: Application
8787
metadata:
8888
name: stage-app-a
8989
namespace: argocd
90-
labels:
90+
annotations:
9191
deploygrid/name: app-a
9292
deploygrid/environment: Stage
9393
deploygrid/group: Apps
@@ -106,7 +106,7 @@ kind: Application
106106
metadata:
107107
name: stage-app-b
108108
namespace: argocd
109-
labels:
109+
annotations:
110110
deploygrid/name: app-b
111111
deploygrid/environment: Stage
112112
deploygrid/group: Apps

api/pkg/config/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ type ClusterConfig struct {
1414
}
1515

1616
type ClustersConfig struct {
17-
Clusters []ClusterConfig `mapstructure:"clusters"`
17+
Clusters []ClusterConfig `mapstructure:"clusters"`
18+
Environments []string `mapstructure:"environments"`
1819
}
1920

2021
type SwaggerConfig struct {

api/pkg/repository/k8s/resources.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ func NewApplicationRepository(client dynamic.Interface) repository.ResourceRepos
3737
simpleName := app.Spec.Source.Chart
3838

3939
return &repository.Resource{
40-
Name: ApplicationName(app.Name),
41-
Labels: app.Labels,
40+
Name: ApplicationName(app.Name),
41+
Labels: app.Labels,
42+
Annotations: app.Annotations,
4243
Components: []repository.Component{
4344
{
4445
Name: ApplicationName(app.Name),
@@ -110,10 +111,11 @@ func NewDeploymentRepository(client dynamic.Interface) repository.ResourceReposi
110111
}
111112

112113
return &repository.Resource{
113-
Name: DeploymentName(dep.Namespace, dep.Name),
114-
Labels: dep.Labels,
115-
Parent: parent,
116-
Components: comps,
114+
Name: DeploymentName(dep.Namespace, dep.Name),
115+
Labels: dep.Labels,
116+
Annotations: dep.Annotations,
117+
Parent: parent,
118+
Components: comps,
117119
}, nil
118120
},
119121
})

api/pkg/repository/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ type ClusterLocation struct {
2525
}
2626

2727
type Resource struct {
28-
Name string
29-
Parent string
30-
Labels map[string]string
31-
Components []Component
28+
Name string
29+
Parent string
30+
Labels map[string]string
31+
Annotations map[string]string
32+
Components []Component
3233
}
3334

3435
type ResourceStore interface {

api/pkg/service/constants.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package service
22

33
const (
4-
LabelDeployGridGroup = "deploygrid/group"
5-
LabelDeployGridName = "deploygrid/name"
6-
LabelDeployGridEnvironment = "deploygrid/environment"
7-
GroupNoGroup = "Default Group"
4+
AnnotationDeployGridGroup = "deploygrid/group"
5+
AnnotationDeployGridName = "deploygrid/name"
6+
AnnotationDeployGridEnvironment = "deploygrid/environment"
7+
GroupNoGroup = "Default Group"
88
)

api/pkg/service/grid.go

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ type resourcesOrError struct {
2020
}
2121

2222
type gridService struct {
23-
clusters map[string]resourcesOrError
24-
accessor repository.ClusterAwareAccessor[*repository.Resources]
25-
stores map[string]stores
26-
lock sync.RWMutex
27-
addressMap map[string]string
23+
clusters map[string]resourcesOrError
24+
accessor repository.ClusterAwareAccessor[*repository.Resources]
25+
stores map[string]stores
26+
lock sync.RWMutex
27+
addressMap map[string]string
28+
environments []string
2829
}
2930

3031
func (g *gridService) updateClusters(ctx context.Context) {
@@ -95,6 +96,7 @@ type gridRow struct {
9596
level int
9697
group string
9798
cells map[string]*gridCell
99+
name string
98100
}
99101

100102
func (g *gridRow) expand() []*deploygrid.Component {
@@ -106,9 +108,8 @@ func (g *gridRow) expand() []*deploygrid.Component {
106108
}
107109

108110
type withParent struct {
109-
parentPath string
110-
currentPath string
111-
node *[]*deploygrid.Component
111+
parentPath string
112+
node *[]*deploygrid.Component
112113
}
113114

114115
pathMap := map[string]bool{}
@@ -148,9 +149,8 @@ func (g *gridRow) expand() []*deploygrid.Component {
148149
var res []*deploygrid.Component
149150

150151
cur := &withParent{
151-
parentPath: "",
152-
currentPath: "",
153-
node: &res,
152+
parentPath: "",
153+
node: &res,
154154
}
155155
st.Push(cur)
156156

@@ -179,43 +179,82 @@ func (g *gridRow) expand() []*deploygrid.Component {
179179
}
180180

181181
*cur.node = append(*cur.node, comp)
182+
st.Push(cur)
182183
cur = &withParent{
183-
parentPath: cur.currentPath,
184-
currentPath: path,
185-
node: &comp.Children,
184+
parentPath: path,
185+
node: &comp.Children,
186186
}
187187
st.Push(cur)
188188
}
189189

190190
return res
191191
}
192192

193-
func newGridRow(group string) *gridRow {
193+
func newGridRow(group string, name string) *gridRow {
194194
return &gridRow{
195+
name: name,
195196
group: group,
196197
cells: map[string]*gridCell{},
197198
}
198199
}
199200

200-
func buildGrid(grid *deploygrid.Grid, rows map[string]*gridRow) {
201+
func buildGrid(grid *deploygrid.Grid, rows map[string]*gridRow, columns []string) {
201202

202203
envs := map[string]bool{}
203-
var comps []*deploygrid.Component
204+
205+
var sorted []*gridRow
204206

205207
for _, rv := range rows {
208+
sorted = append(sorted, rv)
209+
}
210+
211+
slices.SortFunc(sorted, func(a, b *gridRow) int {
212+
return strings.Compare(a.name, b.name)
213+
})
214+
215+
grouped := map[string]*deploygrid.Component{}
216+
217+
for _, rv := range sorted {
206218
for ck, _ := range rv.cells {
207219
envs[ck] = true
208220
}
209-
comps = append(comps, rv.expand()...)
221+
222+
groupName := rv.group
223+
if groupName == "" {
224+
groupName = "Default"
225+
}
226+
comps := rv.expand()
227+
228+
if grp, ok := grouped[groupName]; ok {
229+
grp.Children = append(grp.Children, comps...)
230+
} else {
231+
grp = &deploygrid.Component{
232+
Name: groupName,
233+
ComponentType: "Group",
234+
Children: comps,
235+
}
236+
grouped[groupName] = grp
237+
}
238+
210239
}
211240

212-
grid.Components = comps
213-
for k, _ := range envs {
241+
for _, c := range columns {
214242
grid.Environments = append(grid.Environments, &deploygrid.Environment{
215-
Name: k,
243+
Name: c,
216244
})
217245
}
218246

247+
var comps []*deploygrid.Component
248+
249+
for _, v := range grouped {
250+
comps = append(comps, v)
251+
}
252+
253+
slices.SortFunc(comps, func(a, b *deploygrid.Component) int {
254+
return strings.Compare(a.Name, b.Name)
255+
})
256+
257+
grid.Components = comps
219258
}
220259

221260
func (g *gridService) Init() {
@@ -263,40 +302,41 @@ func (g *gridService) Get(ctx context.Context) (*deploygrid.Grid, error) {
263302
// TODO - first encountered group defines the group container - this should change
264303
for _, v := range data {
265304
for _, e := range v.entries {
266-
group := e.Labels[LabelDeployGridGroup]
305+
group := e.Annotations[AnnotationDeployGridGroup]
267306

268307
if group == "" {
269308
group = GroupNoGroup
270309
}
271310

272-
name, nameOk := e.Labels[LabelDeployGridName]
273-
env, envOk := e.Labels[LabelDeployGridEnvironment]
311+
name, nameOk := e.Annotations[AnnotationDeployGridName]
312+
envs, envsOk := e.Annotations[AnnotationDeployGridEnvironment]
274313

275-
if nameOk && envOk && e.Parent == "" {
314+
if nameOk && envsOk && e.Parent == "" {
276315

277316
row, ok := rowMap[name]
278317
if !ok {
279-
row = newGridRow(group)
318+
row = newGridRow(group, name)
280319
rowMap[name] = row
281320
}
282321

283-
cell, ok := row.cells[env]
284-
if !ok {
285-
cell = newGridCell()
286-
row.cells[env] = cell
287-
}
288-
289-
err := g.buildNodes(ctx, data, &cell.nodes, &e.Components)
322+
for _, env := range strings.Split(envs, ",") {
323+
cell, ok := row.cells[env]
324+
if !ok {
325+
cell = newGridCell()
326+
row.cells[env] = cell
327+
}
290328

291-
if err != nil {
292-
return nil, err
329+
err := g.buildNodes(ctx, data, &cell.nodes, &e.Components)
330+
if err != nil {
331+
return nil, err
332+
}
293333
}
294334

295335
}
296336
}
297337
}
298338

299-
buildGrid(res, rowMap)
339+
buildGrid(res, rowMap, g.environments)
300340

301341
return res, nil
302342
}
@@ -353,9 +393,10 @@ func NewGridService(params GridServiceParams) GridService {
353393
}
354394
}
355395
return &gridService{
356-
accessor: params.Accessor,
357-
addressMap: addressMap,
358-
clusters: map[string]resourcesOrError{},
359-
stores: map[string]stores{},
396+
accessor: params.Accessor,
397+
addressMap: addressMap,
398+
environments: params.ClustersConfig.Environments,
399+
clusters: map[string]resourcesOrError{},
400+
stores: map[string]stores{},
360401
}
361402
}

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Strata</title>
7+
<title>DeployGrid</title>
88
</head>
99
<body>
1010
<div id="root"></div>

0 commit comments

Comments
 (0)