Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Fix tests. #47

Merged
merged 8 commits into from
Dec 16, 2024
Merged

🌱 Fix tests. #47

merged 8 commits into from
Dec 16, 2024

Conversation

guettli
Copy link

@guettli guettli commented Dec 12, 2024

Fix tests.

Up to now, they failed like this:

❯ go test ./...
?       github.com/syself/hetzner-cloud-controller-manager      [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/metrics     [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/mocks       [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/robot/client        [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/robot/client/cache  [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/testsupport [no test files]
?       github.com/syself/hetzner-cloud-controller-manager/internal/util        [no test files]
I1212 11:51:24.314196 3137547 cloud.go:180] Hetzner robot is not support because of insufficient credentials. Robot user name specified: false. Robot password specified: false
I1212 11:51:24.314263 3137547 cloud.go:209] hcloud/newCloud: HCLOUD_NETWORK empty
I1212 11:51:24.314879 3137547 cloud.go:223] Hetzner Cloud k8s cloud controller unknown started
I1212 11:51:24.315038 3137547 cloud.go:180] Hetzner robot is not support because of insufficient credentials. Robot user name specified: false. Robot password specified: false
I1212 11:51:24.315048 3137547 cloud.go:209] hcloud/newCloud: HCLOUD_NETWORK empty
I1212 11:51:24.315196 3137547 cloud.go:180] Hetzner robot is not support because of insufficient credentials. Robot user name specified: false. Robot password specified: false
I1212 11:51:24.315205 3137547 cloud.go:209] hcloud/newCloud: HCLOUD_NETWORK empty
I1212 11:51:24.315636 3137547 cloud.go:176] Not enabling robot API debugging. Set env var ROBOT_DEBUG=true to enable it.
I1212 11:51:24.315645 3137547 cloud.go:209] hcloud/newCloud: HCLOUD_NETWORK empty
I1212 11:51:24.315938 3137547 cloud.go:223] Hetzner Cloud k8s cloud controller unknown started
I1212 11:51:24.316051 3137547 cloud.go:176] Not enabling robot API debugging. Set env var ROBOT_DEBUG=true to enable it.
I1212 11:51:24.316342 3137547 cloud.go:223] Hetzner Cloud k8s cloud controller unknown started
--- Request:
GET /servers/1 HTTP/1.1
Host: 127.0.0.1:34743
User-Agent: hcloud-go/2.2.0
Authorization: REDACTED
Accept-Encoding: gzip



--- Response:
HTTP/1.1 200 OK
Content-Length: 930
Content-Type: text/plain; charset=utf-8
Date: Thu, 12 Dec 2024 10:51:24 GMT

{"server":{"id":1,"name":"foobar","status":"","created":"0001-01-01T00:00:00Z","public_net":{"ipv4":{"id":0,"ip":"","blocked":false,"dns_ptr":""},"ipv6":{"id":0,"ip":"","blocked":false,"dns_ptr":null},"floating_ips":null,"firewalls":null},"private_net":null,"server_type":{"id":0,"name":"","description":"","cores":0,"memory":0,"disk":0,"storage_type":"","cpu_type":"","architecture":"","included_traffic":0,"prices":null,"deprecation":null},"included_traffic":0,"outgoing_traffic":null,"ingoing_traffic":null,"backup_window":null,"rescue_enabled":false,"iso":null,"locked":false,"datacenter":{"id":0,"name":"","description":"","location":{"id":0,"name":"","description":"","country":"","city":"","latitude":0,"longitude":0,"network_zone":""},"server_types":{"supported":null,"available":null}},"image":null,"protection":{"delete":false,"rebuild":false},"labels":null,"volumes":null,"primary_disk_size":0,"placement_group":null}}


--- Request:
GET /servers/2 HTTP/1.1
Host: 127.0.0.1:34743
User-Agent: hcloud-go/2.2.0
Authorization: REDACTED
Accept-Encoding: gzip



--- Response:
HTTP/1.1 404 Not Found
Content-Length: 74
Content-Type: application/json
Date: Thu, 12 Dec 2024 10:51:24 GMT

{"error":{"code":"not_found","message":"","details":null,"Details":null}}


--- FAIL: TestInstances_InstanceExists (0.00s)
    --- FAIL: TestInstances_InstanceExists/existing_robot_server_by_id (0.00s)
        instances_test.go:164: Expected server to exist true but got false
    --- FAIL: TestInstances_InstanceExists/missing_robot_server_by_id (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1503ede]

goroutine 73 [running]:
testing.tRunner.func1.2({0x16d6d80, 0x2785670})
        /usr/local/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1635 +0x35e
panic({0x16d6d80?, 0x2785670?})
        /usr/local/go/src/runtime/panic.go:785 +0x132
github.com/syself/hetzner-cloud-controller-manager/hcloud.getRobotServerByID({0x702989a582d8, 0xc0003ce820}, 0x142, 0xc0005b2f08)
        /home/guettli/syself/hccm2/hcloud/util.go:104 +0x19e
github.com/syself/hetzner-cloud-controller-manager/hcloud.(*instances).lookupServer(0xc0005aaf60, {0x1b76f18, 0x27d45c0}, 0xc0005b2f08)
        /home/guettli/syself/hccm2/hcloud/instances.go:75 +0x2d4
