Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.12] OCPBUGS-15414: extend configmap gatherer to get gatewa… #801

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"local"
17 changes: 12 additions & 5 deletions pkg/gatherers/clusterconfig/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
Expand Down Expand Up @@ -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),
})
}
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