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

A connection error occurs when etcd is not configured with cert #9883

Open
rxy0210 opened this issue Feb 21, 2025 · 0 comments · May be fixed by #9882
Open

A connection error occurs when etcd is not configured with cert #9883

rxy0210 opened this issue Feb 21, 2025 · 0 comments · May be fixed by #9882

Comments

@rxy0210
Copy link

rxy0210 commented Feb 21, 2025

Expected Behavior

If you do not configure the cert file, you can connect to etcd for access

Current Behavior

Unable to connect to etcd

Possible Solution

Set tls to nil

Steps to Reproduce (for bugs)

  1. When I run the above unit test, the following error is reported when I try to connect to the CERt-free etcd.
func createEtcdClient() (api.Client, error) {
	etcdConfig := apiconfig.EtcdConfig{
		EtcdEndpoints: "127.0.0.1:2379",
	}
	etcdV3Client, err := etcdv3.NewEtcdV3Client(&etcdConfig)
	if err != nil {
		return nil, err
	}
	return etcdV3Client, nil
}

func TestEtcdV3Client(t *testing.T) {
	tests := []struct {
		name        string
		cidr        string
		nodeName    string
		expectValue model.BlockAffinity
	}{
		{
			name:     "test1",
			cidr:     "1.1.1.1/26",
			nodeName: "node1",
			expectValue: model.BlockAffinity{
				State:   "confirmed",
				Deleted: false,
			},
		},
	}

	cli, err := createEtcdClient()
	if err != nil {
		t.Errorf("connect to etcd failed, err:%v\n", err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			_, cidr, err := net.ParseCIDR(test.cidr)
			if err != nil {
				t.Fatalf("Failed to parse CIDR: %v", err)
			}
			key := model.BlockAffinityKey{
				Host: test.nodeName,
				CIDR: *cidr,
			}
			get, err := cli.Get(ctx, key, "")
			if err != nil {
				fmt.Printf("create from etcd failed, err:%v\n", err)
				return
			}
			value, ok := get.Value.(*model.BlockAffinity)
			if !ok {
				t.Errorf("Value is not BlockAffinity, err:%v\n", err)
			}
			assert.Equal(t, test.expectValue.State, value.State)
			assert.Equal(t, test.expectValue.Deleted, value.Deleted)
		})
	}

	cancel()
}
=== RUN   TestEtcdV3Client
--- PASS: TestEtcdV3Client (5.01s)
=== RUN   TestEtcdV3Client/test1
{"level":"warn","ts":"2025-02-21T16:27:41.989034+0800","logger":"etcd-client","caller":"v3/retry_interceptor.go:63","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0x1400036a5a0/127.0.0.1:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: authentication handshake failed: EOF\""}
create from etcd failed, err:context deadline exceeded
    --- PASS: TestEtcdV3Client/test1 (5.00s)
PASS
  1. If etcd is configured with cert, it can be accessed normally

Context

Your Environment

  • Calico version
  • Calico dataplane (iptables, windows etc.)
  • Orchestrator version (e.g. kubernetes, mesos, rkt):
  • Operating System and version:
  • Link to your project (optional):
@rxy0210 rxy0210 linked a pull request Feb 21, 2025 that will close this issue
3 tasks
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 a pull request may close this issue.

1 participant