@@ -2,61 +2,75 @@ package clusterconfig
2
2
3
3
import (
4
4
"context"
5
+ "encoding/base64"
6
+ "encoding/pem"
5
7
"fmt"
6
8
"regexp"
7
9
"sort"
8
10
"strings"
9
11
"sync"
10
12
"time"
11
13
12
- configv1 "github.com/openshift/api/config/v1"
13
- "github.com/openshift/client-go/config/clientset/versioned/scheme"
14
- configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
15
- certificatesv1beta1 "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
16
-
17
- "encoding/base64"
18
- "encoding/pem"
19
-
20
14
corev1 "k8s.io/api/core/v1"
21
15
"k8s.io/apimachinery/pkg/api/errors"
22
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
17
"k8s.io/apimachinery/pkg/runtime"
18
+ "k8s.io/apimachinery/pkg/runtime/serializer"
24
19
"k8s.io/apimachinery/pkg/util/json"
20
+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
25
21
"k8s.io/apimachinery/pkg/util/sets"
26
22
kubescheme "k8s.io/client-go/kubernetes/scheme"
23
+ certificatesv1beta1 "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
27
24
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
28
25
"k8s.io/client-go/rest"
29
26
"k8s.io/klog"
30
27
28
+ configv1 "github.com/openshift/api/config/v1"
29
+ registryv1 "github.com/openshift/api/imageregistry/v1"
30
+ openshiftscheme "github.com/openshift/client-go/config/clientset/versioned/scheme"
31
+ configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
32
+ imageregistryv1 "github.com/openshift/client-go/imageregistry/clientset/versioned/typed/imageregistry/v1"
33
+
31
34
"github.com/openshift/insights-operator/pkg/record"
32
35
)
33
36
34
37
var (
35
- serializer = scheme .Codecs .LegacyCodec (configv1 .SchemeGroupVersion )
36
- kubeSerializer = kubescheme .Codecs .LegacyCodec (corev1 .SchemeGroupVersion )
38
+ openshiftSerializer = openshiftscheme .Codecs .LegacyCodec (configv1 .SchemeGroupVersion )
39
+ kubeSerializer = kubescheme .Codecs .LegacyCodec (corev1 .SchemeGroupVersion )
37
40
38
41
// maxEventTimeInterval represents the "only keep events that are maximum 1h old"
39
42
// TODO: make this dynamic like the reporting window based on configured interval
40
43
maxEventTimeInterval = 1 * time .Hour
44
+
45
+ registrySerializer serializer.CodecFactory
46
+ registryScheme = runtime .NewScheme ()
41
47
)
42
48
49
+ func init () {
50
+ utilruntime .Must (registryv1 .AddToScheme (registryScheme ))
51
+ registrySerializer = serializer .NewCodecFactory (registryScheme )
52
+ }
53
+
43
54
// Gatherer is a driving instance invoking collection of data
44
55
type Gatherer struct {
45
- client configv1client.ConfigV1Interface
46
- coreClient corev1client.CoreV1Interface
47
- metricsClient rest.Interface
48
- certClient certificatesv1beta1.CertificatesV1beta1Interface
49
- lock sync.Mutex
50
- lastVersion * configv1.ClusterVersion
56
+ client configv1client.ConfigV1Interface
57
+ coreClient corev1client.CoreV1Interface
58
+ metricsClient rest.Interface
59
+ certClient certificatesv1beta1.CertificatesV1beta1Interface
60
+ registryClient imageregistryv1.ImageregistryV1Interface
61
+ lock sync.Mutex
62
+ lastVersion * configv1.ClusterVersion
51
63
}
52
64
53
65
// New creates new Gatherer
54
- func New (client configv1client.ConfigV1Interface , coreClient corev1client.CoreV1Interface , certClient certificatesv1beta1.CertificatesV1beta1Interface , metricsClient rest.Interface ) * Gatherer {
66
+ func New (client configv1client.ConfigV1Interface , coreClient corev1client.CoreV1Interface , certClient certificatesv1beta1.CertificatesV1beta1Interface , metricsClient rest.Interface ,
67
+ registryClient imageregistryv1.ImageregistryV1Interface ) * Gatherer {
55
68
return & Gatherer {
56
- client : client ,
57
- coreClient : coreClient ,
58
- certClient : certClient ,
59
- metricsClient : metricsClient ,
69
+ client : client ,
70
+ coreClient : coreClient ,
71
+ certClient : certClient ,
72
+ metricsClient : metricsClient ,
73
+ registryClient : registryClient ,
60
74
}
61
75
}
62
76
@@ -74,6 +88,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
74
88
GatherClusterInfrastructure (i ),
75
89
GatherClusterNetwork (i ),
76
90
GatherClusterAuthentication (i ),
91
+ GatherClusterImageRegistry (i ),
77
92
GatherClusterFeatureGates (i ),
78
93
GatherClusterOAuth (i ),
79
94
GatherClusterIngress (i ),
@@ -329,6 +344,22 @@ func GatherClusterAuthentication(i *Gatherer) func() ([]record.Record, []error)
329
344
}
330
345
}
331
346
347
+ // GatherClusterImageRegistry fetches the cluster Image Registry configuration
348
+ //
349
+ // Location in archive: config/imageregistry/
350
+ func GatherClusterImageRegistry (i * Gatherer ) func () ([]record.Record , []error ) {
351
+ return func () ([]record.Record , []error ) {
352
+ config , err := i .registryClient .Configs ().Get ("cluster" , metav1.GetOptions {})
353
+ if errors .IsNotFound (err ) {
354
+ return nil , nil
355
+ }
356
+ if err != nil {
357
+ return nil , []error {err }
358
+ }
359
+ return []record.Record {{Name : "config/imageregistry" , Item : ImageRegistryAnonymizer {config }}}, nil
360
+ }
361
+ }
362
+
332
363
// GatherClusterFeatureGates fetches the cluster FeatureGate - the FeatureGate with name cluster.
333
364
//
334
365
// The Kubernetes api https://github.com/openshift/client-go/blob/master/config/clientset/versioned/typed/config/v1/featuregate.go#L50
@@ -490,17 +521,17 @@ func (r Raw) Marshal(_ context.Context) ([]byte, error) {
490
521
// Anonymizer returns serialized runtime.Object without change
491
522
type Anonymizer struct { runtime.Object }
492
523
493
- // Marshal serializes with OpenShift client-go serializer
524
+ // Marshal serializes with OpenShift client-go openshiftSerializer
494
525
func (a Anonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
495
- return runtime .Encode (serializer , a .Object )
526
+ return runtime .Encode (openshiftSerializer , a .Object )
496
527
}
497
528
498
529
// InfrastructureAnonymizer anonymizes infrastructure
499
530
type InfrastructureAnonymizer struct { * configv1.Infrastructure }
500
531
501
532
// Marshal serializes Infrastructure with anonymization
502
533
func (a InfrastructureAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
503
- return runtime .Encode (serializer , anonymizeInfrastructure (a .Infrastructure ))
534
+ return runtime .Encode (openshiftSerializer , anonymizeInfrastructure (a .Infrastructure ))
504
535
}
505
536
506
537
func anonymizeInfrastructure (config * configv1.Infrastructure ) * configv1.Infrastructure {
@@ -517,15 +548,50 @@ type ClusterVersionAnonymizer struct{ *configv1.ClusterVersion }
517
548
// Marshal serializes ClusterVersion with anonymization
518
549
func (a ClusterVersionAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
519
550
a .ClusterVersion .Spec .Upstream = configv1 .URL (anonymizeURL (string (a .ClusterVersion .Spec .Upstream )))
520
- return runtime .Encode (serializer , a .ClusterVersion )
551
+ return runtime .Encode (openshiftSerializer , a .ClusterVersion )
521
552
}
522
553
523
554
// FeatureGateAnonymizer implements serializaton of FeatureGate with anonymization
524
555
type FeatureGateAnonymizer struct { * configv1.FeatureGate }
525
556
526
557
// Marshal serializes FeatureGate with anonymization
527
558
func (a FeatureGateAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
528
- return runtime .Encode (serializer , a .FeatureGate )
559
+ return runtime .Encode (openshiftSerializer , a .FeatureGate )
560
+ }
561
+
562
+ // IngressAnonymizer implements serialization with marshalling
563
+ type ImageRegistryAnonymizer struct {
564
+ * registryv1.Config
565
+ }
566
+
567
+ // Marshal implements serialization of Ingres.Spec.Domain with anonymization
568
+ func (a ImageRegistryAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
569
+ a .Spec .HTTPSecret = anonymizeString (a .Spec .HTTPSecret )
570
+ if a .Spec .Storage .S3 != nil {
571
+ a .Spec .Storage .S3 .Bucket = anonymizeString (a .Spec .Storage .S3 .Bucket )
572
+ a .Spec .Storage .S3 .KeyID = anonymizeString (a .Spec .Storage .S3 .KeyID )
573
+ a .Spec .Storage .S3 .RegionEndpoint = anonymizeString (a .Spec .Storage .S3 .RegionEndpoint )
574
+ a .Spec .Storage .S3 .Region = anonymizeString (a .Spec .Storage .S3 .Region )
575
+ }
576
+ if a .Spec .Storage .Azure != nil {
577
+ a .Spec .Storage .Azure .AccountName = anonymizeString (a .Spec .Storage .Azure .AccountName )
578
+ a .Spec .Storage .Azure .Container = anonymizeString (a .Spec .Storage .Azure .Container )
579
+ }
580
+ if a .Spec .Storage .GCS != nil {
581
+ a .Spec .Storage .GCS .Bucket = anonymizeString (a .Spec .Storage .GCS .Bucket )
582
+ a .Spec .Storage .GCS .ProjectID = anonymizeString (a .Spec .Storage .GCS .ProjectID )
583
+ a .Spec .Storage .GCS .KeyID = anonymizeString (a .Spec .Storage .GCS .KeyID )
584
+ }
585
+ if a .Spec .Storage .Swift != nil {
586
+ a .Spec .Storage .Swift .AuthURL = anonymizeString (a .Spec .Storage .Swift .AuthURL )
587
+ a .Spec .Storage .Swift .Container = anonymizeString (a .Spec .Storage .Swift .Container )
588
+ a .Spec .Storage .Swift .Domain = anonymizeString (a .Spec .Storage .Swift .Domain )
589
+ a .Spec .Storage .Swift .DomainID = anonymizeString (a .Spec .Storage .Swift .DomainID )
590
+ a .Spec .Storage .Swift .Tenant = anonymizeString (a .Spec .Storage .Swift .Tenant )
591
+ a .Spec .Storage .Swift .TenantID = anonymizeString (a .Spec .Storage .Swift .TenantID )
592
+ a .Spec .Storage .Swift .RegionName = anonymizeString (a .Spec .Storage .Swift .RegionName )
593
+ }
594
+ return runtime .Encode (registrySerializer .LegacyCodec (registryv1 .SchemeGroupVersion ), a .Config )
529
595
}
530
596
531
597
// IngressAnonymizer implements serialization with marshalling
@@ -534,7 +600,7 @@ type IngressAnonymizer struct{ *configv1.Ingress }
534
600
// Marshal implements serialization of Ingres.Spec.Domain with anonymization
535
601
func (a IngressAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
536
602
a .Ingress .Spec .Domain = anonymizeURL (a .Ingress .Spec .Domain )
537
- return runtime .Encode (serializer , a .Ingress )
603
+ return runtime .Encode (openshiftSerializer , a .Ingress )
538
604
}
539
605
540
606
// CompactedEvent holds one Namespace Event
@@ -570,7 +636,7 @@ func (a ProxyAnonymizer) Marshal(_ context.Context) ([]byte, error) {
570
636
a .Proxy .Status .HTTPProxy = anonymizeURLCSV (a .Proxy .Status .HTTPProxy )
571
637
a .Proxy .Status .HTTPSProxy = anonymizeURLCSV (a .Proxy .Status .HTTPSProxy )
572
638
a .Proxy .Status .NoProxy = anonymizeURLCSV (a .Proxy .Status .NoProxy )
573
- return runtime .Encode (serializer , a .Proxy )
639
+ return runtime .Encode (openshiftSerializer , a .Proxy )
574
640
}
575
641
576
642
func anonymizeURLCSV (s string ) string {
@@ -596,7 +662,7 @@ type ClusterOperatorAnonymizer struct{ *configv1.ClusterOperator }
596
662
597
663
// Marshal serializes ClusterOperator
598
664
func (a ClusterOperatorAnonymizer ) Marshal (_ context.Context ) ([]byte , error ) {
599
- return runtime .Encode (serializer , a .ClusterOperator )
665
+ return runtime .Encode (openshiftSerializer , a .ClusterOperator )
600
666
}
601
667
602
668
func isHealthyOperator (operator * configv1.ClusterOperator ) bool {
0 commit comments