Skip to content

Commit 8d22327

Browse files
Merge pull request #733 from njhale/fix-installmodes
fix(installmodes): update support logic to match expected behavior
2 parents eb7ad04 + d039748 commit 8d22327

File tree

9 files changed

+429
-141
lines changed

9 files changed

+429
-141
lines changed

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ k8s.io/api v0.0.0-20181203235848-2dd39edadc55/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j
290290
k8s.io/api v0.0.0-20190118113203-912cbe2bfef3 h1:lV0+KGoNkvZOt4zGT4H83hQrzWMt/US/LSz4z4+BQS4=
291291
k8s.io/api v0.0.0-20190118113203-912cbe2bfef3/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
292292
k8s.io/apiextensions-apiserver v0.0.0-20180905004947-16750353bf97/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
293-
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc h1:IOukeE9HtTwpLslbujLDfRpfFU6tsjq28yO0fjnl/hk=
294293
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
295294
k8s.io/apiextensions-apiserver v0.0.0-20190223021643-57c81b676ab1 h1:G1EvkV2I9OP/boVVnUYNgx7i9Tx22KrZ20l4utk+pPg=
296295
k8s.io/apiextensions-apiserver v0.0.0-20190223021643-57c81b676ab1/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
@@ -302,7 +301,7 @@ k8s.io/apimachinery v0.0.0-20190223001710-c182ff3b9841/go.mod h1:ccL7Eh7zubPUSh9
302301
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170 h1:CqI85nZvPaV+7JFono0nAOGOx2brocqefcOhDPVhHKI=
303302
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w=
304303
k8s.io/client-go v0.0.0-20180718001006-59698c7d9724/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
305-
k8s.io/client-go v8.0.0+incompatible h1:2pUaSg2x6iEHr8cia6zmWhoCXG1EDG9TCx9s//Aq7HY=
304+
k8s.io/client-go v8.0.0+incompatible h1:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4=
306305
k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
307306
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3 h1:f/Aa24HPnPEDWia884BCF94E1b29KYjOTVTHcBzvT2Q=
308307
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
@@ -314,13 +313,12 @@ k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUc
314313
k8s.io/klog v0.1.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
315314
k8s.io/klog v0.2.0 h1:0ElL0OHzF3N+OhoJTL0uca20SxtYt4X4+bzHeqrB83c=
316315
k8s.io/klog v0.2.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
317-
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429 h1:wIDPKpRuwEfyt+ImBaP6wSEZeAR5gYJl/Mlg74L0hHI=
318316
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
319317
k8s.io/kube-aggregator v0.0.0-20190223015803-f706565beac0 h1:WmKaovTZLNG5tUqOJmMYvVn+0raGhizjJ69J3isljro=
320318
k8s.io/kube-aggregator v0.0.0-20190223015803-f706565beac0/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
321319
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd h1:ggv/Vfza0i5xuhUZyYyxcc25AmQvHY8Zi1C2m8WgBvA=
322320
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
323321
k8s.io/kubernetes v1.11.7-beta.0.0.20181219023948-b875d52ea96d/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
324322
k8s.io/kubernetes v1.11.8-beta.0.0.20190124204751-3a10094374f2/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
325-
k8s.io/kubernetes v1.11.8-beta.0.0.20190223014307-4e209c9383fa h1:6yPWg68M4iEjzJl/nXLvviMl6RxGairt1r3+8uaNX/I=
323+
k8s.io/kubernetes v1.11.8-beta.0.0.20190223014307-4e209c9383fa h1:aKI5IFZpu2ilGUMRIMfitvAvTBv8Th2opq5ErM7Y1SU=
326324
k8s.io/kubernetes v1.11.8-beta.0.0.20190223014307-4e209c9383fa/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=

