Skip to content

Commit

Permalink
OCPBUGS-14475: extend configmap gatherer to get gateway-mode-config (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes authored and JoaoFula committed Jan 23, 2024
1 parent 2b4e75a commit ee2b05b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ and tries to fetch `cluster-monitoring-config` from `openshift-monitoring` names
### Changes
- `cluster-monitoring-config` data since versions 4.6.22+ and 4.7.0+
- `cluster-config-v1` since versions 4.9.0+
- `gateway-mode-config` data from 'openshift-network-operator' namespace since 4.14.0+

### Anonymization
If the content of a `ConfigMap` contains a parseable PEM structure (like a certificate), it removes the inside of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"local"
5 changes: 4 additions & 1 deletion pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
return err
}

desiredVersion := os.Getenv("RELEASE_VERSION")
missingVersion := "0.0.1-snapshot"
desiredVersion := missingVersion
if envVersion, exists := os.LookupEnv("RELEASE_VERSION"); exists {
desiredVersion = envVersion
}

// By default, this will exit(0) the process if the featuregates ever change to a different set of values.
featureGateAccessor := featuregates.NewFeatureGateAccess(
Expand Down
15 changes: 10 additions & 5 deletions pkg/gatherers/clusterconfig/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
// ### Changes
// - `cluster-monitoring-config` data since versions 4.6.22+ and 4.7.0+
// - `cluster-config-v1` since versions 4.9.0+
// - `gateway-mode-config` data from 'openshift-network-operator' namespace since 4.14.0+
//
// ### Anonymization
// If the content of a `ConfigMap` contains a parseable PEM structure (like a certificate), it removes the inside of
Expand All @@ -61,10 +62,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 @@ -98,21 +103,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 ee2b05b

Please sign in to comment.