From edc0b6abe1c85952d519b46c7810c22b6ce57615 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Mon, 23 Oct 2023 10:06:52 -0700 Subject: [PATCH] Rename and add comment --- pkg/platform/runtime/buildplan/buildplan.go | 39 ++++++++++----------- pkg/platform/runtime/setup/setup.go | 21 ++++++----- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/pkg/platform/runtime/buildplan/buildplan.go b/pkg/platform/runtime/buildplan/buildplan.go index c53b917b92..737163ac8a 100644 --- a/pkg/platform/runtime/buildplan/buildplan.go +++ b/pkg/platform/runtime/buildplan/buildplan.go @@ -51,34 +51,33 @@ func (al *ArtifactListing) BuildtimeClosure() (artifact.Map, error) { return buildtimeClosure, nil } -func (al *ArtifactListing) ArtifactIDs() ([]artifact.ArtifactID, error) { +func (al *ArtifactListing) ArtifactIDs(buildtimeClosure bool) ([]artifact.ArtifactID, error) { if al.artifactIDs != nil { return al.artifactIDs, nil } - if al.buildtimeClosure != nil { - for _, artifact := range al.buildtimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + if buildtimeClosure { + if al.buildtimeClosure != nil { + for _, artifact := range al.buildtimeClosure { + al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + } + return al.artifactIDs, nil } - return al.artifactIDs, nil - } - if al.runtimeClosure != nil { - for _, artifact := range al.runtimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + buildTimeClosure, err := al.BuildtimeClosure() + if err != nil { + return nil, errs.Wrap(err, "Could not create buildtime closure") } - return al.artifactIDs, nil - } - // Favor the buildtime closure over the runtime closure as it will - // include more artifact IDs - buildTimeClosure, err := al.BuildtimeClosure() - if err != nil { - return nil, errs.Wrap(err, "Could not create buildtime closure") - } - - for _, artifact := range buildTimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + for _, artifact := range buildTimeClosure { + al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + } + } else { + if al.runtimeClosure != nil { + for _, artifact := range al.runtimeClosure { + al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + } + } } return al.artifactIDs, nil diff --git a/pkg/platform/runtime/setup/setup.go b/pkg/platform/runtime/setup/setup.go index 7f7904bdeb..389af26017 100644 --- a/pkg/platform/runtime/setup/setup.go +++ b/pkg/platform/runtime/setup/setup.go @@ -403,18 +403,20 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal } // Compute and handle the change summary - var runtimeArtifacts artifact.Map // Artifacts required for the runtime to function + var requestedArtifacts artifact.Map // Artifacts required for the runtime to function artifactListing := buildplan.NewArtifactListing(buildResult.Build) - // If we are installing build dependencies, then buildtime dependencies are also runtime dependencies + // If we are installing build dependencies, then the requested artifacts + // will include the buildtime closure. Otherwise, we only need the runtime + // closure. if strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") { logging.Debug("Installing build dependencies") - runtimeArtifacts, err = artifactListing.BuildtimeClosure() + requestedArtifacts, err = artifactListing.BuildtimeClosure() if err != nil { return nil, nil, errs.Wrap(err, "Failed to compute buildtime closure") } } else { - runtimeArtifacts, err = artifactListing.RuntimeClosure() + requestedArtifacts, err = artifactListing.RuntimeClosure() if err != nil { return nil, nil, errs.Wrap(err, "Failed to create artifact map from build plan") } @@ -430,7 +432,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal return nil, nil, errs.Wrap(err, "Failed to select setup implementation") } - downloadablePrebuiltResults, err := setup.DownloadsFromBuild(*buildResult.Build, runtimeArtifacts) + downloadablePrebuiltResults, err := setup.DownloadsFromBuild(*buildResult.Build, requestedArtifacts) if err != nil { if errors.Is(err, artifact.CamelRuntimeBuilding) { localeID := "build_status_in_progress" @@ -446,7 +448,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal // buildResult doesn't have namespace info and will happily report internal only artifacts downloadablePrebuiltResults = funk.Filter(downloadablePrebuiltResults, func(ad artifact.ArtifactDownload) bool { - ar, ok := runtimeArtifacts[ad.ArtifactID] + ar, ok := requestedArtifacts[ad.ArtifactID] if !ok { return true } @@ -463,6 +465,9 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeBuild, dimensions) } + // If the build is not ready or if we are installing the buildtime closure + // then we need to include the buildtime closure in the changed artifacts + // and the progress reporting. includeBuildtimeClosure := strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") || !buildResult.BuildReady changedArtifacts, err := buildplan.NewBaseArtifactChangesetByBuildPlan(buildResult.Build, false, includeBuildtimeClosure) if err != nil { @@ -489,7 +494,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal alreadyInstalled := reusableArtifacts(buildResult.Build.Artifacts, storedArtifacts) // Report resolved artifacts - artifactIDs, err := artifactListing.ArtifactIDs() + artifactIDs, err := artifactListing.ArtifactIDs(includeBuildtimeClosure) if err != nil { return nil, nil, errs.Wrap(err, "Could not get artifact IDs from build plan") } @@ -562,7 +567,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeDownload, dimensions) } - err = s.installArtifactsFromBuild(buildResult, runtimeArtifacts, artifact.ArtifactIDsToMap(artifactsToInstall), downloadablePrebuiltResults, setup, resolver, installFunc, logFilePath) + err = s.installArtifactsFromBuild(buildResult, requestedArtifacts, artifact.ArtifactIDsToMap(artifactsToInstall), downloadablePrebuiltResults, setup, resolver, installFunc, logFilePath) if err != nil { return nil, nil, err }