Skip to content

Commit

Permalink
allow deployments to upgrade to hotfix container images (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Jul 18, 2022
1 parent aae0926 commit 54601b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 51 deletions.
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

0 comments on commit 54601b8

Please sign in to comment.