@@ -17,15 +17,12 @@ limitations under the License.
1717package hcloud
1818
1919import (
20- "bytes"
2120 "context"
2221 "encoding/json"
2322 "net"
2423 "net/http"
2524 "reflect"
26- "strings"
2725 "testing"
28- "time"
2926
3027 "github.com/hetznercloud/hcloud-go/v2/hcloud"
3128 "github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
@@ -34,7 +31,6 @@ import (
3431 corev1 "k8s.io/api/core/v1"
3532 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3633 cloudprovider "k8s.io/cloud-provider"
37- "k8s.io/klog/v2"
3834)
3935
4036// TestInstances_InstanceExists also tests [lookupServer]. The other tests
@@ -211,15 +207,10 @@ func TestInstances_InstanceExistsRobotServerCreatedAfterCacheFill(t *testing.T)
211207 }
212208
213209 instances := newInstances (env .Client , robotClient , AddressFamilyIPv4 , 0 )
214- // creationTime keeps the test nodes inside the young-node refresh window.
215- creationTime := metav1 .NewTime (time .Now ())
216210
217211 // Warm the cache while bm-new does not exist yet.
218212 exists , err := instances .InstanceExists (context .TODO (), & corev1.Node {
219- ObjectMeta : metav1.ObjectMeta {
220- Name : "bm-existing" ,
221- CreationTimestamp : creationTime ,
222- },
213+ ObjectMeta : metav1.ObjectMeta {Name : "bm-existing" },
223214 })
224215 if err != nil {
225216 t .Fatalf ("Unexpected error warming cache: %v" , err )
@@ -236,10 +227,7 @@ func TestInstances_InstanceExistsRobotServerCreatedAfterCacheFill(t *testing.T)
236227 })
237228
238229 exists , err = instances .InstanceExists (context .TODO (), & corev1.Node {
239- ObjectMeta : metav1.ObjectMeta {
240- Name : "bm-new" ,
241- CreationTimestamp : creationTime ,
242- },
230+ ObjectMeta : metav1.ObjectMeta {Name : "bm-new" },
243231 })
244232 if err != nil {
245233 t .Fatalf ("Unexpected error for bm-new: %v" , err )
@@ -249,76 +237,6 @@ func TestInstances_InstanceExistsRobotServerCreatedAfterCacheFill(t *testing.T)
249237 }
250238}
251239
252- func TestInstances_InstanceExistsRobotServerLogsSecondYoungNodeMiss (t * testing.T ) {
253- env := newTestEnv ()
254- defer env .Teardown ()
255-
256- resetEnv := Setenv (t ,
257- "ROBOT_USER_NAME" , "user" ,
258- "ROBOT_PASSWORD" , "pass" ,
259- "CACHE_TIMEOUT" , "1h" ,
260- )
261- defer resetEnv ()
262-
263- env .Mux .HandleFunc ("/robot/server" , func (w http.ResponseWriter , _ * http.Request ) {
264- json .NewEncoder (w ).Encode ([]models.ServerResponse {
265- {
266- Server : models.Server {
267- ServerIP : "123.123.123.123" ,
268- ServerIPv6Net : "2a01:f48:111:4221::" ,
269- ServerNumber : 321 ,
270- Name : "bm-existing" ,
271- },
272- },
273- })
274- })
275-
276- robotClient , err := cache .NewCachedRobotClient (t .TempDir (), env .Server .Client (), env .Server .URL + "/robot" )
277- if err != nil {
278- t .Fatalf ("Unexpected error creating cached robot client: %v" , err )
279- }
280-
281- instances := newInstances (env .Client , robotClient , AddressFamilyIPv4 , 0 )
282- node := & corev1.Node {
283- ObjectMeta : metav1.ObjectMeta {
284- Name : "bm-new" ,
285- CreationTimestamp : metav1 .NewTime (time .Now ()),
286- },
287- }
288-
289- state := klog .CaptureState ()
290- defer state .Restore ()
291-
292- // logs captures klog output so the warning can be asserted directly.
293- var logs bytes.Buffer
294- klog .LogToStderr (false )
295- klog .SetOutput (& logs )
296-
297- exists , err := instances .InstanceExists (context .TODO (), node )
298- if err != nil {
299- t .Fatalf ("Unexpected error on first miss: %v" , err )
300- }
301- if exists {
302- t .Fatal ("Expected bm-new to be missing on first lookup" )
303- }
304- klog .Flush ()
305- if strings .Contains (logs .String (), "still missing in robot" ) {
306- t .Fatal ("Did not expect warning log on first miss" )
307- }
308-
309- exists , err = instances .InstanceExists (context .TODO (), node )
310- if err != nil {
311- t .Fatalf ("Unexpected error on second miss: %v" , err )
312- }
313- if exists {
314- t .Fatal ("Expected bm-new to be missing on second lookup" )
315- }
316- klog .Flush ()
317- if ! strings .Contains (logs .String (), `young node "bm-new" still missing in robot after 2 lookup misses` ) {
318- t .Fatalf ("Expected warning log after second miss, got %q" , logs .String ())
319- }
320- }
321-
322240func TestInstances_InstanceShutdown (t * testing.T ) {
323241 env := newTestEnv ()
324242 defer env .Teardown ()
0 commit comments