Skip to content

Commit 7380ee8

Browse files
kahirokunnhligit
authored andcommitted
Add --envoy-ingress-name, and --envoy-ingress-namespace flags. (#4952)
Signed-off-by: kahirokunn <[email protected]>
1 parent 4aee35a commit 7380ee8

File tree

8 files changed

+109
-0
lines changed

8 files changed

+109
-0
lines changed

apis/projectcontour/v1alpha1/contourconfig.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ type EnvoyConfig struct {
253253
// +optional
254254
Service *NamespacedName `json:"service,omitempty"`
255255

256+
// Ingress holds Envoy service parameters for setting Ingress status.
257+
//
258+
// Contour's default is { namespace: "projectcontour", name: "envoy" }.
259+
// +optional
260+
Ingress *NamespacedName `json:"ingress,omitempty"`
261+
256262
// Defines the HTTP Listener for Envoy.
257263
//
258264
// Contour's default is { address: "0.0.0.0", port: 8080, accessLog: "/dev/stdout" }.

cmd/contour/serve.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext)
145145
serve.Flag("envoy-service-https-port", "Kubernetes Service port for HTTPS requests.").PlaceHolder("<port>").IntVar(&ctx.httpsPort)
146146
serve.Flag("envoy-service-name", "Name of the Envoy service to inspect for Ingress status details.").PlaceHolder("<name>").StringVar(&ctx.Config.EnvoyServiceName)
147147
serve.Flag("envoy-service-namespace", "Envoy Service Namespace.").PlaceHolder("<namespace>").StringVar(&ctx.Config.EnvoyServiceNamespace)
148+
serve.Flag("envoy-ingress-name", "Name of the Envoy ingress to inspect for Ingress status details.").PlaceHolder("<name>").StringVar(&ctx.Config.EnvoyIngressName)
149+
serve.Flag("envoy-ingress-namespace", "Envoy Ingress Namespace.").PlaceHolder("<namespace>").StringVar(&ctx.Config.EnvoyIngressNamespace)
148150

149151
serve.Flag("health-address", "Address the health HTTP endpoint will bind to.").PlaceHolder("<ipaddr>").StringVar(&ctx.healthAddr)
150152
serve.Flag("health-port", "Port the health HTTP endpoint will bind to.").PlaceHolder("<port>").IntVar(&ctx.healthPort)
@@ -704,9 +706,28 @@ func (s *Server) doServe() error {
704706
s.log.WithError(err).WithField("resource", "services").Fatal("failed to create informer")
705707
}
706708

709+
ingressHandler := &k8s.IngressStatusLoadBalancerWatcher{
710+
ServiceName: contourConfiguration.Envoy.Service.Name,
711+
LBStatus: lbsw.lbStatus,
712+
Log: s.log.WithField("context", "ingressStatusLoadBalancerWatcher"),
713+
}
714+
715+
var ingressEventHandler cache.ResourceEventHandler = ingressHandler
716+
if contourConfiguration.Envoy.Ingress.Namespace != "" {
717+
handler = k8s.NewNamespaceFilter([]string{contourConfiguration.Envoy.Ingress.Namespace}, handler)
718+
}
719+
720+
if err := informOnResource(&networking_v1.Ingress{}, ingressEventHandler, s.mgr.GetCache()); err != nil {
721+
s.log.WithError(err).WithField("resource", "ingresses").Fatal("failed to create ingresses informer")
722+
}
723+
707724
s.log.WithField("envoy-service-name", contourConfiguration.Envoy.Service.Name).
708725
WithField("envoy-service-namespace", contourConfiguration.Envoy.Service.Namespace).
709726
Info("Watching Service for Ingress status")
727+
728+
s.log.WithField("envoy-ingress-name", contourConfiguration.Envoy.Ingress.Name).
729+
WithField("envoy-ingress-namespace", contourConfiguration.Envoy.Ingress.Namespace).
730+
Info("Watching Ingress for Ingress status")
710731
}
711732

