Skip to content

Commit

Permalink
optionally allow CLUSTER_ENDPOINT to be used rather than the cluster-…
Browse files Browse the repository at this point in the history
…ip (#2138)

* optionally allow CLUSTER_ENDPOINT to be used rather than the kubernetes cluster ip

* remove check for kube-proxy

* add version to readme
  • Loading branch information
bwagner5 authored Nov 16, 2022
1 parent f8bc3b8 commit 1aac6d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ Specifies the cluster name to tag allocated ENIs with. See the "Cluster Name tag

---

#### `CLUSTER_ENDPOINT` (v1.12.1+)

Type: String

Default: `""`

Specifies the cluster endpoint to use for connecting to the api-server without relying on kube-proxy.
This is an optional configuration parameter that can improve the initialization time of the AWS VPC CNI.

---

#### `ENABLE_POD_ENI` (v1.7.0+)

Type: Boolean as a String
Expand Down
4 changes: 2 additions & 2 deletions cmd/aws-k8s-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func main() {
}

func _main() int {
//Do not add anything before initializing logger
// Do not add anything before initializing logger
log := logger.Get()

log.Infof("Starting L-IPAMD %s ...", version.Version)
version.RegisterMetric()

//Check API Server Connectivity
// Check API Server Connectivity
if err := k8sapi.CheckAPIServerConnectivity(); err != nil {
log.Errorf("Failed to check API server connectivity: %s", err)
return 1
Expand Down
27 changes: 19 additions & 8 deletions pkg/k8sapi/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
var log = logger.Get()

func InitializeRestMapper() (meta.RESTMapper, error) {
restCfg, err := ctrl.GetConfig()
restCfg.Burst = 200
restCfg, err := getRestConfig()
if err != nil {
return nil, err
}
restCfg.Burst = 200
mapper, err := apiutil.NewDynamicRESTMapper(restCfg)
if err != nil {
return nil, err
Expand All @@ -37,7 +37,7 @@ func InitializeRestMapper() (meta.RESTMapper, error) {

// CreateKubeClient creates a k8s client
func CreateKubeClient(mapper meta.RESTMapper) (client.Client, error) {
restCfg, err := ctrl.GetConfig()
restCfg, err := getRestConfig()
if err != nil {
return nil, err
}
Expand All @@ -56,12 +56,12 @@ func CreateKubeClient(mapper meta.RESTMapper) (client.Client, error) {

// CreateKubeClient creates a k8s client
func CreateCachedKubeClient(rawK8SClient client.Client, mapper meta.RESTMapper) (client.Client, error) {
restCfg, err := ctrl.GetConfig()
restCfg.Burst = 100

restCfg, err := getRestConfig()
if err != nil {
return nil, err
}
restCfg.Burst = 100

vpcCniScheme := runtime.NewScheme()
clientgoscheme.AddToScheme(vpcCniScheme)
eniconfigscheme.AddToScheme(vpcCniScheme)
Expand Down Expand Up @@ -89,7 +89,7 @@ func CreateCachedKubeClient(rawK8SClient client.Client, mapper meta.RESTMapper)
}
func GetKubeClientSet() (kubernetes.Interface, error) {
// creates the in-cluster config
config, err := rest.InClusterConfig()
config, err := getRestConfig()
if err != nil {
return nil, err
}
Expand All @@ -103,7 +103,7 @@ func GetKubeClientSet() (kubernetes.Interface, error) {
}

func CheckAPIServerConnectivity() error {
restCfg, err := ctrl.GetConfig()
restCfg, err := getRestConfig()
if err != nil {
return err
}
Expand All @@ -130,3 +130,14 @@ func CheckAPIServerConnectivity() error {
return true, nil
})
}

func getRestConfig() (*rest.Config, error) {
restCfg, err := ctrl.GetConfig()
if err != nil {
return nil, err
}
if endpoint, ok := os.LookupEnv("CLUSTER_ENDPOINT"); ok {
restCfg.Host = endpoint
}
return restCfg, nil
}

0 comments on commit 1aac6d0

Please sign in to comment.