From 2c77b225ecf8e7f65499557bd77de1b41370be6f Mon Sep 17 00:00:00 2001 From: Tomas Remes Date: Mon, 26 Jun 2023 13:08:19 +0200 Subject: [PATCH] [release-4.11] OCPBUGS-15446: extend configmap gatherer to get gateway-mode-config (#788) (#791) --- docs/gathered-data.md | 30 +++++++++++++++++++ .../gateway-mode-config/mode.json | 1 + pkg/gatherers/clusterconfig/config_maps.go | 16 ++++++---- .../clusterconfig/config_maps_test.go | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 docs/insights-archive-sample/config/configmaps/openshift-network-operator/gateway-mode-config/mode.json diff --git a/docs/gathered-data.md b/docs/gathered-data.md index 2deb0528e..09526606d 100644 --- a/docs/gathered-data.md +++ b/docs/gathered-data.md @@ -282,6 +282,8 @@ Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.ht * 4.7+ * "cluster-config-v1" ConfigMap since versions: * 4.9+ +* "gateway-mode-config" data from 'openshift-network-operator' namespace since: + * 4.14.0+ ## ContainerImages @@ -546,6 +548,34 @@ Response see: * 4.6+ +## MonitoringPVs + +Collects Persistent Volumes from openshift-monitoring namespace +which matches with ConfigMap configuration yaml + +### API Reference +- https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/core/v1/configmap.go +- https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/core/v1/persistentvolume.go + +### Sample data +- docs/insights-archive-sample/config/persistentvolumes/monitoring-persistent-volume.json + +### Location in archive +- `config/persistentvolumes/{persistent_volume_name}.json` + +### Config ID +`clusterconfig/monitoring_persistent_volumes` + +### Released version +- 4.14 + +### Backported versions +- 4.13 + +### Changes +None + + ## MostRecentMetrics Collects cluster Federated Monitoring metrics. diff --git a/docs/insights-archive-sample/config/configmaps/openshift-network-operator/gateway-mode-config/mode.json b/docs/insights-archive-sample/config/configmaps/openshift-network-operator/gateway-mode-config/mode.json new file mode 100644 index 000000000..8fde6b535 --- /dev/null +++ b/docs/insights-archive-sample/config/configmaps/openshift-network-operator/gateway-mode-config/mode.json @@ -0,0 +1 @@ +"local" \ No newline at end of file diff --git a/pkg/gatherers/clusterconfig/config_maps.go b/pkg/gatherers/clusterconfig/config_maps.go index 84a1c872a..ac4b73cec 100644 --- a/pkg/gatherers/clusterconfig/config_maps.go +++ b/pkg/gatherers/clusterconfig/config_maps.go @@ -39,6 +39,8 @@ import ( // * 4.7+ // * "cluster-config-v1" ConfigMap since versions: // * 4.9+ +// * "gateway-mode-config" data from 'openshift-network-operator' namespace since: +// * 4.14.0+ func (g *Gatherer) GatherConfigMaps(ctx context.Context) ([]record.Record, []error) { gatherKubeClient, err := kubernetes.NewForConfig(g.gatherProtoKubeConfig) if err != nil { @@ -49,10 +51,14 @@ func (g *Gatherer) GatherConfigMaps(ctx context.Context) ([]record.Record, []err records, errs := gatherConfigMaps(ctx, coreClient) - monitoringRec, monitoringErrs := gatherMonitoringCM(ctx, coreClient) + monitoringRec, monitoringErrs := gatherConfigMap(ctx, coreClient, "cluster-monitoring-config", "openshift-monitoring") records = append(records, monitoringRec...) errs = append(errs, monitoringErrs...) + gateayModeConf, networkErrs := gatherConfigMap(ctx, coreClient, "gateway-mode-config", "openshift-network-operator") + records = append(records, gateayModeConf...) + errs = append(errs, networkErrs...) + clusterConfigV1Rec, clusterConfigV1Errs := gatherClusterConfigV1(ctx, coreClient) records = append(records, clusterConfigV1Rec...) errs = append(errs, clusterConfigV1Errs...) @@ -86,21 +92,21 @@ func gatherConfigMaps(ctx context.Context, coreClient corev1client.CoreV1Interfa return records, nil } -func gatherMonitoringCM(ctx context.Context, coreClient corev1client.CoreV1Interface) ([]record.Record, []error) { - monitoringCM, err := coreClient.ConfigMaps("openshift-monitoring").Get(ctx, "cluster-monitoring-config", metav1.GetOptions{}) +func gatherConfigMap(ctx context.Context, coreClient corev1client.CoreV1Interface, name, namespace string) ([]record.Record, []error) { + cm, err := coreClient.ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { return nil, []error{err} } records := make([]record.Record, 0) - for dk, dv := range monitoringCM.Data { + for dk, dv := range cm.Data { j, err := yaml.YAMLToJSON([]byte(dv)) if err != nil { return nil, []error{err} } records = append(records, record.Record{ - Name: fmt.Sprintf("config/configmaps/%s/%s/%s", monitoringCM.Namespace, monitoringCM.Name, strings.TrimSuffix(dk, ".yaml")), + Name: fmt.Sprintf("config/configmaps/%s/%s/%s", cm.Namespace, cm.Name, strings.TrimSuffix(dk, ".yaml")), Item: RawJSON(j), }) } diff --git a/pkg/gatherers/clusterconfig/config_maps_test.go b/pkg/gatherers/clusterconfig/config_maps_test.go index 99c0d3c27..c9b652459 100644 --- a/pkg/gatherers/clusterconfig/config_maps_test.go +++ b/pkg/gatherers/clusterconfig/config_maps_test.go @@ -204,7 +204,7 @@ func Test_ConfigMap_YAML_Data(t *testing.T) { if err != nil { t.Fatalf("cannot create %s config map: %v", tt.testCM.Name, err) } - records, errs := gatherMonitoringCM(context.Background(), coreClient.CoreV1()) + records, errs := gatherConfigMap(context.Background(), coreClient.CoreV1(), tt.testCM.Name, tt.testCM.Namespace) if len(errs) > 0 { if errs[0].Error() != tt.expectedError.Error() { t.Fatalf("unexpected errors: %v", errs[0].Error())