Skip to content

OTA-1531: [2/x] cvo: refactor LoadUpdate #1185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions pkg/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,22 @@ type metadata struct {

func LoadUpdate(dir, releaseImage, excludeIdentifier string, requiredFeatureSet string, profile string,
knownCapabilities []configv1.ClusterVersionCapability) (*Update, error) {
klog.V(2).Infof("Loading updatepayload from %q", dir)
if err := ValidateDirectory(dir); err != nil {
return nil, err
}
var (
cvoDir = filepath.Join(dir, CVOManifestDir)
releaseDir = filepath.Join(dir, ReleaseManifestDir)
)
Comment on lines +143 to +150
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved here from loadUpdatePayloadMetadata


payload, tasks, err := loadUpdatePayloadMetadata(dir, releaseImage, profile)
payload, err := loadPayloadMetadata(releaseDir, releaseImage)
if err != nil {
return nil, err
}

tasks := loadPayloadTasks(releaseDir, cvoDir, releaseImage, profile)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved here from loadUpdatePayloadMetadata


var onlyKnownCaps *configv1.ClusterVersionCapabilitiesStatus

if knownCapabilities != nil {
Expand Down Expand Up @@ -293,47 +303,36 @@ func ValidateDirectory(dir string) error {
return nil
}

type payloadTasks struct {
idir string
preprocess func([]byte) ([]byte, error)
skipFiles sets.Set[string]
}

func loadUpdatePayloadMetadata(dir, releaseImage, clusterProfile string) (*Update, []payloadTasks, error) {
klog.V(2).Infof("Loading updatepayload from %q", dir)
if err := ValidateDirectory(dir); err != nil {
return nil, nil, err
}
var (
cvoDir = filepath.Join(dir, CVOManifestDir)
releaseDir = filepath.Join(dir, ReleaseManifestDir)
)

func loadPayloadMetadata(releaseDir, releaseImage string) (*Update, error) {
release, arch, err := loadReleaseFromMetadata(releaseDir)
if err != nil {
return nil, nil, err
return nil, err
}
release.Image = releaseImage

imageRef, err := loadImageReferences(releaseDir)
if err != nil {
return nil, nil, err
return nil, err
}

if imageRef.Name != release.Version {
return nil, nil, fmt.Errorf("Version from %s (%s) differs from %s (%s)", imageReferencesFile, imageRef.Name, cincinnatiJSONFile, release.Version)
return nil, fmt.Errorf("Version from %s (%s) differs from %s (%s)", imageReferencesFile, imageRef.Name, cincinnatiJSONFile, release.Version)
}

tasks := getPayloadTasks(releaseDir, cvoDir, releaseImage, clusterProfile)

return &Update{
Release: release,
ImageRef: imageRef,
Architecture: arch,
}, tasks, nil
}, nil
}

type payloadTasks struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: Without moving this struct (feels like the code did not change) it would be easier to comparing the change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just wanted this struct closer to loadPayloadTasks that creates this data

idir string
preprocess func([]byte) ([]byte, error)
skipFiles sets.Set[string]
}

func getPayloadTasks(releaseDir, cvoDir, releaseImage, clusterProfile string) []payloadTasks {
func loadPayloadTasks(releaseDir, cvoDir, releaseImage, clusterProfile string) []payloadTasks {
cjf := filepath.Join(releaseDir, cincinnatiJSONFile)
irf := filepath.Join(releaseDir, imageReferencesFile)

Expand Down