Skip to content

Commit

Permalink
interal: Update contour package to xdscache and rename imports
Browse files Browse the repository at this point in the history
Renames the `contour` package to `xdscache` and fixes up all the imports
to make them consistent across the project.

Fixes projectcontour#2938
Fixes projectcontour#2939

Signed-off-by: Steve Sloka <slokas@vmware.com>
  • Loading branch information
stevesloka committed Sep 24, 2020
1 parent 80c2c3a commit 3eee4df
Show file tree
Hide file tree
Showing 80 changed files with 3,736 additions and 3,742 deletions.
10 changes: 5 additions & 5 deletions apis/projectcontour/v1alpha1/extensionservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package v1alpha1

import (
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ type ExtensionServiceSpec struct {

// UpstreamValidation defines how to verify the backend service's certificate
// +optional
UpstreamValidation *contourv1.UpstreamValidation `json:"validation,omitempty"`
UpstreamValidation *contour_api_v1.UpstreamValidation `json:"validation,omitempty"`

// Protocol may be used to specify (or override) the protocol used to reach this Service.
// Values may be tls, h2, h2c. If omitted, protocol-selection falls back on Service annotations.
Expand All @@ -79,12 +79,12 @@ type ExtensionServiceSpec struct {
// that the `Cookie` load balancing strategy cannot be used here.
//
// +optional
LoadBalancerPolicy *contourv1.LoadBalancerPolicy `json:"loadBalancerPolicy,omitempty"`
LoadBalancerPolicy *contour_api_v1.LoadBalancerPolicy `json:"loadBalancerPolicy,omitempty"`

// The timeout policy for requests to the services.
//
// +optional
TimeoutPolicy *contourv1.TimeoutPolicy `json:"timeoutPolicy,omitempty"`
TimeoutPolicy *contour_api_v1.TimeoutPolicy `json:"timeoutPolicy,omitempty"`

// This field sets the version of the GRPC protocol that Envoy uses to
// send requests to the extension service. Since Contour always uses the
Expand All @@ -111,7 +111,7 @@ type ExtensionServiceStatus struct {
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []contourv1.DetailedCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
Conditions []contour_api_v1.DetailedCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

// +genclient
Expand Down
4 changes: 2 additions & 2 deletions cmd/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/projectcontour/contour/internal/build"
envoyv2 "github.com/projectcontour/contour/internal/envoy/v2"
envoy_v2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/projectcontour/contour/internal/k8s"
"github.com/sirupsen/logrus"
kingpin "gopkg.in/alecthomas/kingpin.v2"
Expand Down Expand Up @@ -69,7 +69,7 @@ func main() {
case sdmShutdown.FullCommand():
sdmShutdownCtx.shutdownHandler()
case bootstrap.FullCommand():
if err := envoyv2.WriteBootstrap(bootstrapCtx); err != nil {
if err := envoy_v2.WriteBootstrap(bootstrapCtx); err != nil {
log.WithError(err).Fatal("failed to write bootstrap configuration")
}
case certgenApp.FullCommand():
Expand Down
4 changes: 2 additions & 2 deletions cmd/contour/ingressstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strings"
"sync"

projcontour "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/internal/k8s"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -99,7 +99,7 @@ func (isw *loadBalancerStatusWriter) Start(stop <-chan struct{}) error {
// Create new informer for the new LoadBalancerStatus
factory := isw.clients.NewInformerFactory()
factory.ForResource(v1beta1.SchemeGroupVersion.WithResource("ingresses")).Informer().AddEventHandler(sau)
factory.ForResource(projcontour.HTTPProxyGVR).Informer().AddEventHandler(sau)
factory.ForResource(contour_api_v1.HTTPProxyGVR).Informer().AddEventHandler(sau)

shutdown = make(chan struct{})
ingressInformers.Add(1)
Expand Down
38 changes: 19 additions & 19 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import (

"github.com/envoyproxy/go-control-plane/pkg/cache/v2"
"github.com/envoyproxy/go-control-plane/pkg/server/v2"
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/contour"
contourv2 "github.com/projectcontour/contour/internal/contour/v2"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/debug"
"github.com/projectcontour/contour/internal/health"
Expand All @@ -39,6 +37,8 @@ import (
"github.com/projectcontour/contour/internal/timeout"
"github.com/projectcontour/contour/internal/workgroup"
"github.com/projectcontour/contour/internal/xds"
"github.com/projectcontour/contour/internal/xdscache"
xdscache_v2 "github.com/projectcontour/contour/internal/xdscache/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand Down Expand Up @@ -156,7 +156,7 @@ func validateCRDs(dynamicClient dynamic.Interface, log logrus.FieldLogger) {
for _, crd := range crds.Items {
log = log.WithField("crd", crd.GetName())

if group, _, _ := unstructured.NestedString(crd.Object, "spec", "group"); group != contourv1.GroupName {
if group, _, _ := unstructured.NestedString(crd.Object, "spec", "group"); group != contour_api_v1.GroupName {
log.Debugf("CRD is not in projectcontour.io API group, ignoring")
continue
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
return fmt.Errorf("error parsing request timeout: %w", err)
}

listenerConfig := contourv2.ListenerConfig{
listenerConfig := xdscache_v2.ListenerConfig{
UseProxyProto: ctx.useProxyProto,
HTTPAddress: ctx.httpAddr,
HTTPPort: ctx.httpPort,
Expand Down Expand Up @@ -276,13 +276,13 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {

// Endpoints updates are handled directly by the EndpointsTranslator
// due to their high update rate and their orthogonal nature.
endpointHandler := contourv2.NewEndpointsTranslator(log.WithField("context", "endpointstranslator"))
endpointHandler := xdscache_v2.NewEndpointsTranslator(log.WithField("context", "endpointstranslator"))

resources := []contour.ResourceCache{
contourv2.NewListenerCache(listenerConfig, ctx.statsAddr, ctx.statsPort),
&contourv2.SecretCache{},
&contourv2.RouteCache{},
&contourv2.ClusterCache{},
resources := []xdscache.ResourceCache{
xdscache_v2.NewListenerCache(listenerConfig, ctx.statsAddr, ctx.statsPort),
&xdscache_v2.SecretCache{},
&xdscache_v2.RouteCache{},
&xdscache_v2.ClusterCache{},
endpointHandler,
}

Expand All @@ -292,21 +292,21 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
log.WithField("context", "xDS"))

// snapshotHandler is used to produce new snapshots when the internal state changes for any xDS resource.
snapshotHandler := contour.NewSnapshotHandler(snapshotCache, resources, log.WithField("context", "snapshotHandler"))
snapshotHandler := xdscache.NewSnapshotHandler(snapshotCache, resources, log.WithField("context", "snapshotHandler"))

// register observer for endpoints updates.
endpointHandler.Observer = contour.ComposeObservers(snapshotHandler)
endpointHandler.Observer = xdscache.ComposeObservers(snapshotHandler)

dnsLookupFamily, err := ParseDNSLookupFamily(ctx.DNSLookupFamily)
if err != nil {
return fmt.Errorf("failed to configure configuration file parameter cluster.dns-lookup-family: %w", err)
}

// Build the core Kubernetes event handler.
eventHandler := &contour.EventHandler{
eventHandler := &xdscache.EventHandler{
HoldoffDelay: 100 * time.Millisecond,
HoldoffMaxDelay: 500 * time.Millisecond,
Observer: dag.ComposeObservers(append(contour.ObserversOf(resources), snapshotHandler)...),
Observer: dag.ComposeObservers(append(xdscache.ObserversOf(resources), snapshotHandler)...),
Builder: dag.Builder{
Source: dag.KubernetesCache{
RootNamespaces: ctx.proxyRootNamespaces(),
Expand Down Expand Up @@ -339,7 +339,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
// Wrap eventHandler in a converter for objects from the dynamic client.
// and an EventRecorder which tracks API server events.
dynamicHandler := &k8s.DynamicClientHandler{
Next: &contour.EventRecorder{
Next: &xdscache.EventRecorder{
Next: eventHandler,
Counter: contourMetrics.EventHandlerOperations,
},
Expand Down Expand Up @@ -376,7 +376,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {

informerSyncList.InformOnResources(clusterInformerFactory,
&k8s.DynamicClientHandler{
Next: &contour.EventRecorder{
Next: &xdscache.EventRecorder{
Next: endpointHandler,
Counter: contourMetrics.EventHandlerOperations,
},
Expand Down Expand Up @@ -444,7 +444,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {

// Once we have the leadership detection channel, we can
// push DAG rebuild metrics onto the observer stack.
eventHandler.Observer = &contour.RebuildMetricsObserver{
eventHandler.Observer = &xdscache.RebuildMetricsObserver{
Metrics: contourMetrics,
IsLeader: eventHandler.IsLeader,
NextObserver: eventHandler.Observer,
Expand Down Expand Up @@ -514,7 +514,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
switch ctx.XDSServerType {
case "contour":
grpcServer = xds.RegisterServer(
xds.NewContourServer(log, contour.ResourcesOf(resources)...),
xds.NewContourServer(log, xdscache.ResourcesOf(resources)...),
registry,
ctx.grpcOptions(log)...)
case "envoy":
Expand Down
18 changes: 9 additions & 9 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"
"time"

contourv2 "github.com/projectcontour/contour/internal/contour/v2"
envoyv2 "github.com/projectcontour/contour/internal/envoy/v2"
envoy_v2 "github.com/projectcontour/contour/internal/envoy/v2"
xdscache_v2 "github.com/projectcontour/contour/internal/xdscache/v2"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -166,8 +166,8 @@ func newServeContext() *serveContext {
healthPort: 8000,
metricsAddr: "0.0.0.0",
metricsPort: 8000,
httpAccessLog: contourv2.DEFAULT_HTTP_ACCESS_LOG,
httpsAccessLog: contourv2.DEFAULT_HTTPS_ACCESS_LOG,
httpAccessLog: xdscache_v2.DEFAULT_HTTP_ACCESS_LOG,
httpsAccessLog: xdscache_v2.DEFAULT_HTTPS_ACCESS_LOG,
httpAddr: "0.0.0.0",
httpsAddr: "0.0.0.0",
httpPort: 8080,
Expand Down Expand Up @@ -444,21 +444,21 @@ func ParseDNSLookupFamily(value string) (string, error) {

// parseDefaultHTTPVersions parses a list of supported HTTP versions
// (of the form "HTTP/xx") into a slice of unique version constants.
func parseDefaultHTTPVersions(versions []string) ([]envoyv2.HTTPVersionType, error) {
wanted := map[envoyv2.HTTPVersionType]struct{}{}
func parseDefaultHTTPVersions(versions []string) ([]envoy_v2.HTTPVersionType, error) {
wanted := map[envoy_v2.HTTPVersionType]struct{}{}

for _, v := range versions {
switch strings.ToLower(v) {
case "http/1.1":
wanted[envoyv2.HTTPVersion1] = struct{}{}
wanted[envoy_v2.HTTPVersion1] = struct{}{}
case "http/2":
wanted[envoyv2.HTTPVersion2] = struct{}{}
wanted[envoy_v2.HTTPVersion2] = struct{}{}
default:
return nil, fmt.Errorf("invalid HTTP protocol version %q", v)
}
}

var parsed []envoyv2.HTTPVersionType
var parsed []envoy_v2.HTTPVersionType
for k := range wanted {
parsed = append(parsed, k)

Expand Down
10 changes: 5 additions & 5 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
envoyv2 "github.com/projectcontour/contour/internal/envoy/v2"
envoy_v2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/projectcontour/contour/internal/fixture"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestParseHTTPVersions(t *testing.T) {
cases := map[string]struct {
versions []string
parseError error
parseVersions []envoyv2.HTTPVersionType
parseVersions []envoy_v2.HTTPVersionType
}{
"empty": {
versions: []string{},
Expand All @@ -484,17 +484,17 @@ func TestParseHTTPVersions(t *testing.T) {
"http/1.1": {
versions: []string{"http/1.1", "HTTP/1.1"},
parseError: nil,
parseVersions: []envoyv2.HTTPVersionType{envoyv2.HTTPVersion1},
parseVersions: []envoy_v2.HTTPVersionType{envoy_v2.HTTPVersion1},
},
"http/1.1+http/2": {
versions: []string{"http/1.1", "http/2"},
parseError: nil,
parseVersions: []envoyv2.HTTPVersionType{envoyv2.HTTPVersion1, envoyv2.HTTPVersion2},
parseVersions: []envoy_v2.HTTPVersionType{envoy_v2.HTTPVersion1, envoy_v2.HTTPVersion2},
},
"http/1.1+http/2 duplicated": {
versions: []string{"http/1.1", "http/2", "http/1.1", "http/2"},
parseError: nil,
parseVersions: []envoyv2.HTTPVersionType{envoyv2.HTTPVersion1, envoyv2.HTTPVersion2},
parseVersions: []envoy_v2.HTTPVersionType{envoy_v2.HTTPVersion1, envoy_v2.HTTPVersion2},
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/contour/shutdownmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"time"

contourv2 "github.com/projectcontour/contour/internal/contour/v2"
xdscache_v2 "github.com/projectcontour/contour/internal/xdscache/v2"
"github.com/prometheus/common/expfmt"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
Expand All @@ -40,7 +40,7 @@ const shutdownReadyFile = "/ok"
const shutdownReadyCheckInterval = time.Second * 1

func prometheusLabels() []string {
return []string{contourv2.ENVOY_HTTP_LISTENER, contourv2.ENVOY_HTTPS_LISTENER}
return []string{xdscache_v2.ENVOY_HTTP_LISTENER, xdscache_v2.ENVOY_HTTPS_LISTENER}
}

type shutdownmanagerContext struct {
Expand Down
10 changes: 5 additions & 5 deletions internal/annotation/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"fmt"
"testing"

projectcontour "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"k8s.io/api/networking/v1beta1"
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestAnnotationKindValidation(t *testing.T) {
},
},
"httpproxy": {
obj: &projectcontour.HTTPProxy{},
obj: &contour_api_v1.HTTPProxy{},
annotations: map[string]status{
// Valid only on Service.
"projectcontour.io/max-requests": {
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestAnnotationKindValidation(t *testing.T) {
for _, kind := range []string{
kindOf(&v1.Service{}),
kindOf(&v1beta1.Ingress{}),
kindOf(&projectcontour.HTTPProxy{}),
kindOf(&contour_api_v1.HTTPProxy{}),
} {
for key := range annotationsByKind[kind] {
t.Run(fmt.Sprintf("%s is known and valid for %s", key, kind),
Expand Down Expand Up @@ -588,9 +588,9 @@ func kindOf(obj interface{}) string {
return "Service"
case *v1beta1.Ingress:
return "Ingress"
case *projectcontour.HTTPProxy:
case *contour_api_v1.HTTPProxy:
return "HTTPProxy"
case *projectcontour.TLSCertificateDelegation:
case *contour_api_v1.TLSCertificateDelegation:
return "TLSCertificateDelegation"
default:
return ""
Expand Down
Loading

0 comments on commit 3eee4df

Please sign in to comment.