Skip to content

Commit

Permalink
Make the linter happy
Browse files Browse the repository at this point in the history
Signed-off-by: Lior Okman <lior.okman@sap.com>
  • Loading branch information
liorokman committed May 11, 2024
1 parent 8649ac6 commit 754eb7b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
27 changes: 12 additions & 15 deletions internal/gatewayapi/extensionserverpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (t *Translator) ProcessExtensionServerPolicies(policies []unstructured.Unst
gateways []*GatewayContext,
xdsIR XdsIRMap,
) []unstructured.Unstructured {

var res []unstructured.Unstructured

// Sort based on timestamp
Expand Down Expand Up @@ -87,18 +86,13 @@ func (t *Translator) ProcessExtensionServerPolicies(policies []unstructured.Unst
continue
}

// Set conditions for translation error if it got any
if err := t.translateExtServerPolicyForGateway(policy, gateway, currTarget, xdsIR); err != nil {
status.SetTranslationErrorForPolicyAncestors(&policyStatus,
ancestorRefs,
t.GatewayControllerName,
policy.GetGeneration(),
status.Error2ConditionMsg(err),
)
// Set conditions for translation if it got any
if t.translateExtServerPolicyForGateway(policy, gateway, currTarget, xdsIR) {
// Set Accepted condition if it is unset
// Only add a status condition if the policy was added into the IR
status.SetAcceptedForPolicyAncestors(&policyStatus, ancestorRefs, t.GatewayControllerName)
}

// Set Accepted condition if it is unset
status.SetAcceptedForPolicyAncestors(&policyStatus, ancestorRefs, t.GatewayControllerName)
}
policy.Object["status"] = policyStatusToUnstructured(policyStatus)
}
Expand Down Expand Up @@ -157,8 +151,9 @@ func extractSingleTargetRef(data any) (gwv1a2.LocalPolicyTargetReferenceWithSect

func policyStatusToUnstructured(policyStatus gwv1a2.PolicyStatus) map[string]any {
ret := map[string]any{}
// No need to check the marshal/unmarshal error here
d, _ := json.Marshal(policyStatus)
json.Unmarshal(d, &ret)
_ = json.Unmarshal(d, &ret)
return ret
}

Expand Down Expand Up @@ -195,10 +190,11 @@ func (t *Translator) translateExtServerPolicyForGateway(
policy *unstructured.Unstructured,
gateway *GatewayContext,
target gwv1a2.LocalPolicyTargetReferenceWithSectionName,
xdsIR XdsIRMap) error {

xdsIR XdsIRMap,
) bool {
irKey := t.getIRKey(gateway.Gateway)
gwIR := xdsIR[irKey]
found := false
for _, currListener := range gwIR.HTTP {
listenerName := currListener.Name[strings.LastIndex(currListener.Name, "/")+1:]
if target.SectionName != nil && string(*target.SectionName) != listenerName {
Expand All @@ -207,6 +203,7 @@ func (t *Translator) translateExtServerPolicyForGateway(
currListener.ExtensionRefs = append(currListener.ExtensionRefs, &ir.UnstructuredRef{
Object: policy,
})
found = true
}
return nil
return found
}
4 changes: 1 addition & 3 deletions internal/gatewayapi/extensionserverpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func TestExtractTargetRefs(t *testing.T) {

tests := []struct {
desc string
specInput map[string]any
Expand Down Expand Up @@ -166,10 +165,9 @@ func TestExtractTargetRefs(t *testing.T) {
if currTest.expectedError != "" {
require.EqualError(t, err, currTest.expectedError)
} else {
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, currTest.output, targets)
}
})
}

}
5 changes: 4 additions & 1 deletion internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) {

func unstructuredToPolicyStatus(policyStatus map[string]any) gwv1a2.PolicyStatus {
var ret gwv1a2.PolicyStatus
// No need to check the json marshal/unmarshal error, the policyStatus was
// created via a typed object so the marshalling/unmarshalling will always
// work
d, _ := json.Marshal(policyStatus)
json.Unmarshal(d, &ret)
_ = json.Unmarshal(d, &ret)
return ret
}

Expand Down
5 changes: 2 additions & 3 deletions internal/gatewayapi/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/yaml"

"github.com/envoyproxy/gateway/api/v1alpha1"
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/logging"
"github.com/envoyproxy/gateway/internal/utils/field"
Expand Down Expand Up @@ -79,7 +78,7 @@ func TestTranslate(t *testing.T) {
EnvoyPatchPolicyEnabled: envoyPatchPolicyEnabled,
Namespace: "envoy-gateway-system",
MergeGateways: IsMergeGatewaysEnabled(resources),
Logger: logging.NewLogger(&v1alpha1.EnvoyGatewayLogging{}),
Logger: logging.NewLogger(&egv1a1.EnvoyGatewayLogging{}),
}

// Add common test fixtures
Expand Down Expand Up @@ -276,7 +275,7 @@ func TestTranslateWithExtensionKinds(t *testing.T) {
{Group: "bar.example.io", Kind: "Bar"},
},
MergeGateways: IsMergeGatewaysEnabled(resources),
Logger: logging.NewLogger(&v1alpha1.EnvoyGatewayLogging{}),
Logger: logging.NewLogger(&egv1a1.EnvoyGatewayLogging{}),
}

// Add common test fixtures
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques
return reconcile.Result{}, err
}

if err = r.processExtensionServerPolicies(ctx, gwcResource, resourceMappings); err != nil {
if err = r.processExtensionServerPolicies(ctx, gwcResource); err != nil {
return reconcile.Result{}, err
}

Expand Down Expand Up @@ -1591,7 +1591,7 @@ func (r *gatewayAPIReconciler) processEnvoyExtensionPolicies(

// processExtensionServerPolicies adds directly attached policies intended for the extension server
func (r *gatewayAPIReconciler) processExtensionServerPolicies(
ctx context.Context, resourceTree *gatewayapi.Resources, resourceMap *resourceMappings,
ctx context.Context, resourceTree *gatewayapi.Resources,
) error {
for _, gvk := range r.extServerPolicies {
polList := unstructured.UnstructuredList{}
Expand Down

0 comments on commit 754eb7b

Please sign in to comment.