Skip to content

Commit

Permalink
cleanup helminstall code
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Jul 26, 2023
1 parent ba1ff22 commit b6b2873
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 456 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(log, constants.ControlPlaneAdminConfFilename)
helmClient, err := helm.NewInstaller(constants.ControlPlaneAdminConfFilename)
if err != nil {
log.With(zap.Error(err)).Fatalf("Helm client could not be initialized")
}
Expand Down
2 changes: 0 additions & 2 deletions bootstrapper/internal/kubernetes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ go_library(
"//bootstrapper/internal/kubernetes/k8sapi",
"//bootstrapper/internal/kubernetes/kubewaiter",
"//internal/cloud/cloudprovider",
"//internal/cloud/gcpshared",
"//internal/cloud/metadata",
"//internal/cloud/openstack",
"//internal/constants",
"//internal/deploy/helm",
"//internal/kubernetes",
Expand Down
3 changes: 0 additions & 3 deletions bootstrapper/internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package kubernetes

import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand All @@ -22,8 +21,6 @@ import (
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi"
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
"github.com/edgelesssys/constellation/v2/internal/cloud/openstack"
"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/deploy/helm"
"github.com/edgelesssys/constellation/v2/internal/kubernetes"
Expand Down
1 change: 0 additions & 1 deletion cli/internal/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ go_library(
"@io_k8s_sigs_yaml//:yaml",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_mod//semver",
"@org_uber_go_zap//:zap",
"@org_uber_go_zap//zapcore",
] + select({
"@io_bazel_rules_go//go/platform:android_amd64": [
Expand Down
26 changes: 12 additions & 14 deletions cli/internal/cmd/helminstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/edgelesssys/constellation/v2/internal/constants"
helminstaller "github.com/edgelesssys/constellation/v2/internal/deploy/helm"
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
"github.com/edgelesssys/constellation/v2/internal/logger"
"go.uber.org/zap"
)

type helmInstaller interface {
Expand All @@ -27,29 +25,29 @@ type helmInstaller interface {
) error
}

type helmInstallationClient struct{}
type helmInstallationClient struct {
log debugLog
}

func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret,
idFile clusterid.File,
serviceAccURI string, releases *helminstaller.Releases,
) error {
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(0)).Named("init") // TODO: use the same logger as the rest of the CLI
defer log.Sync()
installer, err := helminstaller.NewInstaller(log, constants.AdminConfFilename)
installer, err := helminstaller.NewInstaller(constants.AdminConfFilename)
if err != nil {
return fmt.Errorf("creating Helm installer: %w", err)
}

serviceVals, err := helm.SetupMicroserviceVals(ctx, log, provider, masterSecret.Salt, idFile.UID, serviceAccURI)
serviceVals, err := helm.SetupMicroserviceVals(ctx, provider, masterSecret.Salt, idFile.UID, serviceAccURI)
if err != nil {
return fmt.Errorf("setting up microservice values: %w", err)
}
fmt.Println("Installing microservices", serviceVals)
h.log.Debugf("Installing microservices", serviceVals)
if err := installer.InstallChartWithValues(ctx, releases.ConstellationServices, serviceVals); err != nil {
return fmt.Errorf("installing microservices: %w", err)
}

log.Infof("Installing cert-manager")
h.log.Debugf("Installing cert-manager")
if err = installer.InstallChart(ctx, releases.CertManager); err != nil {
return fmt.Errorf("installing cert-manager: %w", err)
}
Expand All @@ -69,27 +67,27 @@ func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovi
}
}

log.Infof("Installing CSI deployments")
h.log.Debugf("Installing CSI deployments")
if err := installer.InstallChartWithValues(ctx, *releases.CSI, csiVals); err != nil {
return fmt.Errorf("installing CSI snapshot CRDs: %w", err)
}
}

if releases.AWSLoadBalancerController != nil {
log.Infof("Installing AWS Load Balancer Controller")
h.log.Debugf("Installing AWS Load Balancer Controller")
if err = installer.InstallChart(ctx, *releases.AWSLoadBalancerController); err != nil {
return fmt.Errorf("installing AWS Load Balancer Controller: %w", err)
}
}

