From eb7d4764638e81d082153b52fbeb2a2ebfc500a3 Mon Sep 17 00:00:00 2001 From: Adrian Stobbe Date: Tue, 1 Aug 2023 08:41:54 +0200 Subject: [PATCH] clean helm code from bootstrapper --- bootstrapper/cmd/bootstrapper/BUILD.bazel | 1 - bootstrapper/cmd/bootstrapper/main.go | 16 ++--- bootstrapper/cmd/bootstrapper/test.go | 2 +- .../internal/initserver/initserver.go | 2 - .../internal/initserver/initserver_test.go | 2 +- bootstrapper/internal/kubernetes/BUILD.bazel | 2 - bootstrapper/internal/kubernetes/k8sutil.go | 8 --- .../internal/kubernetes/kubernetes.go | 58 +------------------ .../internal/kubernetes/kubernetes_test.go | 25 +------- cli/internal/cmd/BUILD.bazel | 3 +- cli/internal/cmd/init.go | 7 +-- cli/internal/cmd/init_test.go | 4 +- cli/internal/helm/BUILD.bazel | 7 ++- cli/internal/helm/client.go | 17 ++---- cli/internal/helm/helminstaller.go | 13 ++--- .../deploy => cli/internal}/helm/install.go | 0 cli/internal/helm/loader.go | 17 +++--- cli/internal/helm/loader_test.go | 5 +- .../helm.go => cli/internal/helm/release.go | 0 .../internal/helm/release_test.go | 0 cli/internal/helm/setup.go | 2 +- internal/deploy/helm/BUILD.bazel | 28 --------- 22 files changed, 44 insertions(+), 175 deletions(-) rename {internal/deploy => cli/internal}/helm/install.go (100%) rename internal/deploy/helm/helm.go => cli/internal/helm/release.go (100%) rename internal/deploy/helm/helm_test.go => cli/internal/helm/release_test.go (100%) delete mode 100644 internal/deploy/helm/BUILD.bazel diff --git a/bootstrapper/cmd/bootstrapper/BUILD.bazel b/bootstrapper/cmd/bootstrapper/BUILD.bazel index 4bde699c48..52eab989d1 100644 --- a/bootstrapper/cmd/bootstrapper/BUILD.bazel +++ b/bootstrapper/cmd/bootstrapper/BUILD.bazel @@ -35,7 +35,6 @@ go_library( "//internal/cloud/openstack", "//internal/cloud/qemu", "//internal/constants", - "//internal/deploy/helm", "//internal/file", "//internal/grpc/dialer", "//internal/kubernetes/kubectl", diff --git a/bootstrapper/cmd/bootstrapper/main.go b/bootstrapper/cmd/bootstrapper/main.go index 9c41c9176d..950ef0d754 100644 --- a/bootstrapper/cmd/bootstrapper/main.go +++ b/bootstrapper/cmd/bootstrapper/main.go @@ -32,7 +32,6 @@ import ( openstackcloud "github.com/edgelesssys/constellation/v2/internal/cloud/openstack" qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu" "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/kubernetes/kubectl" "github.com/edgelesssys/constellation/v2/internal/logger" @@ -67,11 +66,6 @@ func main() { var openDevice vtpm.TPMOpenFunc var fs afero.Fs - helmClient, err := helm.NewInstaller(constants.ControlPlaneAdminConfFilename, log) - if err != nil { - log.With(zap.Error(err)).Fatalf("Helm client could not be initialized") - } - attestVariant, err := variant.FromString(os.Getenv(constants.AttestationVariant)) if err != nil { log.With(zap.Error(err)).Fatalf("Failed to parse attestation variant") @@ -96,7 +90,7 @@ func main() { clusterInitJoiner = kubernetes.New( "aws", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.New(), - metadata, helmClient, &kubewaiter.CloudKubeAPIWaiter{}, + metadata, &kubewaiter.CloudKubeAPIWaiter{}, ) openDevice = vtpm.OpenVTPM fs = afero.NewOsFs() @@ -116,7 +110,7 @@ func main() { metadataAPI = metadata clusterInitJoiner = kubernetes.New( "gcp", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.New(), - metadata, helmClient, &kubewaiter.CloudKubeAPIWaiter{}, + metadata, &kubewaiter.CloudKubeAPIWaiter{}, ) openDevice = vtpm.OpenVTPM fs = afero.NewOsFs() @@ -134,7 +128,7 @@ func main() { metadataAPI = metadata clusterInitJoiner = kubernetes.New( "azure", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.New(), - metadata, helmClient, &kubewaiter.CloudKubeAPIWaiter{}, + metadata, &kubewaiter.CloudKubeAPIWaiter{}, ) openDevice = vtpm.OpenVTPM @@ -145,7 +139,7 @@ func main() { metadata := qemucloud.New() clusterInitJoiner = kubernetes.New( "qemu", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.New(), - metadata, helmClient, &kubewaiter.CloudKubeAPIWaiter{}, + metadata, &kubewaiter.CloudKubeAPIWaiter{}, ) metadataAPI = metadata @@ -168,7 +162,7 @@ func main() { } clusterInitJoiner = kubernetes.New( "openstack", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.New(), - metadata, helmClient, &kubewaiter.CloudKubeAPIWaiter{}, + metadata, &kubewaiter.CloudKubeAPIWaiter{}, ) metadataAPI = metadata openDevice = vtpm.OpenVTPM diff --git a/bootstrapper/cmd/bootstrapper/test.go b/bootstrapper/cmd/bootstrapper/test.go index ee7d7dea01..bdf03bbd3c 100644 --- a/bootstrapper/cmd/bootstrapper/test.go +++ b/bootstrapper/cmd/bootstrapper/test.go @@ -22,7 +22,7 @@ type clusterFake struct{} // InitCluster fakes bootstrapping a new cluster with the current node being the master, returning the arguments required to join the cluster. func (c *clusterFake) InitCluster( context.Context, string, string, - []byte, bool, components.Components, []string, *logger.Logger, + bool, components.Components, []string, *logger.Logger, ) ([]byte, error) { return []byte{}, nil } diff --git a/bootstrapper/internal/initserver/initserver.go b/bootstrapper/internal/initserver/initserver.go index cd822890e7..1a5b3ee50a 100644 --- a/bootstrapper/internal/initserver/initserver.go +++ b/bootstrapper/internal/initserver/initserver.go @@ -215,7 +215,6 @@ func (s *Server) Init(req *initproto.InitRequest, stream initproto.API_InitServe kubeconfig, err := s.initializer.InitCluster(stream.Context(), req.KubernetesVersion, clusterName, - req.HelmDeployments, req.ConformanceMode, components.NewComponentsFromInitProto(req.KubernetesComponents), req.ApiserverCertSans, @@ -342,7 +341,6 @@ type ClusterInitializer interface { ctx context.Context, k8sVersion string, clusterName string, - helmDeployments []byte, conformanceMode bool, kubernetesComponents components.Components, apiServerCertSANs []string, diff --git a/bootstrapper/internal/initserver/initserver_test.go b/bootstrapper/internal/initserver/initserver_test.go index a2505becd0..048927e923 100644 --- a/bootstrapper/internal/initserver/initserver_test.go +++ b/bootstrapper/internal/initserver/initserver_test.go @@ -407,7 +407,7 @@ type stubClusterInitializer struct { func (i *stubClusterInitializer) InitCluster( context.Context, string, string, - []byte, bool, components.Components, []string, *logger.Logger, + bool, components.Components, []string, *logger.Logger, ) ([]byte, error) { return i.initClusterKubeconfig, i.initClusterErr } diff --git a/bootstrapper/internal/kubernetes/BUILD.bazel b/bootstrapper/internal/kubernetes/BUILD.bazel index dcddfe228d..c2255148a6 100644 --- a/bootstrapper/internal/kubernetes/BUILD.bazel +++ b/bootstrapper/internal/kubernetes/BUILD.bazel @@ -16,7 +16,6 @@ go_library( "//internal/cloud/cloudprovider", "//internal/cloud/metadata", "//internal/constants", - "//internal/deploy/helm", "//internal/kubernetes", "//internal/logger", "//internal/role", @@ -37,7 +36,6 @@ go_test( "//bootstrapper/internal/kubernetes/kubewaiter", "//internal/cloud/metadata", "//internal/constants", - "//internal/deploy/helm", "//internal/kubernetes", "//internal/logger", "//internal/role", diff --git a/bootstrapper/internal/kubernetes/k8sutil.go b/bootstrapper/internal/kubernetes/k8sutil.go index 3acb4c7bbf..d8bf72f238 100644 --- a/bootstrapper/internal/kubernetes/k8sutil.go +++ b/bootstrapper/internal/kubernetes/k8sutil.go @@ -10,7 +10,6 @@ import ( "context" "net" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" "github.com/edgelesssys/constellation/v2/internal/versions/components" @@ -24,10 +23,3 @@ type clusterUtil interface { FixCilium(ctx context.Context) error StartKubelet() error } - -// helmClient bundles functions related to microservice deployment. -// Only microservices that can be deployed purely via Helm are deployed with this interface. -type helmClient interface { - InstallChart(context.Context, helm.Release) error - InstallChartWithValues(ctx context.Context, release helm.Release, extraValues map[string]any) error -} diff --git a/bootstrapper/internal/kubernetes/kubernetes.go b/bootstrapper/internal/kubernetes/kubernetes.go index 7895d570b9..1d23c2b394 100644 --- a/bootstrapper/internal/kubernetes/kubernetes.go +++ b/bootstrapper/internal/kubernetes/kubernetes.go @@ -9,7 +9,6 @@ package kubernetes import ( "context" - "encoding/json" "fmt" "net" "regexp" @@ -20,7 +19,6 @@ import ( "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/kubernetes" "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" @@ -47,7 +45,6 @@ type kubeAPIWaiter interface { type KubeWrapper struct { cloudProvider string clusterUtil clusterUtil - helmClient helmClient kubeAPIWaiter kubeAPIWaiter configProvider configurationProvider client k8sapi.Client @@ -57,12 +54,11 @@ type KubeWrapper struct { // New creates a new KubeWrapper with real values. func New(cloudProvider string, clusterUtil clusterUtil, configProvider configurationProvider, client k8sapi.Client, - providerMetadata ProviderMetadata, helmClient helmClient, kubeAPIWaiter kubeAPIWaiter, + providerMetadata ProviderMetadata, kubeAPIWaiter kubeAPIWaiter, ) *KubeWrapper { return &KubeWrapper{ cloudProvider: cloudProvider, clusterUtil: clusterUtil, - helmClient: helmClient, kubeAPIWaiter: kubeAPIWaiter, configProvider: configProvider, client: client, @@ -73,15 +69,13 @@ func New(cloudProvider string, clusterUtil clusterUtil, configProvider configura // InitCluster initializes a new Kubernetes cluster and applies pod network provider. func (k *KubeWrapper) InitCluster( - ctx context.Context, versionString, clusterName string, - helmReleasesRaw []byte, conformanceMode bool, kubernetesComponents components.Components, apiServerCertSANs []string, log *logger.Logger, + ctx context.Context, versionString, clusterName string, conformanceMode bool, kubernetesComponents components.Components, apiServerCertSANs []string, log *logger.Logger, ) ([]byte, error) { log.With(zap.String("version", versionString)).Infof("Installing Kubernetes components") if err := k.clusterUtil.InstallComponents(ctx, kubernetesComponents); err != nil { return nil, err } - var nodePodCIDR string var validIPs []net.IP // Step 1: retrieve cloud metadata for Kubernetes configuration @@ -100,10 +94,6 @@ func (k *KubeWrapper) InitCluster( nodeIP := instance.VPCIP subnetworkPodCIDR := instance.SecondaryIPRange - if len(instance.AliasIPRanges) > 0 { - nodePodCIDR = instance.AliasIPRanges[0] - fmt.Println("nodePodCIDR: ", nodePodCIDR) // TODO(elchead): remove all commented code - } // this is the endpoint in "kubeadm init --control-plane-endpoint=:" // TODO(malt3): switch over to DNS name on AWS and Azure @@ -176,50 +166,6 @@ func (k *KubeWrapper) InitCluster( return nil, fmt.Errorf("annotating node with Kubernetes components hash: %w", err) } - // Step 3: configure & start kubernetes controllers - log.Infof("Starting Kubernetes controllers and deployments") - //setupPodNetworkInput := k8sapi.SetupPodNetworkInput{ - // CloudProvider: k.cloudProvider, - // NodeName: nodeName, - // FirstNodePodCIDR: nodePodCIDR, - // SubnetworkPodCIDR: subnetworkPodCIDR, - // LoadBalancerHost: controlPlaneHost, - // LoadBalancerPort: controlPlanePort, - //} - - var helmReleases helm.Releases - if err := json.Unmarshal(helmReleasesRaw, &helmReleases); err != nil { - return nil, fmt.Errorf("unmarshalling helm releases: %w", err) - } - - log.Infof("Installing Cilium") - //ciliumVals, err := k.setupCiliumVals(ctx, setupPodNetworkInput) - //if err != nil { - // return nil, fmt.Errorf("setting up cilium vals: %w", err) - //} - //log.Infof("ciliumVals: %+v\n", ciliumVals) - //if err := k.helmClient.InstallChartWithValues(ctx, helmReleases.Cilium, ciliumVals); err != nil { - // return nil, fmt.Errorf("installing cilium pod network: %w", err) - //} - - //log.Infof("Waiting for Cilium to become healthy") - //timeToStartWaiting := time.Now() - //// TODO(3u13r): Reduce the timeout when we switched the package repository - this is only this high because we once - //// saw polling times of ~16 minutes when hitting a slow PoP from Fastly (GitHub's / ghcr.io CDN). - //waitCtx, cancel = context.WithTimeout(ctx, 20*time.Minute) - //defer cancel() - //if err := k.clusterUtil.WaitForCilium(waitCtx, log); err != nil { - // return nil, fmt.Errorf("waiting for Cilium to become healthy: %w", err) - //} - //timeUntilFinishedWaiting := time.Since(timeToStartWaiting) - //log.With(zap.Duration("duration", timeUntilFinishedWaiting)).Infof("Cilium became healthy") - - //log.Infof("Restarting Cilium") - //if err := k.clusterUtil.FixCilium(ctx); err != nil { - // log.With(zap.Error(err)).Errorf("FixCilium failed") - // // Continue and don't throw an error here - things might be okay. - //} - log.Infof("Setting up internal-config ConfigMap") if err := k.setupInternalConfigMap(ctx); err != nil { return nil, fmt.Errorf("failed to setup internal ConfigMap: %w", err) diff --git a/bootstrapper/internal/kubernetes/kubernetes_test.go b/bootstrapper/internal/kubernetes/kubernetes_test.go index 7bc5139079..eb6d505ce3 100644 --- a/bootstrapper/internal/kubernetes/kubernetes_test.go +++ b/bootstrapper/internal/kubernetes/kubernetes_test.go @@ -17,7 +17,6 @@ import ( "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter" "github.com/edgelesssys/constellation/v2/internal/cloud/metadata" "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/kubernetes" "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" @@ -43,7 +42,6 @@ func TestInitCluster(t *testing.T) { testCases := map[string]struct { clusterUtil stubClusterUtil - helmClient stubHelmClient kubectl stubKubectl kubeAPIWaiter stubKubeAPIWaiter providerMetadata ProviderMetadata @@ -131,14 +129,12 @@ func TestInitCluster(t *testing.T) { }, "kubeadm init fails when deploying cilium": { clusterUtil: stubClusterUtil{kubeconfig: []byte("someKubeconfig")}, - helmClient: stubHelmClient{ciliumError: assert.AnError}, providerMetadata: &stubProviderMetadata{}, wantErr: true, k8sVersion: versions.Default, }, "kubeadm init fails when setting up constellation-services chart": { clusterUtil: stubClusterUtil{kubeconfig: []byte("someKubeconfig")}, - helmClient: stubHelmClient{installChartError: assert.AnError}, kubeAPIWaiter: stubKubeAPIWaiter{}, providerMetadata: &stubProviderMetadata{}, wantErr: true, @@ -182,7 +178,6 @@ func TestInitCluster(t *testing.T) { kube := KubeWrapper{ cloudProvider: "aws", // provide a valid cloud provider for cilium installation clusterUtil: &tc.clusterUtil, - helmClient: &tc.helmClient, providerMetadata: tc.providerMetadata, kubeAPIWaiter: &tc.kubeAPIWaiter, configProvider: &stubConfigProvider{initConfig: k8sapi.KubeadmInitYAML{}}, @@ -192,7 +187,7 @@ func TestInitCluster(t *testing.T) { _, err := kube.InitCluster( context.Background(), string(tc.k8sVersion), "kubernetes", - []byte("{}"), false, nil, nil, logger.NewTest(t), + false, nil, nil, logger.NewTest(t), ) if tc.wantErr { @@ -551,24 +546,6 @@ func (s *stubKubectl) EnforceCoreDNSSpread(_ context.Context) error { return s.enforceCoreDNSSpreadErr } -type stubHelmClient struct { - ciliumError error - installChartError error -} - -func (s *stubHelmClient) InstallChart(ctx context.Context, release helm.Release) error { - return s.InstallChartWithValues(ctx, release, release.Values) -} - -func (s *stubHelmClient) InstallChartWithValues(_ context.Context, release helm.Release, _ map[string]any) error { - switch release.ReleaseName { - case "cilium": - return s.ciliumError - default: - return s.installChartError - } -} - type stubKubeAPIWaiter struct { waitErr error } diff --git a/cli/internal/cmd/BUILD.bazel b/cli/internal/cmd/BUILD.bazel index 953c197823..af327599e8 100644 --- a/cli/internal/cmd/BUILD.bazel +++ b/cli/internal/cmd/BUILD.bazel @@ -67,7 +67,6 @@ go_library( "//internal/config/migration", "//internal/constants", "//internal/crypto", - "//internal/deploy/helm", "//internal/file", "//internal/grpc/dialer", "//internal/grpc/grpclog", @@ -138,6 +137,7 @@ go_test( "//bootstrapper/initproto", "//cli/internal/cloudcmd", "//cli/internal/clusterid", + "//cli/internal/helm", "//cli/internal/iamid", "//cli/internal/kubernetes", "//cli/internal/terraform", @@ -153,7 +153,6 @@ go_test( "//internal/config", "//internal/constants", "//internal/crypto/testvector", - "//internal/deploy/helm", "//internal/file", "//internal/grpc/atlscredentials", "//internal/grpc/dialer", diff --git a/cli/internal/cmd/init.go b/cli/internal/cmd/init.go index 2f1386521b..feb881959b 100644 --- a/cli/internal/cmd/init.go +++ b/cli/internal/cmd/init.go @@ -45,7 +45,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/crypto" - helmdeploy "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/grpclog" @@ -441,9 +440,9 @@ func (i *initCmd) evalFlagArgs(cmd *cobra.Command) (initFlags, error) { if err != nil { return initFlags{}, fmt.Errorf("parsing skip-helm-wait flag: %w", err) } - helmWaitMode := helmdeploy.WaitModeAtomic + helmWaitMode := helm.WaitModeAtomic if skipHelmWait { - helmWaitMode = helmdeploy.WaitModeNone + helmWaitMode = helm.WaitModeNone } i.log.Debugf("Helm wait flag is %t", skipHelmWait) configPath, err := cmd.Flags().GetString("config") @@ -478,7 +477,7 @@ type initFlags struct { configPath string masterSecretPath string conformance bool - helmWaitMode helmdeploy.WaitMode + helmWaitMode helm.WaitMode force bool mergeConfigs bool } diff --git a/cli/internal/cmd/init_test.go b/cli/internal/cmd/init_test.go index bafe7e4a75..1a1ac03c75 100644 --- a/cli/internal/cmd/init_test.go +++ b/cli/internal/cmd/init_test.go @@ -21,6 +21,7 @@ import ( "github.com/edgelesssys/constellation/v2/bootstrapper/initproto" "github.com/edgelesssys/constellation/v2/cli/internal/clusterid" + "github.com/edgelesssys/constellation/v2/cli/internal/helm" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -28,7 +29,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" - helminstaller "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/grpc/atlscredentials" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" @@ -672,7 +672,7 @@ type stubHelmInstaller struct{} func (i *stubHelmInstaller) Install(_ context.Context, _ cloudprovider.Provider, _ uri.MasterSecret, _ clusterid.File, - _ string, _ *helminstaller.Releases, + _ string, _ *helm.Releases, ) error { return nil } diff --git a/cli/internal/helm/BUILD.bazel b/cli/internal/helm/BUILD.bazel index 54d742f049..a52e1accf5 100644 --- a/cli/internal/helm/BUILD.bazel +++ b/cli/internal/helm/BUILD.bazel @@ -8,8 +8,10 @@ go_library( "client.go", "helm.go", "helminstaller.go", + "install.go", "kubernetes_custom.go", "loader.go", + "release.go", "serviceversion.go", "setup.go", "values.go", @@ -428,9 +430,9 @@ go_library( "//internal/compatibility", "//internal/config", "//internal/constants", - "//internal/deploy/helm", "//internal/file", "//internal/kms/uri", + "//internal/retry", "//internal/semver", "//internal/versions", "@com_github_pkg_errors//:errors", @@ -440,6 +442,7 @@ go_library( "@io_k8s_apimachinery//pkg/apis/meta/v1:meta", "@io_k8s_apimachinery//pkg/apis/meta/v1/unstructured", "@io_k8s_apimachinery//pkg/runtime/schema", + "@io_k8s_apimachinery//pkg/util/wait", "@io_k8s_client_go//kubernetes", "@io_k8s_client_go//tools/clientcmd", "@io_k8s_sigs_yaml//:yaml", @@ -459,6 +462,7 @@ go_test( "backup_test.go", "client_test.go", "loader_test.go", + "release_test.go", ], data = glob(["testdata/**"]), embed = [":helm"], @@ -469,7 +473,6 @@ go_test( "//internal/cloud/cloudprovider", "//internal/compatibility", "//internal/config", - "//internal/deploy/helm", "//internal/file", "//internal/logger", "//internal/semver", diff --git a/cli/internal/helm/client.go b/cli/internal/helm/client.go index f0200f5313..c66c0c213c 100644 --- a/cli/internal/helm/client.go +++ b/cli/internal/helm/client.go @@ -13,20 +13,20 @@ import ( "strings" "time" + "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/chart" + "helm.sh/helm/v3/pkg/cli" + "helm.sh/helm/v3/pkg/release" + "github.com/edgelesssys/constellation/v2/cli/internal/clusterid" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/compatibility" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/spf13/afero" - "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart" - "helm.sh/helm/v3/pkg/cli" - "helm.sh/helm/v3/pkg/release" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" @@ -423,7 +423,7 @@ func (c *Client) mergeClusterValues(localValues map[string]any, releaseName stri return nil, fmt.Errorf("getting values for %s: %w", releaseName, err) } - return helm.MergeMaps(clusterValues, localValues), nil + return MergeMaps(clusterValues, localValues), nil } // GetValues queries the cluster for the values of the given release. @@ -456,11 +456,6 @@ func (c *Client) updateCRDs(ctx context.Context, chart *chart.Chart) error { return nil } -type debugLog interface { - Debugf(format string, args ...any) - Sync() -} - type crdClient interface { Initialize(kubeconfig []byte) error ApplyCRD(ctx context.Context, rawCRD []byte) error diff --git a/cli/internal/helm/helminstaller.go b/cli/internal/helm/helminstaller.go index 2af4836761..fb8cd1d902 100644 --- a/cli/internal/helm/helminstaller.go +++ b/cli/internal/helm/helminstaller.go @@ -15,7 +15,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/cloud/openstack" "github.com/edgelesssys/constellation/v2/internal/constants" - helminstaller "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/kms/uri" ) @@ -23,7 +22,7 @@ import ( type SuiteInstaller interface { Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret, idFile clusterid.File, - serviceAccURI string, releases *helminstaller.Releases, + serviceAccURI string, releases *Releases, ) error } @@ -34,7 +33,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, log) + installer, err := NewInstaller(constants.AdminConfFilename, log) if err != nil { return nil, fmt.Errorf("creating Helm installer: %w", err) } @@ -43,7 +42,7 @@ func NewInstallationClient(log debugLog) (SuiteInstaller, error) { func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovider.Provider, masterSecret uri.MasterSecret, idFile clusterid.File, - serviceAccURI string, releases *helminstaller.Releases, + serviceAccURI string, releases *Releases, ) error { tfClient, err := terraform.New(ctx, constants.TerraformWorkingDir) if err != nil { @@ -82,7 +81,7 @@ func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovi } h.log.Debugf("Installing microservices") - serviceVals, err := setupMicroserviceVals(ctx, provider, masterSecret.Salt, idFile.UID, serviceAccURI, output) + serviceVals, err := setupMicroserviceVals(provider, masterSecret.Salt, idFile.UID, serviceAccURI, output) if err != nil { return fmt.Errorf("setting up microservice values: %w", err) } @@ -134,6 +133,6 @@ func (h helmInstallationClient) Install(ctx context.Context, provider cloudprovi } type helmInstaller interface { - InstallChart(context.Context, helminstaller.Release) error - InstallChartWithValues(ctx context.Context, release helminstaller.Release, extraValues map[string]any) error + InstallChart(context.Context, Release) error + InstallChartWithValues(ctx context.Context, release Release, extraValues map[string]any) error } diff --git a/internal/deploy/helm/install.go b/cli/internal/helm/install.go similarity index 100% rename from internal/deploy/helm/install.go rename to cli/internal/helm/install.go diff --git a/cli/internal/helm/loader.go b/cli/internal/helm/loader.go index 622c1de59c..7557365bc5 100644 --- a/cli/internal/helm/loader.go +++ b/cli/internal/helm/loader.go @@ -27,7 +27,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/edgelesssys/constellation/v2/internal/versions" ) @@ -109,7 +108,7 @@ func NewLoader(csp cloudprovider.Provider, k8sVersion versions.ValidK8sVersion, } // Load the embedded helm charts. -func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, helmWaitMode helm.WaitMode, masterSecret, salt []byte) ([]byte, error) { +func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, helmWaitMode WaitMode, masterSecret, salt []byte) ([]byte, error) { releases, err := i.LoadReleases(config, conformanceMode, helmWaitMode, masterSecret, salt) if err != nil { return nil, fmt.Errorf("loading releases: %w", err) @@ -122,7 +121,7 @@ func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, helmWait } // LoadReleases loads the embedded helm charts and returns them as a HelmReleases object. -func (i *ChartLoader) LoadReleases(config *config.Config, conformanceMode bool, helmWaitMode helm.WaitMode, masterSecret, salt []byte) (*helm.Releases, error) { +func (i *ChartLoader) LoadReleases(config *config.Config, conformanceMode bool, helmWaitMode WaitMode, masterSecret, salt []byte) (*Releases, error) { ciliumRelease, err := i.loadRelease(ciliumInfo, helmWaitMode) if err != nil { return nil, fmt.Errorf("loading cilium: %w", err) @@ -147,7 +146,7 @@ func (i *ChartLoader) LoadReleases(config *config.Config, conformanceMode bool, return nil, fmt.Errorf("extending constellation-services values: %w", err) } - releases := helm.Releases{Cilium: ciliumRelease, CertManager: certManagerRelease, ConstellationOperators: operatorRelease, ConstellationServices: conServicesRelease} + releases := Releases{Cilium: ciliumRelease, CertManager: certManagerRelease, ConstellationOperators: operatorRelease, ConstellationServices: conServicesRelease} if config.HasProvider(cloudprovider.AWS) { awsRelease, err := i.loadRelease(awsLBControllerInfo, helmWaitMode) if err != nil { @@ -168,10 +167,10 @@ func (i *ChartLoader) LoadReleases(config *config.Config, conformanceMode bool, // loadRelease loads the embedded chart and values depending on the given info argument. // IMPORTANT: .helmignore rules specifying files in subdirectories are not applied (e.g. crds/kustomization.yaml). -func (i *ChartLoader) loadRelease(info chartInfo, helmWaitMode helm.WaitMode) (helm.Release, error) { +func (i *ChartLoader) loadRelease(info chartInfo, helmWaitMode WaitMode) (Release, error) { chart, err := loadChartsDir(helmFS, info.path) if err != nil { - return helm.Release{}, fmt.Errorf("loading %s chart: %w", info.releaseName, err) + return Release{}, fmt.Errorf("loading %s chart: %w", info.releaseName, err) } var values map[string]any @@ -181,7 +180,7 @@ func (i *ChartLoader) loadRelease(info chartInfo, helmWaitMode helm.WaitMode) (h var ok bool values, ok = ciliumVals[i.csp.String()] if !ok { - return helm.Release{}, fmt.Errorf("cilium values for csp %q not found", i.csp.String()) + return Release{}, fmt.Errorf("cilium values for csp %q not found", i.csp.String()) } case certManagerInfo.releaseName: values = i.loadCertManagerValues() @@ -200,10 +199,10 @@ func (i *ChartLoader) loadRelease(info chartInfo, helmWaitMode helm.WaitMode) (h chartRaw, err := i.marshalChart(chart) if err != nil { - return helm.Release{}, fmt.Errorf("packaging %s chart: %w", info.releaseName, err) + return Release{}, fmt.Errorf("packaging %s chart: %w", info.releaseName, err) } - return helm.Release{Chart: chartRaw, Values: values, ReleaseName: info.releaseName, WaitMode: helmWaitMode}, nil + return Release{Chart: chartRaw, Values: values, ReleaseName: info.releaseName, WaitMode: helmWaitMode}, nil } func (i *ChartLoader) loadAWSLBControllerValues() map[string]any { diff --git a/cli/internal/helm/loader_test.go b/cli/internal/helm/loader_test.go index 4df7453193..e82fb6d5fd 100644 --- a/cli/internal/helm/loader_test.go +++ b/cli/internal/helm/loader_test.go @@ -29,7 +29,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/config" - "github.com/edgelesssys/constellation/v2/internal/deploy/helm" ) // TestLoad checks if the serialized format that Load returns correctly preserves the dependencies of the loaded chart. @@ -39,10 +38,10 @@ func TestLoad(t *testing.T) { config := &config.Config{Provider: config.ProviderConfig{GCP: &config.GCPConfig{}}} chartLoader := ChartLoader{csp: config.GetProvider()} - release, err := chartLoader.Load(config, true, helm.WaitModeAtomic, []byte("secret"), []byte("salt")) + release, err := chartLoader.Load(config, true, WaitModeAtomic, []byte("secret"), []byte("salt")) require.NoError(err) - var helmReleases helm.Releases + var helmReleases Releases err = json.Unmarshal(release, &helmReleases) require.NoError(err) reader := bytes.NewReader(helmReleases.ConstellationServices.Chart) diff --git a/internal/deploy/helm/helm.go b/cli/internal/helm/release.go similarity index 100% rename from internal/deploy/helm/helm.go rename to cli/internal/helm/release.go diff --git a/internal/deploy/helm/helm_test.go b/cli/internal/helm/release_test.go similarity index 100% rename from internal/deploy/helm/helm_test.go rename to cli/internal/helm/release_test.go diff --git a/cli/internal/helm/setup.go b/cli/internal/helm/setup.go index 9410195ad8..7ee95c56cf 100644 --- a/cli/internal/helm/setup.go +++ b/cli/internal/helm/setup.go @@ -41,7 +41,7 @@ func setupCiliumVals(_ context.Context, provider cloudprovider.Provider, _ *k8sH } // setupMicroserviceVals returns the values for the microservice chart. -func setupMicroserviceVals(ctx context.Context, provider cloudprovider.Provider, measurementSalt []byte, uid, serviceAccURI string, output terraform.ApplyOutput) (map[string]any, error) { +func setupMicroserviceVals(provider cloudprovider.Provider, measurementSalt []byte, uid, serviceAccURI string, output terraform.ApplyOutput) (map[string]any, error) { extraVals := map[string]any{ "join-service": map[string]any{ "measurementSalt": base64.StdEncoding.EncodeToString(measurementSalt), diff --git a/internal/deploy/helm/BUILD.bazel b/internal/deploy/helm/BUILD.bazel deleted file mode 100644 index 5cb17b3155..0000000000 --- a/internal/deploy/helm/BUILD.bazel +++ /dev/null @@ -1,28 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_test") - -go_library( - name = "helm", - srcs = [ - "helm.go", - "install.go", - ], - importpath = "github.com/edgelesssys/constellation/v2/internal/deploy/helm", - visibility = ["//:__subpackages__"], - deps = [ - "//internal/constants", - "//internal/retry", - "@io_k8s_apimachinery//pkg/util/wait", - "@sh_helm_helm_v3//pkg/action", - "@sh_helm_helm_v3//pkg/chart", - "@sh_helm_helm_v3//pkg/chart/loader", - "@sh_helm_helm_v3//pkg/cli", - ], -) - -go_test( - name = "helm_test", - srcs = ["helm_test.go"], - embed = [":helm"], - deps = ["@com_github_stretchr_testify//assert"], -)