Skip to content

Commit ec142dc

Browse files
committed
feat: update code to use v1 versions of CRD APIs
The DataGather and InsightsDataGather CRD APIs have been promoted to v1, so the code has been updated to use the latest version. Signed-off-by: Ondrej Pokorny <[email protected]>
1 parent b63bd82 commit ec142dc

27 files changed

+511
-494
lines changed

cmd/obfuscate-archive/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
configv1 "github.com/openshift/api/config/v1"
13-
"github.com/openshift/api/insights/v1alpha2"
13+
insightsv1 "github.com/openshift/api/insights/v1"
1414
"github.com/openshift/insights-operator/pkg/anonymization"
1515
"github.com/openshift/insights-operator/pkg/gather"
1616
"github.com/openshift/insights-operator/pkg/record"
@@ -65,7 +65,7 @@ func obfuscateArchive(path string) (string, error) {
6565
anonBuilder := &anonymization.AnonBuilder{}
6666
anonBuilder.
6767
WithSensitiveValue(clusterBaseDomain, anonymization.ClusterBaseDomainPlaceholder).
68-
WithDataPolicies(v1alpha2.DataPolicyOptionObfuscateNetworking).
68+
WithDataPolicies(insightsv1.DataPolicyOptionObfuscateNetworking).
6969
WithNetworks(networks)
7070
anonymizer, err := anonBuilder.Build()
7171
if err != nil {

pkg/anonymization/anonymizer.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"sync"
3535

3636
configv1 "github.com/openshift/api/config/v1"
37-
"github.com/openshift/api/insights/v1alpha2"
37+
insightsv1 "github.com/openshift/api/insights/v1"
3838
networkv1 "github.com/openshift/api/network/v1"
3939
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
4040
networkv1client "github.com/openshift/client-go/network/clientset/versioned/typed/network/v1"
@@ -90,7 +90,7 @@ type Anonymizer struct {
9090
ipNetworkRegex *regexp.Regexp
9191
secretsClient corev1client.SecretInterface
9292
configurator configobserver.Interface
93-
dataPolicy v1alpha2.DataPolicyOption
93+
dataPolicy insightsv1.DataPolicyOption
9494
configClient configv1client.ConfigV1Interface
9595
networkClient networkv1client.NetworkV1Interface
9696
gatherKubeClient kubernetes.Interface
@@ -109,7 +109,7 @@ func NewAnonymizerFromConfigClient(
109109
configClient configv1client.ConfigV1Interface,
110110
networkClient networkv1client.NetworkV1Interface,
111111
configurator configobserver.Interface,
112-
dataPolicies []v1alpha2.DataPolicyOption,
112+
dataPolicies []insightsv1.DataPolicyOption,
113113
sensitiveVals map[string]string,
114114
) (*Anonymizer, error) {
115115
anonBuilder := &AnonBuilder{}
@@ -306,7 +306,7 @@ func NewAnonymizerFromConfig(
306306
gatherProtoKubeConfig *rest.Config,
307307
protoKubeConfig *rest.Config,
308308
configurator configobserver.Interface,
309-
dataPolicy []v1alpha2.DataPolicyOption,
309+
dataPolicy []insightsv1.DataPolicyOption,
310310
) (*Anonymizer, error) {
311311
sensitiveVals := make(map[string]string)
312312
kubeClient, err := kubernetes.NewForConfig(protoKubeConfig)
@@ -500,11 +500,7 @@ func (anonymizer *Anonymizer) IsObfuscationEnabled() bool {
500500
return true
501501
}
502502

503-
if anonymizer.dataPolicy != "" {
504-
return anonymizer.dataPolicy == v1alpha2.DataPolicyOptionObfuscateNetworking
505-
}
506-
507-
return false
503+
return anonymizer.dataPolicy == insightsv1.DataPolicyOptionObfuscateNetworking
508504
}
509505

510506
// getNextIP returns the next IP address in the current subnetwork and the flag indicating if there was an overflow

pkg/anonymization/anonymizer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88

99
configv1 "github.com/openshift/api/config/v1"
10-
"github.com/openshift/api/insights/v1alpha2"
10+
insightsv1 "github.com/openshift/api/insights/v1"
1111

1212
networkv1 "github.com/openshift/api/network/v1"
1313
configfake "github.com/openshift/client-go/config/clientset/versioned/fake"
@@ -133,7 +133,7 @@ func getAnonymizer(t *testing.T) *Anonymizer {
133133
WithSensitiveValue(clusterBaseDomain, ClusterBaseDomainPlaceholder).
134134
WithSensitiveValue(clusterConfigHost, ClusterHostPlaceholder).
135135
WithConfigurator(mockConfigMapConfigurator).
136-
WithDataPolicies(v1alpha2.DataPolicyOptionObfuscateNetworking).
136+
WithDataPolicies(insightsv1.DataPolicyOptionObfuscateNetworking).
137137
WithNetworks(networks).
138138
WithSecretsClient(kubefake.NewSimpleClientset().CoreV1().Secrets(secretNamespace))
139139
anonymizer, err := anonBuilder.Build()
@@ -449,7 +449,7 @@ func TestNewAnonymizerFromConfigClient(t *testing.T) {
449449
configClient,
450450
networkClient,
451451
mockConfigMapConfigurator,
452-
[]v1alpha2.DataPolicyOption{v1alpha2.DataPolicyOptionObfuscateNetworking},
452+
[]insightsv1.DataPolicyOption{insightsv1.DataPolicyOptionObfuscateNetworking},
453453
make(map[string]string),
454454
)
455455
assert.NoError(t, err)

pkg/anonymization/builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"slices"
66
"strings"
77

8-
"github.com/openshift/api/insights/v1alpha2"
8+
insightsv1 "github.com/openshift/api/insights/v1"
99
v1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
1010
networkv1client "github.com/openshift/client-go/network/clientset/versioned/typed/network/v1"
1111
"github.com/openshift/insights-operator/pkg/config/configobserver"
@@ -41,11 +41,11 @@ func (b *AnonBuilder) WithConfigurator(configurator configobserver.Interface) *A
4141
return b
4242
}
4343

44-
func (b *AnonBuilder) WithDataPolicies(dataPolicy ...v1alpha2.DataPolicyOption) *AnonBuilder {
44+
func (b *AnonBuilder) WithDataPolicies(dataPolicy ...insightsv1.DataPolicyOption) *AnonBuilder {
4545
b.anon.dataPolicy = ""
4646

47-
if slices.Contains(dataPolicy, v1alpha2.DataPolicyOptionObfuscateNetworking) {
48-
b.anon.dataPolicy = v1alpha2.DataPolicyOptionObfuscateNetworking
47+
if slices.Contains(dataPolicy, insightsv1.DataPolicyOptionObfuscateNetworking) {
48+
b.anon.dataPolicy = insightsv1.DataPolicyOptionObfuscateNetworking
4949
}
5050

5151
return b

pkg/anonymization/builder_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package anonymization
33
import (
44
"testing"
55

6-
"github.com/openshift/api/insights/v1alpha2"
6+
insightsv1 "github.com/openshift/api/insights/v1"
77
configfake "github.com/openshift/client-go/config/clientset/versioned/fake"
88
v1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
99
networkfake "github.com/openshift/client-go/network/clientset/versioned/fake"
@@ -23,7 +23,7 @@ func Test_AnonBuilder(t *testing.T) {
2323
sensitiveValues map[string]string
2424
configClient v1.ConfigV1Interface
2525
configurator configobserver.Interface
26-
dataPolicy v1alpha2.DataPolicyOption
26+
dataPolicy insightsv1.DataPolicyOption
2727
kubeClient kubernetes.Interface
2828
networkClient networkv1client.NetworkV1Interface
2929
networks []string
@@ -59,8 +59,8 @@ func Test_AnonBuilder(t *testing.T) {
5959
},
6060
{
6161
name: "method 'WithDataPolicy' sets the policy on the anonymizer instance",
62-
builder: getBuilderInstance().WithDataPolicies(v1alpha2.DataPolicyOptionObfuscateNetworking),
63-
dataPolicy: v1alpha2.DataPolicyOptionObfuscateNetworking,
62+
builder: getBuilderInstance().WithDataPolicies(insightsv1.DataPolicyOptionObfuscateNetworking),
63+
dataPolicy: insightsv1.DataPolicyOptionObfuscateNetworking,
6464
},
6565
{
6666
name: "method 'WithKubeClient' sets the client on the anonymizer instance",

pkg/config/configobserver/configmapobserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type ConfigMapObserver struct {
4242

4343
func NewConfigMapObserver(ctx context.Context, kubeConfig *rest.Config,
4444
eventRecorder events.Recorder,
45-
kubeInformer v1helpers.KubeInformersForNamespaces) (ConfigMapInformer, error) {
45+
kubeInformer v1helpers.KubeInformersForNamespaces,
46+
) (ConfigMapInformer, error) {
4647
cmInformer := kubeInformer.InformersFor(insightsNamespaceName).Core().V1().ConfigMaps().Informer()
4748
kubeClient, err := kubernetes.NewForConfig(kubeConfig)
4849
if err != nil {

pkg/config/configobserver/insighgtsdatagather_observer.go renamed to pkg/config/configobserver/insightsdatagather_observer.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"sync"
66
"time"
77

8-
"github.com/openshift/api/config/v1alpha2"
9-
configCliv1alpha2 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1alpha2"
8+
configv1 "github.com/openshift/api/config/v1"
9+
configCliv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
1010
configinformers "github.com/openshift/client-go/config/informers/externalversions"
1111
"github.com/openshift/library-go/pkg/controller/factory"
1212
"github.com/openshift/library-go/pkg/operator/events"
@@ -17,28 +17,28 @@ import (
1717

1818
type InsightsDataGatherObserver interface {
1919
factory.Controller
20-
GatherConfig() *v1alpha2.GatherConfig
20+
GatherConfig() *configv1.GatherConfig
2121
GatherDisabled() bool
2222
}
2323

2424
type insightsDataGatherController struct {
2525
factory.Controller
2626
lock sync.Mutex
27-
cli configCliv1alpha2.ConfigV1alpha2Interface
28-
gatherConfig *v1alpha2.GatherConfig
27+
cli configCliv1.ConfigV1Interface
28+
gatherConfig *configv1.GatherConfig
2929
}
3030

3131
func NewInsightsDataGatherObserver(kubeConfig *rest.Config,
3232
eventRecorder events.Recorder,
3333
configInformer configinformers.SharedInformerFactory,
3434
) (InsightsDataGatherObserver, error) {
35-
inf := configInformer.Config().V1alpha2().InsightsDataGathers().Informer()
36-
configV1Alpha2Cli, err := configCliv1alpha2.NewForConfig(kubeConfig)
35+
inf := configInformer.Config().V1().InsightsDataGathers().Informer()
36+
configV1Cli, err := configCliv1.NewForConfig(kubeConfig)
3737
if err != nil {
3838
return nil, err
3939
}
4040
c := &insightsDataGatherController{
41-
cli: configV1Alpha2Cli,
41+
cli: configV1Cli,
4242
}
4343

4444
insightDataGatherConf, err := c.cli.InsightsDataGathers().Get(context.Background(), "cluster", metav1.GetOptions{})
@@ -65,7 +65,7 @@ func (i *insightsDataGatherController) sync(ctx context.Context, _ factory.SyncC
6565
}
6666

6767
// GatherConfig provides the complete gather config in a thread-safe way.
68-
func (i *insightsDataGatherController) GatherConfig() *v1alpha2.GatherConfig {
68+
func (i *insightsDataGatherController) GatherConfig() *configv1.GatherConfig {
6969
i.lock.Lock()
7070
defer i.lock.Unlock()
7171
return i.gatherConfig
@@ -77,5 +77,8 @@ func (i *insightsDataGatherController) GatherDisabled() bool {
7777
i.lock.Lock()
7878
defer i.lock.Unlock()
7979

80-
return i.gatherConfig.Gatherers.Mode == v1alpha2.GatheringModeNone
80+
if i.gatherConfig == nil {
81+
return false
82+
}
83+
return i.gatherConfig.Gatherers.Mode == configv1.GatheringModeNone
8184
}

pkg/config/configobserver/insightsdatagather_observer_test.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/openshift/api/config/v1alpha2"
7+
configv1 "github.com/openshift/api/config/v1"
88
fakeConfigCli "github.com/openshift/client-go/config/clientset/versioned/fake"
99
"github.com/stretchr/testify/assert"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -13,54 +13,54 @@ import (
1313
func TestInsightsDataGatherSync(t *testing.T) {
1414
tests := []struct {
1515
name string
16-
insightsDatagatherToUpdated *v1alpha2.InsightsDataGather
17-
expectedGatherConfig *v1alpha2.GatherConfig
16+
insightsDatagatherToUpdated *configv1.InsightsDataGather
17+
expectedGatherConfig *configv1.GatherConfig
1818
expectedDisable bool
1919
}{
2020
{
2121
name: "Obfuscation configured and some disabled gatherers",
22-
insightsDatagatherToUpdated: &v1alpha2.InsightsDataGather{
22+
insightsDatagatherToUpdated: &configv1.InsightsDataGather{
2323
ObjectMeta: metav1.ObjectMeta{
2424
Name: "cluster",
2525
},
26-
Spec: v1alpha2.InsightsDataGatherSpec{
27-
GatherConfig: v1alpha2.GatherConfig{
28-
DataPolicy: []v1alpha2.DataPolicyOption{
29-
v1alpha2.DataPolicyOptionObfuscateNetworking,
26+
Spec: configv1.InsightsDataGatherSpec{
27+
GatherConfig: configv1.GatherConfig{
28+
DataPolicy: []configv1.DataPolicyOption{
29+
configv1.DataPolicyOptionObfuscateNetworking,
3030
},
31-
Gatherers: v1alpha2.Gatherers{
32-
Mode: v1alpha2.GatheringModeCustom,
33-
Custom: &v1alpha2.Custom{
34-
Configs: []v1alpha2.GathererConfig{
31+
Gatherers: configv1.Gatherers{
32+
Mode: configv1.GatheringModeCustom,
33+
Custom: configv1.Custom{
34+
Configs: []configv1.GathererConfig{
3535
{
3636
Name: "fooBar",
37-
State: v1alpha2.GathererStateDisabled,
37+
State: configv1.GathererStateDisabled,
3838
},
3939
{
4040
Name: "barrGather",
41-
State: v1alpha2.GathererStateDisabled,
41+
State: configv1.GathererStateDisabled,
4242
},
4343
},
4444
},
4545
},
4646
},
4747
},
4848
},
49-
expectedGatherConfig: &v1alpha2.GatherConfig{
50-
DataPolicy: []v1alpha2.DataPolicyOption{
51-
v1alpha2.DataPolicyOptionObfuscateNetworking,
49+
expectedGatherConfig: &configv1.GatherConfig{
50+
DataPolicy: []configv1.DataPolicyOption{
51+
configv1.DataPolicyOptionObfuscateNetworking,
5252
},
53-
Gatherers: v1alpha2.Gatherers{
54-
Mode: v1alpha2.GatheringModeCustom,
55-
Custom: &v1alpha2.Custom{
56-
Configs: []v1alpha2.GathererConfig{
53+
Gatherers: configv1.Gatherers{
54+
Mode: configv1.GatheringModeCustom,
55+
Custom: configv1.Custom{
56+
Configs: []configv1.GathererConfig{
5757
{
5858
Name: "fooBar",
59-
State: v1alpha2.GathererStateDisabled,
59+
State: configv1.GathererStateDisabled,
6060
},
6161
{
6262
Name: "barrGather",
63-
State: v1alpha2.GathererStateDisabled,
63+
State: configv1.GathererStateDisabled,
6464
},
6565
},
6666
},
@@ -70,27 +70,27 @@ func TestInsightsDataGatherSync(t *testing.T) {
7070
},
7171
{
7272
name: "Gathering disabled and no obfuscation",
73-
insightsDatagatherToUpdated: &v1alpha2.InsightsDataGather{
73+
insightsDatagatherToUpdated: &configv1.InsightsDataGather{
7474
ObjectMeta: metav1.ObjectMeta{
7575
Name: "cluster",
7676
},
77-
Spec: v1alpha2.InsightsDataGatherSpec{
78-
GatherConfig: v1alpha2.GatherConfig{
79-
DataPolicy: []v1alpha2.DataPolicyOption{
80-
v1alpha2.DataPolicyOptionObfuscateNetworking,
77+
Spec: configv1.InsightsDataGatherSpec{
78+
GatherConfig: configv1.GatherConfig{
79+
DataPolicy: []configv1.DataPolicyOption{
80+
configv1.DataPolicyOptionObfuscateNetworking,
8181
},
82-
Gatherers: v1alpha2.Gatherers{
83-
Mode: v1alpha2.GatheringModeNone,
82+
Gatherers: configv1.Gatherers{
83+
Mode: configv1.GatheringModeNone,
8484
},
8585
},
8686
},
8787
},
88-
expectedGatherConfig: &v1alpha2.GatherConfig{
89-
DataPolicy: []v1alpha2.DataPolicyOption{
90-
v1alpha2.DataPolicyOptionObfuscateNetworking,
88+
expectedGatherConfig: &configv1.GatherConfig{
89+
DataPolicy: []configv1.DataPolicyOption{
90+
configv1.DataPolicyOptionObfuscateNetworking,
9191
},
92-
Gatherers: v1alpha2.Gatherers{
93-
Mode: v1alpha2.GatheringModeNone,
92+
Gatherers: configv1.Gatherers{
93+
Mode: configv1.GatheringModeNone,
9494
},
9595
},
9696
expectedDisable: true,
@@ -99,7 +99,7 @@ func TestInsightsDataGatherSync(t *testing.T) {
9999

100100
for _, tt := range tests {
101101
t.Run(tt.name, func(t *testing.T) {
102-
insightDefaultConfig := &v1alpha2.InsightsDataGather{
102+
insightDefaultConfig := &configv1.InsightsDataGather{
103103
ObjectMeta: metav1.ObjectMeta{
104104
Name: "cluster",
105105
},
@@ -108,7 +108,7 @@ func TestInsightsDataGatherSync(t *testing.T) {
108108
client := fakeConfigCli.NewSimpleClientset(insightDefaultConfig)
109109
idgObserver := insightsDataGatherController{
110110
gatherConfig: &insightDefaultConfig.Spec.GatherConfig,
111-
cli: client.ConfigV1alpha2(),
111+
cli: client.ConfigV1(),
112112
}
113113
err := idgObserver.sync(context.Background(), nil)
114114
assert.NoError(t, err)

0 commit comments

Comments
 (0)