Skip to content

Commit

Permalink
Merge branch 'main' into telemetry-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
zirain committed May 8, 2024
2 parents 7591e44 + 239fdd7 commit ea5d012
Show file tree
Hide file tree
Showing 35 changed files with 1,292 additions and 745 deletions.
File renamed without changes.
File renamed without changes.
268 changes: 162 additions & 106 deletions internal/cmd/egctl/status.go

Large diffs are not rendered by default.

379 changes: 333 additions & 46 deletions internal/cmd/egctl/status_test.go

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions internal/cmd/egctl/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ import (
"sort"
"strings"

adminv3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
bootstrapv3 "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/anypb"
"sigs.k8s.io/yaml"

adminv3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
bootstrapv3 "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/sets"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/yaml"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/api/v1alpha1/validation"
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/ratelimit"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/xds/bootstrap"
"github.com/envoyproxy/gateway/internal/xds/translator"
xds_types "github.com/envoyproxy/gateway/internal/xds/types"
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"

"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
)

func (t *Translator) processBackendTLSPolicy(
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/utils"
"github.com/envoyproxy/gateway/internal/utils/regex"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/utils"
)

Expand Down
66 changes: 0 additions & 66 deletions internal/gatewayapi/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package gatewayapi

import (
"reflect"
"time"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -54,38 +53,6 @@ type ListenerContext struct {
tlsSecrets []*v1.Secret
}

func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionType, status metav1.ConditionStatus, reason gwapiv1.ListenerConditionReason, message string) {
cond := metav1.Condition{
Type: string(conditionType),
Status: status,
Reason: string(reason),
Message: message,
ObservedGeneration: l.gateway.Generation,
LastTransitionTime: metav1.NewTime(time.Now()),
}

idx := -1
for i, existing := range l.gateway.Status.Listeners[l.listenerStatusIdx].Conditions {
if existing.Type == cond.Type {
// return early if the condition is unchanged
if existing.Status == cond.Status &&
existing.Reason == cond.Reason &&
existing.Message == cond.Message &&
existing.ObservedGeneration == cond.ObservedGeneration {
return
}
idx = i
break
}
}

if idx > -1 {
l.gateway.Status.Listeners[l.listenerStatusIdx].Conditions[idx] = cond
} else {
l.gateway.Status.Listeners[l.listenerStatusIdx].Conditions = append(l.gateway.Status.Listeners[l.listenerStatusIdx].Conditions, cond)
}
}

func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1.RouteGroupKind) {
l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds = kinds
}
Expand Down Expand Up @@ -369,39 +336,6 @@ func (r *RouteParentContext) SetListeners(listeners ...*ListenerContext) {
r.listeners = append(r.listeners, listeners...)
}

func (r *RouteParentContext) SetCondition(route RouteContext, conditionType gwapiv1.RouteConditionType, status metav1.ConditionStatus, reason gwapiv1.RouteConditionReason, message string) {
cond := metav1.Condition{
Type: string(conditionType),
Status: status,
Reason: string(reason),
Message: message,
ObservedGeneration: route.GetGeneration(),
LastTransitionTime: metav1.NewTime(time.Now()),
}

idx := -1
routeStatus := GetRouteStatus(route)
for i, existing := range routeStatus.Parents[r.routeParentStatusIdx].Conditions {
if existing.Type == cond.Type {
// return early if the condition is unchanged
if existing.Status == cond.Status &&
existing.Reason == cond.Reason &&
existing.Message == cond.Message &&
existing.ObservedGeneration == cond.ObservedGeneration {
return
}
idx = i
break
}
}

if idx > -1 {
routeStatus.Parents[r.routeParentStatusIdx].Conditions[idx] = cond
} else {
routeStatus.Parents[r.routeParentStatusIdx].Conditions = append(routeStatus.Parents[r.routeParentStatusIdx].Conditions, cond)
}
}

func (r *RouteParentContext) ResetConditions(route RouteContext) {
routeStatus := GetRouteStatus(route)
routeStatus.Parents[r.routeParentStatusIdx].Conditions = make([]metav1.Condition, 0)
Expand Down
5 changes: 4 additions & 1 deletion internal/gatewayapi/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/envoyproxy/gateway/internal/gatewayapi/status"
)

func TestContexts(t *testing.T) {
Expand All @@ -37,7 +39,8 @@ func TestContexts(t *testing.T) {
lctx := gctx.listeners[0]
require.NotNil(t, lctx)

lctx.SetCondition(gwapiv1.ListenerConditionAccepted, metav1.ConditionFalse, gwapiv1.ListenerReasonUnsupportedProtocol, "HTTPS protocol is not supported yet")
status.SetGatewayListenerStatusCondition(lctx.gateway, lctx.listenerStatusIdx,
gwapiv1.ListenerConditionAccepted, metav1.ConditionFalse, gwapiv1.ListenerReasonUnsupportedProtocol, "HTTPS protocol is not supported yet")

require.Len(t, gateway.Status.Listeners, 1)
require.EqualValues(t, "http", gateway.Status.Listeners[0].Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/envoyextensionpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/envoypatchpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
)

func (t *Translator) ProcessEnvoyPatchPolicies(envoyPatchPolicies []*egv1a1.EnvoyPatchPolicy, xdsIR XdsIRMap) {
Expand Down
Loading

0 comments on commit ea5d012

Please sign in to comment.