pkg/api/apis/operators/v1alpha1/clusterserviceversion.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,34 @@ func NewInstallModeSet(modes []InstallMode) (InstallModeSet, error) {
9898
// the given operatorNamespace and list of target namespaces.
9999
func (set InstallModeSet) Supports(operatorNamespace string, namespaces []string) error {
100100
numNamespaces := len(namespaces)
101-
if !set[InstallModeTypeAllNamespaces] && numNamespaces == 1 && namespaces[0] == v1.NamespaceAll {
102-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch all namespaces", InstallModeTypeAllNamespaces)
103-
}
104-
105-
if !set[InstallModeTypeSingleNamespace] && !set[InstallModeTypeMultiNamespace] && numNamespaces == 1 && namespaces[0] != v1.NamespaceAll {
106-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace)
107-
}
108-
109-
if !set[InstallModeTypeMultiNamespace] && numNamespaces > 1 {
110-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch %d namespaces", InstallModeTypeMultiNamespace, numNamespaces)
111-
}
112-
113-
for i, namespace := range namespaces {
114-
if !set[InstallModeTypeOwnNamespace] && namespace == operatorNamespace {
115-
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace)
101+
switch {
102+
case numNamespaces == 0:
103+
return fmt.Errorf("operatorgroup has invalid selected namespaces, cannot configure to watch zero namespaces")
104+
case numNamespaces == 1:
105+
switch namespaces[0] {
106+
case operatorNamespace:
107+
if !set[InstallModeTypeOwnNamespace] {
108+
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace)
109+
}
110+
case v1.NamespaceAll:
111+
if !set[InstallModeTypeAllNamespaces] {
112+
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch all namespaces", InstallModeTypeAllNamespaces)
113+
}
114+
default:
115+
if !set[InstallModeTypeSingleNamespace] {
116+
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace)
117+
}
116118
}
117-
if i > 0 && namespace == v1.NamespaceAll {
118-
return fmt.Errorf("Invalid selected namespaces, NamespaceAll found when |selected namespaces| > 1")
119+
case numNamespaces > 1 && !set[InstallModeTypeMultiNamespace]:
120+
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch %d namespaces", InstallModeTypeMultiNamespace, numNamespaces)
121+
case numNamespaces > 1:
122+
for _, namespace := range namespaces {
123+
if namespace == operatorNamespace && !set[InstallModeTypeOwnNamespace] {
124+
return fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace)
125+
}
126+
if namespace == v1.NamespaceAll {
127+
return fmt.Errorf("operatorgroup has invalid selected namespaces, NamespaceAll found when |selected namespaces| > 1")
128+
}
119129
}
120130
}
121131

