Remove k8s.io/kubernetes dependency

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-10-26 11:24:55 -03:00
parent a762d8a4e3
commit a85e53f4cb
8 changed files with 86 additions and 234 deletions

View file

@ -43,7 +43,6 @@ import (
"k8s.io/ingress-nginx/internal/k8s"
"k8s.io/ingress-nginx/internal/nginx"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/apis/core"
)
const (
@ -155,7 +154,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
n.metricCollector.IncReloadErrorCount()
n.metricCollector.ConfigSuccess(hash, false)
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
n.recorder.Eventf(k8s.IngressNGINXPod, core.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
n.recorder.Eventf(k8s.IngressNGINXPod, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
return err
}
@ -163,7 +162,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
n.metricCollector.ConfigSuccess(hash, true)
n.metricCollector.IncReloadCount()
n.recorder.Eventf(k8s.IngressNGINXPod, core.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
n.recorder.Eventf(k8s.IngressNGINXPod, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
}
isFirstSync := n.runningConfig.Equal(&ingress.Configuration{})

View file

@ -18,15 +18,18 @@ package controller
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strconv"
"strings"
"syscall"
api "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-nginx/internal/ingress"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/util/sysctl"
)
// newUpstream creates an upstream without servers.
@ -52,7 +55,7 @@ func upstreamName(namespace string, service string, port intstr.IntOrString) str
// for acceptance (value of net.core.somaxconn)
// http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
func sysctlSomaxconn() int {
maxConns, err := sysctl.New().GetSysctl("net/core/somaxconn")
maxConns, err := getSysctl("net/core/somaxconn")
if err != nil || maxConns < 512 {
klog.V(3).InfoS("Using default net.core.somaxconn", "value", maxConns)
return 511
@ -117,3 +120,18 @@ func (nc NginxCommand) ExecCommand(args ...string) *exec.Cmd {
func (nc NginxCommand) Test(cfg string) ([]byte, error) {
return exec.Command(nc.Binary, "-c", cfg, "-t").CombinedOutput()
}
// getSysctl returns the value for the specified sysctl setting
func getSysctl(sysctl string) (int, error) {
data, err := ioutil.ReadFile(path.Join("/proc/sys", sysctl))
if err != nil {
return -1, err
}
val, err := strconv.Atoi(strings.Trim(string(data), " \n"))
if err != nil {
return -1, err
}
return val, nil
}

View file

@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"
"k8s.io/ingress-nginx/internal/ingress"
"k8s.io/ingress-nginx/internal/k8s"
@ -208,7 +207,7 @@ func (s *statusSync) runningAddresses() ([]string, error) {
}
name := k8s.GetNodeIPOrName(s.Client, pod.Spec.NodeName, s.UseNodeInternalIP)
if !sliceutils.StringInSlice(name, addrs) {
if !stringInSlice(name, addrs) {
addrs = append(addrs, name)
}
}
@ -365,3 +364,14 @@ func statusAddressFromService(service string, kubeClient clientset.Interface) ([
return nil, fmt.Errorf("unable to extract IP address/es from service %v", service)
}
// stringInSlice returns true if s is in list
func stringInSlice(s string, list []string) bool {
for _, v := range list {
if v == s {
return true
}
}
return false
}