mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-09-03 00:47:17 +00:00
troubleshoot enables collecting all data from a configmap (#395)
Enabled collecting all data from a ConfigMap instead of by key
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
apiVersion: troubleshoot.sh/v1beta2
|
||||
kind: SupportBundle
|
||||
metadata:
|
||||
name: example-collect-all-configmap-data
|
||||
spec:
|
||||
collectors:
|
||||
- configMap:
|
||||
namespace: kurl
|
||||
name: kurl-current-config
|
||||
includeAllData: true
|
||||
- configMap:
|
||||
namespace: kurl
|
||||
name: kurl-last-config
|
||||
includeAllData: true
|
||||
|
||||
|
||||
@@ -33,12 +33,13 @@ type Secret struct {
|
||||
}
|
||||
|
||||
type ConfigMap struct {
|
||||
CollectorMeta `json:",inline" yaml:",inline"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Selector []string `json:"selector,omitempty" yaml:"selector,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
||||
IncludeValue bool `json:"includeValue,omitempty" yaml:"includeValue,omitempty"`
|
||||
CollectorMeta `json:",inline" yaml:",inline"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Selector []string `json:"selector,omitempty" yaml:"selector,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
||||
IncludeValue bool `json:"includeValue,omitempty" yaml:"includeValue,omitempty"`
|
||||
IncludeAllData bool `json:"includeAllData,omitempty" yaml:"includeAllData,omitempty"`
|
||||
}
|
||||
|
||||
type LogLimits struct {
|
||||
|
||||
@@ -16,12 +16,13 @@ import (
|
||||
)
|
||||
|
||||
type ConfigMapOutput struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
ConfigMapExists bool `json:"configMapExists"`
|
||||
KeyExists bool `json:"keyExists"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
ConfigMapExists bool `json:"configMapExists"`
|
||||
KeyExists bool `json:"keyExists"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Data map[string]string `json:"data,omitonempty"`
|
||||
}
|
||||
|
||||
func ConfigMap(ctx context.Context, client kubernetes.Interface, configMapCollector *troubleshootv1beta2.ConfigMap) (map[string][]byte, error) {
|
||||
@@ -81,6 +82,9 @@ func configMapToOutput(configMapCollector *troubleshootv1beta2.ConfigMap, config
|
||||
|
||||
if configMap != nil {
|
||||
foundConfigMap.ConfigMapExists = true
|
||||
if configMapCollector.IncludeAllData {
|
||||
foundConfigMap.Data = configMap.Data
|
||||
}
|
||||
if configMapCollector.Key != "" {
|
||||
if val, ok := configMap.Data[configMapCollector.Key]; ok {
|
||||
foundConfigMap.KeyExists = true
|
||||
|
||||
@@ -213,6 +213,112 @@ func TestConfigMap(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "collectAll",
|
||||
configMapCollector: &troubleshootv1beta2.ConfigMap{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
IncludeAllData: true,
|
||||
},
|
||||
mockConfigMaps: []corev1.ConfigMap{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-configmap",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"test-key1": "test-value1",
|
||||
"test-key2": "test-value2",
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"test-key": "test-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: map[string][]byte{
|
||||
"configmaps/test-namespace/test-configmap.json": mustJSONMarshalIndent(t, ConfigMapOutput{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
ConfigMapExists: true,
|
||||
Data: map[string]string{
|
||||
"test-key1": "test-value1",
|
||||
"test-key2": "test-value2",
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "collectAll no data",
|
||||
configMapCollector: &troubleshootv1beta2.ConfigMap{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
IncludeAllData: true,
|
||||
},
|
||||
mockConfigMaps: []corev1.ConfigMap{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-configmap",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"test-key": "test-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: map[string][]byte{
|
||||
"configmaps/test-namespace/test-configmap.json": mustJSONMarshalIndent(t, ConfigMapOutput{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
ConfigMapExists: true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "collectAll with slectKey",
|
||||
configMapCollector: &troubleshootv1beta2.ConfigMap{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
Key: "test-key1",
|
||||
IncludeAllData: true,
|
||||
},
|
||||
mockConfigMaps: []corev1.ConfigMap{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-configmap",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"test-key1": "test-value1",
|
||||
"test-key2": "test-value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: map[string][]byte{
|
||||
"configmaps/test-namespace/test-configmap/test-key1.json": mustJSONMarshalIndent(t, ConfigMapOutput{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-configmap",
|
||||
ConfigMapExists: true,
|
||||
Key: "test-key1",
|
||||
Data: map[string]string{
|
||||
"test-key1": "test-value1",
|
||||
"test-key2": "test-value2",
|
||||
},
|
||||
KeyExists: true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user