|
8 | 8 | "log" |
9 | 9 | "path/filepath" |
10 | 10 | "text/template" |
| 11 | + "time" |
11 | 12 |
|
12 | 13 | g "github.com/sdslabs/katana/configs" |
13 | 14 | "github.com/sdslabs/katana/lib/utils" |
@@ -106,17 +107,49 @@ func ApplyManifest(kubeconfig *rest.Config, kubeclientset *kubernetes.Clientset, |
106 | 107 | // if deleted, continue |
107 | 108 | // else return a good error telling which resource didn't et deleted. |
108 | 109 |
|
| 110 | + // HOTFIX: 30 sec timeout |
| 111 | + timeout := 30 * time.Second |
109 | 112 |
|
110 | 113 | 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 |
116 | 122 | } |
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 |
118 | 141 | } |
119 | 142 | } |
| 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 | + // } |
120 | 153 | } |
121 | 154 | } |
122 | 155 | } |
|
0 commit comments