Skip to content

Commit

Permalink
Moving protocol to subpackage (istio#15925)
Browse files Browse the repository at this point in the history
This is part of the cleanup of pkg/config. Planning on moving everything here to subpackages.
  • Loading branch information
nmittler authored and istio-testing committed Jul 30, 2019
1 parent 2c1b5dc commit 3573752
Show file tree
Hide file tree
Showing 65 changed files with 536 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"istio.io/istio/galley/pkg/config/processor/transforms/serviceentry/pod"
"istio.io/istio/galley/pkg/config/resource"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"

coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -195,27 +196,27 @@ func TestServicePorts(t *testing.T) {
cases := []struct {
name string
proto coreV1.Protocol
out config.Protocol
out protocol.Instance
}{
{"", coreV1.ProtocolTCP, config.ProtocolTCP},
{"http", coreV1.ProtocolTCP, config.ProtocolHTTP},
{"http-test", coreV1.ProtocolTCP, config.ProtocolHTTP},
{"http", coreV1.ProtocolUDP, config.ProtocolUDP},
{"httptest", coreV1.ProtocolTCP, config.ProtocolTCP},
{"https", coreV1.ProtocolTCP, config.ProtocolHTTPS},
{"https-test", coreV1.ProtocolTCP, config.ProtocolHTTPS},
{"http2", coreV1.ProtocolTCP, config.ProtocolHTTP2},
{"http2-test", coreV1.ProtocolTCP, config.ProtocolHTTP2},
{"grpc", coreV1.ProtocolTCP, config.ProtocolGRPC},
{"grpc-test", coreV1.ProtocolTCP, config.ProtocolGRPC},
{"grpc-web", coreV1.ProtocolTCP, config.ProtocolGRPCWeb},
{"grpc-web-test", coreV1.ProtocolTCP, config.ProtocolGRPCWeb},
{"mongo", coreV1.ProtocolTCP, config.ProtocolMongo},
{"mongo-test", coreV1.ProtocolTCP, config.ProtocolMongo},
{"redis", coreV1.ProtocolTCP, config.ProtocolRedis},
{"redis-test", coreV1.ProtocolTCP, config.ProtocolRedis},
{"mysql", coreV1.ProtocolTCP, config.ProtocolMySQL},
{"mysql-test", coreV1.ProtocolTCP, config.ProtocolMySQL},
{"", coreV1.ProtocolTCP, protocol.TCP},
{"http", coreV1.ProtocolTCP, protocol.HTTP},
{"http-test", coreV1.ProtocolTCP, protocol.HTTP},
{"http", coreV1.ProtocolUDP, protocol.UDP},
{"httptest", coreV1.ProtocolTCP, protocol.TCP},
{"https", coreV1.ProtocolTCP, protocol.HTTPS},
{"https-test", coreV1.ProtocolTCP, protocol.HTTPS},
{"http2", coreV1.ProtocolTCP, protocol.HTTP2},
{"http2-test", coreV1.ProtocolTCP, protocol.HTTP2},
{"grpc", coreV1.ProtocolTCP, protocol.GRPC},
{"grpc-test", coreV1.ProtocolTCP, protocol.GRPC},
{"grpc-web", coreV1.ProtocolTCP, protocol.GRPCWeb},
{"grpc-web-test", coreV1.ProtocolTCP, protocol.GRPCWeb},
{"mongo", coreV1.ProtocolTCP, protocol.Mongo},
{"mongo-test", coreV1.ProtocolTCP, protocol.Mongo},
{"redis", coreV1.ProtocolTCP, protocol.Redis},
{"redis-test", coreV1.ProtocolTCP, protocol.Redis},
{"mysql", coreV1.ProtocolTCP, protocol.MySQL},
{"mysql-test", coreV1.ProtocolTCP, protocol.MySQL},
}

ip := "10.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

mcp "istio.io/api/mcp/v1alpha1"
networking "istio.io/api/networking/v1alpha3"

"istio.io/istio/galley/pkg/config/collection"
"istio.io/istio/galley/pkg/config/event"
"istio.io/istio/galley/pkg/config/meshcfg"
Expand All @@ -41,7 +40,7 @@ import (
"istio.io/istio/galley/pkg/config/processor/transforms/serviceentry/pod"
"istio.io/istio/galley/pkg/config/resource"
"istio.io/istio/galley/pkg/config/testing/fixtures"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
"istio.io/istio/pkg/mcp/snapshot"

coreV1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1060,7 +1059,7 @@ func (b *serviceEntryBuilder) Build() *networking.ServiceEntry {
{
Name: "http",
Number: 80,
Protocol: string(config.ProtocolHTTP),
Protocol: string(protocol.HTTP),
},
},
SubjectAltNames: expectedSubjectAltNames(ns, b.serviceAccounts),
Expand Down
5 changes: 3 additions & 2 deletions galley/pkg/runtime/conversions/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"istio.io/istio/galley/pkg/metadata"
"istio.io/istio/galley/pkg/runtime/resource"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
"istio.io/pkg/log"

ingress "k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -199,7 +200,7 @@ func IngressToGateway(key resource.VersionedKey, meta resource.Metadata, i *ingr
gateway.Servers = append(gateway.Servers, &v1alpha3.Server{
Port: &v1alpha3.Port{
Number: 443,
Protocol: string(config.ProtocolHTTPS),
Protocol: string(protocol.HTTPS),
Name: fmt.Sprintf("https-443-i-%s-%s", name, namespace),
},
Hosts: tls.Hosts,
Expand All @@ -220,7 +221,7 @@ func IngressToGateway(key resource.VersionedKey, meta resource.Metadata, i *ingr
gateway.Servers = append(gateway.Servers, &v1alpha3.Server{
Port: &v1alpha3.Port{
Number: 80,
Protocol: string(config.ProtocolHTTP),
Protocol: string(protocol.HTTP),
Name: fmt.Sprintf("http-80-i-%s-%s", name, namespace),
},
Hosts: []string{"*"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"istio.io/istio/galley/pkg/runtime/projections/serviceentry/pod"
"istio.io/istio/galley/pkg/runtime/resource"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"

coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -373,27 +374,27 @@ func TestServicePorts(t *testing.T) {
cases := []struct {
name string
proto coreV1.Protocol
out config.Protocol
out protocol.Instance
}{
{"", coreV1.ProtocolTCP, config.ProtocolTCP},
{"http", coreV1.ProtocolTCP, config.ProtocolHTTP},
{"http-test", coreV1.ProtocolTCP, config.ProtocolHTTP},
{"http", coreV1.ProtocolUDP, config.ProtocolUDP},
{"httptest", coreV1.ProtocolTCP, config.ProtocolTCP},
{"https", coreV1.ProtocolTCP, config.ProtocolHTTPS},
{"https-test", coreV1.ProtocolTCP, config.ProtocolHTTPS},
{"http2", coreV1.ProtocolTCP, config.ProtocolHTTP2},
{"http2-test", coreV1.ProtocolTCP, config.ProtocolHTTP2},
{"grpc", coreV1.ProtocolTCP, config.ProtocolGRPC},
{"grpc-test", coreV1.ProtocolTCP, config.ProtocolGRPC},
{"grpc-web", coreV1.ProtocolTCP, config.ProtocolGRPCWeb},
{"grpc-web-test", coreV1.ProtocolTCP, config.ProtocolGRPCWeb},
{"mongo", coreV1.ProtocolTCP, config.ProtocolMongo},
{"mongo-test", coreV1.ProtocolTCP, config.ProtocolMongo},
{"redis", coreV1.ProtocolTCP, config.ProtocolRedis},
{"redis-test", coreV1.ProtocolTCP, config.ProtocolRedis},
{"mysql", coreV1.ProtocolTCP, config.ProtocolMySQL},
{"mysql-test", coreV1.ProtocolTCP, config.ProtocolMySQL},
{"", coreV1.ProtocolTCP, protocol.TCP},
{"http", coreV1.ProtocolTCP, protocol.HTTP},
{"http-test", coreV1.ProtocolTCP, protocol.HTTP},
{"http", coreV1.ProtocolUDP, protocol.UDP},
{"httptest", coreV1.ProtocolTCP, protocol.TCP},
{"https", coreV1.ProtocolTCP, protocol.HTTPS},
{"https-test", coreV1.ProtocolTCP, protocol.HTTPS},
{"http2", coreV1.ProtocolTCP, protocol.HTTP2},
{"http2-test", coreV1.ProtocolTCP, protocol.HTTP2},
{"grpc", coreV1.ProtocolTCP, protocol.GRPC},
{"grpc-test", coreV1.ProtocolTCP, protocol.GRPC},
{"grpc-web", coreV1.ProtocolTCP, protocol.GRPCWeb},
{"grpc-web-test", coreV1.ProtocolTCP, protocol.GRPCWeb},
{"mongo", coreV1.ProtocolTCP, protocol.Mongo},
{"mongo-test", coreV1.ProtocolTCP, protocol.Mongo},
{"redis", coreV1.ProtocolTCP, protocol.Redis},
{"redis-test", coreV1.ProtocolTCP, protocol.Redis},
{"mysql", coreV1.ProtocolTCP, protocol.MySQL},
{"mysql-test", coreV1.ProtocolTCP, protocol.MySQL},
}

ip := "10.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"strconv"
"testing"

coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"istio.io/istio/galley/pkg/metadata"
"istio.io/istio/galley/pkg/runtime/processing"
"istio.io/istio/galley/pkg/runtime/projections/serviceentry"
"istio.io/istio/galley/pkg/runtime/projections/serviceentry/pod"
"istio.io/istio/galley/pkg/runtime/resource"

coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
Expand Down
9 changes: 4 additions & 5 deletions galley/pkg/runtime/projections/serviceentry/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"time"

"github.com/gogo/protobuf/types"
coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"istio.io/api/annotation"
mcp "istio.io/api/mcp/v1alpha1"
Expand All @@ -33,10 +35,7 @@ import (
"istio.io/istio/galley/pkg/runtime/projections/serviceentry"
"istio.io/istio/galley/pkg/runtime/projections/serviceentry/pod"
"istio.io/istio/galley/pkg/runtime/resource"
"istio.io/istio/pkg/config"

coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"istio.io/istio/pkg/config/protocol"
)

const (
Expand Down Expand Up @@ -945,7 +944,7 @@ func (b *serviceEntryBuilder) Build() *networking.ServiceEntry {
{
Name: "http",
Number: 80,
Protocol: string(config.ProtocolHTTP),
Protocol: string(protocol.HTTP),
},
},
SubjectAltNames: expectedSubjectAltNames(ns, b.serviceAccounts),
Expand Down
10 changes: 5 additions & 5 deletions istioctl/pkg/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"os"
"strings"

"github.com/hashicorp/go-multierror"
multierror "github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"

mixercrd "istio.io/istio/mixer/pkg/config/crd"
mixerstore "istio.io/istio/mixer/pkg/config/store"
Expand All @@ -32,7 +32,7 @@ import (
"istio.io/istio/pilot/pkg/config/kube/crd"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
"istio.io/pkg/log"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -328,8 +328,8 @@ func servicePortPrefixed(n string) bool {
if i >= 0 {
n = n[:i]
}
protocol := config.ParseProtocol(n)
return protocol == config.ProtocolUnsupported
p := protocol.Parse(n)
return p == protocol.Unsupported
}
func handleNamespace(istioNamespace string) string {
if istioNamespace == "" {
Expand Down
10 changes: 5 additions & 5 deletions pilot/pkg/config/kube/ingress/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
"strings"

"github.com/hashicorp/go-multierror"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"

meshconfig "istio.io/api/mesh/v1alpha1"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/serviceregistry/kube"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
"istio.io/pkg/log"

"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// EncodeIngressRuleName encodes an ingress rule name for a given ingress resource name,
Expand Down Expand Up @@ -81,7 +81,7 @@ func ConvertIngressV1alpha3(ingress v1beta1.Ingress, domainSuffix string) model.
gateway.Servers = append(gateway.Servers, &networking.Server{
Port: &networking.Port{
Number: 443,
Protocol: string(config.ProtocolHTTPS),
Protocol: string(protocol.HTTPS),
Name: fmt.Sprintf("https-443-ingress-%s-%s", ingress.Name, ingress.Namespace),
},
Hosts: tls.Hosts,
Expand All @@ -102,7 +102,7 @@ func ConvertIngressV1alpha3(ingress v1beta1.Ingress, domainSuffix string) model.
gateway.Servers = append(gateway.Servers, &networking.Server{
Port: &networking.Port{
Number: 80,
Protocol: string(config.ProtocolHTTP),
Protocol: string(protocol.HTTP),
Name: fmt.Sprintf("http-80-ingress-%s-%s", ingress.Name, ingress.Namespace),
},
Hosts: []string{"*"},
Expand Down
19 changes: 10 additions & 9 deletions pilot/pkg/model/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"istio.io/istio/pilot/pkg/model"
mock_config "istio.io/istio/pilot/test/mock"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
)

// getByMessageName finds a schema by message name if it is available
Expand Down Expand Up @@ -96,8 +97,8 @@ func TestEventString(t *testing.T) {

func TestPortList(t *testing.T) {
pl := model.PortList{
{Name: "http", Port: 80, Protocol: config.ProtocolHTTP},
{Name: "http-alt", Port: 8080, Protocol: config.ProtocolHTTP},
{Name: "http", Port: 80, Protocol: protocol.HTTP},
{Name: "http-alt", Port: 8080, Protocol: protocol.HTTP},
}

gotNames := pl.GetNames()
Expand Down Expand Up @@ -130,7 +131,7 @@ func TestServiceKey(t *testing.T) {
// Verify Service.Key() delegates to ServiceKey()
{
want := "hostname|http|a=b,c=d"
port := &model.Port{Name: "http", Port: 80, Protocol: config.ProtocolHTTP}
port := &model.Port{Name: "http", Port: 80, Protocol: protocol.HTTP}
labels := config.Labels{"a": "b", "c": "d"}
got := svc.Key(port, labels)
if !reflect.DeepEqual(got, want) {
Expand All @@ -145,19 +146,19 @@ func TestServiceKey(t *testing.T) {
}{
{
port: model.PortList{
{Name: "http", Port: 80, Protocol: config.ProtocolHTTP},
{Name: "http-alt", Port: 8080, Protocol: config.ProtocolHTTP},
{Name: "http", Port: 80, Protocol: protocol.HTTP},
{Name: "http-alt", Port: 8080, Protocol: protocol.HTTP},
},
labels: config.LabelsCollection{{"a": "b", "c": "d"}},
want: "hostname|http,http-alt|a=b,c=d",
},
{
port: model.PortList{{Name: "http", Port: 80, Protocol: config.ProtocolHTTP}},
port: model.PortList{{Name: "http", Port: 80, Protocol: protocol.HTTP}},
labels: config.LabelsCollection{{"a": "b", "c": "d"}},
want: "hostname|http|a=b,c=d",
},
{
port: model.PortList{{Port: 80, Protocol: config.ProtocolHTTP}},
port: model.PortList{{Port: 80, Protocol: protocol.HTTP}},
labels: config.LabelsCollection{{"a": "b", "c": "d"}},
want: "hostname||a=b,c=d",
},
Expand All @@ -167,12 +168,12 @@ func TestServiceKey(t *testing.T) {
want: "hostname||a=b,c=d",
},
{
port: model.PortList{{Name: "http", Port: 80, Protocol: config.ProtocolHTTP}},
port: model.PortList{{Name: "http", Port: 80, Protocol: protocol.HTTP}},
labels: config.LabelsCollection{nil},
want: "hostname|http",
},
{
port: model.PortList{{Name: "http", Port: 80, Protocol: config.ProtocolHTTP}},
port: model.PortList{{Name: "http", Port: 80, Protocol: protocol.HTTP}},
labels: config.LabelsCollection{},
want: "hostname|http",
},
Expand Down
17 changes: 9 additions & 8 deletions pilot/pkg/model/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/monitoring"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/protocol"
)

// MergedGateway describes a set of gateways for a workload merged into a single logical gateway.
Expand Down Expand Up @@ -90,7 +91,7 @@ func MergeGateways(gateways ...Config) *MergedGateway {
sanitizeServerHostNamespace(s, gatewayConfig.Namespace)
gatewayNameForServer[s] = gatewayName
log.Debugf("MergeGateways: gateway %q processing server %v", gatewayName, s.Hosts)
protocol := config.ParseProtocol(s.Port.Protocol)
p := protocol.Parse(s.Port.Protocol)

if s.Tls != nil {
// Envoy will reject config that has multiple filter chain matches with the same matching rules
Expand All @@ -113,11 +114,11 @@ func MergeGateways(gateways ...Config) *MergedGateway {
// for each server (as each server ends up as a separate http connection manager due to filter chain match
// 3. No for everything else.

if p, exists := plaintextServers[s.Port.Number]; exists {
currentProto := config.ParseProtocol(p[0].Port.Protocol)
if currentProto != protocol || !protocol.IsHTTP() {
if server, exists := plaintextServers[s.Port.Number]; exists {
currentProto := protocol.Parse(server[0].Port.Protocol)
if currentProto != p || !p.IsHTTP() {
log.Debugf("skipping server on gateway %s port %s.%d.%s: conflict with existing server %s.%d.%s",
gatewayConfig.Name, s.Port.Name, s.Port.Number, s.Port.Protocol, p[0].Port.Name, p[0].Port.Number, p[0].Port.Protocol)
gatewayConfig.Name, s.Port.Name, s.Port.Number, s.Port.Protocol, server[0].Port.Name, server[0].Port.Number, server[0].Port.Protocol)
recordRejectedConfig(gatewayName)
continue
}
Expand Down Expand Up @@ -245,12 +246,12 @@ func checkDuplicates(hosts []string, knownHosts map[string]struct{}) []string {
// different ports, the optimization (one RDS instead of two) could quickly become useless the moment the set of
// hosts on the two servers start differing -- necessitating the need for two different RDS routes.
func gatewayRDSRouteName(server *networking.Server, cfg Config) string {
protocol := config.ParseProtocol(server.Port.Protocol)
if protocol.IsHTTP() {
p := protocol.Parse(server.Port.Protocol)
if p.IsHTTP() {
return fmt.Sprintf("http.%d", server.Port.Number)
}

if protocol == config.ProtocolHTTPS && server.Tls != nil && !config.IsPassThroughServer(server) {
if p == protocol.HTTPS && server.Tls != nil && !config.IsPassThroughServer(server) {
return fmt.Sprintf("https.%d.%s.%s.%s",
server.Port.Number, server.Port.Name, cfg.Name, cfg.Namespace)
}
Expand Down
Loading

0 comments on commit 3573752

Please sign in to comment.