@@ -32,9 +32,11 @@ import (
32
32
33
33
configv1 "github.com/openshift/api/config/v1"
34
34
registryv1 "github.com/openshift/api/imageregistry/v1"
35
+ networkv1 "github.com/openshift/api/network/v1"
35
36
openshiftscheme "github.com/openshift/client-go/config/clientset/versioned/scheme"
36
37
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
37
38
imageregistryv1 "github.com/openshift/client-go/imageregistry/clientset/versioned/typed/imageregistry/v1"
39
+ networkv1client "github.com/openshift/client-go/network/clientset/versioned/typed/network/v1"
38
40
39
41
"github.com/openshift/insights-operator/pkg/record"
40
42
"github.com/openshift/insights-operator/pkg/record/diskrecorder"
66
68
maxEventTimeInterval = 1 * time .Hour
67
69
68
70
registrySerializer serializer.CodecFactory
71
+ networkSerializer serializer.CodecFactory
69
72
registryScheme = runtime .NewScheme ()
73
+ networkScheme = runtime .NewScheme ()
70
74
71
75
// logTailLines sets maximum number of lines to fetch from pod logs
72
76
logTailLines = int64 (100 )
@@ -79,13 +83,16 @@ var (
79
83
80
84
func init () {
81
85
utilruntime .Must (registryv1 .AddToScheme (registryScheme ))
86
+ utilruntime .Must (networkv1 .AddToScheme (networkScheme ))
87
+ networkSerializer = serializer .NewCodecFactory (networkScheme )
82
88
registrySerializer = serializer .NewCodecFactory (registryScheme )
83
89
}
84
90
85
91
// Gatherer is a driving instance invoking collection of data
86
92
type Gatherer struct {
87
93
client configv1client.ConfigV1Interface
88
94
coreClient corev1client.CoreV1Interface
95
+ networkClient networkv1client.NetworkV1Interface
89
96
metricsClient rest.Interface
90
97
certClient certificatesv1beta1.CertificatesV1beta1Interface
91
98
registryClient imageregistryv1.ImageregistryV1Interface
@@ -96,14 +103,15 @@ type Gatherer struct {
96
103
97
104
// New creates new Gatherer
98
105
func New (client configv1client.ConfigV1Interface , coreClient corev1client.CoreV1Interface , certClient certificatesv1beta1.CertificatesV1beta1Interface , metricsClient rest.Interface ,
99
- registryClient imageregistryv1.ImageregistryV1Interface , crdClient apixv1beta1client.ApiextensionsV1beta1Interface ) * Gatherer {
106
+ registryClient imageregistryv1.ImageregistryV1Interface , crdClient apixv1beta1client.ApiextensionsV1beta1Interface , networkClient networkv1client. NetworkV1Interface ) * Gatherer {
100
107
return & Gatherer {
101
108
client : client ,
102
109
coreClient : coreClient ,
103
110
certClient : certClient ,
104
111
metricsClient : metricsClient ,
105
112
registryClient : registryClient ,
106
113
crdClient : crdClient ,
114
+ networkClient : networkClient ,
107
115
}
108
116
}
109
117
@@ -130,6 +138,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
130
138
GatherClusterProxy (i ),
131
139
GatherCertificateSigningRequests (i ),
132
140
GatherCRD (i ),
141
+ GatherHostSubnet (i ),
133
142
)
134
143
}
135
144
@@ -509,6 +518,30 @@ func GatherClusterNetwork(i *Gatherer) func() ([]record.Record, []error) {
509
518
}
510
519
}
511
520
521
+ // GatherHostSubnet collects HostSubnet information
522
+ //
523
+ // The Kubernetes api https://github.com/openshift/client-go/blob/master/network/clientset/versioned/typed/network/v1/hostsubnet.go
524
+ // Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.html#hostsubnet-v1-network-openshift-io
525
+ //
526
+ // Location in archive: config/hostsubnet/
527
+ func GatherHostSubnet (i * Gatherer ) func () ([]record.Record , []error ) {
528
+ return func () ([]record.Record , []error ) {
529
+
530
+ hostSubnetList , err := i .networkClient .HostSubnets ().List (metav1.ListOptions {})
531
+ if errors .IsNotFound (err ) {
532
+ return nil , nil
533
+ }
534
+ if err != nil {
535
+ return nil , []error {err }
536
+ }
537
+ records := make ([]record.Record , 0 , len (hostSubnetList .Items ))
538
+ for _ , h := range hostSubnetList .Items {
539
+ records = append (records , record.Record {Name : fmt .Sprintf ("config/hostsubnet/%s" , h .Host ), Item : HostSubnetAnonymizer {& h }})
540
+ }
541
+ return records , nil
542
+ }
543
+ }
544
+
512
545
// GatherClusterAuthentication fetches the cluster Authentication - the Authentication with name cluster.
513
546
//
514
547
// The Kubernetes api https://github.com/openshift/client-go/blob/master/config/clientset/versioned/typed/config/v1/authentication.go#L50
@@ -1027,6 +1060,14 @@ func anonymizeString(s string) string {
1027
1060
return strings .Repeat ("x" , len (s ))
1028
1061
}
1029
1062
1063
+ func anonymizeSliceOfStrings (slice []string ) []string {
1064
+ anonymizedSlice := make ([]string , len (slice ), len (slice ))
1065
+ for i , s := range slice {
1066
+ anonymizedSlice [i ] = anonymizeString (s )
1067
+ }
1068
+ return anonymizedSlice
1069
+ }
1070
+
1030
1071
func isProductNamespacedKey (key string ) bool {
1031
1072
return strings .Contains (key , "openshift.io/" ) || strings .Contains (key , "k8s.io/" ) || strings .Contains (key , "kubernetes.io/" )
1032
1073
}
@@ -1123,6 +1164,23 @@ func (a ConfigMapAnonymizer) GetExtension() string {
1123
1164
return ""
1124
1165
}
1125
1166
1167
+ // HostSubnetAnonymizer implements HostSubnet serialization wiht anonymization
1168
+ type HostSubnetAnonymizer struct { * networkv1.HostSubnet }
1169
+
1170
+ // Marshal implements HostSubnet serialization
1171
+ func (a HostSubnetAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
1172
+ a .HostSubnet .HostIP = anonymizeString (a .HostSubnet .HostIP )
1173
+ a .HostSubnet .Subnet = anonymizeString (a .HostSubnet .Subnet )
1174
+ a .HostSubnet .EgressIPs = anonymizeSliceOfStrings (a .HostSubnet .EgressIPs )
1175
+ a .HostSubnet .EgressCIDRs = anonymizeSliceOfStrings (a .HostSubnet .EgressCIDRs )
1176
+ return runtime .Encode (networkSerializer .LegacyCodec (networkv1 .SchemeGroupVersion ), a .HostSubnet )
1177
+ }
1178
+
1179
+ // GetExtension returns extension for HostSubnet object
1180
+ func (a HostSubnetAnonymizer ) GetExtension () string {
1181
+ return "json"
1182
+ }
1183
+
1126
1184
func anonymizeConfigMap (dv []byte ) string {
1127
1185
anonymizedPemBlock := `-----BEGIN CERTIFICATE-----
1128
1186
ANONYMIZED
0 commit comments