This commit is contained in:
Manuel de Brito Fontes 2017-09-17 15:42:31 -03:00
parent f478084cd8
commit 0661eaa08c
29 changed files with 264 additions and 281 deletions

View file

@ -9,19 +9,10 @@ notifications:
email: true
go:
- 1.8.3
- 1.9
go_import_path: k8s.io/ingress
env:
global:
# to add additional secure variables:
# docker run --rm caktux/travis-cli encrypt key=value -r kubernetes/ingress
- RELEASE="ci-${TRAVIS_BUILD_ID}"
before_script:
- export PATH=$PATH:$PWD/hack/e2e-internal/
jobs:
include:
- stage: Static Check
@ -34,4 +25,3 @@ jobs:
- go get github.com/modocache/gover
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
- make cover
#- make test-e2e

View file

@ -2,24 +2,6 @@ all: fmt lint vet
BUILDTAGS=
# building inside travis generates a custom version of the
# backends in order to run e2e tests agains the build.
ifdef TRAVIS_BUILD_ID
RELEASE := ci-build-${TRAVIS_BUILD_ID}
endif
# 0.0 shouldn't clobber any release builds
RELEASE?=0.0
# by default build a linux version
GOOS?=linux
REPO_INFO=$(shell git config --get remote.origin.url)
ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif
# base package. It contains the common and backends code
PKG := "k8s.io/ingress"

View file