log.Infof("Installing constellation operators")
h.log.Debugf("Installing constellation operators")
operatorVals, err := helm.SetupOperatorVals(ctx, idFile.UID)
if err != nil {
log.With(zap.Error(err)).Fatalf("Failed to set up operator values")
return fmt.Errorf("setting up operator values: %w", err)
}
err = installer.InstallChartWithValues(ctx, releases.ConstellationOperators, operatorVals)
if err != nil {
log.With(zap.Error(err)).Fatalf("Failed to install constellation operators")
return fmt.Errorf("installing constellation operators: %w", err)
}

// TODO(elchead): AB394 do cilium after version upgrade
Expand Down
1 change: 0 additions & 1 deletion cli/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator atls.V
if err != nil {
return err
}
// install helm charts
if i.helmInstaller != nil {
if err := i.helmInstaller.Install(cmd.Context(), provider, masterSecret, idFile, serviceAccURI, releases); err != nil {
return fmt.Errorf("installing Helm charts: %w", err)
Expand Down
1 change: 1 addition & 0 deletions cli/internal/helm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ go_test(
"backup_test.go",
"client_test.go",
"loader_test.go",
"setup_test.go",
],
data = glob(["testdata/**"]),
embed = [":helm"],
Expand Down
47 changes: 1 addition & 46 deletions cli/internal/helm/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ProviderMetadata interface {
}

// SetupMicroserviceVals returns the values for the microservice chart.
func SetupMicroserviceVals(ctx context.Context, log debugLog, provider cloudprovider.Provider, measurementSalt []byte, uid, serviceAccURI string) (map[string]any, error) {
func SetupMicroserviceVals(ctx context.Context, provider cloudprovider.Provider, measurementSalt []byte, uid, serviceAccURI string) (map[string]any, error) {
tfClient, err := terraform.New(ctx, constants.TerraformWorkingDir)
if err != nil {
return nil, fmt.Errorf("creating Terraform client: %w", err)
Expand All @@ -34,9 +34,6 @@ func SetupMicroserviceVals(ctx context.Context, log debugLog, provider cloudprov
if err != nil {
return nil, fmt.Errorf("getting Terraform output: %w", err)
}
log.Debugf("Terraform cluster output: %+v", output) // TODO why not working? (propagate debug to logger).
fmt.Printf("A Terraform cluster output: %+v\n", output)

extraVals := map[string]any{
"join-service": map[string]any{
"measurementSalt": base64.StdEncoding.EncodeToString(measurementSalt),
Expand Down Expand Up @@ -140,45 +137,3 @@ func SetupOperatorVals(_ context.Context, uid string) (map[string]any, error) {
},
}, nil
}

//func GetMetadaClient(ctx context.Context, provider cloudprovider.Provider) (metadataAPI ProviderMetadata, err error) {
// switch provider {
// case cloudprovider.AWS:
// metadata, err := aws.New(ctx)
// if err != nil {
// return nil, fmt.Errorf("creating AWS metadata client: %w", err)
// // log.With(zap.Error(err)).Fatalf("Failed to set up AWS metadata API")
// }
// metadataAPI = metadata
// case cloudprovider.GCP:
// metadata, err := gcp.New(ctx)
// if err != nil {
// return nil, fmt.Errorf("creating GCP metadata client: %w", err)
// }
// metadataAPI = metadata
// case cloudprovider.Azure:
// metadata, err := azure.New(ctx)
// if err != nil {
// return nil, fmt.Errorf("creating Azure metadata client: %w", err)
// }
// metadataAPI = metadata
// case cloudprovider.QEMU:
// metadata := qemu.New()
// metadataAPI = metadata
// case cloudprovider.OpenStack:
// metadata, err := openstack.New(ctx)
// if err != nil {
// return nil, fmt.Errorf("creating OpenStack metadata client: %w", err)
// }
// metadataAPI = metadata
// default:
// return nil, fmt.Errorf("unsupported cloud provider: %s", provider)
// // metadataAPI = &providerMetadataFake{}
// // cloudLogger = &logging.NopLogger{}
// // var simulatedTPMCloser io.Closer
// // openDevice, simulatedTPMCloser = simulator.NewSimulatedTPMOpenFunc()
// // defer simulatedTPMCloser.Close()
// // fs = afero.NewMemMapFs()
// }
// return metadataAPI, nil
//}
Loading

0 comments on commit b6b2873

Please sign in to comment.