Skip to content

Commit

Permalink
Merge pull request #203 from gujingit/feature/endpoint
Browse files Browse the repository at this point in the history
Feature/endpoint
  • Loading branch information
aoxn authored Sep 8, 2020
2 parents 748f81e + cfd403c commit 8daf1a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
24 changes: 13 additions & 11 deletions cloud-controller-manager/alicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import (
"github.com/denverdino/aliyungo/slb"
"io"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/cloud-provider"
"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/node"
"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/route"
Expand Down Expand Up @@ -62,6 +64,8 @@ type Cloud struct {
vpcID string
//cid string
ifactory informers.SharedInformerFactory
// kubernetes client
kclient kubernetes.Interface
}

var (
Expand Down Expand Up @@ -185,8 +189,8 @@ func newAliCloud(mgr *ClientMgr, rtableids string) (*Cloud, error) {

// Initialize passes a Kubernetes clientBuilder interface to the cloud provider
func (c *Cloud) Initialize(builder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) {
shared := informers.NewSharedInformerFactory(
builder.ClientOrDie("shared-informers"), syncPeriod())
c.kclient = builder.ClientOrDie("shared-informers")
shared := informers.NewSharedInformerFactory(c.kclient, syncPeriod())
if route.Options.ConfigCloudRoutes {
cidr := route.Options.ClusterCIDR
if len(strings.TrimSpace(cidr)) == 0 {
Expand Down Expand Up @@ -270,8 +274,8 @@ func (c *Cloud) GetLoadBalancer(ctx context.Context, clusterName string, service
return nil, exists, err
}

zone, record, exists, err := c.climgr.PrivateZones().findExactRecordByService(ctx, service, lb.Address, lb.AddressIPVersion)
if err != nil || !exists {
zone, record, _, err := c.climgr.PrivateZones().findExactRecordByService(ctx, service, lb.Address, lb.AddressIPVersion)
if err != nil {
return nil, exists, err
}

Expand Down Expand Up @@ -322,13 +326,11 @@ func (c *Cloud) EnsureLoadBalancer(
}
}
// set up endpoints
eps, err := c.ifactory.
Core().V1().
Endpoints().
Lister().
Endpoints(
service.Namespace,
).Get(service.Name)
eps, err := c.kclient.
CoreV1().
Endpoints(service.Namespace).
Get(context.TODO(), service.Name, metav1.GetOptions{})

if err != nil {
if strings.Contains(err.Error(), "not found") {
// compatible with nil endpoint
Expand Down
14 changes: 0 additions & 14 deletions cloud-controller-manager/controller/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ func (con *Controller) HandlerForEndpointChange(
ep2, ok2 := objb.(*v1.Endpoints)
if ok1 && ok2 && !reflect.DeepEqual(ep1.Subsets, ep2.Subsets) {
klog.Infof("controller: endpoints update event, endpoints [%s/%s]", ep1.Namespace, ep1.Name)
logSubsetInfo(ep1, "old")
logSubsetInfo(ep2, "new")
syncEndpoints(ep2)
}
},
Expand Down Expand Up @@ -777,15 +775,3 @@ func getLogMessage(err error) string {
}
return message
}

// TODO: remove me
func logSubsetInfo(endpoint *v1.Endpoints, version string) {
if endpoint == nil {
klog.Error("endpoint is nil")
return
}
for i, ep := range endpoint.Subsets {
klog.Infof("[%s/%s]: %s , Subset index=%d, port len=%d, ready len=%d, not ready len=%d",
endpoint.Namespace, endpoint.Name, version, i, len(ep.Ports), len(ep.Addresses), len(ep.NotReadyAddresses))
}
}
5 changes: 3 additions & 2 deletions cloud-controller-manager/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ func (f *FrameWork) RunCustomized(
}

func (f *FrameWork) Run(run CustomizedTest) error {
//
// initialize kubernetes client
f.Cloud.kclient = fake.NewSimpleClientset(f.Endpoint, f.SVC)
// initialize shared informer factory before run any test.
f.Cloud.ifactory = informers.NewSharedInformerFactory(
fake.NewSimpleClientset(f.Endpoint, f.SVC), 0,
f.Cloud.kclient, 0,
)
// set informer
inform := f.Cloud.ifactory.Core().V1().Endpoints().Informer()
Expand Down

0 comments on commit 8daf1a9

Please sign in to comment.