-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #208. config: Add SetComponents method to update the components in the private config. package/create.Create: Add logic to expand locally imported components within the parent build config. types: Add Import field to Zarf.Component as expirement (expected to change). * #208. ADD packager/compose.go: Created compose logic for imported components and nested import components. UPDATE types.go: Added ZarfImport type with a path variable as the associated type with ZarfComponent.Import field (this sets up sha verification additions in the future, still need team imput). UPDATE Packager/Common.go: pulled confirming optional component logic out of getValidComponents to play with composed package validation (need to validate expected behavior). UPDATE Packager/Create.go: Replaced the initial compose logic with call to GetComposedAssets(). ADD examples/compose-example: a simple composition example for explicit example. * #208. UPDATE cli/config: Delete SetSeedImages method as it is no longer needed. UPDATE packager/compose: removed the logic working with SeedImages as it is not necessary for composition. UPDATE packager/create.go: seperate the GetComposedAssets call from the seed images. Set seedImages variable using the config.GetSeedImages() method. * #208. ADD e2e_composability_test: set up basic tests to ensure that the composed packages flux and games are properly deployed together. UPDATE examples/Makefile with the package-example-composability command and added that command to the package-examples command. RENAME examples/composable-example -> examples/composable-packages * #208, #351. UPDATE packager/validate: add the ValidateImportPackage method for use with compose.go. UPDATE packager/compose: add the hasValidSubPackage method and replaced the hasSubPackage calls. Updated the hasSubPackage method to validate only that the Component.Import field exists. Clean up index names in prepComponentToCompose. * #208, #351. UPDATE docer/components: Added new section on composing packages. ADD examples/composable-packages/README: with instructions on running doom using composition from the games example zarf.yaml. UPDATE examples/composable-packages/zarf.yaml: removed the flux package as the game is a more clear example and still shows the same composability without the need of flux since the games package does not rely on flux * #208, #351. UPDATE packager/compose: added the shouldAddImportedPackage method when pulling in imported components. Updated shouldAddImportedPackage method to no longer prompt if --confirm flag is passed * #208, #351. FIX packager/compose: to no longer add the optional composed package when the user chooses to not import that composed packages. * #208. UPDATE e2e_composability_test: removed the tests verifying flux due to remove of flux composed component in the composability example. * #208, #351. UPDATE Makefile: add package-example-compose for e2e tests. Update .github/workflows/test*: add package-compose-example to make packages stage. UPDATE packager/compose: rename GetComposedAssets to GetComposedComponents UPDATE reference in packager/create. refactored and rename hasValidSubPackage to validateOrBail. Rename shouldAddImportedPackage to shouldComposePackage. Extracted component required logic to componentConfirmedForInclusion. UPDATE e2e/e2e_composability_test: to work with new testing strategy.
- Loading branch information
1 parent
fd478b8
commit 3fb8b65
Showing
17 changed files
with
457 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package packager | ||
|
||
import ( | ||
"github.com/defenseunicorns/zarf/cli/config" | ||
"github.com/defenseunicorns/zarf/cli/internal/message" | ||
"github.com/defenseunicorns/zarf/cli/internal/packager/validate" | ||
"github.com/defenseunicorns/zarf/cli/internal/utils" | ||
"github.com/defenseunicorns/zarf/cli/types" | ||
) | ||
|
||
func GetComposedComponents() (components []types.ZarfComponent) { | ||
for _, component := range config.GetComponents() { | ||
// Check for standard component. | ||
if !hasComposedPackage(&component) { | ||
// Append standard component to list. | ||
components = append(components, component) | ||
} else if shouldComposePackage(&component) { // Validate and confirm inclusion of imported package. | ||
// Expand and add components from imported package. | ||
importedComponents := getSubPackageAssets(component) | ||
components = append(components, importedComponents...) | ||
} | ||
} | ||
// Update the parent package config with the expanded sub components. | ||
// This is important when the deploy package is created. | ||
config.SetComponents(components) | ||
return components | ||
} | ||
|
||
// Returns true if import field is populated. | ||
func hasComposedPackage(component *types.ZarfComponent) bool { | ||
return component.Import != types.ZarfImport{} | ||
} | ||
|
||
// Validates and confirms inclusion of imported package. | ||
func shouldComposePackage(component *types.ZarfComponent) bool { | ||
validateOrBail(component) | ||
return componentConfirmedForInclusion(component) | ||
} | ||
|
||
// Returns true if confirm flag is true, the component is required, or the user confirms inclusion. | ||
func componentConfirmedForInclusion(component *types.ZarfComponent) bool { | ||
return config.DeployOptions.Confirm || component.Required || ConfirmOptionalComponent(*component) | ||
} | ||
|
||
// Validates the sub component, exits program if validation fails. | ||
func validateOrBail(component *types.ZarfComponent) { | ||
if err := validate.ValidateImportPackage(component); err != nil { | ||
message.Fatalf(err, "Invalid import definition in the %s component: %s", component.Name, err) | ||
} | ||
} | ||
|
||
// Get expanded components from imported component. | ||
func getSubPackageAssets(importComponent types.ZarfComponent) (components []types.ZarfComponent) { | ||
// Read the imported package. | ||
importedPackage := getSubPackage(&importComponent) | ||
// Iterate imported components. | ||
for _, componentToCompose := range importedPackage.Components { | ||
// Check for standard component. | ||
if !hasComposedPackage(&componentToCompose) { | ||
// Doctor standard component name and included files. | ||
prepComponentToCompose(&componentToCompose, importedPackage.Metadata.Name, importComponent.Import.Path) | ||
components = append(components, componentToCompose) | ||
} else if shouldComposePackage(&componentToCompose) { | ||
// Recurse on imported components. | ||
components = append(components, getSubPackageAssets(componentToCompose)...) | ||
} | ||
} | ||
return components | ||
} | ||
|
||
// Reads the locally imported zarf.yaml | ||
func getSubPackage(component *types.ZarfComponent) (importedPackage types.ZarfPackage) { | ||
utils.ReadYaml(component.Import.Path+"zarf.yaml", &importedPackage) | ||
return importedPackage | ||
} | ||
|
||
// Updates the name and sets all local asset paths relative to the importing package. | ||
func prepComponentToCompose(component *types.ZarfComponent, parentPackageName string, importPath string) { | ||
// Prefix component name with parent package name to distinguish similarly named components. | ||
component.Name = parentPackageName + "-" + component.Name | ||
|
||
// Prefix composed component file paths. | ||
for fileIdx, file := range component.Files { | ||
component.Files[fileIdx].Source = getComposedFilePath(file.Source, importPath) | ||
} | ||
|
||
// Prefix non-url composed component chart values files. | ||
for chartIdx, chart := range component.Charts { | ||
for valuesIdx, valuesFile := range chart.ValuesFiles { | ||
component.Charts[chartIdx].ValuesFiles[valuesIdx] = getComposedFilePath(valuesFile, importPath) | ||
} | ||
} | ||
|
||
// Prefix non-url composed manifest files and kustomizations. | ||
for manifestIdx, manifest := range component.Manifests { | ||
for fileIdx, file := range manifest.Files { | ||
component.Manifests[manifestIdx].Files[fileIdx] = getComposedFilePath(file, importPath) | ||
} | ||
for kustomIdx, kustomization := range manifest.Kustomizations { | ||
component.Manifests[manifestIdx].Kustomizations[kustomIdx] = getComposedFilePath(kustomization, importPath) | ||
} | ||
} | ||
} | ||
|
||
// Prefix file path with importPath if original file path is not a url. | ||
func getComposedFilePath(originalPath string, pathPrefix string) string { | ||
// Return original if it is a remote file. | ||
if utils.IsUrl(originalPath) { | ||
return originalPath | ||
} | ||
// Add prefix for local files. | ||
return pathPrefix + originalPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.