Skip to content
Merged
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
23 changes: 18 additions & 5 deletions update/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"k8s.io/utils/ptr"
)

// ReleaseTrigger is used to request a new release for the application.
const ReleaseTrigger = "RELEASE_TRIGGER"

// BuildTrigger is used to request a retry-build for the application.
const BuildTrigger = "BUILD_TRIGGER"

Expand All @@ -40,7 +43,8 @@ type applicationCmd struct {
ScheduledJob *scheduledJob `embed:"" prefix:"scheduled-job-"`
DeleteWorkerJob *string `help:"Delete a worker job by name"`
DeleteScheduledJob *string `help:"Delete a scheduled job by name"`
RetryBuild *bool `help:"Retries build for the application if set to true." placeholder:"false"`
RetryRelease *bool `help:"Retries release for the application." placeholder:"false"`
RetryBuild *bool `help:"Retries build for the application." placeholder:"false"`
GitInformationServiceURL string `help:"URL of the git information service." default:"https://git-info.deplo.io" env:"GIT_INFORMATION_SERVICE_URL" hidden:""`
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
Debug bool `help:"Enable debug messages" default:"false"`
Expand Down Expand Up @@ -244,21 +248,26 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) {
app.Spec.ForProvider.Language = apps.Language(*cmd.Language)
}

runtimeEnv := make(map[string]string)
if cmd.Env != nil {
runtimeEnv = cmd.Env
}
if cmd.RetryRelease != nil && *cmd.RetryRelease {
runtimeEnv[ReleaseTrigger] = triggerTimestamp()
}
var delEnv []string
if cmd.DeleteEnv != nil {
delEnv = *cmd.DeleteEnv
}
app.Spec.ForProvider.Config.Env = util.UpdateEnvVars(app.Spec.ForProvider.Config.Env, cmd.Env, delEnv)
app.Spec.ForProvider.Config.Env = util.UpdateEnvVars(app.Spec.ForProvider.Config.Env, runtimeEnv, delEnv)

buildEnv := make(map[string]string)
if cmd.BuildEnv != nil {
buildEnv = cmd.BuildEnv
}

if cmd.RetryBuild != nil && *cmd.RetryBuild {
buildEnv[BuildTrigger] = time.Now().UTC().Format(time.RFC3339)
buildEnv[BuildTrigger] = triggerTimestamp()
}

var buildDelEnv []string
if cmd.DeleteBuildEnv != nil {
buildDelEnv = *cmd.DeleteBuildEnv
Expand All @@ -276,6 +285,10 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) {
}
}

func triggerTimestamp() string {
return time.Now().UTC().Format(time.RFC3339)
}

func (job deployJob) applyUpdates(cfg *apps.Config) {
if job.Enabled != nil && !*job.Enabled {
// if enabled is explicitly set to false we set the DeployJob field to
Expand Down
27 changes: 26 additions & 1 deletion update/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func TestApplication(t *testing.T) {
assert.Equal(t, *cmd.DeployJob.Name, updated.Spec.ForProvider.Config.DeployJob.Name)
assert.Equal(t, *cmd.DeployJob.Timeout, updated.Spec.ForProvider.Config.DeployJob.Timeout.Duration)
assert.Equal(t, *cmd.DeployJob.Retries, *updated.Spec.ForProvider.Config.DeployJob.Retries)
// RetryBuild should be not set by default:
// Retry Release/Build should be not set by default:
assert.Nil(t, util.EnvVarByName(updated.Spec.ForProvider.Config.Env, ReleaseTrigger))
assert.Nil(t, util.EnvVarByName(updated.Spec.ForProvider.BuildEnv, BuildTrigger))
},
},
Expand Down Expand Up @@ -359,6 +360,30 @@ func TestApplication(t *testing.T) {
assert.Nil(t, updated.Spec.ForProvider.Config.DeployJob)
},
},
"retry release": {
orig: existingApp,
cmd: applicationCmd{
resourceCmd: resourceCmd{
Name: existingApp.Name,
},
RetryRelease: ptr.To(true),
},
checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) {
assert.NotNil(t, util.EnvVarByName(updated.Spec.ForProvider.Config.Env, ReleaseTrigger))
},
},
"do not retry release": {
orig: existingApp,
cmd: applicationCmd{
resourceCmd: resourceCmd{
Name: existingApp.Name,
},
RetryRelease: ptr.To(false),
},
checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) {
assert.Nil(t, util.EnvVarByName(updated.Spec.ForProvider.Config.Env, ReleaseTrigger))
},
},
"retry build": {
orig: existingApp,
cmd: applicationCmd{
Expand Down
Loading