712733
xdsServer := &xdsServer{

cmd/contour/servecontext.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
544544
Name: ctx.Config.EnvoyServiceName,
545545
Namespace: ctx.Config.EnvoyServiceNamespace,
546546
},
547+
Ingress: &contour_api_v1alpha1.NamespacedName{
548+
Name: ctx.Config.EnvoyIngressName,
549+
Namespace: ctx.Config.EnvoyIngressNamespace,
550+
},
547551
HTTPListener: &contour_api_v1alpha1.EnvoyListener{
548552
Address: ctx.httpAddr,
549553
Port: ctx.httpPort,

internal/k8s/statusaddress.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,63 @@ func lbStatusToGatewayAddresses(lbs v1.LoadBalancerStatus) []gatewayapi_v1.Gatew
307307

308308
return addrs
309309
}
310+
311+
// IngressStatusLoadBalancerWatcher implements ResourceEventHandler and
312+
// watches for changes to the status.loadbalancer field
313+
// Note that we specifically *don't* inspect inside the struct, as sending empty values
314+
// is desirable to clear the status.
315+
type IngressStatusLoadBalancerWatcher struct {
316+
IngressName string
317+
LBStatus chan networking_v1.IngressLoadBalancerStatus
318+
Log logrus.FieldLogger
319+
}
320+
321+
func (s *IngressStatusLoadBalancerWatcher) OnAdd(obj interface{}) {
322+
ingress, ok := obj.(*networking_v1.Ingress)
323+
if !ok {
324+
// not a service
325+
return
326+
}
327+
if ingress.Name != s.IngressName {
328+
return
329+
}
330+
s.Log.WithField("name", ingress.Name).
331+
WithField("namespace", ingress.Namespace).
332+
Debug("received new service address")
333+
334+
s.notify(ingress.Status.LoadBalancer)
335+
}
336+
337+
func (s *IngressStatusLoadBalancerWatcher) OnUpdate(oldObj, newObj interface{}) {
338+
ingress, ok := newObj.(*networking_v1.Ingress)
339+
if !ok {
340+
// not a service
341+
return
342+
}
343+
if ingress.Name != s.IngressName {
344+
return
345+
}
346+
s.Log.WithField("name", ingress.Name).
347+
WithField("namespace", ingress.Namespace).
348+
Debug("received new service address")
349+
350+
s.notify(ingress.Status.LoadBalancer)
351+
}
352+
353+
func (s *IngressStatusLoadBalancerWatcher) OnDelete(obj interface{}) {
354+
ingress, ok := obj.(*networking_v1.Ingress)
355+
if !ok {
356+
// not a service
357+
return
358+
}
359+
if ingress.Name != s.IngressName {
360+
return
361+
}
362+
s.notify(networking_v1.IngressLoadBalancerStatus{
363+
Ingress: nil,
364+
})
365+
}
366+
367+
func (s *IngressStatusLoadBalancerWatcher) notify(lbstatus networking_v1.IngressLoadBalancerStatus) {
368+
s.LBStatus <- lbstatus
369+
}

internal/provisioner/model/names.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func (c *Contour) EnvoyServiceName() string {
3232
return "envoy-" + c.Name
3333
}
3434

35+
// EnvoyIngressName returns the name of the Envoy Ingress resource.
36+
func (c *Contour) EnvoyIngressName() string {
37+
return "envoy-" + c.Name
38+
}
39+
3540
// ContourDeploymentName returns the name of the Contour Deployment resource.
3641
func (c *Contour) ContourDeploymentName() string {
3742
return "contour-" + c.Name

internal/provisioner/objects/contourconfig/contourconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func setGatewayConfig(config *contour_api_v1alpha1.ContourConfiguration, contour
7272
Namespace: contour.Namespace,
7373
Name: contour.EnvoyServiceName(),
7474
}
75+
config.Spec.Envoy.Ingress = &contour_api_v1alpha1.NamespacedName{
76+
Namespace: contour.Namespace,
77+
Name: contour.EnvoyIngressName(),
78+
}
7579
}
7680

7781
// EnsureContourConfigDeleted deletes a ContourConfig for the provided contour, if the configured owner labels exist.

internal/provisioner/objects/deployment/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func DesiredDeployment(contour *model.Contour, image string) *appsv1.Deployment
9393
fmt.Sprintf("--contour-config-name=%s", contour.ContourConfigurationName()),
9494
fmt.Sprintf("--leader-election-resource-name=%s", contour.LeaderElectionLeaseName()),
9595
fmt.Sprintf("--envoy-service-name=%s", contour.EnvoyServiceName()),
96+
fmt.Sprintf("--envoy-ingress-name=%s", contour.EnvoyIngressName()),
9697
fmt.Sprintf("--kubernetes-debug=%d", contour.Spec.KubernetesLogLevel),
9798
}
9899

pkg/config/parameters.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,12 @@ type Parameters struct {
644644
// Name of the envoy service to inspect for Ingress status details.
645645
EnvoyServiceName string `yaml:"envoy-service-name,omitempty"`
646646

647+
// Namespace of the envoy ingress to inspect for Ingress status details.
648+
EnvoyIngressNamespace string `yaml:"envoy-ingress-namespace,omitempty"`
649+
650+
// Name of the envoy ingress to inspect for Ingress status details.
651+
EnvoyIngressName string `yaml:"envoy-ingress-name,omitempty"`
652+
647653
// DefaultHTTPVersions defines the default set of HTTPS
648654
// versions the proxy should accept. HTTP versions are
649655
// strings of the form "HTTP/xx". Supported versions are
@@ -1027,6 +1033,8 @@ func Defaults() Parameters {
10271033
},
10281034
EnvoyServiceName: "envoy",
10291035
EnvoyServiceNamespace: contourNamespace,
1036+
EnvoyIngressName: "envoy",
1037+
EnvoyIngressNamespace: contourNamespace,
10301038
DefaultHTTPVersions: []HTTPVersionType{},
10311039
Cluster: ClusterParameters{
10321040
DNSLookupFamily: AutoClusterDNSFamily,

0 commit comments

Comments
 (0)