Skip to content

Commit

Permalink
use gw-api style for namespace selector
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc committed Jan 29, 2025
1 parent e9dee32 commit acfea54
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 81 deletions.
23 changes: 16 additions & 7 deletions api/v1alpha1/policy_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,28 @@ type TargetSelector struct {
// MatchLabels are the set of label selectors for identifying the targeted resource
MatchLabels map[string]string `json:"matchLabels"`

// NamespaceSelector determines if the label selectors specified in MatchLabels are applied in
// the policy namespace or across all namespaces.
// Namespaces determines if the resource from all namespaces or the current namespace
// are considered when matching by label selectors specified in MatchLabels.
// Note: when referencing targets in a different namespace, appropriate ReferenceGrants must be
// configured to allow the selection.
// +optional
// +notImplementedHide
NamespaceSelector *NamespaceSelector `json:"namespaceSelector,omitempty"`
Namespaces *TargetSelectorNamespaces `json:"namespaces,omitempty"`
}

// NamespaceSelector is a selector for selecting either all namespaces or the current namespace.
type NamespaceSelector struct {
// Boolean describing whether all namespaces are selected.
Any bool `json:"any,omitempty"`
type FromNamespaces string

const (
// FromNamespacesAll indicates that the target selector should apply to targets from all namespaces
FromNamespacesAll FromNamespaces = "All"
)

// TargetSelectorNamespaces determines which namespaces are used when selecting policy targets.
type TargetSelectorNamespaces struct {
// Indicates where targets would be selected for the Policy's TargetSelector.
// +kubebuilder:validation:Enum=All
// +kubebuilder:validation:Required
FromNamespaces FromNamespaces `json:"omitempty"`
}

func (p PolicyTargetReferences) GetTargetRefs() []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName {
Expand Down
36 changes: 18 additions & 18 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1504,17 +1504,21 @@ spec:
description: MatchLabels are the set of label selectors for
identifying the targeted resource
type: object
namespaceSelector:
namespaces:
description: |-
NamespaceSelector determines if the label selectors specified in MatchLabels are applied in
the policy namespace or across all namespaces.
Namespaces determines if the resource from all namespaces or the current namespace
are considered when matching by label selectors specified in MatchLabels.
Note: when referencing targets in a different namespace, appropriate ReferenceGrants must be
configured to allow the selection.
properties:
any:
description: Boolean describing whether all namespaces are
selected.
type: boolean
omitempty:
description: Indicates where targets would be selected for
the Policy's TargetSelector.
enum:
- All
type: string
required:
- omitempty
type: object
required:
- kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,17 +614,21 @@ spec:
description: MatchLabels are the set of label selectors for
identifying the targeted resource
type: object
namespaceSelector:
namespaces:
description: |-
NamespaceSelector determines if the label selectors specified in MatchLabels are applied in
the policy namespace or across all namespaces.
Namespaces determines if the resource from all namespaces or the current namespace
are considered when matching by label selectors specified in MatchLabels.
Note: when referencing targets in a different namespace, appropriate ReferenceGrants must be
configured to allow the selection.
properties:
any:
description: Boolean describing whether all namespaces are
selected.
type: boolean
omitempty:
description: Indicates where targets would be selected for
the Policy's TargetSelector.
enum:
- All
type: string
required:
- omitempty
type: object
required:
- kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,17 +1197,21 @@ spec:
description: MatchLabels are the set of label selectors for
identifying the targeted resource
type: object
namespaceSelector:
namespaces:
description: |-
NamespaceSelector determines if the label selectors specified in MatchLabels are applied in
the policy namespace or across all namespaces.
Namespaces determines if the resource from all namespaces or the current namespace
are considered when matching by label selectors specified in MatchLabels.
Note: when referencing targets in a different namespace, appropriate ReferenceGrants must be
configured to allow the selection.
properties:
any:
description: Boolean describing whether all namespaces are
selected.
type: boolean
omitempty:
description: Indicates where targets would be selected for
the Policy's TargetSelector.
enum:
- All
type: string
required:
- omitempty
type: object
required:
- kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4413,17 +4413,21 @@ spec:
description: MatchLabels are the set of label selectors for
identifying the targeted resource
type: object
namespaceSelector:
namespaces:
description: |-
NamespaceSelector determines if the label selectors specified in MatchLabels are applied in
the policy namespace or across all namespaces.
Namespaces determines if the resource from all namespaces or the current namespace
are considered when matching by label selectors specified in MatchLabels.
Note: when referencing targets in a different namespace, appropriate ReferenceGrants must be
configured to allow the selection.
properties:
any:
description: Boolean describing whether all namespaces are
selected.
type: boolean
omitempty:
description: Indicates where targets would be selected for
the Policy's TargetSelector.
enum:
- All
type: string
required:
- omitempty
type: object
required:
- kind
Expand Down
42 changes: 28 additions & 14 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,20 @@ _Appears in:_
| `after` | _[EnvoyFilter](#envoyfilter)_ | true | | After defines the filter that should come after the filter.<br />Only one of Before or After must be set. |


#### FromNamespaces

_Underlying type:_ _string_



_Appears in:_
- [TargetSelectorNamespaces](#targetselectornamespaces)

| Value | Description |
| ----- | ----------- |
| `All` | FromNamespacesAll indicates that the target selector should apply to targets from all namespaces<br /> |


#### GRPCActiveHealthChecker


Expand Down Expand Up @@ -2898,20 +2912,6 @@ _Appears in:_
| `OpenTelemetry` | |


#### NamespaceSelector



NamespaceSelector is a selector for selecting either all namespaces or the current namespace.

_Appears in:_
- [TargetSelector](#targetselector)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `any` | _boolean_ | true | | Boolean describing whether all namespaces are selected. |


#### OIDC


Expand Down Expand Up @@ -4318,6 +4318,20 @@ _Appears in:_
| `matchLabels` | _object (keys:string, values:string)_ | true | | MatchLabels are the set of label selectors for identifying the targeted resource |


#### TargetSelectorNamespaces



TargetSelectorNamespaces determines which namespaces are used when selecting policy targets.

_Appears in:_
- [TargetSelector](#targetselector)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `omitempty` | _[FromNamespaces](#fromnamespaces)_ | true | | Indicates where targets would be selected for the Policy's TargetSelector. |


#### Timeout


Expand Down
42 changes: 28 additions & 14 deletions site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,20 @@ _Appears in:_
| `after` | _[EnvoyFilter](#envoyfilter)_ | true | | After defines the filter that should come after the filter.<br />Only one of Before or After must be set. |


#### FromNamespaces

_Underlying type:_ _string_



_Appears in:_
- [TargetSelectorNamespaces](#targetselectornamespaces)

| Value | Description |
| ----- | ----------- |
| `All` | FromNamespacesAll indicates that the target selector should apply to targets from all namespaces<br /> |


#### GRPCActiveHealthChecker


Expand Down Expand Up @@ -2898,20 +2912,6 @@ _Appears in:_
| `OpenTelemetry` | |


#### NamespaceSelector



NamespaceSelector is a selector for selecting either all namespaces or the current namespace.

_Appears in:_
- [TargetSelector](#targetselector)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `any` | _boolean_ | true | | Boolean describing whether all namespaces are selected. |


#### OIDC


Expand Down Expand Up @@ -4318,6 +4318,20 @@ _Appears in:_
| `matchLabels` | _object (keys:string, values:string)_ | true | | MatchLabels are the set of label selectors for identifying the targeted resource |


#### TargetSelectorNamespaces



TargetSelectorNamespaces determines which namespaces are used when selecting policy targets.

_Appears in:_
- [TargetSelector](#targetselector)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `omitempty` | _[FromNamespaces](#fromnamespaces)_ | true | | Indicates where targets would be selected for the Policy's TargetSelector. |


#### Timeout


Expand Down

0 comments on commit acfea54

Please sign in to comment.