Skip to content

Commit

Permalink
fixup! cleanup helminstall code
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Jul 26, 2023
1 parent 024f1bf commit d8c0b54
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 608 deletions.
15 changes: 0 additions & 15 deletions bootstrapper/internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,3 @@ func (k *KubeWrapper) setupCiliumVals(ctx context.Context, in k8sapi.SetupPodNet

return vals, nil
}

type ccmConfigGetter interface {
GetCCMConfig(ctx context.Context, providerID, cloudServiceAccountURI string) ([]byte, error)
}

type constellationServicesConfig struct {
measurementSalt []byte
subnetworkPodCIDR string
cloudServiceAccountURI string
loadBalancerIP string
}

type openstackMetadata interface {
GetNetworkIDs(ctx context.Context) ([]string, error)
}
37 changes: 23 additions & 14 deletions cli/internal/cmd/helminstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,41 @@ import (
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
)

type helmInstaller interface {
// helmSuiteInstaller installs all Helm charts required for a constellation cluster.
type helmSuiteInstaller interface {
Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret,
idFile clusterid.File,
serviceAccURI string, releases *helminstaller.Releases,
) error
}

type helmInstallationClient struct {
log debugLog
log debugLog
installer helmInstaller
}

func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret,
idFile clusterid.File,
serviceAccURI string, releases *helminstaller.Releases,
) error {
func newHelmInstallationClient(log debugLog) (helmSuiteInstaller, error) {
installer, err := helminstaller.NewInstaller(constants.AdminConfFilename)
if err != nil {
return fmt.Errorf("creating Helm installer: %w", err)
return nil, fmt.Errorf("creating Helm installer: %w", err)
}
return &helmInstallationClient{log: log, installer: installer}, nil
}

func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret,
idFile clusterid.File,
serviceAccURI string, releases *helminstaller.Releases,
) error {
serviceVals, err := helm.SetupMicroserviceVals(ctx, provider, masterSecret.Salt, idFile.UID, serviceAccURI)
if err != nil {
return fmt.Errorf("setting up microservice values: %w", err)
}
h.log.Debugf("Installing microservices", serviceVals)
if err := installer.InstallChartWithValues(ctx, releases.ConstellationServices, serviceVals); err != nil {
if err := h.installer.InstallChartWithValues(ctx, releases.ConstellationServices, serviceVals); err != nil {
return fmt.Errorf("installing microservices: %w", err)
}

h.log.Debugf("Installing cert-manager")
if err = installer.InstallChart(ctx, releases.CertManager); err != nil {
if err = h.installer.InstallChart(ctx, releases.CertManager); err != nil {
return fmt.Errorf("installing cert-manager: %w", err)
}

Expand All @@ -68,14 +72,14 @@ func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovi
}

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

if releases.AWSLoadBalancerController != nil {
h.log.Debugf("Installing AWS Load Balancer Controller")
if err = installer.InstallChart(ctx, *releases.AWSLoadBalancerController); err != nil {
if err = h.installer.InstallChart(ctx, *releases.AWSLoadBalancerController); err != nil {
return fmt.Errorf("installing AWS Load Balancer Controller: %w", err)
}
}
Expand All @@ -85,11 +89,16 @@ func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovi
if err != nil {
return fmt.Errorf("setting up operator values: %w", err)
}
err = installer.InstallChartWithValues(ctx, releases.ConstellationOperators, operatorVals)
err = h.installer.InstallChartWithValues(ctx, releases.ConstellationOperators, operatorVals)
if err != nil {
return fmt.Errorf("installing constellation operators: %w", err)
}

// TODO(elchead): AB394 do cilium after version upgrade
// TODO(elchead): AB#3294 do cilium after version upgrade
return nil
}

type helmInstaller interface {
InstallChart(context.Context, helminstaller.Release) error
InstallChartWithValues(ctx context.Context, release helminstaller.Release, extraValues map[string]any) error
}
13 changes: 10 additions & 3 deletions cli/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
package cmd

import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -78,7 +79,7 @@ type initCmd struct {
spinner spinnerInterf
masterSecret uri.MasterSecret
fh *file.Handler
helmInstaller helmInstaller
helmInstaller helmSuiteInstaller
}

// runInitialize runs the initialize command.
Expand All @@ -102,7 +103,11 @@ func runInitialize(cmd *cobra.Command, _ []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), time.Hour)
defer cancel()
cmd.SetContext(ctx)
i := &initCmd{log: log, spinner: spinner, merger: &kubeconfigMerger{log: log}, fh: &fileHandler, helmInstaller: helmInstallationClient{log}}
helmInstaller, err := newHelmInstallationClient(log)
if err != nil {
return fmt.Errorf("creating Helm installer: %w", err)
}
i := &initCmd{log: log, spinner: spinner, merger: &kubeconfigMerger{log: log}, fh: &fileHandler, helmInstaller: helmInstaller}
fetcher := attestationconfigapi.NewFetcher()
return i.initialize(cmd, newDialer, fileHandler, license.NewClient(), fetcher)
}
Expand Down Expand Up @@ -227,7 +232,8 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator atls.V
i.log.Debugf("Writing Constellation ID file")
idFile.CloudProvider = provider

