diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index 14c3e2f31a..3557544e14 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -134,8 +134,8 @@ func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, } // RecordPackageDeploymentAndWait records the deployment of a package to the cluster and waits for any webhooks to complete. -func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int, component v1alpha1.ZarfComponent, skipWebhooks bool) (*types.DeployedPackage, error) { - deployedPackage, err := c.RecordPackageDeployment(ctx, pkg, components, connectStrings, generation) +func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, generation int, component v1alpha1.ZarfComponent, skipWebhooks bool) (*types.DeployedPackage, error) { + deployedPackage, err := c.RecordPackageDeployment(ctx, pkg, components, generation) if err != nil { return nil, err } @@ -174,7 +174,7 @@ func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alph } // RecordPackageDeployment saves metadata about a package that has been deployed to the cluster. -func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int) (deployedPackage *types.DeployedPackage, err error) { +func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, generation int) (deployedPackage *types.DeployedPackage, err error) { packageName := pkg.Metadata.Name // Attempt to load information about webhooks for the package @@ -187,6 +187,16 @@ func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.Zarf componentWebhooks = existingPackageSecret.ComponentWebhooks } + // TODO: This is done for backwards compartibility and could be removed in the future. + connectStrings := types.ConnectStrings{} + for _, comp := range components { + for _, chart := range comp.InstalledCharts { + for k, v := range chart.ConnectStrings { + connectStrings[k] = v + } + } + } + deployedPackage = &types.DeployedPackage{ Name: packageName, CLIVersion: config.CLIVersion, diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a3c5529e5a..1325a70b46 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -36,7 +36,6 @@ type Packager struct { cluster *cluster.Cluster layout *layout.PackagePaths hpaModified bool - connectStrings types.ConnectStrings source sources.PackageSource } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 5f4a24e09b..517bff7d60 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -113,7 +113,6 @@ func (p *Packager) Deploy(ctx context.Context) error { } p.hpaModified = false - p.connectStrings = make(types.ConnectStrings) // Reset registry HPA scale down whether an error occurs or not defer p.resetRegistryHPA(ctx) @@ -182,7 +181,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon // Update the package secret to indicate that we are attempting to deploy this component if p.isConnectedToCluster() { - if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, p.connectStrings, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { + if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { message.Debugf("Unable to record package deployment for component %s: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) } } @@ -193,7 +192,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon if p.cfg.Pkg.IsInitConfig() { charts, deployErr = p.deployInitComponent(ctx, component) } else { - charts, deployErr = p.deployComponent(ctx, component, false /* keep img checksum */, false /* always push images */) + charts, deployErr = p.deployComponent(ctx, component, false, false) } onDeploy := component.Actions.OnDeploy @@ -210,7 +209,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon // Update the package secret to indicate that we failed to deploy this component deployedComponents[idx].Status = types.ComponentStatusFailed if p.isConnectedToCluster() { - if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, p.connectStrings, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { + if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) } } @@ -221,7 +220,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon deployedComponents[idx].InstalledCharts = charts deployedComponents[idx].Status = types.ComponentStatusSucceeded if p.isConnectedToCluster() { - if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, p.connectStrings, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { + if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, packageGeneration, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) } } @@ -361,7 +360,8 @@ func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfC charts := []types.InstalledChart{} if hasCharts || hasManifests { - if charts, err = p.installChartAndManifests(ctx, componentPath, component); err != nil { + charts, err = p.installChartAndManifests(ctx, componentPath, component) + if err != nil { return nil, err } } @@ -680,16 +680,11 @@ func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths p.cfg.PkgOpts.Retries), ) - addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) + connectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) if err != nil { return nil, err } - installedCharts = append(installedCharts, types.InstalledChart{Namespace: chart.Namespace, ChartName: installedChartName}) - - // Iterate over any connectStrings and add to the main map - for name, description := range addedConnectStrings { - p.connectStrings[name] = description - } + installedCharts = append(installedCharts, types.InstalledChart{Namespace: chart.Namespace, ChartName: installedChartName, ConnectStrings: connectStrings}) } for _, manifest := range component.Manifests { @@ -733,17 +728,11 @@ func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths } // Install the chart. - addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) + connectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) if err != nil { return nil, err } - - installedCharts = append(installedCharts, types.InstalledChart{Namespace: manifest.Namespace, ChartName: installedChartName}) - - // Iterate over any connectStrings and add to the main map - for name, description := range addedConnectStrings { - p.connectStrings[name] = description - } + installedCharts = append(installedCharts, types.InstalledChart{Namespace: manifest.Namespace, ChartName: installedChartName, ConnectStrings: connectStrings}) } return installedCharts, nil @@ -752,7 +741,15 @@ func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths func (p *Packager) printTablesForDeployment(ctx context.Context, componentsToDeploy []types.DeployedComponent) error { // If not init config, print the application connection table if !p.cfg.Pkg.IsInitConfig() { - message.PrintConnectStringTable(p.connectStrings) + connectStrings := types.ConnectStrings{} + for _, comp := range componentsToDeploy { + for _, chart := range comp.InstalledCharts { + for k, v := range chart.ConnectStrings { + connectStrings[k] = v + } + } + } + message.PrintConnectStringTable(connectStrings) return nil } // Don't print if cluster is not configured diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index 49232ddc1b..de7af6f4af 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -16,7 +16,6 @@ import ( "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/creator" "github.com/zarf-dev/zarf/src/pkg/packager/filters" - "github.com/zarf-dev/zarf/src/types" ) // DevDeploy creates + deploys a package in one shot @@ -75,8 +74,6 @@ func (p *Packager) DevDeploy(ctx context.Context) error { message.HeaderInfof("📦 PACKAGE DEPLOY %s", p.cfg.Pkg.Metadata.Name) - p.connectStrings = make(types.ConnectStrings) - if !p.cfg.CreateOpts.NoYOLO { p.cfg.Pkg.Metadata.YOLO = true } else { diff --git a/src/types/k8s.go b/src/types/k8s.go index 84ad8d7994..696be20b79 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -119,8 +119,9 @@ type Webhook struct { // InstalledChart contains information about a Helm Chart that has been deployed to a cluster. type InstalledChart struct { - Namespace string `json:"namespace"` - ChartName string `json:"chartName"` + Namespace string `json:"namespace"` + ChartName string `json:"chartName"` + ConnectStrings ConnectStrings `json:"connectStrings,omitempty"` } // GitServerInfo contains information Zarf uses to communicate with a git repository to push/pull repositories to.