Skip to content

Commit 5a1759e

Browse files
authored
Merge pull request #93 from datum-cloud/feat/connector-envoypatch
feat: Add connector EnvoyPatchPolicy for HTTPProxy backends
2 parents 0cd5e40 + a29d2c2 commit 5a1759e

File tree

11 files changed

+1802
-54
lines changed

11 files changed

+1802
-54
lines changed

api/v1alpha/httpproxy_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ const (
218218
// This condition is present and true when a hostname defined in an HTTPProxy
219219
// is in use by another resource.
220220
HTTPProxyConditionHostnamesInUse = "HostnamesInUse"
221+
222+
// This condition is true when connector metadata has been programmed
223+
// via the downstream EnvoyPatchPolicy.
224+
HTTPProxyConditionConnectorMetadataProgrammed = "ConnectorMetadataProgrammed"
221225
)
222226

223227
const (
@@ -228,6 +232,9 @@ const (
228232
// HTTPProxyReasonProgrammed indicates that the HTTP proxy has been programmed.
229233
HTTPProxyReasonProgrammed = "Programmed"
230234

235+
// HTTPProxyReasonConnectorMetadataApplied indicates connector metadata has been applied.
236+
HTTPProxyReasonConnectorMetadataApplied = "ConnectorMetadataApplied"
237+
231238
// HTTPProxyReasonConflict indicates that the HTTP proxy encountered a conflict
232239
// when being programmed.
233240
HTTPProxyReasonConflict = "Conflict"

cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ func main() {
218218
}
219219

220220
if err := (&controller.HTTPProxyReconciler{
221-
Config: serverConfig,
221+
Config: serverConfig,
222+
DownstreamCluster: downstreamCluster,
222223
}).SetupWithManager(mgr); err != nil {
223224
setupLog.Error(err, "unable to create controller", "controller", "HTTPProxy")
224225
os.Exit(1)

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ rules:
127127
- get
128128
- patch
129129
- update
130+
- apiGroups:
131+
- gateway.envoyproxy.io
132+
resources:
133+
- httproutefilters
134+
verbs:
135+
- create
136+
- delete
137+
- get
138+
- list
139+
- patch
140+
- update
141+
- watch
130142
- apiGroups:
131143
- gateway.networking.k8s.io
132144
resources:

internal/config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ type GatewayConfig struct {
470470
// +default={"gateway.networking.datumapis.com/certificate-issuer": "auto"}
471471
ListenerTLSOptions map[gatewayv1.AnnotationKey]gatewayv1.AnnotationValue `json:"listenerTLSOptions"`
472472

473+
// ConnectorInternalListenerName is the Envoy internal listener name used by
474+
// connector tunnel routing patches.
475+
//
476+
// +default="connector-tunnel"
477+
ConnectorInternalListenerName string `json:"connectorInternalListenerName,omitempty"`
478+
473479
// Coraza specifies configuration for the Coraza WAF.
474480
Coraza CorazaConfig `json:"coraza,omitempty"`
475481

@@ -527,6 +533,13 @@ func (c *GatewayConfig) GatewayDNSAddress(gateway *gatewayv1.Gateway) string {
527533
return fmt.Sprintf("%s.%s", strings.ReplaceAll(string(gateway.UID), "-", ""), c.TargetDomain)
528534
}
529535

536+
func (c *GatewayConfig) ConnectorTunnelListenerName() string {
537+
if c.ConnectorInternalListenerName == "" {
538+
return "connector-tunnel"
539+
}
540+
return c.ConnectorInternalListenerName
541+
}
542+
530543
// +k8s:deepcopy-gen=true
531544

532545
type CorazaConfig struct {

internal/config/zz_generated.defaults.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/connector_controller.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1717
ctrl "sigs.k8s.io/controller-runtime"
1818
"sigs.k8s.io/controller-runtime/pkg/client"
19+
"sigs.k8s.io/controller-runtime/pkg/cluster"
1920
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2021
"sigs.k8s.io/controller-runtime/pkg/handler"
2122
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -105,6 +106,19 @@ func (r *ConnectorReconciler) Reconcile(ctx context.Context, req mcreconcile.Req
105106
apimeta.SetStatusCondition(&connector.Status.Conditions, *acceptedCondition)
106107
apimeta.SetStatusCondition(&connector.Status.Conditions, *readyCondition)
107108

109+
if acceptedCondition.Status != metav1.ConditionTrue {
110+
readyCondition.Status = metav1.ConditionFalse
111+
readyCondition.Reason = networkingv1alpha1.ConnectorReasonNotReady
112+
readyCondition.Message = "Waiting for ConnectorClass to be resolved."
113+
apimeta.SetStatusCondition(&connector.Status.Conditions, *readyCondition)
114+
if !equality.Semantic.DeepEqual(*originalStatus, connector.Status) {
115+
if statusErr := cl.GetClient().Status().Update(ctx, &connector); statusErr != nil {
116+
return ctrl.Result{}, fmt.Errorf("failed updating connector status: %w", statusErr)
117+
}
118+
}
119+
return ctrl.Result{}, nil
120+
}
121+
108122
leaseDurationSeconds := r.connectorLeaseDurationSeconds()
109123
if connector.Status.LeaseRef == nil || connector.Status.LeaseRef.Name == "" {
110124
lease := &coordinationv1.Lease{
@@ -214,6 +228,41 @@ func (r *ConnectorReconciler) SetupWithManager(mgr mcmanager.Manager) error {
214228

215229
return mcbuilder.ControllerManagedBy(mgr).
216230
For(&networkingv1alpha1.Connector{}).
231+
Watches(
232+
&networkingv1alpha1.ConnectorClass{},
233+
func(clusterName string, cl cluster.Cluster) handler.TypedEventHandler[client.Object, mcreconcile.Request] {
234+
return handler.TypedEnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []mcreconcile.Request {
235+
logger := log.FromContext(ctx)
236+
237+
connectorClass, ok := obj.(*networkingv1alpha1.ConnectorClass)
238+
if !ok {
239+
return nil
240+
}
241+
242+
var connectors networkingv1alpha1.ConnectorList
243+
if err := cl.GetClient().List(ctx, &connectors); err != nil {
244+
logger.Error(err, "failed to list Connectors for ConnectorClass watch", "connectorClass", connectorClass.Name)
245+
return nil
246+
}
247+
248+
var requests []mcreconcile.Request
249+
for i := range connectors.Items {
250+
connector := &connectors.Items[i]
251+
if connector.Spec.ConnectorClassName != connectorClass.Name {
252+
continue
253+
}
254+
requests = append(requests, mcreconcile.Request{
255+
ClusterName: clusterName,
256+
Request: ctrl.Request{
257+
NamespacedName: client.ObjectKeyFromObject(connector),
258+
},
259+
})
260+
}
261+
262+
return requests
263+
})
264+
},
265+
).
217266
Watches(
218267
&coordinationv1.Lease{},
219268
mchandler.EnqueueRequestForOwner(&networkingv1alpha1.Connector{}, handler.OnlyControllerOwner()),

0 commit comments

Comments
 (0)