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

Commit

Permalink
Add ObservedAutoUpgrade status field to replace API Server validation
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <mtslaton1@gmail.com>
  • Loading branch information
tylerslaton committed Jul 13, 2023
1 parent a35ef7d commit 30063c3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type AppInstanceStatus struct {
DevSession *DevSessionInstanceSpec `json:"devSession,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
ObservedImageDigest string `json:"observedImageDigest,omitempty"`
ObservedAutoUpgrade bool `json:"observedAutoUpgrade,omitempty"`
Columns AppColumns `json:"columns,omitempty"`
Ready bool `json:"ready,omitempty"`
Namespace string `json:"namespace,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cli
import (
"io"

"github.com/acorn-io/runtime/pkg/autoupgrade"
cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/dev"
"github.com/acorn-io/runtime/pkg/imagesource"
"github.com/acorn-io/z"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -64,6 +66,11 @@ func (s *Dev) Run(cmd *cobra.Command, args []string) error {
return err
}

// Ensure opts.AutoUpgrade is set if is implied by opts.AutoUpgradeInterval or imageSource.Image's pattern.
if opts.AutoUpgrade == nil || !*opts.AutoUpgrade {
opts.AutoUpgrade = z.P(autoupgrade.ImpliedAutoUpgrade(opts.AutoUpgradeInterval, imageSource.Image))
}

return dev.Dev(cmd.Context(), c, &dev.Options{
ImageSource: imageSource,
Run: opts,
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/appdefinition/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ package appdefinition
import (
"github.com/acorn-io/baaah/pkg/router"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/autoupgrade"
)

func UpdateObservedFields(req router.Request, resp router.Response) error {
app := req.Object.(*v1.AppInstance)
app.Status.ObservedImageDigest = app.Status.AppImage.Digest
app.Status.ObservedGeneration = app.Generation
app.Status.ObservedAutoUpgrade = impliedAutoUpgrade(app.Spec)
return nil
}

func impliedAutoUpgrade(appSpec v1.AppInstanceSpec) bool {
au := appSpec.AutoUpgrade != nil && *appSpec.AutoUpgrade
if !au && autoupgrade.ImpliedAutoUpgrade(appSpec.AutoUpgradeInterval, appSpec.Image) {
au = true
}
return au
}
6 changes: 6 additions & 0 deletions pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions pkg/server/registry/apigroups/acorn/apps/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ func (s *Validator) Validate(ctx context.Context, obj runtime.Object) (result fi
return
}

au := app.Spec.AutoUpgrade
if (au == nil || !*au) && autoupgrade.ImpliedAutoUpgrade(app.Spec.AutoUpgradeInterval, app.Spec.Image) {
result = append(result, field.Invalid(field.NewPath("spec", "autoUpgrade"), app.Spec.AutoUpgrade, "must be true if autoupgrade options are set"))
return
}

var (
imageGrantedPerms []v1.Permissions
checkImage = app.Spec.Image
Expand Down

0 comments on commit 30063c3

Please sign in to comment.