diff --git a/scheduler/resource/cdn.go b/scheduler/resource/cdn.go index 6acbf8243..2f367a01d 100644 --- a/scheduler/resource/cdn.go +++ b/scheduler/resource/cdn.go @@ -213,9 +213,13 @@ func newCDNClient(dynconfig config.DynconfigInterface, hostManager HostManager, // Dynamic config notify function func (c *cdnClient) OnNotify(data *config.DynconfigData) { - ips := getCDNIPs(data.CDNs) + var cdns []config.CDN + for _, cdn := range data.CDNs { + cdns = append(cdns, *cdn) + } + if reflect.DeepEqual(c.data, data) { - logger.Infof("cdn addresses deep equal: %v", ips) + logger.Infof("cdn addresses deep equal: %#v", cdns) return } @@ -239,7 +243,7 @@ func (c *cdnClient) OnNotify(data *config.DynconfigData) { // Update grpc cdn addresses c.UpdateState(cdnsToNetAddrs(data.CDNs)) - logger.Infof("cdn addresses have been updated: %v", ips) + logger.Infof("cdn addresses have been updated: %#v", cdns) } // cdnsToHosts coverts []*config.CDN to map[string]*Host. @@ -318,13 +322,3 @@ func diffCDNs(cx []*config.CDN, cy []*config.CDN) []*config.CDN { return diff } - -// getCDNIPs get ips by []*config.CDN. -func getCDNIPs(cdns []*config.CDN) []string { - ips := []string{} - for _, cdn := range cdns { - ips = append(ips, cdn.IP) - } - - return ips -} diff --git a/scheduler/resource/cdn_test.go b/scheduler/resource/cdn_test.go index 7fb3d9617..1de17ee99 100644 --- a/scheduler/resource/cdn_test.go +++ b/scheduler/resource/cdn_test.go @@ -618,44 +618,3 @@ func TestCDNClient_diffCDNs(t *testing.T) { }) } } - -func TestCDNClient_getCDNIPs(t *testing.T) { - tests := []struct { - name string - cdns []*config.CDN - expect func(t *testing.T, ips []string) - }{ - { - name: "cdns covert to hosts", - cdns: []*config.CDN{ - { - ID: 1, - Hostname: mockRawCDNHost.HostName, - IP: mockRawCDNHost.Ip, - Port: mockRawCDNHost.RpcPort, - DownloadPort: mockRawCDNHost.DownPort, - Location: mockRawCDNHost.Location, - IDC: mockRawCDNHost.Idc, - }, - }, - expect: func(t *testing.T, ips []string) { - assert := assert.New(t) - assert.Equal(ips[0], mockRawCDNHost.Ip) - }, - }, - { - name: "cdns is empty", - cdns: []*config.CDN{}, - expect: func(t *testing.T, ips []string) { - assert := assert.New(t) - assert.Equal(len(ips), 0) - }, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - tc.expect(t, getCDNIPs(tc.cdns)) - }) - } -}