Skip to content
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

add protection and facilitate debugging wrong assets #2179

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions pkg/controller/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func (c *Controller) getKeychainForTenant(ctx context.Context, ref name.Referenc
// Attempts to fetch given image and then extracts and keeps relevant files
// (minio, minio.sha256sum & minio.minisig) at a pre-defined location (/tmp/webhook/v1/update)
func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest string, err error) {
c.removeArtifacts() // remove before a fresh fetch.

basePath := updatePath

if err = os.MkdirAll(basePath, 1777); err != nil {
Expand Down Expand Up @@ -166,13 +168,15 @@ func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest string, err
if err != nil {
return latest, err
}
defer func() {
_ = f.Close()
}()

// Tarball writes a file called image.tar
// This file in turn has each container layer present inside in the form `<layer-hash>.tar.gz`
if err = tarball.Write(ref, img, f); err != nil {
f.Close()
return latest, err
}

if err = f.Close(); err != nil {
return latest, err
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,11 @@ func (c *Controller) syncHandler(key string) (Result, error) {
tenantName, images[0], tenant.Spec.Image)

latest, err := c.fetchArtifacts(tenant)
defer c.removeArtifacts()
if err != nil {
// Do not remove assets with errors, keep them for investigation.
return WrapResult(Result{}, err)
}
defer c.removeArtifacts()
updateURL, err := tenant.UpdateURL(latest, fmt.Sprintf("http://operator.%s.svc.%s:%s%s",
miniov2.GetNSFromFile(),
miniov2.GetClusterDomain(),
Expand Down
Loading