mirror of https://github.com/linkerd/linkerd2.git
Move controller/util and web/util packages to pkg (#1109)
Signed-off-by: Kevin Lingerfelt <kl@buoyant.io>
This commit is contained in:
parent
b6d429e80d
commit
9f1df963e9
|
|
@ -5,7 +5,6 @@ COPY cli cli
|
|||
COPY controller/k8s controller/k8s
|
||||
COPY controller/api controller/api
|
||||
COPY controller/gen controller/gen
|
||||
COPY controller/util controller/util
|
||||
COPY pkg pkg
|
||||
RUN mkdir -p /out
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import (
|
|||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
apiUtil "github.com/runconduit/conduit/controller/api/util"
|
||||
"github.com/runconduit/conduit/controller/api/util"
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
|
@ -73,7 +73,7 @@ func newCmdTap() *cobra.Command {
|
|||
# tap the test namespace, filter by request to prod namespace
|
||||
conduit tap ns/test --to ns/prod`,
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
ValidArgs: apiUtil.ValidTargets,
|
||||
ValidArgs: util.ValidTargets,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
req, err := buildTapByResourceRequest(args, options)
|
||||
if err != nil {
|
||||
|
|
@ -114,22 +114,22 @@ func buildTapByResourceRequest(
|
|||
options *tapOptions,
|
||||
) (*pb.TapByResourceRequest, error) {
|
||||
|
||||
target, err := apiUtil.BuildResource(options.namespace, resource...)
|
||||
target, err := util.BuildResource(options.namespace, resource...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("target resource invalid: %s", err)
|
||||
}
|
||||
if !contains(apiUtil.ValidTargets, target.Type) {
|
||||
if !contains(util.ValidTargets, target.Type) {
|
||||
return nil, fmt.Errorf("unsupported resource type [%s]", target.Type)
|
||||
}
|
||||
|
||||
matches := []*pb.TapByResourceRequest_Match{}
|
||||
|
||||
if options.toResource != "" {
|
||||
destination, err := apiUtil.BuildResource(options.toNamespace, options.toResource)
|
||||
destination, err := util.BuildResource(options.toNamespace, options.toResource)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("destination resource invalid: %s", err)
|
||||
}
|
||||
if !contains(apiUtil.ValidDestinations, destination.Type) {
|
||||
if !contains(util.ValidDestinations, destination.Type) {
|
||||
return nil, fmt.Errorf("unsupported resource type [%s]", target.Type)
|
||||
}
|
||||
|
||||
|
|
@ -241,7 +241,7 @@ func writeTapEventsToBuffer(tapClient pb.Api_TapByResourceClient, w *tabwriter.W
|
|||
}
|
||||
|
||||
func renderTapEvent(event *common.TapEvent) string {
|
||||
dst := util.AddressToString(event.GetDestination())
|
||||
dst := addr.AddressToString(event.GetDestination())
|
||||
dstLabels := event.GetDestinationMeta().GetLabels()
|
||||
dstPod := dstLabels["pod"]
|
||||
isSecured := "no"
|
||||
|
|
@ -255,7 +255,7 @@ func renderTapEvent(event *common.TapEvent) string {
|
|||
}
|
||||
|
||||
flow := fmt.Sprintf("src=%s dst=%s",
|
||||
util.AddressToString(event.GetSource()),
|
||||
addr.AddressToString(event.GetSource()),
|
||||
dst,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/golang/protobuf/ptypes/duration"
|
||||
"github.com/runconduit/conduit/controller/api/public"
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
"github.com/runconduit/conduit/pkg/k8s"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
|
@ -185,11 +185,11 @@ func TestEventToString(t *testing.T) {
|
|||
|
||||
return &common.TapEvent{
|
||||
Source: &common.TcpAddress{
|
||||
Ip: util.IPV4(1, 2, 3, 4),
|
||||
Ip: addr.IPV4(1, 2, 3, 4),
|
||||
Port: 5555,
|
||||
},
|
||||
Destination: &common.TcpAddress{
|
||||
Ip: util.IPV4(2, 3, 4, 5),
|
||||
Ip: addr.IPV4(2, 3, 4, 5),
|
||||
Port: 6666,
|
||||
},
|
||||
Event: &common.TapEvent_Http_{Http: httpEvent},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
destination "github.com/runconduit/conduit/controller/gen/proxy/destination"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
|
@ -58,7 +58,7 @@ func NewServer(addr string, destinationClient destination.DestinationClient) (*g
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
s := util.NewGrpcServer()
|
||||
s := prometheus.NewGrpcServer()
|
||||
srv := server{destinationClient: destinationClient}
|
||||
destination.RegisterDestinationServer(s, &srv)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
tapPb "github.com/runconduit/conduit/controller/gen/controller/tap"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
|
@ -209,7 +209,7 @@ func NewServer(
|
|||
),
|
||||
}
|
||||
|
||||
instrumentedHandler := util.WithTelemetry(baseHandler)
|
||||
instrumentedHandler := prometheus.WithTelemetry(baseHandler)
|
||||
|
||||
return &http.Server{
|
||||
Addr: addr,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/runconduit/conduit/controller/destination"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
"github.com/runconduit/conduit/pkg/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
|
@ -60,7 +60,7 @@ func main() {
|
|||
server.Serve(lis)
|
||||
}()
|
||||
|
||||
go util.NewMetricsServer(*metricsAddr)
|
||||
go prometheus.NewMetricsServer(*metricsAddr)
|
||||
|
||||
<-stop
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/runconduit/conduit/controller/api/proxy"
|
||||
"github.com/runconduit/conduit/controller/destination"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
"github.com/runconduit/conduit/pkg/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
|
@ -49,7 +49,7 @@ func main() {
|
|||
server.Serve(lis)
|
||||
}()
|
||||
|
||||
go util.NewMetricsServer(*metricsAddr)
|
||||
go prometheus.NewMetricsServer(*metricsAddr)
|
||||
|
||||
<-stop
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/runconduit/conduit/controller/api/public"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/tap"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
"github.com/runconduit/conduit/pkg/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
|
@ -79,7 +79,7 @@ func main() {
|
|||
server.ListenAndServe()
|
||||
}()
|
||||
|
||||
go util.NewMetricsServer(*metricsAddr)
|
||||
go prometheus.NewMetricsServer(*metricsAddr)
|
||||
|
||||
<-stop
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/tap"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
"github.com/runconduit/conduit/pkg/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
|
@ -57,7 +57,7 @@ func main() {
|
|||
server.Serve(lis)
|
||||
}()
|
||||
|
||||
go util.NewMetricsServer(*metricsAddr)
|
||||
go prometheus.NewMetricsServer(*metricsAddr)
|
||||
|
||||
<-stop
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
|
@ -345,14 +345,14 @@ func (sp *servicePort) updateService(newService *v1.Service) {
|
|||
}
|
||||
|
||||
func (sp *servicePort) updateAddresses(newAddresses []common.TcpAddress) {
|
||||
log.Debugf("Updating %s:%d to %s", sp.service, sp.port, util.AddressesToString(newAddresses))
|
||||
log.Debugf("Updating %s:%d to %s", sp.service, sp.port, addr.AddressesToString(newAddresses))
|
||||
|
||||
if len(newAddresses) == 0 {
|
||||
for _, listener := range sp.listeners {
|
||||
listener.NoEndpoints(true)
|
||||
}
|
||||
} else {
|
||||
add, remove := util.DiffAddresses(sp.addresses, newAddresses)
|
||||
add, remove := addr.DiffAddresses(sp.addresses, newAddresses)
|
||||
for _, listener := range sp.listeners {
|
||||
listener.Update(add, remove)
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ func addresses(endpoints *v1.Endpoints, port intstr.IntOrString) []common.TcpAdd
|
|||
ips := make([]common.IPAddress, 0)
|
||||
for _, subset := range endpoints.Subsets {
|
||||
for _, address := range subset.Addresses {
|
||||
ip, err := util.ParseIPV4(address.IP)
|
||||
ip, err := addr.ParseIPV4(address.IP)
|
||||
if err != nil {
|
||||
log.Printf("%s is not a valid IP address", address.IP)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
)
|
||||
|
||||
func TestEndpointsWatcher(t *testing.T) {
|
||||
|
|
@ -126,7 +126,7 @@ spec:
|
|||
|
||||
actualAddresses := make([]string, 0)
|
||||
for _, add := range listener.added {
|
||||
actualAddresses = append(actualAddresses, util.AddressToString(&add))
|
||||
actualAddresses = append(actualAddresses, addr.AddressToString(&add))
|
||||
}
|
||||
sort.Strings(actualAddresses)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package destination
|
|||
import (
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/proxy/destination"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
pkgK8s "github.com/runconduit/conduit/pkg/k8s"
|
||||
log "github.com/sirupsen/logrus"
|
||||
coreV1 "k8s.io/api/core/v1"
|
||||
|
|
@ -88,7 +88,7 @@ func (l *endpointListener) toWeightedAddrSet(endpoints []common.TcpAddress) *pb.
|
|||
func (l *endpointListener) toWeightedAddr(address common.TcpAddress) *pb.WeightedAddr {
|
||||
var tlsIdentity *pb.TlsIdentity
|
||||
metricLabelsForPod := map[string]string{}
|
||||
ipAsString := util.IPToString(address.Ip)
|
||||
ipAsString := addr.IPToString(address.Ip)
|
||||
|
||||
resultingPods, err := l.podsByIp(ipAsString)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/proxy/destination"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/addr"
|
||||
pkgK8s "github.com/runconduit/conduit/pkg/k8s"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -112,7 +112,7 @@ func TestEndpointListener(t *testing.T) {
|
|||
expectedReplicationControllerName := "rc-name"
|
||||
|
||||
addedAddress1 := common.TcpAddress{Ip: &common.IPAddress{Ip: &common.IPAddress_Ipv4{Ipv4: 666}}, Port: 1}
|
||||
ipForAddr1 := util.IPToString(addedAddress1.Ip)
|
||||
ipForAddr1 := addr.IPToString(addedAddress1.Ip)
|
||||
podForAddedAddress1 := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: expectedPodName,
|
||||
|
|
@ -169,7 +169,7 @@ func TestEndpointListener(t *testing.T) {
|
|||
}
|
||||
|
||||
addedAddress := common.TcpAddress{Ip: &common.IPAddress{Ip: &common.IPAddress_Ipv4{Ipv4: 666}}, Port: 1}
|
||||
ipForAddr := util.IPToString(addedAddress.Ip)
|
||||
ipForAddr := addr.IPToString(addedAddress.Ip)
|
||||
podForAddedAddress := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: expectedPodName,
|
||||
|
|
@ -213,7 +213,7 @@ func TestEndpointListener(t *testing.T) {
|
|||
expectedConduitNamespace := "conduit-namespace"
|
||||
|
||||
addedAddress := common.TcpAddress{Ip: &common.IPAddress{Ip: &common.IPAddress_Ipv4{Ipv4: 666}}, Port: 1}
|
||||
ipForAddr := util.IPToString(addedAddress.Ip)
|
||||
ipForAddr := addr.IPToString(addedAddress.Ip)
|
||||
podForAddedAddress := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: expectedPodName,
|
||||
|
|
@ -304,7 +304,7 @@ func TestEndpointListener(t *testing.T) {
|
|||
backingMap := map[string][]*v1.Pod{}
|
||||
|
||||
for _, pod := range exp.pods {
|
||||
ipForAddr := util.IPToString(exp.address.Ip)
|
||||
ipForAddr := addr.IPToString(exp.address.Ip)
|
||||
podForAddedAddress := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: pod.pod,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/proxy/destination"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
"k8s.io/api/core/v1"
|
||||
|
|
@ -52,7 +52,7 @@ func NewServer(addr, k8sDNSZone string, enableTLS bool, k8sAPI *k8s.API, done ch
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
s := util.NewGrpcServer()
|
||||
s := prometheus.NewGrpcServer()
|
||||
pb.RegisterDestinationServer(s, &srv)
|
||||
|
||||
go func() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/runconduit/conduit/controller/destination"
|
||||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/proxy/destination"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
addrUtil "github.com/runconduit/conduit/pkg/addr"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func main() {
|
|||
log.Println("Add:")
|
||||
log.Printf("labels: %v", updateType.Add.MetricLabels)
|
||||
for _, addr := range updateType.Add.Addrs {
|
||||
log.Printf("- %s:%d", util.IPToString(addr.Addr.GetIp()), addr.Addr.Port)
|
||||
log.Printf("- %s:%d", addrUtil.IPToString(addr.Addr.GetIp()), addr.Addr.Port)
|
||||
log.Printf(" - labels: %v", addr.MetricLabels)
|
||||
switch identityType := addr.GetTlsIdentity().GetStrategy().(type) {
|
||||
case *pb.TlsIdentity_K8SPodNamespace_:
|
||||
|
|
@ -64,7 +64,7 @@ func main() {
|
|||
case *pb.Update_Remove:
|
||||
log.Println("Remove:")
|
||||
for _, addr := range updateType.Remove.Addrs {
|
||||
log.Printf("- %s:%d", util.IPToString(addr.GetIp()), addr.Port)
|
||||
log.Printf("- %s:%d", addrUtil.IPToString(addr.GetIp()), addr.Port)
|
||||
}
|
||||
log.Println()
|
||||
case *pb.Update_NoEndpoints:
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ import (
|
|||
proxy "github.com/runconduit/conduit/controller/gen/proxy/tap"
|
||||
public "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/controller/k8s"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
pkgK8s "github.com/runconduit/conduit/pkg/k8s"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
|
@ -291,7 +291,7 @@ func NewServer(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
s := util.NewGrpcServer()
|
||||
s := prometheus.NewGrpcServer()
|
||||
srv := server{
|
||||
tapPort: tapPort,
|
||||
k8sAPI: k8sAPI,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package util
|
||||
package addr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package util
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/web/util/filesonly"
|
||||
"github.com/runconduit/conduit/pkg/filesonly"
|
||||
"github.com/runconduit/conduit/pkg/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ func NewServer(addr, templateDir, staticDir, uuid, controllerNamespace, webpackD
|
|||
HandleMethodNotAllowed: false, // disable 405s
|
||||
}
|
||||
|
||||
wrappedServer := util.WithTelemetry(server)
|
||||
wrappedServer := prometheus.WithTelemetry(server)
|
||||
handler := &handler{
|
||||
apiClient: apiClient,
|
||||
render: server.RenderTemplate,
|
||||
|
|
|
|||
Loading…
Reference in New Issue