pkg/api/apis/operators/v1alpha1/clusterserviceversion_test.go

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -123,127 +123,151 @@ func TestSupports(t *testing.T) {
123123
},
124124
operatorNamespace: "operators",
125125
namespaces: []string{},
126-
expectedErr: nil,
126+
expectedErr: fmt.Errorf("operatorgroup has invalid selected namespaces, cannot configure to watch zero namespaces"),
127127
},
128128
{
129-
description: "OneNamespace",
129+
description: "OwnNamespace/OperatorNamespace/Supported",
130130
installModeSet: InstallModeSet{
131131
InstallModeTypeOwnNamespace: true,
132-
InstallModeTypeSingleNamespace: true,
133-
InstallModeTypeMultiNamespace: true,
134-
InstallModeTypeAllNamespaces: true,
132+
InstallModeTypeSingleNamespace: false,
133+
InstallModeTypeMultiNamespace: false,
134+
InstallModeTypeAllNamespaces: false,
135135
},
136136
operatorNamespace: "operators",
137-
namespaces: []string{"ns-0"},
137+
namespaces: []string{"operators"},
138138
expectedErr: nil,
139139
},
140140
{
141-
description: "MultipleNamespaces/MultiNamespaceUnsupported",
141+
description: "SingleNamespace/OtherNamespace/Supported",
142142
installModeSet: InstallModeSet{
143-
InstallModeTypeOwnNamespace: true,
143+
InstallModeTypeOwnNamespace: false,
144144
InstallModeTypeSingleNamespace: true,
145145
InstallModeTypeMultiNamespace: false,
146-
InstallModeTypeAllNamespaces: true,
146+
InstallModeTypeAllNamespaces: false,
147147
},
148148
operatorNamespace: "operators",
149-
namespaces: []string{"ns-0", "ns-1"},
150-
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch 2 namespaces", InstallModeTypeMultiNamespace),
149+
namespaces: []string{"ns-0"},
150+
expectedErr: nil,
151151
},
152152
{
153-
description: "MultipleNamespaces/OwnNamespaceUnsupported",
153+
description: "MultiNamespace/OtherNamespaces/Supported",
154154
installModeSet: InstallModeSet{
155155
InstallModeTypeOwnNamespace: false,
156-
InstallModeTypeSingleNamespace: true,
156+
InstallModeTypeSingleNamespace: false,
157157
InstallModeTypeMultiNamespace: true,
158-
InstallModeTypeAllNamespaces: true,
158+
InstallModeTypeAllNamespaces: false,
159159
},
160160
operatorNamespace: "operators",
161-
namespaces: []string{"ns-0", "ns-1", "operators"},
162-
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace),
161+
namespaces: []string{"ns-0", "ns-2"},
162+
expectedErr: nil,
163163
},
164164
{
165-
description: "SingleNamespace/SingleAndMultiNamespaceUnsupported",
165+
description: "AllNamespaces/NamespaceAll/Supported",
166166
installModeSet: InstallModeSet{
167-
InstallModeTypeOwnNamespace: true,
167+
InstallModeTypeOwnNamespace: false,
168168
InstallModeTypeSingleNamespace: false,
169169
InstallModeTypeMultiNamespace: false,
170170
InstallModeTypeAllNamespaces: true,
171171
},
172172
operatorNamespace: "operators",
173-
namespaces: []string{"ns-0"},
174-
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace),
173+
namespaces: []string{""},
174+
expectedErr: nil,
175175
},
176176
{
177-
description: "SingleNamespace/MultiNamespaceDecomposes",
177+
description: "OwnNamespace/OperatorNamespace/Unsupported",
178178
installModeSet: InstallModeSet{
179-
InstallModeTypeOwnNamespace: true,
180-
InstallModeTypeSingleNamespace: false,
179+
InstallModeTypeOwnNamespace: false,
180+
InstallModeTypeSingleNamespace: true,
181181
InstallModeTypeMultiNamespace: true,
182182
InstallModeTypeAllNamespaces: true,
183183
},
184184
operatorNamespace: "operators",
185-
namespaces: []string{"ns-0"},
186-
expectedErr: nil,
185+
namespaces: []string{"operators"},
186+
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace),
187187
},
188188
{
189-
description: "SingleNamespace/OwnNamespaceUnsupported",
189+
description: "OwnNamespace/IncludesOperatorNamespace/Unsupported",
190190
installModeSet: InstallModeSet{
191191
InstallModeTypeOwnNamespace: false,
192192
InstallModeTypeSingleNamespace: true,
193193
InstallModeTypeMultiNamespace: true,
194194
InstallModeTypeAllNamespaces: true,
195195
},
196196
operatorNamespace: "operators",
197-
namespaces: []string{"operators"},
197+
namespaces: []string{"ns-0", "operators"},
198198
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch own namespace", InstallModeTypeOwnNamespace),
199199
},
200200
{
201-
description: "AllNamespaces/AllNamespacesSupported",
201+
description: "MultiNamespace/OtherNamespaces/Unsupported",
202202
installModeSet: InstallModeSet{
203203
InstallModeTypeOwnNamespace: true,
204204
InstallModeTypeSingleNamespace: true,
205+
InstallModeTypeMultiNamespace: false,
206+
InstallModeTypeAllNamespaces: true,
207+
},
208+
operatorNamespace: "operators",
209+
namespaces: []string{"ns-0", "ns-1"},
210+
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch 2 namespaces", InstallModeTypeMultiNamespace),
211+
},
212+
{
213+
description: "SingleNamespace/OtherNamespace/Unsupported",
214+
installModeSet: InstallModeSet{
215+
InstallModeTypeOwnNamespace: true,
216+
InstallModeTypeSingleNamespace: false,
205217
InstallModeTypeMultiNamespace: true,
206218
InstallModeTypeAllNamespaces: true,
207219
},
208220
operatorNamespace: "operators",
209-
namespaces: []string{corev1.NamespaceAll},
210-
expectedErr: nil,
221+
namespaces: []string{"ns-0"},
222+
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace),
211223
},
212224
{
213-
description: "AllNamespaces/AllNamespacesUnsupported",
225+
description: "AllNamespaces/NamespaceAll/Unsupported",
214226
installModeSet: InstallModeSet{
215227
InstallModeTypeOwnNamespace: true,
216228
InstallModeTypeSingleNamespace: true,
217229
InstallModeTypeMultiNamespace: true,
218230
InstallModeTypeAllNamespaces: false,
219231
},
220232
operatorNamespace: "operators",
221-
namespaces: []string{corev1.NamespaceAll},
233+
namespaces: []string{""},
222234
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch all namespaces", InstallModeTypeAllNamespaces),
223235
},
224236
{
225-
description: "NoNamespaces/EmptyInstallModeSet",
237+
description: "AllNamespaces/IncludingNamespaceAll/Unsupported",
238+
installModeSet: InstallModeSet{
239+
InstallModeTypeOwnNamespace: true,
240+
InstallModeTypeSingleNamespace: true,
241+
InstallModeTypeMultiNamespace: true,
242+
InstallModeTypeAllNamespaces: true,
243+
},
244+
operatorNamespace: "operators",
245+
namespaces: []string{"", "ns-0"},
246+
expectedErr: fmt.Errorf("operatorgroup has invalid selected namespaces, NamespaceAll found when |selected namespaces| > 1"),
247+
},
248+
{
249+
description: "NoNamespaces/EmptyInstallModeSet/Unsupported",
226250
installModeSet: InstallModeSet{},
227251
operatorNamespace: "",
228252
namespaces: []string{},
229-
expectedErr: nil,
253+
expectedErr: fmt.Errorf("operatorgroup has invalid selected namespaces, cannot configure to watch zero namespaces"),
230254
},
231255
{
232-
description: "MultipleNamespaces/EmptyInstallModeSet",
256+
description: "MultiNamespace/OtherNamespaces/EmptyInstallModeSet/Unsupported",
233257
installModeSet: InstallModeSet{},
234258
operatorNamespace: "operators",
235259
namespaces: []string{"ns-0", "ns-1"},
236260
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch 2 namespaces", InstallModeTypeMultiNamespace),
237261
},
238262
{
239-
description: "SingleNamespace/EmptyInstallModeSet",
263+
description: "SingleNamespace/OtherNamespace/EmptyInstallModeSet/Unsupported",
240264
installModeSet: InstallModeSet{},
241265
operatorNamespace: "operators",
242266
namespaces: []string{"ns-0"},
243267
expectedErr: fmt.Errorf("%s InstallModeType not supported, cannot configure to watch one namespace", InstallModeTypeSingleNamespace),
244268
},
245269
{
246-
description: "AllNamespaces/EmptyInstallModeSet",
270+
description: "AllNamespaces/NamespaceAll/EmptyInstallModeSet/Unsupported",
247271
installModeSet: InstallModeSet{},
248272
operatorNamespace: "operators",
249273
namespaces: []string{corev1.NamespaceAll},

pkg/api/apis/operators/v1alpha1/clusterserviceversion_types.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,13 @@ const (
2323
type InstallModeType string
2424

2525
const (
26-
// InstallModeTypeOwnNamespace indicates that the operator can be configured
27-
// to watch the namespace it is installed into.
26+
// InstallModeTypeOwnNamespace indicates that the operator can be a member of an `OperatorGroup` that selects its own namespace.
2827
InstallModeTypeOwnNamespace InstallModeType = "OwnNamespace"
29-
// InstallModeTypeSingleNamespace indicates that the operator can be
30-
// configured to watch a single namespace, which is configurable via
31-
// OperatorGroups' spec.targetNamespaces field.
28+
// InstallModeTypeSingleNamespace indicates that the operator can be a member of an `OperatorGroup` that selects one namespace.
3229
InstallModeTypeSingleNamespace InstallModeType = "SingleNamespace"
33-
// InstallModeTypeMultiNamespace indicates that the operator can be
34-
// configured to watch multiple namespaces via the OperatorGroup's
35-
// spec.targetNamespaces field.
30+
// InstallModeTypeMultiNamespace indicates that the operator can be a member of an `OperatorGroup` that selects more than one namespace.
3631
InstallModeTypeMultiNamespace InstallModeType = "MultiNamespace"
37-
// InstallModeTypeAllNamespaces indicates that the operator can configured
38-
// to wwatch all namespaces by setting the OperatorGroup's
39-
// spec.targetNamespaces field to "NamespaceAll".
32+
// InstallModeTypeAllNamespaces indicates that the operator can be a member of an `OperatorGroup` that selects all namespaces (target namespace set is the empty string "").
4033
InstallModeTypeAllNamespaces InstallModeType = "AllNamespaces"
4134
)
4235

0 commit comments

Comments
 (0)