Move codes to pkg (#46)

This commit is contained in:
Yang
2022-11-09 20:37:40 +08:00
committed by GitHub
parent b09b68c1e0
commit ecba3a0265
54 changed files with 62 additions and 65 deletions

View File

@@ -30,7 +30,7 @@ jobs:
run: make build run: make build
- name: "run go test and out codecov" - name: "run go test and out codecov"
run: make prebuild; go test ./cmd/... ./ingress/... -race -coverprofile=coverage.out -covermode=atomic run: make prebuild; go test ./cmd/... ./pkg/... -race -coverprofile=coverage.out -covermode=atomic
- name: "upload coverage" - name: "upload coverage"
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v3

View File

@@ -15,6 +15,7 @@
package main package main
import ( import (
"fmt"
"os" "os"
"time" "time"
@@ -26,13 +27,10 @@ import (
"istio.io/pkg/log" "istio.io/pkg/log"
"istio.io/pkg/version" "istio.io/pkg/version"
"github.com/alibaba/higress/cmd/higress/bootstrap" "github.com/alibaba/higress/pkg/bootstrap"
) )
var ( var (
probeAddr string
enableLeaderElection bool
serverArgs *bootstrap.ServerArgs serverArgs *bootstrap.ServerArgs
loggingOptions = log.DefaultOptions() loggingOptions = log.DefaultOptions()
@@ -43,13 +41,10 @@ var (
serveCmd = &cobra.Command{ serveCmd = &cobra.Command{
Use: "serve", Use: "serve",
Aliases: []string{"serve"}, Aliases: []string{"serve"},
Short: "Starts the ingress controller", Short: "Starts the higress ingress controller",
Example: "higress serve", Example: "higress serve",
PreRunE: func(c *cobra.Command, args []string) error { PreRunE: func(c *cobra.Command, args []string) error {
if err := log.Configure(loggingOptions); err != nil { return log.Configure(loggingOptions)
return err
}
return nil
}, },
RunE: func(c *cobra.Command, args []string) error { RunE: func(c *cobra.Command, args []string) error {
cmd.PrintFlags(c.Flags()) cmd.PrintFlags(c.Flags())
@@ -59,10 +54,12 @@ var (
server, err := bootstrap.NewServer(serverArgs) server, err := bootstrap.NewServer(serverArgs)
if err != nil { if err != nil {
return err return fmt.Errorf("fail to create higress server: %v", err)
} }
server.Start(stop) if err := server.Start(stop); err != nil {
return fmt.Errorf("fail to start higress server: %v", err)
}
cmd.WaitSignal(stop) cmd.WaitSignal(stop)

View File

@@ -20,7 +20,6 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/alibaba/higress/ingress/kube/common"
prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
@@ -46,8 +45,9 @@ import (
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
ingressconfig "github.com/alibaba/higress/ingress/config" ingressconfig "github.com/alibaba/higress/pkg/ingress/config"
"github.com/alibaba/higress/ingress/mcp" "github.com/alibaba/higress/pkg/ingress/kube/common"
"github.com/alibaba/higress/pkg/ingress/mcp"
) )
type XdsOptions struct { type XdsOptions struct {

View File

@@ -37,13 +37,13 @@ import (
listersv1 "k8s.io/client-go/listers/core/v1" listersv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
"github.com/alibaba/higress/ingress/kube/ingress" "github.com/alibaba/higress/pkg/ingress/kube/ingress"
"github.com/alibaba/higress/ingress/kube/ingressv1" "github.com/alibaba/higress/pkg/ingress/kube/ingressv1"
secretkube "github.com/alibaba/higress/ingress/kube/secret/kube" secretkube "github.com/alibaba/higress/pkg/ingress/kube/secret/kube"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
var ( var (

View File

@@ -28,10 +28,10 @@ import (
ingress "k8s.io/api/networking/v1" ingress "k8s.io/api/networking/v1"
ingressv1beta1 "k8s.io/api/networking/v1beta1" ingressv1beta1 "k8s.io/api/networking/v1beta1"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
controllerv1beta1 "github.com/alibaba/higress/ingress/kube/ingress" controllerv1beta1 "github.com/alibaba/higress/pkg/ingress/kube/ingress"
controllerv1 "github.com/alibaba/higress/ingress/kube/ingressv1" controllerv1 "github.com/alibaba/higress/pkg/ingress/kube/ingressv1"
) )
func TestNormalizeWeightedCluster(t *testing.T) { func TestNormalizeWeightedCluster(t *testing.T) {

View File

@@ -21,8 +21,8 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
const ( const (

View File

@@ -29,7 +29,7 @@ import (
listerv1 "k8s.io/client-go/listers/core/v1" listerv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
) )
func TestAuthParse(t *testing.T) { func TestAuthParse(t *testing.T) {

View File

@@ -20,8 +20,8 @@ import (
networking "istio.io/api/networking/v1alpha3" networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/model" "istio.io/istio/pilot/pkg/model"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
const ( const (

View File

@@ -18,12 +18,13 @@ import (
"strings" "strings"
networking "istio.io/api/networking/v1alpha3" networking "istio.io/api/networking/v1alpha3"
"github.com/alibaba/higress/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log"
"istio.io/istio/pilot/pkg/credentials/kube" "istio.io/istio/pilot/pkg/credentials/kube"
"istio.io/istio/pilot/pkg/model" "istio.io/istio/pilot/pkg/model"
gatewaytool "istio.io/istio/pkg/config/gateway" gatewaytool "istio.io/istio/pkg/config/gateway"
"istio.io/istio/pkg/config/security" "istio.io/istio/pkg/config/security"
"github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/pkg/ingress/log"
) )
const ( const (

View File

@@ -19,7 +19,7 @@ import (
networking "istio.io/api/networking/v1alpha3" networking "istio.io/api/networking/v1alpha3"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
const ( const (

View File

@@ -22,7 +22,7 @@ import (
networking "istio.io/api/networking/v1alpha3" networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/model/credentials" "istio.io/istio/pilot/pkg/model/credentials"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
) )
const ( const (

View File

@@ -24,7 +24,7 @@ import (
listerv1 "k8s.io/client-go/listers/core/v1" listerv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
) )
type ServiceKey struct { type ServiceKey struct {

View File

@@ -28,7 +28,7 @@ import (
"istio.io/istio/pkg/config/schema/collections" "istio.io/istio/pkg/config/schema/collections"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
type PathType string type PathType string

View File

@@ -28,7 +28,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/version" "k8s.io/apimachinery/pkg/util/version"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
// V1Available check if the "networking/v1" Ingress is available. // V1Available check if the "networking/v1" Ingress is available.

View File

@@ -22,7 +22,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
) )
func TestConstructRouteName(t *testing.T) { func TestConstructRouteName(t *testing.T) {

View File

@@ -48,11 +48,11 @@ import (
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
"github.com/alibaba/higress/ingress/kube/secret" "github.com/alibaba/higress/pkg/ingress/kube/secret"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
var ( var (

View File

@@ -20,7 +20,7 @@ import (
"k8s.io/api/networking/v1beta1" "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
) )
func TestShouldProcessIngressUpdate(t *testing.T) { func TestShouldProcessIngressUpdate(t *testing.T) {

View File

@@ -16,6 +16,8 @@ package ingress
import ( import (
"context" "context"
common2 "github.com/alibaba/higress/pkg/ingress/kube/common"
. "github.com/alibaba/higress/pkg/ingress/log"
"reflect" "reflect"
"sort" "sort"
"time" "time"
@@ -28,9 +30,6 @@ import (
listerv1 "k8s.io/client-go/listers/core/v1" listerv1 "k8s.io/client-go/listers/core/v1"
ingresslister "k8s.io/client-go/listers/networking/v1beta1" ingresslister "k8s.io/client-go/listers/networking/v1beta1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/common"
. "github.com/alibaba/higress/ingress/log"
) )
// statusSyncer keeps the status IP in each Ingress resource updated // statusSyncer keeps the status IP in each Ingress resource updated
@@ -62,7 +61,7 @@ func newStatusSyncer(localKubeClient, client kubelib.Client, controller *control
func (s *statusSyncer) run(stopCh <-chan struct{}) { func (s *statusSyncer) run(stopCh <-chan struct{}) {
cache.WaitForCacheSync(stopCh, s.controller.HasSynced) cache.WaitForCacheSync(stopCh, s.controller.HasSynced)
ticker := time.NewTicker(common.DefaultStatusUpdateInterval) ticker := time.NewTicker(common2.DefaultStatusUpdateInterval)
for { for {
select { select {
case <-stopCh: case <-stopCh:
@@ -77,14 +76,14 @@ func (s *statusSyncer) run(stopCh <-chan struct{}) {
} }
func (s *statusSyncer) runUpdateStatus() error { func (s *statusSyncer) runUpdateStatus() error {
svcList, err := s.serviceLister.Services(s.watchedNamespace).List(common.SvcLabelSelector) svcList, err := s.serviceLister.Services(s.watchedNamespace).List(common2.SvcLabelSelector)
if err != nil { if err != nil {
return err return err
} }
IngressLog.Debugf("found number %d of svc", len(svcList)) IngressLog.Debugf("found number %d of svc", len(svcList))
lbStatusList := common.GetLbStatusList(svcList) lbStatusList := common2.GetLbStatusList(svcList)
if len(lbStatusList) == 0 { if len(lbStatusList) == 0 {
return nil return nil
} }
@@ -111,7 +110,7 @@ func (s *statusSyncer) updateStatus(status []coreV1.LoadBalancerIngress) error {
} }
curIPs := ingress.Status.LoadBalancer.Ingress curIPs := ingress.Status.LoadBalancer.Ingress
sort.SliceStable(curIPs, common.SortLbIngressList(curIPs)) sort.SliceStable(curIPs, common2.SortLbIngressList(curIPs))
if reflect.DeepEqual(status, curIPs) { if reflect.DeepEqual(status, curIPs) {
IngressLog.Debugf("skipping update of Ingress %v/%v within cluster %s (no change)", IngressLog.Debugf("skipping update of Ingress %v/%v within cluster %s (no change)",

View File

@@ -47,11 +47,11 @@ import (
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"github.com/alibaba/higress/ingress/kube/annotations" "github.com/alibaba/higress/pkg/ingress/kube/annotations"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
"github.com/alibaba/higress/ingress/kube/secret" "github.com/alibaba/higress/pkg/ingress/kube/secret"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
var ( var (

View File

@@ -20,7 +20,7 @@ import (
v1 "k8s.io/api/networking/v1" v1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
) )
func TestShouldProcessIngressUpdate(t *testing.T) { func TestShouldProcessIngressUpdate(t *testing.T) {

View File

@@ -29,8 +29,8 @@ import (
ingresslister "k8s.io/client-go/listers/networking/v1" ingresslister "k8s.io/client-go/listers/networking/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
// statusSyncer keeps the status IP in each Ingress resource updated // statusSyncer keeps the status IP in each Ingress resource updated

View File

@@ -33,10 +33,10 @@ import (
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"github.com/alibaba/higress/ingress/kube/common" "github.com/alibaba/higress/pkg/ingress/kube/common"
"github.com/alibaba/higress/ingress/kube/secret" "github.com/alibaba/higress/pkg/ingress/kube/secret"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
. "github.com/alibaba/higress/ingress/log" . "github.com/alibaba/higress/pkg/ingress/log"
) )
var _ secret.Controller = &controller{} var _ secret.Controller = &controller{}

View File

@@ -18,7 +18,7 @@ import (
listerv1 "k8s.io/client-go/listers/core/v1" listerv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"github.com/alibaba/higress/ingress/kube/util" "github.com/alibaba/higress/pkg/ingress/kube/util"
) )
type Controller interface { type Controller interface {