Skip to content

Commit 06a2dbf

Browse files
committed
HOTFIX- throttling issue
1 parent ae2d6ae commit 06a2dbf

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

lib/deployment/deployment.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"path/filepath"
1010
"text/template"
11+
"time"
1112

1213
g "github.com/sdslabs/katana/configs"
1314
"github.com/sdslabs/katana/lib/utils"
@@ -106,17 +107,49 @@ func ApplyManifest(kubeconfig *rest.Config, kubeclientset *kubernetes.Clientset,
106107
// if deleted, continue
107108
// else return a good error telling which resource didn't et deleted.
108109

110+
// HOTFIX: 30 sec timeout
111+
timeout := 30 * time.Second
109112

110113
defer watcher.Stop()
111-
for event := range watcher.ResultChan() {
112-
if event.Type == watch.Deleted {
113-
_, err = dri.Create(context.Background(), unstructuredObj, metav1.CreateOptions{})
114-
if err != nil {
115-
return err
114+
115+
done := make(chan bool)
116+
go func() {
117+
for event := range watcher.ResultChan() {
118+
if event.Type == watch.Deleted {
119+
log.Printf("Resource %s deleted, re-creating it", unstructuredObj.GetName())
120+
done <- true
121+
break
116122
}
117-
break
123+
}
124+
}()
125+
126+
// Wait for either the event or timeout
127+
select {
128+
case <-done:
129+
// Resource deleted and we can re-create it
130+
_, err = dri.Create(context.Background(), unstructuredObj, metav1.CreateOptions{})
131+
if err != nil {
132+
log.Printf("Failed to re-create resource %s: %v", unstructuredObj.GetName(), err)
133+
return err
134+
}
135+
case <-time.After(timeout):
136+
// Timeout reached
137+
_, err = dri.Create(context.Background(), unstructuredObj, metav1.CreateOptions{})
138+
if err != nil {
139+
log.Printf("[Timedout] Failed to re-create resource %s: %v", unstructuredObj.GetName(), err)
140+
return err
118141
}
119142
}
143+
144+
// for event := range watcher.ResultChan() {
145+
// if event.Type == watch.Deleted {
146+
// _, err = dri.Create(context.Background(), unstructuredObj, metav1.CreateOptions{})
147+
// if err != nil {
148+
// return err
149+
// }
150+
// break
151+
// }
152+
// }
120153
}
121154
}
122155
}

0 commit comments

Comments
 (0)