Skip to content

Commit

Permalink
[release-4.11] OCPBUGS-15446: extend configmap gatherer to get gatewa…
Browse files Browse the repository at this point in the history
…y-mode-config (openshift#788) (openshift#791)
  • Loading branch information
tremes committed Jun 27, 2023
1 parent abc6aa2 commit 2c77b22
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
30 changes: 30 additions & 0 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"local"
16 changes: 11 additions & 5 deletions pkg/gatherers/clusterconfig/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
Expand Down Expand Up @@ -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),
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gatherers/clusterconfig/config_maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 2c77b22

Please sign in to comment.