fix(version): add specific version for updater image [BE-11153] (#12227)

pull/12251/head
Oscar Zhou 2024-09-21 14:54:08 +12:00 committed by GitHub
parent cee997e0b3
commit d3d3d50569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 2 deletions

View File

@ -234,7 +234,7 @@ func getEndpointCheckinInterval(endpoint *portainer.Endpoint, settings *portaine
{endpoint.Edge.SnapshotInterval, settings.Edge.SnapshotInterval},
}
for i := range len(intervals) {
for i := range intervals {
effectiveInterval := intervals[i][0]
if effectiveInterval <= 0 {
effectiveInterval = intervals[i][1]

View File

@ -36,10 +36,12 @@ func (service *service) upgradeDocker(environment *portainer.Endpoint, licenseKe
return err
}
updaterImage := getUpdaterImage()
composeFile, err := mustache.RenderFile(templateName, map[string]string{
"image": image,
"skip_pull_image": skipPullImageEnv,
"updater_image": os.Getenv(updaterImageEnvVar),
"updater_image": updaterImage,
"license": licenseKey,
"envType": envType,
})
@ -115,3 +117,11 @@ func (service *service) checkImageForDocker(ctx context.Context, environment *po
return nil
}
}
func getUpdaterImage() string {
updaterImage := os.Getenv(updaterImageEnvVar)
if updaterImage == "" {
updaterImage = "portainer/portainer-updater:" + portainer.APIVersion
}
return updaterImage
}

View File

@ -0,0 +1,29 @@
package upgrade
import (
"os"
"testing"
portainer "github.com/portainer/portainer/api"
)
func TestGetUpdaterImage(t *testing.T) {
t.Run("updater image Environment Variable is set", func(t *testing.T) {
os.Setenv(updaterImageEnvVar, "portainer/portainer-updater:pr111")
expect := "portainer/portainer-updater:pr111"
updaterImage := getUpdaterImage()
if updaterImage != expect {
t.Fatalf("expected %v, got %v", expect, updaterImage)
}
})
t.Run("updater image Environment Variable not set", func(t *testing.T) {
os.Unsetenv(updaterImageEnvVar)
expect := "portainer/portainer-updater:" + portainer.APIVersion
updaterImage := getUpdaterImage()
if updaterImage != expect {
t.Fatalf("expected %v, got %v", expect, updaterImage)
}
})
}