Skip to content

Commit f10fcb0

Browse files
author
Michael Sauter
committed
Exclude excluded kinds from export
Fixes #245.
1 parent 85c3782 commit f10fcb0

2 files changed

Lines changed: 80 additions & 19 deletions

File tree

pkg/openshift/filter.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import (
1010
)
1111

1212
var availableKinds = []string{
13-
"svc",
14-
"route",
15-
"dc",
16-
"deployment",
17-
"bc",
18-
"is",
19-
"pvc",
20-
"template",
21-
"cm",
22-
"secret",
23-
"rolebinding",
24-
"serviceaccount",
25-
"cronjob",
26-
"job",
27-
"limitrange",
28-
"quota",
29-
"hpa",
30-
"statefulset",
13+
"Service",
14+
"Route",
15+
"DeploymentConfig",
16+
"Deployment",
17+
"BuildConfig",
18+
"ImageStream",
19+
"PersistentVolumeClaim",
20+
"Template",
21+
"ConfigMap",
22+
"Secret",
23+
"RoleBinding",
24+
"ServiceAccount",
25+
"CronJob",
26+
"Job",
27+
"LimitRange",
28+
"ResourceQuota",
29+
"HorizontalPodAutoscaler",
30+
"StatefulSet",
3131
}
3232

3333
type ResourceFilter struct {
@@ -186,5 +186,11 @@ func (f *ResourceFilter) ConvertToKinds() string {
186186
if len(kinds) == 0 {
187187
kinds = availableKinds
188188
}
189-
return strings.Join(kinds, ",")
189+
kindsWithoutExcluded := []string{}
190+
for _, k := range kinds {
191+
if !utils.Includes(f.ExcludedKinds, k) {
192+
kindsWithoutExcluded = append(kindsWithoutExcluded, k)
193+
}
194+
}
195+
return strings.Join(kindsWithoutExcluded, ",")
190196
}

pkg/openshift/filter_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,61 @@ func TestNewResourceFilter(t *testing.T) {
9393
t.Errorf("Kinds incorrect, got: %v, want: %v.", actual, expected)
9494
}
9595

96+
actual, err = NewResourceFilter("", "", []string{"rolebinding", "serviceaccount"})
97+
expected = &ResourceFilter{
98+
ExcludedKinds: []string{"RoleBinding", "ServiceAccount"},
99+
Kinds: []string{},
100+
Name: "",
101+
Label: "",
102+
}
103+
if err != nil || !reflect.DeepEqual(actual, expected) {
104+
t.Errorf("Kinds incorrect, got: %v, want: %v.", actual, expected)
105+
}
106+
107+
}
108+
109+
func TestConvertToKinds(t *testing.T) {
110+
tests := map[string]struct {
111+
filter *ResourceFilter
112+
want string
113+
}{
114+
"kinds": {
115+
filter: &ResourceFilter{
116+
ExcludedKinds: []string{},
117+
Kinds: []string{"RoleBinding", "ServiceAccount"},
118+
Name: "",
119+
Label: "",
120+
},
121+
want: "RoleBinding,ServiceAccount",
122+
},
123+
"excluded kinds": {
124+
filter: &ResourceFilter{
125+
ExcludedKinds: []string{"RoleBinding", "ServiceAccount"},
126+
Kinds: []string{},
127+
Name: "",
128+
Label: "",
129+
},
130+
want: "Service,Route,DeploymentConfig,Deployment,BuildConfig,ImageStream,PersistentVolumeClaim,Template,ConfigMap,Secret,CronJob,Job,LimitRange,ResourceQuota,HorizontalPodAutoscaler,StatefulSet",
131+
},
132+
"kinds and excluded kinds": {
133+
filter: &ResourceFilter{
134+
ExcludedKinds: []string{"RoleBinding", "Route"},
135+
Kinds: []string{"Service", "Route", "DeploymentConfig"},
136+
Name: "",
137+
Label: "",
138+
},
139+
want: "Service,DeploymentConfig",
140+
},
141+
}
142+
143+
for name, tc := range tests {
144+
t.Run(name, func(t *testing.T) {
145+
got := tc.filter.ConvertToKinds()
146+
if got != tc.want {
147+
t.Errorf("Got: %+v, want: %+v. Filter is: %+v", got, tc.want, tc.filter)
148+
}
149+
})
150+
}
96151
}
97152

98153
func TestSatisfiedBy(t *testing.T) {

0 commit comments

Comments
 (0)