From 43da6bc23d3401c8f99e80267906769433c6cfe0 Mon Sep 17 00:00:00 2001 From: Tomas Remes Date: Mon, 26 Jun 2023 13:08:19 +0200 Subject: [PATCH] [release-4.12] OCPBUGS-15414: extend configmap gatherer to get gateway-mode-config (#788) (#791) --- docs/gathered-data.md | 3 +++ .../gateway-mode-config/mode.json | 1 + pkg/gatherers/clusterconfig/config_maps.go | 17 ++++++++++++----- pkg/gatherers/clusterconfig/config_maps_test.go | 2 +- 4 files changed, 17 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 a802d2bf5..e9ced2c44 100644 --- a/docs/gathered-data.md +++ b/docs/gathered-data.md @@ -311,6 +311,9 @@ Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.ht * "cluster-config-v1" ConfigMap since versions: - 4.9+ +* "gateway-mode-config" data from 'openshift-network-operator' namespace since: + - 4.14.0+ + ## ContainerImages 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 b368a54a8..9ea0e9f6f 100644 --- a/pkg/gatherers/clusterconfig/config_maps.go +++ b/pkg/gatherers/clusterconfig/config_maps.go @@ -41,6 +41,9 @@ import ( // // * "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 { @@ -51,10 +54,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...) @@ -88,21 +95,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 5e980260a..986bdf794 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())