Skip to content

Commit

Permalink
Providing startTime and currentTime to facilitate timeout in case of …
Browse files Browse the repository at this point in the history
…ytt wait rules

Signed-off-by: Rohit Aggarwal <rohit.aggarwal@broadcom.com>
  • Loading branch information
rohitagg2020 committed Sep 26, 2024
1 parent b7ceac1 commit 57419c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/kapp/resourcesmisc/custom_waiting_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
}

if s.waitRule.Ytt != nil {
startTime, found := timeoutMap.Load(s.resource.Description())
if !found {
startTime = time.Now().Unix()
timeoutMap.Store(s.resource.Description(), startTime)
}
configObj, err := WaitRuleContractV1{
ResourceMatcher: ctlres.AnyMatcher{
Matchers: ctlconf.ResourceMatchers(s.waitRule.ResourceMatchers).AsResourceMatchers()},
Starlark: s.waitRule.Ytt.FuncContractV1.Resource,
Starlark: s.waitRule.Ytt.FuncContractV1.Resource,
CurrentTime: time.Now().Unix(),
StartTime: startTime.(int64),
}.Apply(s.resource)
if err != nil {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
Expand Down
3 changes: 3 additions & 0 deletions pkg/kapp/resourcesmisc/wait_rule_contract_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
type WaitRuleContractV1 struct {
ResourceMatcher ctlres.ResourceMatcher
Starlark string
CurrentTime int64
StartTime int64
}

type waitRuleContractV1Result struct {
Expand Down Expand Up @@ -48,6 +50,7 @@ func (t WaitRuleContractV1) evalYtt(res ctlres.Resource) (*WaitRuleContractV1Res
}
return yaml.Marshal(res.DeepCopyRaw())
}
opts.DataValuesFlags.KVsFromStrings = []string{fmt.Sprintf("startTime=%d", t.StartTime), fmt.Sprintf("currentTime=%d", t.CurrentTime)}

filesToProcess := []*files.File{
files.MustNewFileFromSource(files.NewBytesSource("resource.star", []byte(t.Starlark))),
Expand Down

0 comments on commit 57419c9

Please sign in to comment.