Skip to content

Commit 02ded51

Browse files
committed
Add helper func
1 parent c8315c8 commit 02ded51

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

crds/operators.coreos.com_olmconfigs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ spec:
4343
disableCopiedCSVs:
4444
description: DisableCopiedCSVs is used to disable OLM's "Copied CSV" feature for operators installed at the cluster scope, where a cluster scoped operator is one that has been installed in an OperatorGroup that targets all namespaces. When reenabled, OLM will recreate the "Copied CSVs" for each cluster scoped operator.
4545
type: boolean
46-
default: false
4746
status:
4847
description: OLMConfigStatus is the status for an OLMConfig resource.
4948
type: object

crds/zz_defs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/operators/v1/olmconfig_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package v1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func boolPointer(in bool) *bool {
10+
return &in
11+
}
12+
13+
func TestCopiedCSVsAreEnabled(t *testing.T) {
14+
tests := []struct {
15+
description string
16+
olmConfig *OLMConfig
17+
expected bool
18+
}{
19+
{
20+
description: "NilConfig",
21+
olmConfig: nil,
22+
expected: false,
23+
},
24+
{
25+
description: "MissingSpec",
26+
olmConfig: &OLMConfig{},
27+
expected: false,
28+
},
29+
{
30+
description: "MissingFeatures",
31+
olmConfig: &OLMConfig{
32+
Spec: OLMConfigSpec{},
33+
},
34+
expected: false,
35+
},
36+
{
37+
description: "MissingDisableCopiedCSVs",
38+
olmConfig: &OLMConfig{
39+
Spec: OLMConfigSpec{},
40+
},
41+
expected: false,
42+
},
43+
{
44+
description: "CopiedCSVsDisabled",
45+
olmConfig: &OLMConfig{
46+
Spec: OLMConfigSpec{
47+
Features: Features{
48+
DisableCopiedCSVs: boolPointer(true),
49+
},
50+
},
51+
},
52+
expected: false,
53+
},
54+
{
55+
description: "CopiedCSVsEnabled",
56+
olmConfig: &OLMConfig{
57+
Spec: OLMConfigSpec{
58+
Features: Features{
59+
DisableCopiedCSVs: boolPointer(false),
60+
},
61+
},
62+
},
63+
expected: true,
64+
},
65+
}
66+
67+
for _, tt := range tests {
68+
t.Run(tt.description, func(t *testing.T) {
69+
require.EqualValues(t, tt.expected, tt.olmConfig.CopiedCSVsAreEnabled())
70+
})
71+
}
72+
}

pkg/operators/v1/olmconfig_types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ type OLMConfigSpec struct {
1111

1212
// Features contains the list of configurable OLM features.
1313
type Features struct {
14-
// +kubebuilder:default=false
1514

1615
// DisableCopiedCSVs is used to disable OLM's "Copied CSV" feature
1716
// for operators installed at the cluster scope, where a cluster
1817
// scoped operator is one that has been installed in an
1918
// OperatorGroup that targets all namespaces.
2019
// When reenabled, OLM will recreate the "Copied CSVs" for each
2120
// cluster scoped operator.
22-
DisableCopiedCSVs bool `json:"disableCopiedCSVs,omitempty"`
21+
DisableCopiedCSVs *bool `json:"disableCopiedCSVs,omitempty"`
2322
}
2423

2524
// OLMConfigStatus is the status for an OLMConfig resource.
@@ -56,3 +55,16 @@ type OLMConfigList struct {
5655
func init() {
5756
SchemeBuilder.Register(&OLMConfig{}, &OLMConfigList{})
5857
}
58+
59+
func (config *OLMConfig) CopiedCSVsAreEnabled() bool {
60+
if config == nil {
61+
return true
62+
}
63+
64+
disableCopiedCSVs := config.Spec.Features.DisableCopiedCSVs
65+
if disableCopiedCSVs != nil {
66+
return !*disableCopiedCSVs
67+
}
68+
69+
return true
70+
}

0 commit comments

Comments
 (0)