err = i.writeOutput(idFile, resp, flags.mergeConfigs, cmd.OutOrStdout(), fileHandler)
bufferedOutput := &bytes.Buffer{}
err = i.writeOutput(idFile, resp, flags.mergeConfigs, bufferedOutput, fileHandler)
if err != nil {
return err
}
Expand All @@ -236,6 +242,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator atls.V
return fmt.Errorf("installing Helm charts: %w", err)
}
}
cmd.Println(bufferedOutput.String())
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions cli/internal/helm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ go_library(
"//internal/cloud/azureshared",
"//internal/cloud/cloudprovider",
"//internal/cloud/gcpshared",
"//internal/cloud/metadata",
"//internal/compatibility",
"//internal/config",
"//internal/constants",
Expand Down Expand Up @@ -451,7 +450,6 @@ go_test(
"backup_test.go",
"client_test.go",
"loader_test.go",
"setup_test.go",
],
data = glob(["testdata/**"]),
embed = [":helm"],
Expand Down
35 changes: 15 additions & 20 deletions cli/internal/helm/setup.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/

package helm

import (
Expand All @@ -10,20 +16,9 @@ import (
"github.com/edgelesssys/constellation/v2/internal/cloud/azureshared"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
"github.com/edgelesssys/constellation/v2/internal/constants"
)

// ProviderMetadata implementers read/write cloud provider metadata.
type ProviderMetadata interface {
// UID returns the unique identifier for the constellation.
UID(ctx context.Context) (string, error)
// Self retrieves the current instance.
Self(ctx context.Context) (metadata.InstanceMetadata, error)
// GetLoadBalancerEndpoint retrieves the load balancer endpoint.
GetLoadBalancerEndpoint(ctx context.Context) (host, port string, err error)
}

// SetupMicroserviceVals returns the values for the microservice chart.
func SetupMicroserviceVals(ctx context.Context, provider cloudprovider.Provider, measurementSalt []byte, uid, serviceAccURI string) (map[string]any, error) {
tfClient, err := terraform.New(ctx, constants.TerraformWorkingDir)
Expand Down Expand Up @@ -84,6 +79,15 @@ func SetupMicroserviceVals(ctx context.Context, provider cloudprovider.Provider,
return extraVals, nil
}

// SetupOperatorVals returns the values for the constellation-operator chart.
func SetupOperatorVals(_ context.Context, uid string) (map[string]any, error) {
return map[string]any{
"constellation-operator": map[string]any{
"constellationUID": uid,
},
}, nil
}

type cloudConfig struct {
Cloud string `json:"cloud,omitempty"`
TenantID string `json:"tenantId,omitempty"`
Expand Down Expand Up @@ -128,12 +132,3 @@ func getCCMConfig(tfOutput terraform.AzureApplyOutput, serviceAccURI string) ([]

return json.Marshal(config)
}

// SetupOperatorVals returns the values for the constellation-operator chart.
func SetupOperatorVals(_ context.Context, uid string) (map[string]any, error) {
return map[string]any{
"constellation-operator": map[string]any{
"constellationUID": uid,
},
}, nil
}
Loading

0 comments on commit d8c0b54

Please sign in to comment.