Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit bc2a23d

Browse files
authored
Prevent implicit Docker Hub resolution when auto-upgrade is turned on (#1845)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent 7de6a4f commit bc2a23d

File tree

23 files changed

+137
-53
lines changed

23 files changed

+137
-53
lines changed

integration/build/build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestBuildNestedAcornWithLocalImage(t *testing.T) {
241241
}
242242

243243
// build the Nginx image
244-
source := imagesource.NewImageSource("./testdata/nested/nginx.Acornfile", []string{}, []string{}, []string{})
244+
source := imagesource.NewImageSource("./testdata/nested/nginx.Acornfile", []string{}, []string{}, []string{}, false)
245245
image, _, err := source.GetImageAndDeployArgs(helper.GetCTX(t), c)
246246
if err != nil {
247247
t.Fatal(err)

integration/dev/dev_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDev(t *testing.T) {
6060
eg := errgroup.Group{}
6161
eg.Go(func() error {
6262
return dev.Dev(subCtx, helper.BuilderClient(t, ns.Name), &dev.Options{
63-
ImageSource: imagesource.NewImageSource(acornCueFile, []string{tmp}, nil, nil),
63+
ImageSource: imagesource.NewImageSource(acornCueFile, []string{tmp}, nil, nil, false),
6464
Run: client.AppRunOptions{
6565
Name: "test-app",
6666
},

integration/run/run_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/acorn-io/runtime/pkg/appdefinition"
2020
"github.com/acorn-io/runtime/pkg/client"
2121
"github.com/acorn-io/runtime/pkg/config"
22+
"github.com/acorn-io/runtime/pkg/imagesource"
2223
kclient "github.com/acorn-io/runtime/pkg/k8sclient"
2324
"github.com/acorn-io/runtime/pkg/labels"
2425
"github.com/acorn-io/runtime/pkg/run"
@@ -1698,3 +1699,55 @@ func TestAutoUpgradeImageValidation(t *testing.T) {
16981699
}
16991700
assert.ErrorContains(t, err, "could not find local image for myimage:latest - if you are trying to use a remote image, specify the full registry")
17001701
}
1702+
1703+
func TestAutoUpgradeLocalImage(t *testing.T) {
1704+
ctx := helper.GetCTX(t)
1705+
1706+
helper.StartController(t)
1707+
restConfig, err := restconfig.New(scheme.Scheme)
1708+
if err != nil {
1709+
t.Fatal("error while getting rest config:", err)
1710+
}
1711+
kclient := helper.MustReturn(kclient.Default)
1712+
project := helper.TempProject(t, kclient)
1713+
1714+
c, err := client.New(restConfig, project.Name, project.Name)
1715+
if err != nil {
1716+
t.Fatal(err)
1717+
}
1718+
1719+
// Attempt to run an auto-upgrade app with a non-existent local image. Should get an error.
1720+
_, err = c.AppRun(ctx, "mylocalimage", &client.AppRunOptions{
1721+
AutoUpgrade: &[]bool{true}[0],
1722+
})
1723+
if err == nil {
1724+
t.Fatalf("expected to get a not found error, instead got %v", err)
1725+
}
1726+
assert.ErrorContains(t, err, "could not find local image for mylocalimage - if you are trying to use a remote image, specify the full registry")
1727+
1728+
// Next, build the local image
1729+
image, err := c.AcornImageBuild(ctx, "./testdata/named/Acornfile", &client.AcornImageBuildOptions{})
1730+
if err != nil {
1731+
t.Fatal(err)
1732+
}
1733+
1734+
// Tag the image
1735+
err = c.ImageTag(ctx, image.ID, "mylocalimage")
1736+
if err != nil {
1737+
t.Fatal(err)
1738+
}
1739+
1740+
// Deploy the app
1741+
imageSource := imagesource.NewImageSource("", []string{"mylocalimage"}, []string{}, nil, true)
1742+
appImage, _, err := imageSource.GetImageAndDeployArgs(ctx, c)
1743+
if err != nil {
1744+
t.Fatal(err)
1745+
}
1746+
1747+
_, err = c.AppRun(ctx, appImage, &client.AppRunOptions{
1748+
AutoUpgrade: &[]bool{true}[0],
1749+
})
1750+
if err != nil {
1751+
t.Fatal(err)
1752+
}
1753+
}

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ type ImageDetails struct {
208208
DeployArgs v1.GenericMap `json:"deployArgs,omitempty"`
209209
Profiles []string `json:"profiles,omitempty"`
210210
Auth *RegistryAuth `json:"auth,omitempty"`
211+
// NoDefaultRegistry - if true, do not assume a default registry on the image if none is specified
212+
NoDefaultRegistry bool `json:"noDefaultRegistry,omitempty"`
211213

212214
// Output Params
213215
AppImage v1.AppImage `json:"appImage,omitempty"`

pkg/apis/internal.acorn.io/v1/appinstance.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,20 @@ func (a AppInstanceStatus) GetDevMode() bool {
172172
}
173173

174174
type AppInstanceStatus struct {
175-
DevSession *DevSessionInstanceSpec `json:"devSession,omitempty"`
176-
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
177-
ObservedImageDigest string `json:"observedImageDigest,omitempty"`
178-
Columns AppColumns `json:"columns,omitempty"`
179-
Ready bool `json:"ready,omitempty"`
180-
Namespace string `json:"namespace,omitempty"`
181-
AppImage AppImage `json:"appImage,omitempty"`
182-
AvailableAppImage string `json:"availableAppImage,omitempty"`
183-
AvailableAppImageRemote bool `json:"availableAppImageRemote,omitempty"`
184-
ConfirmUpgradeAppImage string `json:"confirmUpgradeAppImage,omitempty"`
185-
ConfirmUpgradeAppImageRemote bool `json:"confirmUpgradeAppImageRemote,omitempty"`
186-
AppSpec AppSpec `json:"appSpec,omitempty"`
187-
AppStatus AppStatus `json:"appStatus,omitempty"`
188-
Scheduling map[string]Scheduling `json:"scheduling,omitempty"`
189-
Conditions []Condition `json:"conditions,omitempty"`
190-
Defaults Defaults `json:"defaults,omitempty"`
175+
DevSession *DevSessionInstanceSpec `json:"devSession,omitempty"`
176+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
177+
ObservedImageDigest string `json:"observedImageDigest,omitempty"`
178+
Columns AppColumns `json:"columns,omitempty"`
179+
Ready bool `json:"ready,omitempty"`
180+
Namespace string `json:"namespace,omitempty"`
181+
AppImage AppImage `json:"appImage,omitempty"`
182+
AvailableAppImage string `json:"availableAppImage,omitempty"`
183+
ConfirmUpgradeAppImage string `json:"confirmUpgradeAppImage,omitempty"`
184+
AppSpec AppSpec `json:"appSpec,omitempty"`
185+
AppStatus AppStatus `json:"appStatus,omitempty"`
186+
Scheduling map[string]Scheduling `json:"scheduling,omitempty"`
187+
Conditions []Condition `json:"conditions,omitempty"`
188+
Defaults Defaults `json:"defaults,omitempty"`
191189
}
192190

193191
type Defaults struct {

pkg/autoupgrade/daemon.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ func (d *daemon) refreshImages(ctx context.Context, apps map[kclient.ObjectKey]v
209209
// This satisfies the usecase of autoUpgrade with an app's tag is something static, like "latest"
210210
// However, if the tag is a pattern and the current image has no tag, we don't want to check for a digest because this would
211211
// result in a digest upgrade even though no tag matched.
212-
var remote bool
213212
if !updated && (!isPattern || current.Identifier() != "") {
214213
nextAppImage = imageKey.image
215214
var pullErr error
@@ -222,8 +221,6 @@ func (d *daemon) refreshImages(ctx context.Context, apps map[kclient.ObjectKey]v
222221
if localDigest, ok, _ := d.client.resolveLocalTag(ctx, app.Namespace, imageKey.image); ok && localDigest != "" {
223222
digest = localDigest
224223
}
225-
} else {
226-
remote = true
227224
}
228225

229226
if digest == "" && pullErr != nil {
@@ -252,18 +249,14 @@ func (d *daemon) refreshImages(ctx context.Context, apps map[kclient.ObjectKey]v
252249
continue
253250
}
254251
app.Status.AvailableAppImage = nextAppImage
255-
app.Status.AvailableAppImageRemote = remote
256252
app.Status.ConfirmUpgradeAppImage = ""
257-
app.Status.ConfirmUpgradeAppImageRemote = false
258253
case "notify":
259254
if app.Status.ConfirmUpgradeAppImage == nextAppImage {
260255
d.appKeysPrevCheck[appKey] = updateTime
261256
continue
262257
}
263258
app.Status.ConfirmUpgradeAppImage = nextAppImage
264-
app.Status.ConfirmUpgradeAppImageRemote = remote
265259
app.Status.AvailableAppImage = ""
266-
app.Status.AvailableAppImageRemote = false
267260
default:
268261
logrus.Warnf("Unrecognized auto-upgrade mode %v for %v", mode, app.Name)
269262
continue

pkg/cli/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (s *Build) Run(cmd *cobra.Command, args []string) error {
4444
return err
4545
}
4646

47-
helper := imagesource.NewImageSource(s.File, args, s.Profile, s.Platform)
47+
helper := imagesource.NewImageSource(s.File, args, s.Profile, s.Platform, false)
4848
image, _, err := helper.GetImageAndDeployArgs(cmd.Context(), c)
4949
if err != nil {
5050
return err

pkg/cli/dev.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *Dev) Run(cmd *cobra.Command, args []string) error {
5757
return err
5858
}
5959

60-
imageSource := imagesource.NewImageSource(s.File, args, s.Profile, nil)
60+
imageSource := imagesource.NewImageSource(s.File, args, s.Profile, nil, s.AutoUpgrade != nil && *s.AutoUpgrade)
6161

6262
opts, err := s.ToOpts()
6363
if err != nil {

pkg/cli/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (s *Render) Run(cmd *cobra.Command, args []string) error {
3232
return err
3333
}
3434

35-
imageAndArgs := imagesource.NewImageSource(s.File, args, s.Profile, nil)
35+
imageAndArgs := imagesource.NewImageSource(s.File, args, s.Profile, nil, false)
3636

3737
appDef, _, err := imageAndArgs.GetAppDefinition(cmd.Context(), c)
3838
if err != nil {

pkg/cli/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (s *Run) Run(cmd *cobra.Command, args []string) (err error) {
229229
}
230230

231231
var (
232-
imageSource = imagesource.NewImageSource(s.File, args, s.Profile, nil)
232+
imageSource = imagesource.NewImageSource(s.File, args, s.Profile, nil, s.AutoUpgrade != nil && *s.AutoUpgrade)
233233
app *apiv1.App
234234
updated bool
235235
)

0 commit comments

Comments
 (0)