github.com/syself/hetzner-cloud-controller-manager/hcloud.(*instances).InstanceExists(0xc0005aaf60, {0x1b76f18, 0x27d45c0}, 0xc0005b2f08)
        /home/guettli/syself/hccm2/hcloud/instances.go:104 +0x85
github.com/syself/hetzner-cloud-controller-manager/hcloud.TestInstances_InstanceExists.func7(0xc0000e41a0)
        /home/guettli/syself/hccm2/hcloud/instances_test.go:159 +0x45
testing.tRunner(0xc0000e41a0, 0xc0002f8180)
        /usr/local/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 63
        /usr/local/go/src/testing/testing.go:1743 +0x390
FAIL    github.com/syself/hetzner-cloud-controller-manager/hcloud       0.017s
ok      github.com/syself/hetzner-cloud-controller-manager/internal/annotation  0.005s
--- FAIL: TestRateLimitIsExceeded (0.00s)
    ratelimit_test.go:31:
                Error Trace:    /home/guettli/syself/hccm2/internal/hcops/ratelimit_test.go:31
                Error:          Not equal:
                                expected: true
                                actual  : false
                Test:           TestRateLimitIsExceeded
I1212 11:51:24.317086 3137550 load_balancer.go:480] "detach from network" op="hcops/LoadBalancerOps.detachFromNetwork" loadBalancerID=4 networkID=14
I1212 11:51:24.317223 3137550 load_balancer.go:504] "attach to network" op="hcops/LoadBalancerOps.attachToNetwork" loadBalancerID=4 networkID=15
I1212 11:51:24.317766 3137550 load_balancer.go:504] "attach to network" op="hcops/LoadBalancerOps.attachToNetwork" loadBalancerID=5 networkID=15
I1212 11:51:24.317899 3137550 load_balancer.go:521] "retry due to conflict or lock" op="hcops/LoadBalancerOps.attachToNetwork" delay="1s" err=" (conflict)"
I1212 11:51:25.318268 3137550 load_balancer.go:504] "attach to network" op="hcops/LoadBalancerOps.attachToNetwork" loadBalancerID=5 networkID=15
I1212 11:51:25.318354 3137550 load_balancer.go:521] "retry due to conflict or lock" op="hcops/LoadBalancerOps.attachToNetwork" delay="1s" err=" (locked)"
--- FAIL: TestLoadBalancerOps_ReconcileHCLBTargets (0.00s)
    --- FAIL: TestLoadBalancerOps_ReconcileHCLBTargets/add_k8s_nodes_as_hc_Load_Balancer_targets (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1299ac1]

goroutine 127 [running]:
testing.tRunner.func1.2({0x13b2ee0, 0x21aa2a0})
        /usr/local/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1635 +0x35e
panic({0x13b2ee0?, 0x21aa2a0?})
        /usr/local/go/src/runtime/panic.go:785 +0x132
github.com/syself/hetzner-cloud-controller-manager/internal/hcops.(*LoadBalancerOps).ReconcileHCLBTargets(0xc0005a6870, {0x1777850, 0x21f48e0}, 0xc0002898c0, 0xc0005a9688, {0xc0005ad0e0, 0x4, 0xc0003d37d0?})
        /home/guettli/syself/hccm2/internal/hcops/load_balancer.go:732 +0x1841
github.com/syself/hetzner-cloud-controller-manager/internal/hcops_test.TestLoadBalancerOps_ReconcileHCLBTargets.func2(0xc000515380, 0xc000442600?)
        /home/guettli/syself/hccm2/internal/hcops/load_balancer_test.go:1177 +0x4f
github.com/syself/hetzner-cloud-controller-manager/internal/hcops_test.(*LBReconcilementTestCase).run(0xc000442600, 0xc000515380)
        /home/guettli/syself/hccm2/internal/hcops/load_balancer_test.go:627 +0x239
testing.tRunner(0xc000515380, 0xc00005c6d0)
        /usr/local/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 126
        /usr/local/go/src/testing/testing.go:1743 +0x390
FAIL    github.com/syself/hetzner-cloud-controller-manager/internal/hcops       2.019s
open ../../hack/.token-dev: no such file or directory
FAIL    github.com/syself/hetzner-cloud-controller-manager/tests/e2e    0.011s
FAIL

These e2e tests seem to be hard-coded to a specific environment.

I tried to get them running with a kind cluster, but failed.
@guettli guettli requested a review from janiskemper December 12, 2024 13:30
hcloud/util.go Outdated
@@ -101,6 +104,9 @@ func getRobotServerByID(c robotclient.Client, id int, node *corev1.Node) (*model
}

// check whether name matches - otherwise this server does not belong to the respective node anymore
if server == nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't happen right? If there is an error code for "server not found"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error code was "server not found", then a nil pointer exception happens, because server was nil.

I made the old code easier to read. It now looks like this:

	server, err := c.ServerGet(id)
	if models.IsError(err, models.ErrorCodeServerNotFound) {
		return nil, nil
	}
	if err != nil {
		hcops.HandleRateLimitExceededError(err, node)
		return nil, fmt.Errorf("%s: %w", op, err)
	}

	// check whether name matches - otherwise this server does not belong to the respective node anymore
	if server.Name != node.Name {
		return nil, nil
	}

The old check looked like this:

        if err != nil && !models.IsError(err, models.ErrorCodeServerNotFound) {

Is that ok for you?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes looks good

@guettli guettli merged commit 2005984 into main Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants