Skip to content

Commit

Permalink
Update controller code to process v1alpha2 ObservabilityPolicies
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Jan 8, 2025
1 parent 1e9c4f0 commit b62fb4c
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 478 deletions.
21 changes: 21 additions & 0 deletions apis/v1alpha2/policy_methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1alpha2

import (
"sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// FIXME(kate-osborn): https://github.com/nginxinc/nginx-gateway-fabric/issues/1939.
// Figure out a way to generate these methods for all our policies.
// These methods implement the policies.Policy interface which extends client.Object to add the following methods.

func (p *ObservabilityPolicy) GetTargetRefs() []v1alpha2.LocalPolicyTargetReference {
return p.Spec.TargetRefs
}

func (p *ObservabilityPolicy) GetPolicyStatus() v1alpha2.PolicyStatus {
return p.Status
}

func (p *ObservabilityPolicy) SetPolicyStatus(status v1alpha2.PolicyStatus) {
p.Status = status
}
36 changes: 19 additions & 17 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
ngfAPIv1alpha1 "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
ngfAPIv1alpha2 "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha2"
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller"
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/filter"
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/index"
Expand Down Expand Up @@ -83,7 +84,8 @@ func init() {
utilruntime.Must(gatewayv1alpha2.Install(scheme))
utilruntime.Must(apiv1.AddToScheme(scheme))
utilruntime.Must(discoveryV1.AddToScheme(scheme))
utilruntime.Must(ngfAPI.AddToScheme(scheme))
utilruntime.Must(ngfAPIv1alpha1.AddToScheme(scheme))
utilruntime.Must(ngfAPIv1alpha2.AddToScheme(scheme))
utilruntime.Must(apiext.AddToScheme(scheme))
utilruntime.Must(appsv1.AddToScheme(scheme))
}
Expand Down Expand Up @@ -314,15 +316,15 @@ func createPolicyManager(
) *policies.CompositeValidator {
cfgs := []policies.ManagerConfig{
{
GVK: mustExtractGVK(&ngfAPI.ClientSettingsPolicy{}),
GVK: mustExtractGVK(&ngfAPIv1alpha1.ClientSettingsPolicy{}),
Validator: clientsettings.NewValidator(validator),
},
{
GVK: mustExtractGVK(&ngfAPI.ObservabilityPolicy{}),
GVK: mustExtractGVK(&ngfAPIv1alpha2.ObservabilityPolicy{}),
Validator: observability.NewValidator(validator),
},
{
GVK: mustExtractGVK(&ngfAPI.UpstreamSettingsPolicy{}),
GVK: mustExtractGVK(&ngfAPIv1alpha1.UpstreamSettingsPolicy{}),
Validator: upstreamsettings.NewValidator(validator),
},
}
Expand Down Expand Up @@ -483,7 +485,7 @@ func registerControllers(
},
},
{
objectType: &ngfAPI.NginxProxy{},
objectType: &ngfAPIv1alpha1.NginxProxy{},
options: []controller.Option{
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
},
Expand All @@ -495,19 +497,19 @@ func registerControllers(
},
},
{
objectType: &ngfAPI.ClientSettingsPolicy{},
objectType: &ngfAPIv1alpha1.ClientSettingsPolicy{},
options: []controller.Option{
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
},
},
{
objectType: &ngfAPI.ObservabilityPolicy{},
objectType: &ngfAPIv1alpha2.ObservabilityPolicy{},
options: []controller.Option{
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
},
},
{
objectType: &ngfAPI.UpstreamSettingsPolicy{},
objectType: &ngfAPIv1alpha1.UpstreamSettingsPolicy{},
options: []controller.Option{
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
},
Expand Down Expand Up @@ -540,7 +542,7 @@ func registerControllers(
if cfg.ConfigName != "" {
controllerRegCfgs = append(controllerRegCfgs,
ctlrCfg{
objectType: &ngfAPI.NginxGateway{},
objectType: &ngfAPIv1alpha1.NginxGateway{},
options: []controller.Option{
controller.WithNamespacedNameFilter(filter.CreateSingleResourceFilter(controlConfigNSName)),
},
Expand All @@ -559,7 +561,7 @@ func registerControllers(
if cfg.SnippetsFilters {
controllerRegCfgs = append(controllerRegCfgs,
ctlrCfg{
objectType: &ngfAPI.SnippetsFilter{},
objectType: &ngfAPIv1alpha1.SnippetsFilter{},
options: []controller.Option{
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
},
Expand Down Expand Up @@ -744,11 +746,11 @@ func prepareFirstEventBatchPreparerArgs(cfg config.Config) ([]client.Object, []c
&discoveryV1.EndpointSliceList{},
&gatewayv1.HTTPRouteList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
&gatewayv1.GRPCRouteList{},
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
partialObjectMetadataList,
}

Expand All @@ -764,7 +766,7 @@ func prepareFirstEventBatchPreparerArgs(cfg config.Config) ([]client.Object, []c
if cfg.SnippetsFilters {
objectLists = append(
objectLists,
&ngfAPI.SnippetsFilterList{},
&ngfAPIv1alpha1.SnippetsFilterList{},
)
}

Expand Down Expand Up @@ -792,7 +794,7 @@ func setInitialConfig(
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var conf ngfAPI.NginxGateway
var conf ngfAPIv1alpha1.NginxGateway
// Polling to wait for CRD to exist if the Deployment is created first.
if err := wait.PollUntilContextCancel(
ctx,
Expand Down
47 changes: 24 additions & 23 deletions internal/mode/static/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
ngfAPIv1alpha1 "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
ngfAPIv1alpha2 "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha2"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/config"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
)
Expand Down Expand Up @@ -62,12 +63,12 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
&gatewayv1.HTTPRouteList{},
&gatewayv1.GatewayList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
&gatewayv1.GRPCRouteList{},
partialObjectMetadataList,
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
},
},
{
Expand All @@ -92,12 +93,12 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
&discoveryV1.EndpointSliceList{},
&gatewayv1.HTTPRouteList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
&gatewayv1.GRPCRouteList{},
partialObjectMetadataList,
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
},
},
{
Expand All @@ -123,14 +124,14 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
&discoveryV1.EndpointSliceList{},
&gatewayv1.HTTPRouteList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
partialObjectMetadataList,
&gatewayv1alpha3.BackendTLSPolicyList{},
&gatewayv1alpha2.TLSRouteList{},
&gatewayv1.GRPCRouteList{},
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
},
},
{
Expand All @@ -155,13 +156,13 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
&discoveryV1.EndpointSliceList{},
&gatewayv1.HTTPRouteList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
partialObjectMetadataList,
&gatewayv1.GRPCRouteList{},
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.SnippetsFilterList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.SnippetsFilterList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
},
},
{
Expand All @@ -187,15 +188,15 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
&discoveryV1.EndpointSliceList{},
&gatewayv1.HTTPRouteList{},
&gatewayv1beta1.ReferenceGrantList{},
&ngfAPI.NginxProxyList{},
&ngfAPIv1alpha1.NginxProxyList{},
partialObjectMetadataList,
&gatewayv1alpha3.BackendTLSPolicyList{},
&gatewayv1alpha2.TLSRouteList{},
&gatewayv1.GRPCRouteList{},
&ngfAPI.ClientSettingsPolicyList{},
&ngfAPI.ObservabilityPolicyList{},
&ngfAPI.SnippetsFilterList{},
&ngfAPI.UpstreamSettingsPolicyList{},
&ngfAPIv1alpha1.ClientSettingsPolicyList{},
&ngfAPIv1alpha2.ObservabilityPolicyList{},
&ngfAPIv1alpha1.SnippetsFilterList{},
&ngfAPIv1alpha1.UpstreamSettingsPolicyList{},
},
},
}
Expand Down
Loading

0 comments on commit b62fb4c

Please sign in to comment.