Skip to content

Commit

Permalink
use debugLog in helm installer
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Jul 27, 2023
1 parent d44c6b6 commit 277988a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bootstrapper/cmd/bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
var openDevice vtpm.TPMOpenFunc
var fs afero.Fs

helmClient, err := helm.NewInstaller(constants.ControlPlaneAdminConfFilename)
helmClient, err := helm.NewInstaller(constants.ControlPlaneAdminConfFilename, log)
if err != nil {
log.With(zap.Error(err)).Fatalf("Helm client could not be initialized")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/helm/helminstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type helmInstallationClient struct {

// NewInstallationClient creates a new Helm installation client to install all Helm charts required for a constellation cluster.
func NewInstallationClient(log debugLog) (SuiteInstaller, error) {
installer, err := helminstaller.NewInstaller(constants.AdminConfFilename)
installer, err := helminstaller.NewInstaller(constants.AdminConfFilename, log)
if err != nil {
return nil, fmt.Errorf("creating Helm installer: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion cli/internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ func (c *Client) ShowCluster(ctx context.Context, provider cloudprovider.Provide

azureUAMIOutput, ok := tfState.Values.Outputs["user_assigned_identity"]
if !ok {
return ApplyOutput{}, errors.New("invalid type in user_assigned_identity output: not a string")
return ApplyOutput{}, errors.New("no user_assigned_identity output found")
}
azureUAMI, ok := azureUAMIOutput.Value.(string)
if !ok {
return ApplyOutput{}, errors.New("invalid type in user_assigned_identity output: not a string")
}

rgOutput, ok := tfState.Values.Outputs["resource_group"]
if !ok {
Expand Down
2 changes: 0 additions & 2 deletions internal/deploy/helm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ go_library(
visibility = ["//:__subpackages__"],
deps = [
"//internal/constants",
"//internal/logger",
"//internal/retry",
"@io_k8s_apimachinery//pkg/util/wait",
"@org_uber_go_zap//:zap",
"@sh_helm_helm_v3//pkg/action",
"@sh_helm_helm_v3//pkg/chart",
"@sh_helm_helm_v3//pkg/chart/loader",
Expand Down
27 changes: 13 additions & 14 deletions internal/deploy/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"time"

"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/internal/retry"
"go.uber.org/zap"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
Expand All @@ -31,24 +29,25 @@ const (
maximumRetryAttempts = 3
)

type debugLog interface {
Debugf(format string, args ...any)
Sync()
}

// Installer is a wrapper for a helm install action.
type Installer struct {
*action.Install
log *logger.Logger
log debugLog
}


// NewInstaller creates a new Installer with the given logger.
func NewInstaller(kubeconfig string) (*Installer, error) {
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(0)).Named("helm-installer") // TODO(elchead): discuss: use structured logging as in bootstrapper or use plain Debugf?
defer log.Sync()

func NewInstaller(kubeconfig string, logger debugLog) (*Installer, error) {
settings := cli.New()
settings.KubeConfig = kubeconfig

actionConfig := &action.Configuration{}
if err := actionConfig.Init(settings.RESTClientGetter(), constants.HelmNamespace,
"secret", log.Infof); err != nil {
"secret", logger.Debugf); err != nil {
return nil, err
}

Expand All @@ -58,7 +57,7 @@ func NewInstaller(kubeconfig string) (*Installer, error) {

return &Installer{
Install: action,
log: log,
log: logger,
}, nil
}

Expand Down Expand Up @@ -119,7 +118,7 @@ func (h *Installer) install(ctx context.Context, chartRaw []byte, values map[str
return fmt.Errorf("helm install: %w", err)
}
retryLoopFinishDuration := time.Since(retryLoopStartTime)
h.log.With(zap.String("chart", chart.Name()), zap.Duration("duration", retryLoopFinishDuration)).Infof("Helm chart installation finished")
h.log.Debugf("Helm chart %q installation finished after %s", chart.Name(), retryLoopFinishDuration)

return nil
}
Expand Down Expand Up @@ -147,14 +146,14 @@ type installDoer struct {
Installer *Installer
chart *chart.Chart
values map[string]any
log *logger.Logger
log debugLog
}

// Do logs which chart is installed and tries to install it.
func (i installDoer) Do(ctx context.Context) error {
i.log.With(zap.String("chart", i.chart.Name())).Infof("Trying to install Helm chart")
i.log.Debugf("Trying to install Helm chart %s", i.chart.Name())
if _, err := i.Installer.RunWithContext(ctx, i.chart, i.values); err != nil {
i.log.With(zap.Error(err), zap.String("chart", i.chart.Name())).Errorf("Helm chart installation failed")
i.log.Debugf("Helm chart installation % failed: %v", i.chart.Name(), err)
return err
}

Expand Down

0 comments on commit 277988a

Please sign in to comment.