Skip to content

Commit

Permalink
s/verifiedFor/requiredSoakTime
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
krancour committed Jan 10, 2025
1 parent 069e7f1 commit efcd497
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/stage_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func (s *Stage) ListAvailableFreight(
ApprovedFor: s.Name,
VerifiedIn: req.Sources.Stages,
}
if verifiedFor := req.Sources.VerifiedFor; verifiedFor != nil {
listOpts.VerifiedBefore = &metav1.Time{Time: time.Now().Add(-verifiedFor.Duration)}
if requiredSoak := req.Sources.RequiredSoakTime; requiredSoak != nil {
listOpts.VerifiedBefore = &metav1.Time{Time: time.Now().Add(-requiredSoak.Duration)}
}
}
freightFromWarehouse, err := warehouse.ListFreight(ctx, c, listOpts)
Expand Down Expand Up @@ -176,8 +176,8 @@ func (s *Stage) IsFreightAvailable(freight *Freight) bool {
}
for _, source := range req.Sources.Stages {
if freight.IsVerifiedIn(source) {
return req.Sources.VerifiedFor == nil ||
freight.GetLongestSoak(source) >= req.Sources.VerifiedFor.Duration
return req.Sources.RequiredSoakTime == nil ||
freight.GetLongestSoak(source) >= req.Sources.RequiredSoakTime.Duration
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha1/stage_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func TestStage_ListAvailableFreight(t *testing.T) {
{
Origin: testWarehouse2Origin,
Sources: FreightSources{
Stages: []string{testStage},
VerifiedFor: &metav1.Duration{Duration: time.Hour},
Stages: []string{testStage},
RequiredSoakTime: &metav1.Duration{Duration: time.Hour},
},
},
},
Expand Down Expand Up @@ -500,8 +500,8 @@ func TestStage_IsFreightAvailable(t *testing.T) {
RequestedFreight: []FreightRequest{{
Origin: testOrigin,
Sources: FreightSources{
Stages: []string{"upstream-stage"},
VerifiedFor: &metav1.Duration{Duration: time.Hour},
Stages: []string{"upstream-stage"},
RequiredSoakTime: &metav1.Duration{Duration: time.Hour},
},
}},
},
Expand All @@ -525,8 +525,8 @@ func TestStage_IsFreightAvailable(t *testing.T) {
RequestedFreight: []FreightRequest{{
Origin: testOrigin,
Sources: FreightSources{
Stages: []string{"upstream-stage"},
VerifiedFor: &metav1.Duration{Duration: 2 * time.Hour},
Stages: []string{"upstream-stage"},
RequiredSoakTime: &metav1.Duration{Duration: 2 * time.Hour},
},
}},
},
Expand All @@ -552,8 +552,8 @@ func TestStage_IsFreightAvailable(t *testing.T) {
RequestedFreight: []FreightRequest{{
Origin: testOrigin,
Sources: FreightSources{
Stages: []string{"upstream-stage"},
VerifiedFor: &metav1.Duration{Duration: time.Hour},
Stages: []string{"upstream-stage"},
RequiredSoakTime: &metav1.Duration{Duration: time.Hour},
},
}},
},
Expand Down
14 changes: 9 additions & 5 deletions api/v1alpha1/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ type FreightSources struct {
// Direct field must be true. i.e. Between the two fields, at least on source
// must be specified.
Stages []string `json:"stages,omitempty" protobuf:"bytes,2,rep,name=stages"`
// VerifiedFor specifies the duration for which the requested Freight must
// have been verified in the upstream Stages before it can be considered
// for promotion to this Stage. This is an optional field, and if not set,
// the default value is "0s" (i.e. immediate promotion is allowed).
// RequiredSoakTime specifies a minimum duration for which the requested
// Freight must have continuously occupied ("soaked in") in an upstream Stage
// before becoming available for promotion to this Stage. This is an optional
// field. If nil or zero, no soak time is required. Any soak time requirement
// is in ADDITION to the requirement that Freight be verified in an upstream
// Stage to become available for promotion to this Stage, although a manual
// approval for promotion to this Stage will supersede any soak time
// requirement.
//
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(s|m|h))+$"
VerifiedFor *metav1.Duration `json:"verifiedFor,omitempty" protobuf:"bytes,3,opt,name=verifiedFor"`
RequiredSoakTime *metav1.Duration `json:"requiredSoakTime,omitempty" protobuf:"bytes,3,opt,name=requiredSoakTime"`
}

// PromotionTemplate defines a template for a Promotion that can be used to
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/stages/regular_stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4806,8 +4806,8 @@ func TestRegularStageReconciler_autoPromoteFreight(t *testing.T) {
Name: "test-warehouse",
},
Sources: kargoapi.FreightSources{
Stages: []string{"upstream-stage"},
VerifiedFor: &metav1.Duration{Duration: time.Hour},
Stages: []string{"upstream-stage"},
RequiredSoakTime: &metav1.Duration{Duration: time.Hour},
},
},
},
Expand Down

0 comments on commit efcd497

Please sign in to comment.