Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
eaaefa1b
Commit
eaaefa1b
authored
Aug 16, 2017
by
Justin Scott
Committed by
GitHub
Aug 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2816 from jascott1/i1696
feat(tiller): sort manifests alphabetically if they are same kind
parents
8e5a733b
f2390509
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
5 deletions
+71
-5
kind_sorter.go
pkg/tiller/kind_sorter.go
+10
-5
kind_sorter_test.go
pkg/tiller/kind_sorter_test.go
+61
-0
No files found.
pkg/tiller/kind_sorter.go
View file @
eaaefa1b
...
@@ -114,14 +114,19 @@ func (k *kindSorter) Swap(i, j int) { k.manifests[i], k.manifests[j] = k.manifes
...
@@ -114,14 +114,19 @@ func (k *kindSorter) Swap(i, j int) { k.manifests[i], k.manifests[j] = k.manifes
func
(
k
*
kindSorter
)
Less
(
i
,
j
int
)
bool
{
func
(
k
*
kindSorter
)
Less
(
i
,
j
int
)
bool
{
a
:=
k
.
manifests
[
i
]
a
:=
k
.
manifests
[
i
]
b
:=
k
.
manifests
[
j
]
b
:=
k
.
manifests
[
j
]
first
,
ok
:=
k
.
ordering
[
a
.
head
.
Kind
]
first
,
aok
:=
k
.
ordering
[
a
.
head
.
Kind
]
if
!
ok
{
second
,
bok
:=
k
.
ordering
[
b
.
head
.
Kind
]
// Unknown is always last
if
first
==
second
{
// same kind (including unknown) so sub sort alphanumeric
return
a
.
name
<
b
.
name
}
// unknown kind is last
if
!
aok
{
return
false
return
false
}
}
second
,
ok
:=
k
.
ordering
[
b
.
head
.
Kind
]
if
!
bok
{
if
!
ok
{
return
true
return
true
}
}
// sort different kinds
return
first
<
second
return
first
<
second
}
}
pkg/tiller/kind_sorter_test.go
View file @
eaaefa1b
...
@@ -147,3 +147,64 @@ func TestKindSorter(t *testing.T) {
...
@@ -147,3 +147,64 @@ func TestKindSorter(t *testing.T) {
})
})
}
}
}
}
// TestKindSorterSubSort verifies manifests of same kind are also sorted alphanumeric
func
TestKindSorterSubSort
(
t
*
testing
.
T
)
{
manifests
:=
[]
manifest
{
{
name
:
"a"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ClusterRole"
},
},
{
name
:
"A"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ClusterRole"
},
},
{
name
:
"0"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ConfigMap"
},
},
{
name
:
"1"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ConfigMap"
},
},
{
name
:
"z"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ClusterRoleBinding"
},
},
{
name
:
"!"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"ClusterRoleBinding"
},
},
{
name
:
"u3"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"Unknown"
},
},
{
name
:
"u1"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"Unknown"
},
},
{
name
:
"u2"
,
head
:
&
util
.
SimpleHead
{
Kind
:
"Unknown"
},
},
}
for
_
,
test
:=
range
[]
struct
{
description
string
order
SortOrder
expected
string
}{
// expectation is sorted by kind (unknown is last) and then sub sorted alphabetically within each group
{
"cm,clusterRole,clusterRoleBinding,Unknown"
,
InstallOrder
,
"01Aa!zu1u2u3"
},
}
{
var
buf
bytes
.
Buffer
t
.
Run
(
test
.
description
,
func
(
t
*
testing
.
T
)
{
defer
buf
.
Reset
()
for
_
,
r
:=
range
sortByKind
(
manifests
,
test
.
order
)
{
buf
.
WriteString
(
r
.
name
)
}
if
got
:=
buf
.
String
();
got
!=
test
.
expected
{
t
.
Errorf
(
"Expected %q, got %q"
,
test
.
expected
,
got
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment