diff --git a/config/crds/troubleshoot.sh_collectors.yaml b/config/crds/troubleshoot.sh_collectors.yaml index 203fe76f5..2294cc5ef 100644 --- a/config/crds/troubleshoot.sh_collectors.yaml +++ b/config/crds/troubleshoot.sh_collectors.yaml @@ -349,6 +349,8 @@ spec: type: object helm: properties: + collectValues: + type: boolean collectorName: type: string exclude: diff --git a/config/crds/troubleshoot.sh_preflights.yaml b/config/crds/troubleshoot.sh_preflights.yaml index b4f4edbd3..38633d6ba 100644 --- a/config/crds/troubleshoot.sh_preflights.yaml +++ b/config/crds/troubleshoot.sh_preflights.yaml @@ -1910,6 +1910,8 @@ spec: type: object helm: properties: + collectValues: + type: boolean collectorName: type: string exclude: diff --git a/config/crds/troubleshoot.sh_supportbundles.yaml b/config/crds/troubleshoot.sh_supportbundles.yaml index 4d5928f23..f514aa753 100644 --- a/config/crds/troubleshoot.sh_supportbundles.yaml +++ b/config/crds/troubleshoot.sh_supportbundles.yaml @@ -1941,6 +1941,8 @@ spec: type: object helm: properties: + collectValues: + type: boolean collectorName: type: string exclude: diff --git a/pkg/apis/troubleshoot/v1beta2/collector_shared.go b/pkg/apis/troubleshoot/v1beta2/collector_shared.go index 4c16c74f1..408bfb44f 100644 --- a/pkg/apis/troubleshoot/v1beta2/collector_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/collector_shared.go @@ -257,6 +257,7 @@ type Helm struct { CollectorMeta `json:",inline" yaml:",inline"` Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"` + CollectValues bool `json:"collectValues,omitempty" yaml:"collectValues,omitempty"` } type Goldpinger struct { diff --git a/pkg/collect/helm.go b/pkg/collect/helm.go index c886c1120..9f95f8c09 100644 --- a/pkg/collect/helm.go +++ b/pkg/collect/helm.go @@ -39,10 +39,11 @@ type ReleaseInfo struct { // Helm release version information struct type VersionInfo struct { - Revision string `json:"revision"` - Date string `json:"date"` - Status string `json:"status"` - IsPending bool `json:"isPending,omitempty"` + Revision string `json:"revision"` + Date string `json:"date"` + Status string `json:"status"` + IsPending bool `json:"isPending,omitempty"` + Values map[string]interface{} `json:"values,omitempty"` } func (c *CollectHelm) Title() string { @@ -57,7 +58,7 @@ func (c *CollectHelm) Collect(progressChan chan<- interface{}) (CollectorResult, output := NewResult() - releaseInfos, err := helmReleaseHistoryCollector(c.Collector.ReleaseName, c.Collector.Namespace) + releaseInfos, err := helmReleaseHistoryCollector(c.Collector.ReleaseName, c.Collector.Namespace, c.Collector.CollectValues) if err != nil { return nil, errors.Wrap(err, "failed to get Helm release history") } @@ -72,6 +73,9 @@ func (c *CollectHelm) Collect(progressChan chan<- interface{}) (CollectorResult, } filePath := fmt.Sprintf("helm/%s.json", namespace) + if c.Collector.ReleaseName != "" { + filePath = fmt.Sprintf("helm/%s/%s.json", namespace, c.Collector.ReleaseName) + } err := output.SaveResult(c.BundlePath, filePath, bytes.NewBuffer(helmHistoryJson)) if err != nil { @@ -82,7 +86,7 @@ func (c *CollectHelm) Collect(progressChan chan<- interface{}) (CollectorResult, return output, nil } -func helmReleaseHistoryCollector(releaseName string, namespace string) ([]ReleaseInfo, error) { +func helmReleaseHistoryCollector(releaseName string, namespace string, collectValues bool) ([]ReleaseInfo, error) { var results []ReleaseInfo actionConfig := new(action.Configuration) @@ -103,7 +107,7 @@ func helmReleaseHistoryCollector(releaseName string, namespace string) ([]Releas ChartVersion: r.Chart.Metadata.Version, AppVersion: r.Chart.Metadata.AppVersion, Namespace: r.Namespace, - VersionInfo: getVersionInfo(actionConfig, releaseName), + VersionInfo: getVersionInfo(actionConfig, releaseName, collectValues), }) return results, nil } @@ -124,26 +128,31 @@ func helmReleaseHistoryCollector(releaseName string, namespace string) ([]Releas ChartVersion: r.Chart.Metadata.Version, AppVersion: r.Chart.Metadata.AppVersion, Namespace: r.Namespace, - VersionInfo: getVersionInfo(actionConfig, r.Name), + VersionInfo: getVersionInfo(actionConfig, r.Name, collectValues), }) } return results, nil } -func getVersionInfo(actionConfig *action.Configuration, releaseName string) []VersionInfo { +func getVersionInfo(actionConfig *action.Configuration, releaseName string, collectValues bool) []VersionInfo { versionCollect := []VersionInfo{} history, _ := action.NewHistory(actionConfig).Run(releaseName) for _, release := range history { + values := map[string]interface{}{} + if collectValues { + values = getHelmValues(actionConfig, releaseName, release.Version) + } versionCollect = append(versionCollect, VersionInfo{ Revision: strconv.Itoa(release.Version), Date: release.Info.LastDeployed.String(), Status: release.Info.Status.String(), IsPending: release.Info.Status.IsPending(), + Values: values, }) } return versionCollect @@ -158,3 +167,10 @@ func helmReleaseInfoByNamespaces(releaseInfo []ReleaseInfo) map[string][]Release return releaseInfoByNamespace } + +func getHelmValues(actionConfig *action.Configuration, releaseName string, revision int) map[string]interface{} { + getAction := action.NewGetValues(actionConfig) + getAction.Version = revision + helmValues, _ := getAction.Run(releaseName) + return helmValues +} diff --git a/schemas/collector-troubleshoot-v1beta2.json b/schemas/collector-troubleshoot-v1beta2.json index befed5e47..29f5dd4af 100644 --- a/schemas/collector-troubleshoot-v1beta2.json +++ b/schemas/collector-troubleshoot-v1beta2.json @@ -483,6 +483,9 @@ "helm": { "type": "object", "properties": { + "collectValues": { + "type": "boolean" + }, "collectorName": { "type": "string" }, diff --git a/schemas/preflight-troubleshoot-v1beta2.json b/schemas/preflight-troubleshoot-v1beta2.json index 52b951024..0db213b27 100644 --- a/schemas/preflight-troubleshoot-v1beta2.json +++ b/schemas/preflight-troubleshoot-v1beta2.json @@ -2888,6 +2888,9 @@ "helm": { "type": "object", "properties": { + "collectValues": { + "type": "boolean" + }, "collectorName": { "type": "string" }, diff --git a/schemas/supportbundle-troubleshoot-v1beta2.json b/schemas/supportbundle-troubleshoot-v1beta2.json index dde428bfd..4c3682fbd 100644 --- a/schemas/supportbundle-troubleshoot-v1beta2.json +++ b/schemas/supportbundle-troubleshoot-v1beta2.json @@ -2934,6 +2934,9 @@ "helm": { "type": "object", "properties": { + "collectValues": { + "type": "boolean" + }, "collectorName": { "type": "string" },