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

allow deployments to upgrade to hotfix container images #1207

Merged
merged 1 commit into from
Jul 18, 2022
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
30 changes: 0 additions & 30 deletions pkg/apis/minio.min.io/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,6 @@ func (t *Tenant) KESReplicas() int32 {
return replicas
}

const (
minioReleaseTagTimeLayout = "2006-01-02T15-04-05Z"
releasePrefix = "RELEASE"
)

// ReleaseTagToReleaseTime - converts a 'RELEASE.2017-09-29T19-16-56Z.hotfix' into the build time
func ReleaseTagToReleaseTime(releaseTag string) (releaseTime time.Time, err error) {
fields := strings.Split(releaseTag, ".")
if len(fields) < 2 || len(fields) > 3 {
return releaseTime, fmt.Errorf("%s is not a valid release tag", releaseTag)
}
if fields[0] != releasePrefix {
return releaseTime, fmt.Errorf("%s is not a valid release tag", releaseTag)
}
return time.Parse(minioReleaseTagTimeLayout, fields[1])
}

// ExtractTar extracts all tar files from the list `filesToExtract` and puts the files in the `basePath` location
func ExtractTar(filesToExtract []string, basePath, tarFileName string) error {
tarFile, err := os.Open(basePath + tarFileName)
Expand Down Expand Up @@ -426,19 +409,6 @@ func (t *Tenant) HasKESEnabled() bool {
return t.Spec.KES != nil
}

// UpdateURL returns the URL for the sha256sum location of the new binary
func (t *Tenant) UpdateURL(lrTime time.Time, overrideURL string) (string, error) {
if overrideURL == "" {
overrideURL = miniov2.DefaultMinIOUpdateURL
}
u, err := url.Parse(overrideURL)
if err != nil {
return "", err
}
u.Path = u.Path + "/minio." + releasePrefix + "." + lrTime.Format(minioReleaseTagTimeLayout) + ".sha256sum"
return u.String(), nil
}

// MinIOServerHostAddress similar to MinIOServerHost but returns host with port
func (t *Tenant) MinIOServerHostAddress() string {
var port int
Expand Down
25 changes: 11 additions & 14 deletions pkg/apis/minio.min.io/v2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,23 @@ func (t *Tenant) KESReplicas() int32 {
const (
minioReleaseTagTimeLayout = "2006-01-02T15-04-05Z"
minioReleaseTagTimeLayoutBackup = "2006-01-02T15:04:05Z"
releasePrefix = "RELEASE"
)

// ReleaseTagToReleaseTime - converts a 'RELEASE.2017-09-29T19-16-56Z.hotfix' into the build time
func ReleaseTagToReleaseTime(releaseTag string) (releaseTime time.Time, err error) {
fields := strings.Split(releaseTag, ".")
if len(fields) == 1 {
releaseTime, err = time.Parse(minioReleaseTagTimeLayout, fields[0])
if err != nil {
return time.Parse(minioReleaseTagTimeLayoutBackup, fields[0])
}
return releaseTime, nil
if len(fields) < 1 {
return releaseTime, fmt.Errorf("%s not a valid release tag", releaseTag)
}
if len(fields) < 2 || len(fields) > 3 {
return releaseTime, fmt.Errorf("%s is not a valid release tag", releaseTag)
releaseTimeStr := fields[0]
if len(fields) > 1 {
releaseTimeStr = fields[1]
}
if fields[0] != releasePrefix {
return releaseTime, fmt.Errorf("%s is not a valid release tag", releaseTag)
releaseTime, err = time.Parse(minioReleaseTagTimeLayout, releaseTimeStr)
if err != nil {
return time.Parse(minioReleaseTagTimeLayoutBackup, releaseTimeStr)
}
return time.Parse(minioReleaseTagTimeLayout, fields[1])
return releaseTime, nil
}

// ExtractTar extracts all tar files from the list `filesToExtract` and puts the files in the `basePath` location
Expand Down Expand Up @@ -597,15 +594,15 @@ func (t *Tenant) GetKESEnvVars() (env []corev1.EnvVar) {
}

// UpdateURL returns the URL for the sha256sum location of the new binary
func (t *Tenant) UpdateURL(lrTime time.Time, overrideURL string) (string, error) {
func (t *Tenant) UpdateURL(ltag string, overrideURL string) (string, error) {
if overrideURL == "" {
overrideURL = DefaultMinIOUpdateURL
}
u, err := url.Parse(overrideURL)
if err != nil {
return "", err
}
u.Path = u.Path + "/minio." + releasePrefix + "." + lrTime.Format(minioReleaseTagTimeLayout) + ".sha256sum"
u.Path = u.Path + "/minio." + ltag + ".sha256sum"
return u.String(), nil
}

Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/cluster/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/docker/cli/cli/config/configfile"

Expand Down Expand Up @@ -93,7 +93,7 @@ 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 time.Time, err error) {
func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest string, err error) {
basePath := updatePath

if err = os.MkdirAll(basePath, 1777); err != nil {
Expand Down Expand Up @@ -196,8 +196,7 @@ func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest time.Time, e
srcShaSum := "minio.sha256sum"
srcSig := "minio.minisig"

latest, err = miniov2.ReleaseTagToReleaseTime(tag)
if err != nil {
if _, err = miniov2.ReleaseTagToReleaseTime(tag); err != nil {
return latest, err
}

Expand All @@ -209,11 +208,11 @@ func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest time.Time, e
// rename all files to add tag specific values in the name.
// this is because minio updater looks for files in this name format.
for s, d := range filesToRename {
if err = os.Rename(basePath+s, basePath+d); err != nil {
return latest, err
if err = os.Rename(filepath.Join(basePath, s), filepath.Join(basePath, d)); err != nil {
return tag, err
}
}
return latest, nil
return tag, nil
}

// Remove all the files created during upload process
Expand Down