Skip to content

Commit f925f03

Browse files
authored
Extract preflight specs from templated Helm charts (#2592)
1 parent e7a8faa commit f925f03

File tree

3 files changed

+325
-13
lines changed

3 files changed

+325
-13
lines changed

api/internal/managers/app/release/manager.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package release
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
78
"github.com/replicatedhq/embedded-cluster/api/pkg/template"
89
"github.com/replicatedhq/embedded-cluster/api/types"
910
"github.com/replicatedhq/embedded-cluster/pkg/release"
1011
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1112
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
13+
troubleshootloader "github.com/replicatedhq/troubleshoot/pkg/loader"
1214
"github.com/sirupsen/logrus"
1315
)
1416

@@ -17,6 +19,7 @@ type AppReleaseManager interface {
1719
TemplateHelmChartCRs(ctx context.Context, configValues types.AppConfigValues) ([]*kotsv1beta2.HelmChart, error)
1820
DryRunHelmChart(ctx context.Context, templatedCR *kotsv1beta2.HelmChart) ([][]byte, error)
1921
GenerateHelmValues(ctx context.Context, templatedCR *kotsv1beta2.HelmChart) (map[string]any, error)
22+
ExtractTroubleshootKinds(ctx context.Context, manifests [][]byte) (*troubleshootloader.TroubleshootKinds, error)
2023
}
2124

2225
type appReleaseManager struct {
@@ -54,7 +57,7 @@ func WithLicense(license *kotsv1beta1.License) AppReleaseManagerOption {
5457
}
5558

5659
// NewAppReleaseManager creates a new AppReleaseManager
57-
func NewAppReleaseManager(config kotsv1beta1.Config, opts ...AppReleaseManagerOption) AppReleaseManager {
60+
func NewAppReleaseManager(config kotsv1beta1.Config, opts ...AppReleaseManagerOption) (AppReleaseManager, error) {
5861
manager := &appReleaseManager{
5962
rawConfig: config,
6063
}
@@ -63,6 +66,10 @@ func NewAppReleaseManager(config kotsv1beta1.Config, opts ...AppReleaseManagerOp
6366
opt(manager)
6467
}
6568

69+
if manager.releaseData == nil {
70+
return nil, fmt.Errorf("release data not found")
71+
}
72+
6673
if manager.logger == nil {
6774
manager.logger = logger.NewDiscardLogger()
6875
}
@@ -75,5 +82,5 @@ func NewAppReleaseManager(config kotsv1beta1.Config, opts ...AppReleaseManagerOp
7582
)
7683
}
7784

78-
return manager
85+
return manager, nil
7986
}

api/internal/managers/app/release/template.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ import (
1111
"github.com/replicatedhq/embedded-cluster/pkg-new/constants"
1212
"github.com/replicatedhq/embedded-cluster/pkg/helm"
1313
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
14+
troubleshootloader "github.com/replicatedhq/troubleshoot/pkg/loader"
1415
kyaml "sigs.k8s.io/yaml"
1516
)
1617

1718
// TemplateHelmChartCRs templates the HelmChart CRs from release data using the template engine and config values
1819
func (m *appReleaseManager) TemplateHelmChartCRs(ctx context.Context, configValues types.AppConfigValues) ([]*kotsv1beta2.HelmChart, error) {
19-
if m.releaseData == nil {
20-
return nil, fmt.Errorf("release data not initialized")
21-
}
22-
2320
if m.templateEngine == nil {
2421
return nil, fmt.Errorf("template engine not initialized")
2522
}
@@ -72,10 +69,6 @@ func (m *appReleaseManager) DryRunHelmChart(ctx context.Context, templatedCR *ko
7269
return nil, fmt.Errorf("templated CR is nil")
7370
}
7471

75-
if m.releaseData == nil {
76-
return nil, fmt.Errorf("release data not initialized")
77-
}
78-
7972
// Check if the chart should be excluded
8073
if !templatedCR.Spec.Exclude.IsEmpty() {
8174
exclude, err := templatedCR.Spec.Exclude.Boolean()
@@ -181,3 +174,22 @@ func (m *appReleaseManager) GenerateHelmValues(ctx context.Context, templatedCR
181174

182175
return helmValues, nil
183176
}
177+
178+
// ExtractTroubleshootKinds extracts troubleshoot specifications from Helm chart manifests
179+
func (m *appReleaseManager) ExtractTroubleshootKinds(ctx context.Context, manifests [][]byte) (*troubleshootloader.TroubleshootKinds, error) {
180+
// Convert [][]byte manifests to []string for troubleshootloader
181+
rawSpecs := make([]string, len(manifests))
182+
for i, manifest := range manifests {
183+
rawSpecs[i] = string(manifest)
184+
}
185+
186+
// Use troubleshootloader to parse all specs
187+
tsKinds, err := troubleshootloader.LoadSpecs(ctx, troubleshootloader.LoadOptions{
188+
RawSpecs: rawSpecs,
189+
})
190+
if err != nil {
191+
return nil, fmt.Errorf("load troubleshoot specs: %w", err)
192+
}
193+
194+
return tsKinds, nil
195+
}

0 commit comments

Comments
 (0)