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

chore: rename concerning commit in relevant commit #96

Merged
merged 1 commit into from
Mar 20, 2023
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
2 changes: 1 addition & 1 deletion docs/contents/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The status of a `TerraformLayer` is defined using the [conditions standards defi

- `IsPlanArtifactUpToDate`. This condition is used for drift detection. The evaluation is made by compraing the timestamp of the last `terraform plan` which ran and the current date. The timestamp of the last plan is "stored" using an annotation.
- `IsApplyUpToDate`. This condition is used to check if an `apply` needs to run after the last `plan`. Comparison is made by comparing a checksum of the last planned binary and a checksum last applied binary stored in the annotations.
- `IsLastConcerningCommitPlanned`. This condition is used to check if a new commit has been made to the layer and need to be applied. It is evaluated by comparing the commit used for the last `plan`, the last commit which intoduced changes to the layer and the last commit made to the same branch of the repository. Those commits are "stored" as annotations.
- `IsLastRelevantCommitPlanned`. This condition is used to check if a new commit has been made to the layer and need to be applied. It is evaluated by comparing the commit used for the last `plan`, the last commit which intoduced changes to the layer and the last commit made to the same branch of the repository. Those commits are "stored" as annotations.

> N.B. We use annotations to store information because we do not want to rely too heavily on the uptime of the redis instance.

Expand Down
4 changes: 2 additions & 2 deletions internal/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const (
Failure string = "runner.terraform.padok.cloud/failure"
Lock string = "runner.terraform.padok.cloud/lock"

LastBranchCommit string = "webhook.terraform.padok.cloud/branch-commit"
LastConcerningCommit string = "webhook.terraform.padok.cloud/concerning-commit"
LastBranchCommit string = "webhook.terraform.padok.cloud/branch-commit"
LastRelevantCommit string = "webhook.terraform.padok.cloud/relevant-commit"

ForceApply string = "notifications.terraform.padok.cloud/force-apply"
)
Expand Down
18 changes: 9 additions & 9 deletions internal/controllers/terraformlayer/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func (r *Reconciler) IsPlanArtifactUpToDate(t *configv1alpha1.TerraformLayer) (m
return condition, false
}

func (r *Reconciler) IsLastConcernginCommitPlanned(t *configv1alpha1.TerraformLayer) (metav1.Condition, bool) {
func (r *Reconciler) IsLastRelevantCommitPlanned(t *configv1alpha1.TerraformLayer) (metav1.Condition, bool) {
condition := metav1.Condition{
Type: "IsLastConcerningCommitPlanned",
Type: "IsLastRelevantCommitPlanned",
ObservedGeneration: t.GetObjectMeta().GetGeneration(),
Status: metav1.ConditionUnknown,
LastTransitionTime: metav1.NewTime(time.Now()),
Expand All @@ -65,27 +65,27 @@ func (r *Reconciler) IsLastConcernginCommitPlanned(t *configv1alpha1.TerraformLa
condition.Status = metav1.ConditionTrue
return condition, true
}
lastConcerningCommit, ok := t.Annotations[annotations.LastConcerningCommit]
lastRelevantCommit, ok := t.Annotations[annotations.LastRelevantCommit]
if !ok {
condition.Reason = "NoCommitReceived"
condition.Message = "No commit has been received from webhook"
condition.Status = metav1.ConditionTrue
return condition, true
}
if lastBranchCommit != lastConcerningCommit {
if lastBranchCommit != lastRelevantCommit {
condition.Reason = "CommitAlreadyHadnled"
condition.Message = "The last concerning commit should already have been planned"
condition.Message = "The last relevant commit should already have been planned"
condition.Status = metav1.ConditionTrue
return condition, true
}
if lastPlannedCommit == lastBranchCommit {
condition.Reason = "LastConcerningCommitPlanned"
condition.Message = "The last concerngin commit has already been planned"
condition.Reason = "LastRelevantCommitPlanned"
condition.Message = "The last relevant commit has already been planned"
condition.Status = metav1.ConditionTrue
return condition, true
}
condition.Reason = "LastConcerningCommitNotPlanned"
condition.Message = "The last received concerning commit has not been planned yet"
condition.Reason = "LastRelevantCommitNotPlanned"
condition.Message = "The last received relevant commit has not been planned yet"
condition.Status = metav1.ConditionFalse
return condition, false
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/terraformlayer/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func (r *Reconciler) GetState(ctx context.Context, layer *configv1alpha1.Terrafo
log := log.WithContext(ctx)
c1, isPlanArtifactUpToDate := r.IsPlanArtifactUpToDate(layer)
c2, isApplyUpToDate := r.IsApplyUpToDate(layer)
c3, isLastConcerningCommitPlanned := r.IsLastConcernginCommitPlanned(layer)
c3, isLastRelevantCommitPlanned := r.IsLastRelevantCommitPlanned(layer)
// c3, hasFailed := HasFailed(r)
conditions := []metav1.Condition{c1, c2, c3}
switch {
case isPlanArtifactUpToDate && isApplyUpToDate:
log.Infof("layer %s is up to date, waiting for a new drift detection cycle", layer.Name)
return &Idle{}, conditions
case !isPlanArtifactUpToDate || !isLastConcerningCommitPlanned:
case !isPlanArtifactUpToDate || !isLastRelevantCommitPlanned:
log.Infof("layer %s needs to be planned, acquiring lock and creating a new runner", layer.Name)
return &PlanNeeded{}, conditions
case isPlanArtifactUpToDate && !isApplyUpToDate:
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (w *Webhook) Handle(payload interface{}) {
}
ann[annotations.LastBranchCommit] = change.shaAfter
if layerFilesHaveChanged(&layer, changedFiles) {
ann[annotations.LastConcerningCommit] = change.shaAfter
ann[annotations.LastRelevantCommit] = change.shaAfter
}
err = annotations.Add(context.TODO(), w.Client, layer, ann)
if err != nil {
Expand Down