Skip to content

Commit

Permalink
remove oci differential components
Browse files Browse the repository at this point in the history
Signed-off-by: razzle <[email protected]>
  • Loading branch information
Noxsios committed Oct 25, 2023
1 parent 25f6697 commit 620feb8
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 66 deletions.
4 changes: 0 additions & 4 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) {
cfg.SetVariableMap = make(map[string]*types.ZarfSetVariable)
}

if cfg.Pkg.Build.OCIImportedComponents == nil {
cfg.Pkg.Build.OCIImportedComponents = make(map[string]string)
}

var (
err error
pkgr = &Packager{
Expand Down
6 changes: 0 additions & 6 deletions src/pkg/packager/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ func (p *Packager) composeComponents() error {
}
message.Debugf("%s", chain)

if chain.ContainsOCIImport() {
url, name := chain.OCIImportDefinition()
// Save all the OCI imported components into our build data
p.cfg.Pkg.Build.OCIImportedComponents[url] = name
}

// migrate any deprecated component configurations now
warnings := chain.Migrate(p.cfg.Pkg.Build)
p.warnings = append(p.warnings, warnings...)
Expand Down
8 changes: 0 additions & 8 deletions src/pkg/packager/composer/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ func (ic *ImportChain) ContainsOCIImport() bool {
return ic.tail.prev != nil && ic.tail.prev.Import.URL != ""
}

// OCIImportDefinition returns the url and name of the remote import
func (ic *ImportChain) OCIImportDefinition() (string, string) {
if !ic.ContainsOCIImport() {
return "", ""
}
return ic.tail.prev.Import.URL, ic.tail.prev.ImportName()
}

func (ic *ImportChain) fetchOCISkeleton() error {
if !ic.ContainsOCIImport() {
return nil
Expand Down
43 changes: 0 additions & 43 deletions src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ func (p *Packager) Create() (err error) {
p.cfg.Pkg.Metadata.Version = config.CLIVersion
}

// Before we compose the components (and render the imported OCI components), we need to remove any components that are not needed for a differential build
if err := p.removeDifferentialComponentsFromPackage(); err != nil {
return err
}

// Compose components into a single zarf.yaml file
if err := p.composeComponents(); err != nil {
return err
Expand Down Expand Up @@ -667,44 +662,6 @@ func (p *Packager) loadDifferentialData() error {
p.cfg.CreateOpts.DifferentialData.DifferentialImages = allIncludedImagesMap
p.cfg.CreateOpts.DifferentialData.DifferentialRepos = allIncludedReposMap
p.cfg.CreateOpts.DifferentialData.DifferentialPackageVersion = differentialZarfConfig.Metadata.Version
p.cfg.CreateOpts.DifferentialData.DifferentialOCIComponents = differentialZarfConfig.Build.OCIImportedComponents

return nil
}

// removeDifferentialComponentsFromPackage will remove unchanged OCI imported components from a differential package creation
func (p *Packager) removeDifferentialComponentsFromPackage() error {
// Remove components that were imported and already built into the reference package
if len(p.cfg.CreateOpts.DifferentialData.DifferentialOCIComponents) > 0 {
componentsToRemove := []int{}

for idx, component := range p.cfg.Pkg.Components {
// if the component is imported from an OCI package and everything is the same, don't include this package
if helpers.IsOCIURL(component.Import.URL) {
if _, alsoExists := p.cfg.CreateOpts.DifferentialData.DifferentialOCIComponents[component.Import.URL]; alsoExists {

// If the component spec is not empty, we will still include it in the differential package
// NOTE: We are ignoring fields that are not relevant to the differential build
if component.IsEmpty([]string{"Name", "Required", "Description", "Default", "Import"}) {
componentsToRemove = append(componentsToRemove, idx)
}
}
}
}

// Remove the components that are already included (via OCI Import) in the reference package
if len(componentsToRemove) > 0 {
for i, componentIndex := range componentsToRemove {
indexToRemove := componentIndex - i
componentToRemove := p.cfg.Pkg.Components[indexToRemove]

// If we are removing a component, add it to the build metadata and remove it from the list of OCI components for this package
p.cfg.Pkg.Build.DifferentialMissing = append(p.cfg.Pkg.Build.DifferentialMissing, componentToRemove.Name)

p.cfg.Pkg.Components = append(p.cfg.Pkg.Components[:indexToRemove], p.cfg.Pkg.Components[indexToRemove+1:]...)
}
}
}

return nil
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/e2e/52_oci_compose_differential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func (suite *OCIDifferentialSuite) Test_0_Create_Differential_OCI() {
// Check the metadata and build data for the normal package
suite.Equal(normalZarfConfig.Metadata.Version, "v0.24.0")
suite.False(normalZarfConfig.Build.Differential)
suite.Len(normalZarfConfig.Build.OCIImportedComponents, 1)
suite.Equal(normalZarfConfig.Build.OCIImportedComponents["oci://127.0.0.1:555/helm-charts:0.0.1-skeleton"], "demo-helm-oci-chart")

// Check the component data for the normal package
suite.Len(normalZarfConfig.Components, 3)
Expand All @@ -111,7 +109,6 @@ func (suite *OCIDifferentialSuite) Test_0_Create_Differential_OCI() {
suite.True(differentialZarfConfig.Build.Differential)
suite.Len(differentialZarfConfig.Build.DifferentialMissing, 1)
suite.Equal(differentialZarfConfig.Build.DifferentialMissing[0], "demo-helm-oci-chart")
suite.Len(differentialZarfConfig.Build.OCIImportedComponents, 0)

// Check the component data for the differential package
suite.Len(differentialZarfConfig.Components, 2)
Expand Down
1 change: 0 additions & 1 deletion src/types/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type ZarfBuildData struct {
Differential bool `json:"differential,omitempty" jsonschema:"description=Whether this package was created with differential components"`
RegistryOverrides map[string]string `json:"registryOverrides,omitempty" jsonschema:"description=Any registry domains that were overridden on package create when pulling images"`
DifferentialMissing []string `json:"differentialMissing,omitempty" jsonschema:"description=List of components that were not included in this package due to differential packaging"`
OCIImportedComponents map[string]string `json:"OCIImportedComponents,omitempty" jsonschema:"description=Map of components that were imported via OCI. The keys are OCI Package URLs and values are the component names"`
LastNonBreakingVersion string `json:"lastNonBreakingVersion,omitempty" jsonschema:"description=The minimum version of Zarf that does not have breaking package structure changes"`
}

Expand Down
1 change: 0 additions & 1 deletion src/types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,4 @@ type DifferentialData struct {
DifferentialPackageVersion string
DifferentialImages map[string]bool
DifferentialRepos map[string]bool
DifferentialOCIComponents map[string]string
}

0 comments on commit 620feb8

Please sign in to comment.