@ -35,8 +35,7 @@ import (
"github.com/spf13/pflag"
proxyproto "github.com/armon/go-proxyproto"
api "k8s.io/api/core/v1"
api_v1 "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/ingress/controllers/nginx/pkg/config"
@ -83,7 +82,7 @@ func newNGINXController() *NGINXController {
n := &NGINXController{
binary: ngx,
configmap: &api_v1.ConfigMap{},
configmap: &apiv1.ConfigMap{},
isIPV6Enabled: isIPv6Enabled(),
resolver: h,
ports: &config.ListenPorts{},
@ -123,7 +122,7 @@ type NGINXController struct {
controller *controller.GenericController
t *ngx_template.Template
configmap *api_v1.ConfigMap
configmap *apiv1.ConfigMap
storeLister ingress.StoreLister
@ -309,7 +308,7 @@ func (n NGINXController) DefaultEndpoint() ingress.Endpoint {
return ingress.Endpoint{
Address: "127.0.0.1",
Port: fmt.Sprintf("%v", n.ports.Default),
Target: &api.ObjectReference{},
Target: &apiv1.ObjectReference{},
}
}
@ -443,7 +442,7 @@ Error: %v
}
// SetConfig sets the configured configmap
func (n *NGINXController) SetConfig(cmap *api_v1.ConfigMap) {
func (n *NGINXController) SetConfig(cmap *apiv1.ConfigMap) {
n.configmap = cmap
n.isProxyProtocolEnabled = false
@ -469,7 +468,7 @@ func (n *NGINXController) SetListers(lister ingress.StoreLister) {
}
// UpdateIngressStatus custom Ingress status update
func (n *NGINXController) UpdateIngressStatus(*extensions.Ingress) []api_v1.LoadBalancerIngress {
func (n *NGINXController) UpdateIngressStatus(*extensions.Ingress) []apiv1.LoadBalancerIngress {
return nil
}
@ -598,7 +597,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
}
if exists {
setHeaders = cmap.(*api_v1.ConfigMap).Data
setHeaders = cmap.(*apiv1.ConfigMap).Data
}
}
@ -610,7 +609,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
}
if exists {
addHeaders = cmap.(*api_v1.ConfigMap).Data
addHeaders = cmap.(*apiv1.ConfigMap).Data
}
}
@ -623,7 +622,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
}
if exists {
secret := s.(*api_v1.Secret)
secret := s.(*apiv1.Secret)
nsSecName := strings.Replace(secretName, "/", "-", -1)
dh, ok := secret.Data["dhparam.pem"]

View file

@ -6,6 +6,7 @@ import (
"net"
"github.com/golang/glog"
"github.com/paultag/sniff/parser"
)

View file

@ -24,9 +24,9 @@ import (
"os/exec"
"syscall"
"k8s.io/kubernetes/pkg/util/sysctl"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/util/sysctl"
)
// sysctlSomaxconn returns the value of net.core.somaxconn, i.e.

View file

@ -18,6 +18,7 @@ package collector
import (
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
)

View file

@ -20,6 +20,7 @@ import (
"path/filepath"
"github.com/golang/glog"
common "github.com/ncabatoff/process-exporter"
"github.com/ncabatoff/process-exporter/proc"
"github.com/prometheus/client_golang/prometheus"

View file

@ -20,6 +20,7 @@ import (
"reflect"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
)

View file

@ -23,6 +23,7 @@ import (
"strings"
"github.com/golang/glog"
"github.com/mitchellh/mapstructure"
"k8s.io/ingress/controllers/nginx/pkg/config"

View file

@ -30,6 +30,7 @@ import (
text_template "text/template"
"github.com/golang/glog"
"github.com/pborman/uuid"
extensions "k8s.io/api/extensions/v1beta1"

View file

@ -19,6 +19,7 @@ package template
import (
"encoding/json"
"io/ioutil"
"net"
"os"
"path"
"reflect"
@ -29,7 +30,6 @@ import (
"k8s.io/ingress/core/pkg/ingress"
"k8s.io/ingress/core/pkg/ingress/annotations/authreq"
"k8s.io/ingress/core/pkg/ingress/annotations/rewrite"
"net"
)
var (

View file

@ -18,6 +18,7 @@ package controller
import (
"github.com/golang/glog"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/ingress/core/pkg/ingress/annotations/alias"
"k8s.io/ingress/core/pkg/ingress/annotations/auth"

View file

@ -19,9 +19,9 @@ package controller
import (
"testing"
api "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress/core/pkg/ingress/defaults"
@ -40,19 +40,19 @@ const (
)
type mockCfg struct {
MockSecrets map[string]*api.Secret
MockServices map[string]*api.Service
MockSecrets map[string]*apiv1.Secret
MockServices map[string]*apiv1.Service
}
func (m mockCfg) GetDefaultBackend() defaults.Backend {
return defaults.Backend{}
}
func (m mockCfg) GetSecret(name string) (*api.Secret, error) {
func (m mockCfg) GetSecret(name string) (*apiv1.Secret, error) {
return m.MockSecrets[name], nil
}
func (m mockCfg) GetService(name string) (*api.Service, error) {
func (m mockCfg) GetService(name string) (*apiv1.Service, error) {
return m.MockServices[name], nil
}
@ -88,9 +88,9 @@ func buildIngress() *extensions.Ingress {
}
return &extensions.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
@ -142,9 +142,9 @@ func TestSecureUpstream(t *testing.T) {
func TestSecureVerifyCACert(t *testing.T) {
ec := newAnnotationExtractor(mockCfg{
MockSecrets: map[string]*api.Secret{
MockSecrets: map[string]*apiv1.Secret{
"default/secure-verify-ca": {
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "secure-verify-ca",
},
},

View file

@ -23,7 +23,7 @@ import (
"github.com/golang/glog"
api "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/ingress/core/pkg/ingress"
@ -75,9 +75,9 @@ func (ic *GenericController) getPemCertificate(secretName string) (*ingress.SSLC
return nil, fmt.Errorf("secret named %v does not exist", secretName)
}
secret := secretInterface.(*api.Secret)
cert, okcert := secret.Data[api.TLSCertKey]
key, okkey := secret.Data[api.TLSPrivateKeyKey]
secret := secretInterface.(*apiv1.Secret)
cert, okcert := secret.Data[apiv1.TLSCertKey]
key, okkey := secret.Data[apiv1.TLSPrivateKeyKey]
ca := secret.Data["ca.crt"]

View file

@ -18,15 +18,15 @@ package controller
import (
"encoding/base64"
"fmt"
"io/ioutil"
"testing"
"fmt"
api_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"
cache_client "k8s.io/client-go/tools/cache"
"k8s.io/ingress/core/pkg/ingress"
"k8s.io/ingress/core/pkg/ingress/store"
"k8s.io/kubernetes/pkg/api"
@ -70,9 +70,9 @@ func buildIngListenerForBackendSSL() store.IngressLister {
return ingLister
}
func buildSecretForBackendSSL() *api_v1.Secret {
return &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
func buildSecretForBackendSSL() *apiv1.Secret {
return &apiv1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_secret",
Namespace: api.NamespaceDefault,
},

View file

@ -28,7 +28,7 @@ import (
"github.com/golang/glog"
api "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/fields"
@ -37,11 +37,12 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
unversionedcore "k8s.io/client-go/kubernetes/typed/core/v1"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
fcache "k8s.io/client-go/tools/cache/testing"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/ingress/core/pkg/ingress"
"k8s.io/ingress/core/pkg/ingress/annotations/class"
"k8s.io/ingress/core/pkg/ingress/annotations/healthcheck"
@ -157,7 +158,7 @@ func newIngressController(config *Configuration) *GenericController {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventBroadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{
eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{
Interface: config.Client.CoreV1().Events(config.Namespace),
})
@ -166,7 +167,7 @@ func newIngressController(config *Configuration) *GenericController {
stopLock: &sync.Mutex{},
stopCh: make(chan struct{}),
syncRateLimiter: flowcontrol.NewTokenBucketRateLimiter(0.3, 1),
recorder: eventBroadcaster.NewRecorder(scheme.Scheme, api.EventSource{
recorder: eventBroadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{
Component: "ingress-controller",
}),
sslCertTracker: newSSLCertTracker(),
@ -185,7 +186,7 @@ func newIngressController(config *Configuration) *GenericController {
glog.Infof("ignoring add for ingress %v based on annotation %v with value %v", addIng.Name, class.IngressKey, a)
return
}
ic.recorder.Eventf(addIng, api.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", addIng.Namespace, addIng.Name))
ic.recorder.Eventf(addIng, apiv1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", addIng.Namespace, addIng.Name))
ic.syncQueue.Enqueue(obj)
},
DeleteFunc: func(obj interface{}) {
@ -207,7 +208,7 @@ func newIngressController(config *Configuration) *GenericController {
glog.Infof("ignoring delete for ingress %v based on annotation %v", delIng.Name, class.IngressKey)
return
}
ic.recorder.Eventf(delIng, api.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", delIng.Namespace, delIng.Name))
ic.recorder.Eventf(delIng, apiv1.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", delIng.Namespace, delIng.Name))
ic.syncQueue.Enqueue(obj)
},
UpdateFunc: func(old, cur interface{}) {
@ -217,12 +218,12 @@ func newIngressController(config *Configuration) *GenericController {
validCur := class.IsValid(curIng, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass)
if !validOld && validCur {
glog.Infof("creating ingress %v based on annotation %v", curIng.Name, class.IngressKey)
ic.recorder.Eventf(curIng, api.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
ic.recorder.Eventf(curIng, apiv1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
} else if validOld && !validCur {
glog.Infof("removing ingress %v based on annotation %v", curIng.Name, class.IngressKey)
ic.recorder.Eventf(curIng, api.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
ic.recorder.Eventf(curIng, apiv1.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
} else if validCur && !reflect.DeepEqual(old, cur) {
ic.recorder.Eventf(curIng, api.EventTypeNormal, "UPDATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
ic.recorder.Eventf(curIng, apiv1.EventTypeNormal, "UPDATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
}
ic.syncQueue.Enqueue(cur)
@ -232,13 +233,13 @@ func newIngressController(config *Configuration) *GenericController {
secrEventHandler := cache.ResourceEventHandlerFuncs{
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
sec := cur.(*api.Secret)
sec := cur.(*apiv1.Secret)
key := fmt.Sprintf("%v/%v", sec.Namespace, sec.Name)
ic.syncSecret(key)
}
},
DeleteFunc: func(obj interface{}) {
sec, ok := obj.(*api.Secret)
sec, ok := obj.(*apiv1.Secret)
if !ok {
// If we reached here it means the secret was deleted but its final state is unrecorded.
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
@ -246,7 +247,7 @@ func newIngressController(config *Configuration) *GenericController {
glog.Errorf("couldn't get object from tombstone %#v", obj)
return
}
sec, ok = tombstone.Obj.(*api.Secret)
sec, ok = tombstone.Obj.(*apiv1.Secret)
if !ok {
glog.Errorf("Tombstone contained object that is not a Secret: %#v", obj)
return
@ -265,8 +266,8 @@ func newIngressController(config *Configuration) *GenericController {
ic.syncQueue.Enqueue(obj)
},
UpdateFunc: func(old, cur interface{}) {
oep := old.(*api.Endpoints)
ocur := cur.(*api.Endpoints)
oep := old.(*apiv1.Endpoints)
ocur := cur.(*apiv1.Endpoints)
if !reflect.DeepEqual(ocur.Subsets, oep.Subsets) {
ic.syncQueue.Enqueue(cur)
}
@ -275,7 +276,7 @@ func newIngressController(config *Configuration) *GenericController {
mapEventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
upCmap := obj.(*api.ConfigMap)
upCmap := obj.(*apiv1.ConfigMap)
mapKey := fmt.Sprintf("%s/%s", upCmap.Namespace, upCmap.Name)
if mapKey == ic.cfg.ConfigMapName {
glog.V(2).Infof("adding configmap %v to backend", mapKey)
@ -285,7 +286,7 @@ func newIngressController(config *Configuration) *GenericController {
},
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
upCmap := cur.(*api.ConfigMap)
upCmap := cur.(*apiv1.ConfigMap)
mapKey := fmt.Sprintf("%s/%s", upCmap.Namespace, upCmap.Name)
if mapKey == ic.cfg.ConfigMapName {
glog.V(2).Infof("updating configmap backend (%v)", mapKey)
@ -294,15 +295,15 @@ func newIngressController(config *Configuration) *GenericController {
}
// updates to configuration configmaps can trigger an update
if mapKey == ic.cfg.ConfigMapName || mapKey == ic.cfg.TCPConfigMapName || mapKey == ic.cfg.UDPConfigMapName {
ic.recorder.Eventf(upCmap, api.EventTypeNormal, "UPDATE", fmt.Sprintf("ConfigMap %v", mapKey))
ic.recorder.Eventf(upCmap, apiv1.EventTypeNormal, "UPDATE", fmt.Sprintf("ConfigMap %v", mapKey))
ic.syncQueue.Enqueue(cur)
}
}
},
}
watchNs := api.NamespaceAll
if ic.cfg.ForceNamespaceIsolation && ic.cfg.Namespace != api.NamespaceAll {
watchNs := apiv1.NamespaceAll
if ic.cfg.ForceNamespaceIsolation && ic.cfg.Namespace != apiv1.NamespaceAll {
watchNs = ic.cfg.Namespace
}
@ -312,29 +313,29 @@ func newIngressController(config *Configuration) *GenericController {
ic.endpLister.Store, ic.endpController = cache.NewInformer(
cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "endpoints", ic.cfg.Namespace, fields.Everything()),
&api.Endpoints{}, ic.cfg.ResyncPeriod, eventHandler)
&apiv1.Endpoints{}, ic.cfg.ResyncPeriod, eventHandler)
ic.secrLister.Store, ic.secrController = cache.NewInformer(
cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "secrets", watchNs, fields.Everything()),
&api.Secret{}, ic.cfg.ResyncPeriod, secrEventHandler)
&apiv1.Secret{}, ic.cfg.ResyncPeriod, secrEventHandler)
ic.mapLister.Store, ic.mapController = cache.NewInformer(
cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "configmaps", watchNs, fields.Everything()),
&api.ConfigMap{}, ic.cfg.ResyncPeriod, mapEventHandler)
&apiv1.ConfigMap{}, ic.cfg.ResyncPeriod, mapEventHandler)
ic.svcLister.Store, ic.svcController = cache.NewInformer(
cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "services", ic.cfg.Namespace, fields.Everything()),
&api.Service{}, ic.cfg.ResyncPeriod, cache.ResourceEventHandlerFuncs{})
&apiv1.Service{}, ic.cfg.ResyncPeriod, cache.ResourceEventHandlerFuncs{})
var nodeListerWatcher cache.ListerWatcher
if config.DisableNodeList {
nodeListerWatcher = fcache.NewFakeControllerSource()
} else {
nodeListerWatcher = cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "nodes", api.NamespaceAll, fields.Everything())
nodeListerWatcher = cache.NewListWatchFromClient(ic.cfg.Client.CoreV1().RESTClient(), "nodes", apiv1.NamespaceAll, fields.Everything())
}
ic.nodeLister.Store, ic.nodeController = cache.NewInformer(
nodeListerWatcher,
&api.Node{}, ic.cfg.ResyncPeriod, cache.ResourceEventHandlerFuncs{})
&apiv1.Node{}, ic.cfg.ResyncPeriod, cache.ResourceEventHandlerFuncs{})
if config.UpdateStatus {
ic.syncStatus = status.NewStatusSyncer(status.Config{
@ -382,7 +383,7 @@ func (ic GenericController) GetDefaultBackend() defaults.Backend {
}
// GetPublishService returns the configured service used to set ingress status
func (ic GenericController) GetPublishService() *api.Service {
func (ic GenericController) GetPublishService() *apiv1.Service {
s, err := ic.GetService(ic.cfg.PublishService)
if err != nil {
return nil
@ -397,7 +398,7 @@ func (ic GenericController) GetRecorder() record.EventRecorder {
}
// GetSecret searches for a secret in the local secrets Store
func (ic GenericController) GetSecret(name string) (*api.Secret, error) {
func (ic GenericController) GetSecret(name string) (*apiv1.Secret, error) {
s, exists, err := ic.secrLister.Store.GetByKey(name)
if err != nil {
return nil, err
@ -405,11 +406,11 @@ func (ic GenericController) GetSecret(name string) (*api.Secret, error) {
if !exists {
return nil, fmt.Errorf("secret %v was not found", name)
}
return s.(*api.Secret), nil
return s.(*apiv1.Secret), nil
}
// GetService searches for a service in the local secrets Store
func (ic GenericController) GetService(name string) (*api.Service, error) {
func (ic GenericController) GetService(name string) (*apiv1.Service, error) {
s, exists, err := ic.svcLister.Store.GetByKey(name)
if err != nil {
return nil, err
@ -417,10 +418,10 @@ func (ic GenericController) GetService(name string) (*api.Service, error) {
if !exists {
return nil, fmt.Errorf("service %v was not found", name)
}
return s.(*api.Service), nil
return s.(*apiv1.Service), nil
}
func (ic *GenericController) getConfigMap(ns, name string) (*api.ConfigMap, error) {
func (ic *GenericController) getConfigMap(ns, name string) (*apiv1.ConfigMap, error) {
s, exists, err := ic.mapLister.Store.GetByKey(fmt.Sprintf("%v/%v", ns, name))
if err != nil {
return nil, err
@ -428,7 +429,7 @@ func (ic *GenericController) getConfigMap(ns, name string) (*api.ConfigMap, erro
if !exists {
return nil, fmt.Errorf("configmap %v was not found", name)
}
return s.(*api.ConfigMap), nil
return s.(*apiv1.ConfigMap), nil
}
// sync collects all the pieces required to assemble the configuration file and
@ -474,8 +475,8 @@ func (ic *GenericController) syncIngress(key interface{}) error {
pcfg := ingress.Configuration{
Backends: upstreams,
Servers: servers,
TCPEndpoints: ic.getStreamServices(ic.cfg.TCPConfigMapName, api.ProtocolTCP),
UDPEndpoints: ic.getStreamServices(ic.cfg.UDPConfigMapName, api.ProtocolUDP),
TCPEndpoints: ic.getStreamServices(ic.cfg.TCPConfigMapName, apiv1.ProtocolTCP),
UDPEndpoints: ic.getStreamServices(ic.cfg.UDPConfigMapName, apiv1.ProtocolUDP),
PassthroughBackends: passUpstreams,
}
@ -503,7 +504,7 @@ func (ic *GenericController) syncIngress(key interface{}) error {
return nil
}
func (ic *GenericController) getStreamServices(configmapName string, proto api.Protocol) []ingress.L4Service {
func (ic *GenericController) getStreamServices(configmapName string, proto apiv1.Protocol) []ingress.L4Service {
glog.V(3).Infof("obtaining information about stream services of type %v located in configmap %v", proto, configmapName)
if configmapName == "" {
// no configmap configured
@ -549,7 +550,7 @@ func (ic *GenericController) getStreamServices(configmapName string, proto api.P
useProxyProtocol := false
// Proxy protocol is possible if the service is TCP
if len(nsSvcPort) == 3 && proto == api.ProtocolTCP {
if len(nsSvcPort) == 3 && proto == apiv1.ProtocolTCP {
if strings.ToUpper(nsSvcPort[2]) == "PROXY" {
useProxyProtocol = true
}
@ -572,7 +573,7 @@ func (ic *GenericController) getStreamServices(configmapName string, proto api.P
continue
}
svc := svcObj.(*api.Service)
svc := svcObj.(*apiv1.Service)
var endps []ingress.Endpoint
targetPort, err := strconv.Atoi(svcPort)
@ -643,8 +644,8 @@ func (ic *GenericController) getDefaultUpstream() *ingress.Backend {
return upstream
}
svc := svcObj.(*api.Service)
endps := ic.getEndpoints(svc, &svc.Spec.Ports[0], api.ProtocolTCP, &healthcheck.Upstream{})
svc := svcObj.(*apiv1.Service)
endps := ic.getEndpoints(svc, &svc.Spec.Ports[0], apiv1.ProtocolTCP, &healthcheck.Upstream{})
if len(endps) == 0 {
glog.Warningf("service %v does not have any active endpoints", svcKey)
endps = []ingress.Endpoint{ic.cfg.Backend.DefaultEndpoint()}
@ -811,7 +812,7 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
// check if the location contains endpoints and a custom default backend
if location.DefaultBackend != nil {
sp := location.DefaultBackend.Spec.Ports[0]
endps := ic.getEndpoints(location.DefaultBackend, &sp, api.ProtocolTCP, &healthcheck.Upstream{})
endps := ic.getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, &healthcheck.Upstream{})
if len(endps) > 0 {
glog.V(3).Infof("using custom default backend in server %v location %v (service %v/%v)",
server.Hostname, location.Path, location.DefaultBackend.Namespace, location.DefaultBackend.Name)
@ -1004,7 +1005,7 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing
continue
}
upstreams[name].Service = s.(*api.Service)
upstreams[name].Service = s.(*apiv1.Service)
}
}
}
@ -1019,7 +1020,7 @@ func (ic *GenericController) getServiceClusterEndpoint(svcKey string, backend *e
return endpoint, fmt.Errorf("service %v does not exist", svcKey)
}
svc := svcObj.(*api.Service)
svc := svcObj.(*apiv1.Service)
if svc.Spec.ClusterIP == "" {
return endpoint, fmt.Errorf("No ClusterIP found for service %s", svcKey)
}
@ -1046,7 +1047,7 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
return upstreams, err
}
svc := svcObj.(*api.Service)
svc := svcObj.(*apiv1.Service)
glog.V(3).Infof("obtaining port information for service %v", svcKey)
for _, servicePort := range svc.Spec.Ports {
// targetPort could be a string, use the name or the port (int)
@ -1054,7 +1055,7 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
servicePort.TargetPort.String() == backendPort ||
servicePort.Name == backendPort {
endps := ic.getEndpoints(svc, &servicePort, api.ProtocolTCP, hz)
endps := ic.getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, hz)
if len(endps) == 0 {
glog.Warningf("service %v does not have any active endpoints", svcKey)
}
@ -1175,7 +1176,7 @@ func (ic *GenericController) createServers(data []interface{},
IsDefBackend: true,
Backend: un,
Proxy: ngxProxy,
Service: &api.Service{},
Service: &apiv1.Service{},
},
}, SSLPassthrough: sslpt}
}
@ -1262,9 +1263,9 @@ func (ic *GenericController) createServers(data []interface{},
// getEndpoints returns a list of <endpoint ip>:<port> for a given service/target port combination.
func (ic *GenericController) getEndpoints(
s *api.Service,
servicePort *api.ServicePort,
proto api.Protocol,
s *apiv1.Service,
servicePort *apiv1.ServicePort,
proto apiv1.Protocol,
hz *healthcheck.Upstream) []ingress.Endpoint {
upsServers := []ingress.Endpoint{}
@ -1275,7 +1276,7 @@ func (ic *GenericController) getEndpoints(
adus := make(map[string]bool)
// ExternalName services
if s.Spec.Type == api.ServiceTypeExternalName {
if s.Spec.Type == apiv1.ServiceTypeExternalName {
targetPort := servicePort.TargetPort.IntValue()
// check for invalid port value
if targetPort <= 0 {

View file

@ -15,13 +15,13 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/pflag"
api "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/server/healthz"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmd_api "k8s.io/client-go/tools/clientcmd/api"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/ingress/core/pkg/ingress"
"k8s.io/ingress/core/pkg/k8s"
@ -70,7 +70,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
resyncPeriod = flags.Duration("sync-period", 600*time.Second,
`Relist and confirm cloud resources this often. Default is 10 minutes`)
watchNamespace = flags.String("watch-namespace", api.NamespaceAll,
watchNamespace = flags.String("watch-namespace", apiv1.NamespaceAll,
`Namespace to watch for Ingress. Default is to watch all namespaces`)
healthzPort = flags.Int("healthz-port", 10254, "port for healthz endpoint.")
@ -130,7 +130,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
glog.Fatalf("invalid format for service %v: %v", *defaultSvc, err)
}
_, err = kubeClient.Core().Services(ns).Get(name, meta_v1.GetOptions{})
_, err = kubeClient.Core().Services(ns).Get(name, metav1.GetOptions{})
if err != nil {
if strings.Contains(err.Error(), "cannot get services in the namespace") {
glog.Fatalf("✖ It seems the cluster it is running with Authorization enabled (like RBAC) and there is no permissions for the ingress controller. Please check the configuration")
@ -145,7 +145,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
glog.Fatalf("invalid service format: %v", err)
}
svc, err := kubeClient.CoreV1().Services(ns).Get(name, meta_v1.GetOptions{})
svc, err := kubeClient.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
if err != nil {
glog.Fatalf("unexpected error getting information about service %v: %v", *publishSvc, err)
}
@ -163,7 +163,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
}
if *watchNamespace != "" {
_, err = kubeClient.CoreV1().Namespaces().Get(*watchNamespace, meta_v1.GetOptions{})
_, err = kubeClient.CoreV1().Namespaces().Get(*watchNamespace, metav1.GetOptions{})
if err != nil {
glog.Fatalf("no watchNamespace with name %v found: %v", *watchNamespace, err)
}
@ -266,7 +266,7 @@ func buildConfigFromFlags(masterURL, kubeconfigPath string) (*rest.Config, error
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
&clientcmd.ConfigOverrides{
ClusterInfo: clientcmd_api.Cluster{
ClusterInfo: clientcmdapi.Cluster{
Server: masterURL,
},
}).ClientConfig()

View file

@ -18,6 +18,7 @@ package controller
import (
"github.com/prometheus/client_golang/prometheus"
"k8s.io/ingress/core/pkg/ingress"
)

View file

@ -18,6 +18,7 @@ package controller
import (
"github.com/golang/glog"
"github.com/imdario/mergo"
api "k8s.io/api/core/v1"

View file

@ -17,7 +17,7 @@ limitations under the License.
package resolver
import (
api "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/ingress/core/pkg/ingress/defaults"
)
@ -31,7 +31,7 @@ type DefaultBackend interface {
// Secret has a method that searches for secrets contenating
// the namespace and name using a the character /
type Secret interface {
GetSecret(string) (*api.Secret, error)
GetSecret(string) (*apiv1.Secret, error)
}
// AuthCertificate resolves a given secret name into an SSL certificate.
@ -44,7 +44,7 @@ type AuthCertificate interface {
// Service has a method that searches for services contenating
// the namespace and name using a the character /
type Service interface {
GetService(string) (*api.Service, error)
GetService(string) (*apiv1.Service, error)
}
// AuthSSLCert contains the necessary information to do certificate based

View file

@ -20,7 +20,7 @@ import (
"crypto/x509"
"time"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
@ -72,8 +72,8 @@ func (c LocationByPath) Less(i, j int) bool {
// SSLCert describes a SSL certificate to be used in a server
type SSLCert struct {
meta_v1.ObjectMeta `json:"metadata,omitempty"`
Certificate *x509.Certificate `json:"certificate,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Certificate *x509.Certificate `json:"certificate,omitempty"`
// CAFileName contains the path to the file with the root certificate
CAFileName string `json:"caFileName"`
// PemFileName contains the path to the file with the certificate and key concatenated

View file

@ -19,7 +19,7 @@ package ingress
import (
"testing"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func buildBackendByNameServers() BackendByNameServers {
@ -365,7 +365,7 @@ func TestLocationByPathLess(t *testing.T) {
func TestGetObjectKindForSSLCert(t *testing.T) {
fk := &SSLCert{
ObjectMeta: meta_v1.ObjectMeta{},
ObjectMeta: metav1.ObjectMeta{},
CAFileName: "ca_file",
PemFileName: "pemfile",
PemSHA: "pem_sha",

View file

@ -26,9 +26,9 @@ import (
"github.com/golang/glog"
v1 "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
@ -68,7 +68,7 @@ type Config struct {
IngressClass string
// CustomIngressStatus allows to set custom values in Ingress status
CustomIngressStatus func(*extensions.Ingress) []v1.LoadBalancerIngress
CustomIngressStatus func(*extensions.Ingress) []apiv1.LoadBalancerIngress
}
// statusSync keeps the status IP in each Ingress rule updated executing a periodic check
@ -134,7 +134,7 @@ func (s statusSync) Shutdown() {
}
glog.Infof("removing address from ingress status (%v)", addrs)
s.updateStatus([]v1.LoadBalancerIngress{})
s.updateStatus([]apiv1.LoadBalancerIngress{})
}
func (s *statusSync) sync(key interface{}) error {
@ -197,13 +197,13 @@ func NewStatusSyncer(config Config) Sync {
broadcaster := record.NewBroadcaster()
hostname, _ := os.Hostname()
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{
recorder := broadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{
Component: "ingress-leader-elector",
Host: hostname,
})
lock := resourcelock.ConfigMapLock{
ConfigMapMeta: meta_v1.ObjectMeta{Namespace: pod.Namespace, Name: electionID},
ConfigMapMeta: metav1.ObjectMeta{Namespace: pod.Namespace, Name: electionID},
Client: config.Client.CoreV1(),
LockConfig: resourcelock.ResourceLockConfig{
Identity: pod.Name,
@ -233,7 +233,7 @@ func NewStatusSyncer(config Config) Sync {
func (s *statusSync) runningAddresses() ([]string, error) {
if s.PublishService != "" {
ns, name, _ := k8s.ParseNameNS(s.PublishService)
svc, err := s.Client.CoreV1().Services(ns).Get(name, meta_v1.GetOptions{})
svc, err := s.Client.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
if err != nil {
return nil, err
}
@ -254,7 +254,7 @@ func (s *statusSync) runningAddresses() ([]string, error) {
}
// get information about all the pods running the ingress controller
pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(meta_v1.ListOptions{
pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(s.pod.Labels).String(),
})
if err != nil {
@ -272,7 +272,7 @@ func (s *statusSync) runningAddresses() ([]string, error) {
}
func (s *statusSync) isRunningMultiplePods() bool {
pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(meta_v1.ListOptions{
pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(s.pod.Labels).String(),
})
if err != nil {
@ -283,13 +283,13 @@ func (s *statusSync) isRunningMultiplePods() bool {
}
// sliceToStatus converts a slice of IP and/or hostnames to LoadBalancerIngress
func sliceToStatus(endpoints []string) []v1.LoadBalancerIngress {
lbi := []v1.LoadBalancerIngress{}
func sliceToStatus(endpoints []string) []apiv1.LoadBalancerIngress {
lbi := []apiv1.LoadBalancerIngress{}
for _, ep := range endpoints {
if net.ParseIP(ep) == nil {
lbi = append(lbi, v1.LoadBalancerIngress{Hostname: ep})
lbi = append(lbi, apiv1.LoadBalancerIngress{Hostname: ep})
} else {
lbi = append(lbi, v1.LoadBalancerIngress{IP: ep})
lbi = append(lbi, apiv1.LoadBalancerIngress{IP: ep})
}
}
@ -300,7 +300,7 @@ func sliceToStatus(endpoints []string) []v1.LoadBalancerIngress {
// updateStatus changes the status information of Ingress rules
// If the backend function CustomIngressStatus returns a value different
// of nil then it uses the returned value or the newIngressPoint values
func (s *statusSync) updateStatus(newIngressPoint []v1.LoadBalancerIngress) {
func (s *statusSync) updateStatus(newIngressPoint []apiv1.LoadBalancerIngress) {
ings := s.IngressLister.List()
var wg sync.WaitGroup
wg.Add(len(ings))
@ -315,7 +315,7 @@ func (s *statusSync) updateStatus(newIngressPoint []v1.LoadBalancerIngress) {
go func(wg *sync.WaitGroup, ing *extensions.Ingress) {
defer wg.Done()
ingClient := s.Client.Extensions().Ingresses(ing.Namespace)
currIng, err := ingClient.Get(ing.Name, meta_v1.GetOptions{})
currIng, err := ingClient.Get(ing.Name, metav1.GetOptions{})
if err != nil {
glog.Errorf("unexpected error searching Ingress %v/%v: %v", ing.Namespace, ing.Name, err)
return
@ -346,7 +346,7 @@ func (s *statusSync) updateStatus(newIngressPoint []v1.LoadBalancerIngress) {
wg.Wait()
}
func ingressSliceEqual(lhs, rhs []v1.LoadBalancerIngress) bool {
func ingressSliceEqual(lhs, rhs []apiv1.LoadBalancerIngress) bool {
if len(lhs) != len(rhs) {
return false
}
@ -363,7 +363,7 @@ func ingressSliceEqual(lhs, rhs []v1.LoadBalancerIngress) bool {
}
// loadBalancerIngressByIP sorts LoadBalancerIngress using the field IP
type loadBalancerIngressByIP []v1.LoadBalancerIngress
type loadBalancerIngressByIP []apiv1.LoadBalancerIngress
func (c loadBalancerIngressByIP) Len() int { return len(c) }
func (c loadBalancerIngressByIP) Swap(i, j int) { c[i], c[j] = c[j], c[i] }

View file

@ -22,21 +22,21 @@ import (
"testing"
"time"
api_v1 "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/pkg/api"
"k8s.io/ingress/core/pkg/ingress/annotations/class"
cache_store "k8s.io/ingress/core/pkg/ingress/store"
"k8s.io/ingress/core/pkg/ingress/store"
"k8s.io/ingress/core/pkg/k8s"
"k8s.io/ingress/core/pkg/task"
)
func buildLoadBalancerIngressByIP() loadBalancerIngressByIP {
return []api_v1.LoadBalancerIngress{
return []apiv1.LoadBalancerIngress{
{
IP: "10.0.0.1",
Hostname: "foo1",
@ -58,100 +58,100 @@ func buildLoadBalancerIngressByIP() loadBalancerIngressByIP {
func buildSimpleClientSet() *testclient.Clientset {
return testclient.NewSimpleClientset(
&api_v1.PodList{Items: []api_v1.Pod{
&apiv1.PodList{Items: []apiv1.Pod{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo1",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
Labels: map[string]string{
"lable_sig": "foo_pod",
},
},
Spec: api_v1.PodSpec{
Spec: apiv1.PodSpec{
NodeName: "foo_node_2",
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo2",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
Labels: map[string]string{
"lable_sig": "foo_no",
},
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo3",
Namespace: api.NamespaceSystem,
Labels: map[string]string{
"lable_sig": "foo_pod",
},
},
Spec: api_v1.PodSpec{
Spec: apiv1.PodSpec{
NodeName: "foo_node_2",
},
},
}},
&api_v1.ServiceList{Items: []api_v1.Service{
&apiv1.ServiceList{Items: []apiv1.Service{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
Status: api_v1.ServiceStatus{
LoadBalancer: api_v1.LoadBalancerStatus{
Status: apiv1.ServiceStatus{
LoadBalancer: apiv1.LoadBalancerStatus{
Ingress: buildLoadBalancerIngressByIP(),
},
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_non_exist",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
},
}},
&api_v1.NodeList{Items: []api_v1.Node{
&apiv1.NodeList{Items: []apiv1.Node{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_node_1",
},
Status: api_v1.NodeStatus{
Addresses: []api_v1.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api_v1.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
}, {
Type: api_v1.NodeExternalIP,
Type: apiv1.NodeExternalIP,
Address: "10.0.0.2",
},
},
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_node_2",
},
Status: api_v1.NodeStatus{
Addresses: []api_v1.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api_v1.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "11.0.0.1",
},
{
Type: api_v1.NodeExternalIP,
Type: apiv1.NodeExternalIP,
Address: "11.0.0.2",
},
},
},
},
}},
&api_v1.EndpointsList{Items: []api_v1.Endpoints{
&apiv1.EndpointsList{Items: []apiv1.Endpoints{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "ingress-controller-leader",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
SelfLink: "/api/v1/namespaces/default/endpoints/ingress-controller-leader",
},
}}},
@ -166,13 +166,13 @@ func fakeSynFn(interface{}) error {
func buildExtensionsIngresses() []extensions.Ingress {
return []extensions.Ingress{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_ingress_1",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
Status: extensions.IngressStatus{
LoadBalancer: api_v1.LoadBalancerStatus{
Ingress: []api_v1.LoadBalancerIngress{
LoadBalancer: apiv1.LoadBalancerStatus{
Ingress: []apiv1.LoadBalancerIngress{
{
IP: "10.0.0.1",
Hostname: "foo1",
@ -182,7 +182,7 @@ func buildExtensionsIngresses() []extensions.Ingress {
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_ingress_different_class",
Namespace: api.NamespaceDefault,
Annotations: map[string]string{
@ -190,8 +190,8 @@ func buildExtensionsIngresses() []extensions.Ingress {
},
},
Status: extensions.IngressStatus{
LoadBalancer: api_v1.LoadBalancerStatus{
Ingress: []api_v1.LoadBalancerIngress{
LoadBalancer: apiv1.LoadBalancerStatus{
Ingress: []apiv1.LoadBalancerIngress{
{
IP: "0.0.0.0",
Hostname: "foo.bar.com",
@ -201,45 +201,45 @@ func buildExtensionsIngresses() []extensions.Ingress {
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_ingress_2",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
Status: extensions.IngressStatus{
LoadBalancer: api_v1.LoadBalancerStatus{
Ingress: []api_v1.LoadBalancerIngress{},
LoadBalancer: apiv1.LoadBalancerStatus{
Ingress: []apiv1.LoadBalancerIngress{},
},
},
},
}
}
func buildIngressListener() cache_store.IngressLister {
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
store.Add(&extensions.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
func buildIngressListener() store.IngressLister {
s := cache.NewStore(cache.MetaNamespaceKeyFunc)
s.Add(&extensions.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_ingress_non_01",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
}})
store.Add(&extensions.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
s.Add(&extensions.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "foo_ingress_1",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
},
Status: extensions.IngressStatus{
LoadBalancer: api_v1.LoadBalancerStatus{
LoadBalancer: apiv1.LoadBalancerStatus{
Ingress: buildLoadBalancerIngressByIP(),
},
},
})
return cache_store.IngressLister{Store: store}
return store.IngressLister{Store: s}
}
func buildStatusSync() statusSync {
return statusSync{
pod: &k8s.PodInfo{
Name: "foo_base_pod",
Namespace: api_v1.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
Labels: map[string]string{
"lable_sig": "foo_pod",
},
@ -247,9 +247,9 @@ func buildStatusSync() statusSync {
syncQueue: task.NewTaskQueue(fakeSynFn),
Config: Config{
Client: buildSimpleClientSet(),
PublishService: api_v1.NamespaceDefault + "/" + "foo",
PublishService: apiv1.NamespaceDefault + "/" + "foo",
IngressLister: buildIngressListener(),
CustomIngressStatus: func(*extensions.Ingress) []api_v1.LoadBalancerIngress {
CustomIngressStatus: func(*extensions.Ingress) []apiv1.LoadBalancerIngress {
return nil
},
},
@ -259,7 +259,7 @@ func buildStatusSync() statusSync {
func TestStatusActions(t *testing.T) {
// make sure election can be created
os.Setenv("POD_NAME", "foo1")
os.Setenv("POD_NAMESPACE", api_v1.NamespaceDefault)
os.Setenv("POD_NAMESPACE", apiv1.NamespaceDefault)
c := Config{
Client: buildSimpleClientSet(),
PublishService: "",
@ -267,7 +267,7 @@ func TestStatusActions(t *testing.T) {
DefaultIngressClass: "nginx",
IngressClass: "",
UpdateStatusOnShutdown: true,
CustomIngressStatus: func(*extensions.Ingress) []api_v1.LoadBalancerIngress {
CustomIngressStatus: func(*extensions.Ingress) []apiv1.LoadBalancerIngress {
return nil
},
}
@ -288,10 +288,10 @@ func TestStatusActions(t *testing.T) {
fk.sync("just-test")
// PublishService is empty, so the running address is: ["11.0.0.2"]
// after updated, the ingress's ip should only be "11.0.0.2"
newIPs := []api_v1.LoadBalancerIngress{{
newIPs := []apiv1.LoadBalancerIngress{{
IP: "11.0.0.2",
}}
fooIngress1, err1 := fk.Client.Extensions().Ingresses(api_v1.NamespaceDefault).Get("foo_ingress_1", meta_v1.GetOptions{})
fooIngress1, err1 := fk.Client.Extensions().Ingresses(apiv1.NamespaceDefault).Get("foo_ingress_1", metav1.GetOptions{})
if err1 != nil {
t.Fatalf("unexpected error")
}
@ -303,8 +303,8 @@ func TestStatusActions(t *testing.T) {
// execute shutdown
fk.Shutdown()
// ingress should be empty
newIPs2 := []api_v1.LoadBalancerIngress{}
fooIngress2, err2 := fk.Client.Extensions().Ingresses(api_v1.NamespaceDefault).Get("foo_ingress_1", meta_v1.GetOptions{})
newIPs2 := []apiv1.LoadBalancerIngress{}
fooIngress2, err2 := fk.Client.Extensions().Ingresses(apiv1.NamespaceDefault).Get("foo_ingress_1", metav1.GetOptions{})
if err2 != nil {
t.Fatalf("unexpected error")
}
@ -313,7 +313,7 @@ func TestStatusActions(t *testing.T) {
t.Fatalf("returned %v but expected %v", fooIngress2CurIPs, newIPs2)
}
oic, err := fk.Client.Extensions().Ingresses(api.NamespaceDefault).Get("foo_ingress_different_class", meta_v1.GetOptions{})
oic, err := fk.Client.Extensions().Ingresses(api.NamespaceDefault).Get("foo_ingress_different_class", metav1.GetOptions{})
if err != nil {
t.Fatalf("unexpected error")
}
@ -379,7 +379,7 @@ func TestUpdateStatus(t *testing.T) {
sort.Sort(loadBalancerIngressByIP(newIPs))
fk.updateStatus(newIPs)
fooIngress1, err1 := fk.Client.Extensions().Ingresses(api_v1.NamespaceDefault).Get("foo_ingress_1", meta_v1.GetOptions{})
fooIngress1, err1 := fk.Client.Extensions().Ingresses(apiv1.NamespaceDefault).Get("foo_ingress_1", metav1.GetOptions{})
if err1 != nil {
t.Fatalf("unexpected error")
}
@ -388,13 +388,13 @@ func TestUpdateStatus(t *testing.T) {
t.Fatalf("returned %v but expected %v", fooIngress1CurIPs, newIPs)
}
fooIngress2, err2 := fk.Client.Extensions().Ingresses(api_v1.NamespaceDefault).Get("foo_ingress_2", meta_v1.GetOptions{})
fooIngress2, err2 := fk.Client.Extensions().Ingresses(apiv1.NamespaceDefault).Get("foo_ingress_2", metav1.GetOptions{})
if err2 != nil {
t.Fatalf("unexpected error")
}
fooIngress2CurIPs := fooIngress2.Status.LoadBalancer.Ingress
if !ingressSliceEqual(fooIngress2CurIPs, []api_v1.LoadBalancerIngress{}) {
t.Fatalf("returned %v but expected %v", fooIngress2CurIPs, []api_v1.LoadBalancerIngress{})
if !ingressSliceEqual(fooIngress2CurIPs, []apiv1.LoadBalancerIngress{}) {
t.Fatalf("returned %v but expected %v", fooIngress2CurIPs, []apiv1.LoadBalancerIngress{})
}
}
@ -408,7 +408,7 @@ func TestSliceToStatus(t *testing.T) {
r := sliceToStatus(fkEndpoints)
if r == nil {
t.Fatalf("returned nil but expected a valid []api_v1.LoadBalancerIngress")
t.Fatalf("returned nil but expected a valid []apiv1.LoadBalancerIngress")
}
rl := len(r)
if rl != 3 {
@ -416,21 +416,21 @@ func TestSliceToStatus(t *testing.T) {
}
re1 := r[0]
if re1.Hostname != "opensource-k8s-ingress" {
t.Fatalf("returned %v but expected %v", re1, api_v1.LoadBalancerIngress{Hostname: "opensource-k8s-ingress"})
t.Fatalf("returned %v but expected %v", re1, apiv1.LoadBalancerIngress{Hostname: "opensource-k8s-ingress"})
}
re2 := r[1]
if re2.IP != "10.0.0.1" {
t.Fatalf("returned %v but expected %v", re2, api_v1.LoadBalancerIngress{IP: "10.0.0.1"})
t.Fatalf("returned %v but expected %v", re2, apiv1.LoadBalancerIngress{IP: "10.0.0.1"})
}
re3 := r[2]
if re3.IP != "2001:db8::68" {
t.Fatalf("returned %v but expected %v", re3, api_v1.LoadBalancerIngress{IP: "2001:db8::68"})
t.Fatalf("returned %v but expected %v", re3, apiv1.LoadBalancerIngress{IP: "2001:db8::68"})
}
}
func TestIngressSliceEqual(t *testing.T) {
fk1 := buildLoadBalancerIngressByIP()
fk2 := append(buildLoadBalancerIngressByIP(), api_v1.LoadBalancerIngress{
fk2 := append(buildLoadBalancerIngressByIP(), apiv1.LoadBalancerIngress{
IP: "10.0.0.5",
Hostname: "foo5",
})
@ -440,8 +440,8 @@ func TestIngressSliceEqual(t *testing.T) {
fk4[2].IP = "11.0.0.3"
fooTests := []struct {
lhs []api_v1.LoadBalancerIngress
rhs []api_v1.LoadBalancerIngress
lhs []apiv1.LoadBalancerIngress
rhs []apiv1.LoadBalancerIngress
er bool
}{
{fk1, fk1, true},
@ -450,7 +450,7 @@ func TestIngressSliceEqual(t *testing.T) {
{fk4, fk1, false},
{fk1, nil, false},
{nil, nil, true},
{[]api_v1.LoadBalancerIngress{}, []api_v1.LoadBalancerIngress{}, true},
{[]apiv1.LoadBalancerIngress{}, []apiv1.LoadBalancerIngress{}, true},
}
for _, fooTest := range fooTests {
@ -466,7 +466,7 @@ func TestLoadBalancerIngressByIPLen(t *testing.T) {
ips loadBalancerIngressByIP
el int
}{
{[]api_v1.LoadBalancerIngress{}, 0},
{[]apiv1.LoadBalancerIngress{}, 0},
{buildLoadBalancerIngressByIP(), 4},
{nil, 0},
}

View file

@ -21,7 +21,7 @@ import (
"github.com/spf13/pflag"
api "k8s.io/api/core/v1"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apiserver/pkg/server/healthz"
@ -78,7 +78,7 @@ type Controller interface {
//
OnUpdate(Configuration) error
// ConfigMap content of --configmap
SetConfig(*api.ConfigMap)
SetConfig(*apiv1.ConfigMap)
// SetListers allows the access of store listers present in the generic controller
// This avoid the use of the kubernetes client.
SetListers(StoreLister)
@ -97,7 +97,7 @@ type Controller interface {
// UpdateIngressStatus custom callback used to update the status in an Ingress rule
// This allows custom implementations
// If the function returns nil the standard functions will be executed.
UpdateIngressStatus(*extensions.Ingress) []api.LoadBalancerIngress
UpdateIngressStatus(*extensions.Ingress) []apiv1.LoadBalancerIngress
// DefaultEndpoint returns the Endpoint to use as default when the
// referenced service does not exists. This should return the content
// of to the default backend
@ -152,9 +152,9 @@ type Configuration struct {
// Backend describes one or more remote server/s (endpoints) associated with a service
// +k8s:deepcopy-gen=true
type Backend struct {
// Name represents an unique api.Service name formatted as <namespace>-<name>-<port>
// Name represents an unique apiv1.Service name formatted as <namespace>-<name>-<port>
Name string `json:"name"`
Service *api.Service `json:"service,omitempty"`
Service *apiv1.Service `json:"service,omitempty"`
Port intstr.IntOrString `json:"port"`
// This indicates if the communication protocol between the backend and the endpoint is HTTP or HTTPS
// Allowing the use of HTTPS
@ -208,7 +208,7 @@ type Endpoint struct {
// to consider the endpoint unavailable
FailTimeout int `json:"failTimeout"`
// Target returns a reference to the object providing the endpoint
Target *api.ObjectReference `json:"target,omipempty"`
Target *apiv1.ObjectReference `json:"target,omipempty"`
}
// Server describes a website
@ -270,7 +270,7 @@ type Location struct {
// Backend describes the name of the backend to use.
Backend string `json:"backend"`
// Service describes the referenced services from the ingress
Service *api.Service `json:"service,omitempty"`
Service *apiv1.Service `json:"service,omitempty"`
// Port describes to which port from the service
Port intstr.IntOrString `json:"port"`
// Overwrite the Host header passed into the backend. Defaults to
@ -326,7 +326,7 @@ type Location struct {
ClientBodyBufferSize string `json:"clientBodyBufferSize,omitempty"`
// DefaultBackend allows the use of a custom default backend for this location.
// +optional
DefaultBackend *api.Service `json:"defaultBackend,omitempty"`
DefaultBackend *apiv1.Service `json:"defaultBackend,omitempty"`
}
// SSLPassthroughBackend describes a SSL upstream server configured
@ -334,7 +334,7 @@ type Location struct {
// The endpoints must provide the TLS termination exposing the required SSL certificate.
// The ingress controller only pipes the underlying TCP connection
type SSLPassthroughBackend struct {
Service *api.Service `json:"service,omitEmpty"`
Service *apiv1.Service `json:"service,omitEmpty"`
Port intstr.IntOrString `json:"port"`
// Backend describes the endpoints to use.
Backend string `json:"namespace,omitempty"`
@ -357,7 +357,7 @@ type L4Backend struct {
Port intstr.IntOrString `json:"port"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Protocol api.Protocol `json:"protocol"`
Protocol apiv1.Protocol `json:"protocol"`
// +optional
UseProxyProtocol bool `json:"useProxyProtocol"`
}

View file

@ -21,8 +21,8 @@ import (
"os"
"strings"
api "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
)
@ -39,20 +39,20 @@ func ParseNameNS(input string) (string, string, error) {
// GetNodeIP returns the IP address of a node in the cluster
func GetNodeIP(kubeClient clientset.Interface, name string) string {
var externalIP string
node, err := kubeClient.Core().Nodes().Get(name, meta_v1.GetOptions{})
node, err := kubeClient.Core().Nodes().Get(name, metav1.GetOptions{})
if err != nil {
return externalIP
}
for _, address := range node.Status.Addresses {
if address.Type == api.NodeExternalIP {
if address.Type == apiv1.NodeExternalIP {
if address.Address != "" {
externalIP = address.Address
break
}
}
if externalIP == "" && address.Type == api.NodeInternalIP {
if externalIP == "" && address.Type == apiv1.NodeInternalIP {
externalIP = address.Address
}
}
@ -79,7 +79,7 @@ func GetPodDetails(kubeClient clientset.Interface) (*PodInfo, error) {
return nil, fmt.Errorf("unable to get POD information (missing POD_NAME or POD_NAMESPACE environment variable")
}
pod, _ := kubeClient.Core().Pods(podNs).Get(podName, meta_v1.GetOptions{})
pod, _ := kubeClient.Core().Pods(podNs).Get(podName, metav1.GetOptions{})
if pod == nil {
return nil, fmt.Errorf("unable to get POD information")
}

View file

@ -20,8 +20,8 @@ import (
"os"
"testing"
api "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"
)
@ -66,14 +66,14 @@ func TestGetNodeIP(t *testing.T) {
{testclient.NewSimpleClientset(), "demo", ""},
// node not exist
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
ObjectMeta: meta_v1.ObjectMeta{
{testclient.NewSimpleClientset(&apiv1.NodeList{Items: []apiv1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
},
},
@ -81,14 +81,14 @@ func TestGetNodeIP(t *testing.T) {
}}}), "notexistnode", ""},
// node exist
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
ObjectMeta: meta_v1.ObjectMeta{
{testclient.NewSimpleClientset(&apiv1.NodeList{Items: []apiv1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
},
},
@ -96,28 +96,28 @@ func TestGetNodeIP(t *testing.T) {
}}}), "demo", "10.0.0.1"},
// search the correct node
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{
{testclient.NewSimpleClientset(&apiv1.NodeList{Items: []apiv1.Node{
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "demo1",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
},
},
},
},
{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "demo2",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.2",
},
},
@ -126,17 +126,17 @@ func TestGetNodeIP(t *testing.T) {
}}), "demo2", "10.0.0.2"},
// get NodeExternalIP
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
ObjectMeta: meta_v1.ObjectMeta{
{testclient.NewSimpleClientset(&apiv1.NodeList{Items: []apiv1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
}, {
Type: api.NodeExternalIP,
Type: apiv1.NodeExternalIP,
Address: "10.0.0.2",
},
},
@ -144,17 +144,17 @@ func TestGetNodeIP(t *testing.T) {
}}}), "demo", "10.0.0.2"},
// get NodeInternalIP
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
ObjectMeta: meta_v1.ObjectMeta{
{testclient.NewSimpleClientset(&apiv1.NodeList{Items: []apiv1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeExternalIP,
Type: apiv1.NodeExternalIP,
Address: "",
}, {
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.2",
},
},
@ -181,7 +181,7 @@ func TestGetPodDetails(t *testing.T) {
// POD_NAME not exist
os.Setenv("POD_NAME", "")
os.Setenv("POD_NAMESPACE", api.NamespaceDefault)
os.Setenv("POD_NAMESPACE", apiv1.NamespaceDefault)
_, err2 := GetPodDetails(testclient.NewSimpleClientset())
if err2 == nil {
t.Errorf("expected an error but returned nil")
@ -197,7 +197,7 @@ func TestGetPodDetails(t *testing.T) {
// POD not exist
os.Setenv("POD_NAME", "testpod")
os.Setenv("POD_NAMESPACE", api.NamespaceDefault)
os.Setenv("POD_NAMESPACE", apiv1.NamespaceDefault)
_, err4 := GetPodDetails(testclient.NewSimpleClientset())
if err4 == nil {
t.Errorf("expected an error but returned nil")
@ -205,24 +205,24 @@ func TestGetPodDetails(t *testing.T) {
// success to get PodInfo
fkClient := testclient.NewSimpleClientset(
&api.PodList{Items: []api.Pod{{
ObjectMeta: meta_v1.ObjectMeta{
&apiv1.PodList{Items: []apiv1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
Namespace: api.NamespaceDefault,
Namespace: apiv1.NamespaceDefault,
Labels: map[string]string{
"first": "first_label",
"second": "second_label",
},
},
}}},
&api.NodeList{Items: []api.Node{{
ObjectMeta: meta_v1.ObjectMeta{
&apiv1.NodeList{Items: []apiv1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
},
Status: api.NodeStatus{
Addresses: []api.NodeAddress{
Status: apiv1.NodeStatus{
Addresses: []apiv1.NodeAddress{
{
Type: api.NodeInternalIP,
Type: apiv1.NodeInternalIP,
Address: "10.0.0.1",
},
},

View file

@ -36,6 +36,7 @@ import (
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/ingress/core/pkg/file"
"k8s.io/ingress/core/pkg/ingress"
)

View file

@ -25,6 +25,7 @@ import (
certutil "k8s.io/client-go/util/cert"
"k8s.io/client-go/util/cert/triple"
"k8s.io/ingress/core/pkg/ingress"
)