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

Adds a new update strategy: manual #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ImageUpdaterConfig struct {
GitCommitMail string
GitCommitMessage *template.Template
DisableKubeEvents bool
ManualTagValue string
}

// newRootCommand implements the root command of argocd-image-updater
Expand Down
4 changes: 3 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newRunCommand() *cobra.Command {
var warmUpCache bool = true
var commitMessagePath string
var commitMessageTpl string

var runCmd = &cobra.Command{
Use: "run",
Short: "Runs the argocd-image-updater with a set of options",
Expand Down Expand Up @@ -223,7 +224,7 @@ func newRunCommand() *cobra.Command {
runCmd.Flags().StringVar(&cfg.GitCommitMail, "git-commit-email", env.GetStringVal("GIT_COMMIT_EMAIL", "[email protected]"), "E-Mail address to use for Git commits")
runCmd.Flags().StringVar(&commitMessagePath, "git-commit-message-path", defaultCommitTemplatePath, "Path to a template to use for Git commit messages")
runCmd.Flags().BoolVar(&cfg.DisableKubeEvents, "disable-kube-events", env.GetBoolVal("IMAGE_UPDATER_KUBE_EVENTS", false), "Disable kubernetes events")

runCmd.Flags().StringVar(&cfg.ManualTagValue, "manual-tag-value", "", "Defines the image tag that will be used to update the app")
return runCmd
}

Expand Down Expand Up @@ -309,6 +310,7 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR
GitCommitEmail: cfg.GitCommitMail,
GitCommitMessage: cfg.GitCommitMessage,
DisableKubeEvents: cfg.DisableKubeEvents,
ManualTagValue: cfg.ManualTagValue,
}
res := argocd.UpdateApplication(upconf, syncState)
result.NumApplicationsProcessed += 1
Expand Down
26 changes: 20 additions & 6 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type UpdateConfiguration struct {
GitCommitMessage *template.Template
DisableKubeEvents bool
IgnorePlatforms bool
ManualTagValue string
}

type GitCredsSource func(app *v1alpha1.Application) (git.Creds, error)
Expand Down Expand Up @@ -196,6 +197,12 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
}

vc.Strategy = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations)
// If strategy is manual but no tag has been set, default to SemVer
if vc.Strategy == image.StrategyManual && updateConf.ManualTagValue == "" {
imgCtx.Infof("strategy is set to %s but it requires a tag defined via --manual-tag-value. Defaulting to %s strategy instead.", vc.Strategy.String(), image.StrategySemVer.String())
vc.Strategy = image.StrategySemVer
}

vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations)
vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations)
vc.Options = applicationImage.
Expand Down Expand Up @@ -234,13 +241,20 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
result.NumErrors += 1
continue
}
var tags *tag.ImageTagList = tag.NewImageTagList()

// Get list of available image tags from the repository
tags, err := rep.GetTags(applicationImage, regClient, &vc)
if err != nil {
imgCtx.Errorf("Could not get tags from registry: %v", err)
result.NumErrors += 1
continue
if vc.Strategy != image.StrategyManual {
// Get list of available image tags from the repository
tags, err = rep.GetTags(applicationImage, regClient, &vc)
if err != nil {
imgCtx.Errorf("Could not get tags from registry: %v", err)
result.NumErrors += 1
continue
}
} else {
manualTag := tag.NewImageTag(updateConf.ManualTagValue, time.Unix(0, 0), "")

tags.Add(manualTag)
}

imgCtx.Tracef("List of available tags found: %v", tags.Tags())
Expand Down
2 changes: 2 additions & 0 deletions pkg/image/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy {
return StrategyAlphabetical
case "digest":
return StrategyDigest
case "manual":
return StrategyManual
default:
logCtx.Warnf("Unknown sort option %s -- using semver", val)
return StrategySemVer
Expand Down
6 changes: 6 additions & 0 deletions pkg/image/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
StrategyAlphabetical UpdateStrategy = 2
// VersionSortDigest uses latest digest of an image
StrategyDigest UpdateStrategy = 3
// VersionManual uses a user provided tag for an image
StrategyManual UpdateStrategy = 4
)

func (us UpdateStrategy) String() string {
Expand All @@ -34,6 +36,8 @@ func (us UpdateStrategy) String() string {
return "alphabetical"
case StrategyDigest:
return "digest"
case StrategyManual:
return "manual"
}

return "unknown"
Expand Down Expand Up @@ -93,6 +97,8 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
availableTags = tagList.SortByDate()
case StrategyDigest:
availableTags = tagList.SortAlphabetically()
case StrategyManual:
availableTags = tagList.SortAlphabetically()
}

considerTags := tag.SortableImageTagList{}
Expand Down