Skip to content

Commit

Permalink
Merge 770b424 into 3946b6d
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaramsatya committed Dec 3, 2020
2 parents 3946b6d + 770b424 commit 947da1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,17 @@ func (cont *AciController) Init() {

cont.log.Debug("Initializing IPAM")
cont.initIpam()
//@FIXME need to set this value based on feature capability supported by cluster
// check if the cluster supports endpoint slices
// if cluster doesn't have the support fallback to endpoints
if cont.config.EnabledEndpointSlice {
kubeClient := cont.env.(*K8sEnvironment).kubeClient
if util.IsEndPointSlicesSupported(kubeClient) {
cont.serviceEndPoints = &serviceEndpointSlice{}
cont.serviceEndPoints.(*serviceEndpointSlice).cont = cont
cont.log.Info("Initializing ServiceEndpointSlices")
} else {
cont.serviceEndPoints = &serviceEndpoint{}
cont.serviceEndPoints.(*serviceEndpoint).cont = cont
cont.log.Info("Initializing ServiceEndpoints")
}

err = cont.env.Init(cont)
Expand Down
9 changes: 7 additions & 2 deletions pkg/hostagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/noironetworks/aci-containers/pkg/ipam"
md "github.com/noironetworks/aci-containers/pkg/metadata"
snatpolicy "github.com/noironetworks/aci-containers/pkg/snatpolicy/apis/aci.snat/v1"
"github.com/noironetworks/aci-containers/pkg/util"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -262,13 +263,17 @@ func (agent *HostAgent) Init() {
}
agent.log.Info("Loaded cached endpoint CNI metadata: ", len(agent.epMetadata))
agent.buildUsedIPs()
//@TODO need to set this value based on feature capability currently turnedoff
if agent.config.EnabledEndpointSlice {
// check if the cluster supports endpoint slices
// if cluster doesn't have the support fallback to endpoints
kubeClient := agent.env.(*K8sEnvironment).kubeClient
if util.IsEndPointSlicesSupported(kubeClient) {
agent.serviceEndPoints = &serviceEndpointSlice{}
agent.serviceEndPoints.(*serviceEndpointSlice).agent = agent
agent.log.Info("Initializing ServiceEndpointSlices")
} else {
agent.serviceEndPoints = &serviceEndpoint{}
agent.serviceEndPoints.(*serviceEndpoint).agent = agent
agent.log.Info("Initializing ServiceEndpoints")
}
err = agent.env.Init(agent)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package util

import (
"context"
"encoding/json"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

func DeepCopyObj(src, dst interface{}) error {
Expand All @@ -29,3 +32,11 @@ func DeepCopyObj(src, dst interface{}) error {
}
return nil
}

func IsEndPointSlicesSupported(kubeClient *kubernetes.Clientset) bool {
esobj, err := kubeClient.DiscoveryV1beta1().EndpointSlices("default").Get(context.TODO(), "kubernetes", metav1.GetOptions{})
if err == nil && esobj != nil {
return true
}
return false
}

0 comments on commit 947da1b

Please sign in to comment.