Skip to content

Commit

Permalink
fix: disallow konnectID references
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Dec 19, 2024
1 parent f78f740 commit 2a289cb
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 49 deletions.
4 changes: 2 additions & 2 deletions api/configuration/v1alpha1/key_set_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const (
// KeySetRef is the schema for the KeySetRef type.
// It is used to reference a KeySet entity.
// +kubebuilder:validation:XValidation:rule="self.type == 'namespacedRef' ? has(self.namespacedRef) : true", message="when type is namespacedRef, namespacedRef must be set"
// +kubebuilder:validation:XValidation:rule="self.type == 'konnectID' ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KeySetRef struct {
// Type defines type of the KeySet object reference. It can be one of:
// - konnectID
// - namespacedRef
//
// +kubebuilder:validation:Enum=namespacedRef
Type KeySetRefType `json:"type"`

// KonnectID is the schema for the KonnectID type.
Expand Down
3 changes: 1 addition & 2 deletions api/configuration/v1alpha1/konnect_controlplaneref_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const (
// +apireference:kgo:include
type ControlPlaneRef struct {
// Type indicates the type of the control plane being referenced. Allowed values:
// - konnectID
// - konnectNamespacedRef
// - kic
//
// The default is kic, which implies that the Control Plane is KIC.
//
// +kubebuilder:validation:Enum=konnectID;konnectNamespacedRef;kic
// +kubebuilder:validation:Enum=konnectNamespacedRef;kic
// +kubebuilder:default:=kic
Type string `json:"type,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down Expand Up @@ -141,13 +139,15 @@ spec:
- name
type: object
type:
allOf:
- enum:
- konnectID
- namespacedRef
- enum:
- namespacedRef
description: |-
Type defines type of the KeySet object reference. It can be one of:
- konnectID
- namespacedRef
enum:
- konnectID
- namespacedRef
type: string
required:
- type
Expand All @@ -156,8 +156,6 @@ spec:
- message: when type is namespacedRef, namespacedRef must be set
rule: 'self.type == ''namespacedRef'' ? has(self.namespacedRef)
: true'
- message: when type is konnectID, konnectID must be set
rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
kid:
description: |-
KID is a unique identifier for a key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ spec:
default: kic
description: |-
Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ It is used to reference a Control Plane entity.

| Field | Description |
| --- | --- |
| `type` _string_ | Type indicates the type of the control plane being referenced. Allowed values: - konnectID - konnectNamespacedRef - kic<br /><br /> The default is kic, which implies that the Control Plane is KIC. |
| `type` _string_ | Type indicates the type of the control plane being referenced. Allowed values: - konnectNamespacedRef - kic<br /><br /> The default is kic, which implies that the Control Plane is KIC. |
| `konnectID` _string_ | KonnectID is the schema for the KonnectID type. This field is required when the Type is konnectID. |
| `konnectNamespacedRef` _[KonnectNamespacedRef](#konnectnamespacedref)_ | KonnectNamespacedRef is a reference to a Konnect Control Plane entity inside the cluster. It contains the name of the Konnect Control Plane. This field is required when the Type is konnectNamespacedRef. |

Expand Down Expand Up @@ -776,7 +776,7 @@ It is used to reference a KeySet entity.

| Field | Description |
| --- | --- |
| `type` _[KeySetRefType](#keysetreftype)_ | Type defines type of the KeySet object reference. It can be one of: - konnectID - namespacedRef |
| `type` _[KeySetRefType](#keysetreftype)_ | Type defines type of the KeySet object reference. It can be one of: - namespacedRef |
| `konnectID` _string_ | KonnectID is the schema for the KonnectID type. This field is required when the Type is konnectID. |
| `namespacedRef` _[KeySetNamespacedRef](#keysetnamespacedref)_ | NamespacedRef is a reference to a KeySet entity inside the cluster. This field is required when the Type is namespacedRef. |

Expand Down
5 changes: 4 additions & 1 deletion test/crdsvalidation/kongkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func TestKongKey(t *testing.T) {
},
},
},
// TODO change when konnectID ref is allowed
ExpectedErrorMessage: lo.ToPtr("Unsupported value: \"konnectID\": supported values: \"namespacedRef\""),
},
{
Name: "when type is 'konnectID', konnectID is required",
Expand All @@ -177,7 +179,8 @@ func TestKongKey(t *testing.T) {
},
},
},
ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
// TODO change when konnectID ref is allowed
ExpectedErrorMessage: lo.ToPtr("Unsupported value: \"konnectID\": supported values: \"namespacedRef\""),
},
{
Name: "unknown type is not accepted",
Expand Down
15 changes: 9 additions & 6 deletions test/crdsvalidation/suite_crd_ref_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ func NewCRDValidationTestCasesGroupCPRefChange[
},
})
ret = append(ret, CRDValidationTestCase[T]{
Name: "providing konnectNamespacedRef when type is konnectID yields an error",
TestObject: obj,
ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
Name: "providing konnectNamespacedRef when type is konnectID yields an error",
TestObject: obj,
// TODO: change when konnectID is allowed
// ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
ExpectedErrorMessage: lo.ToPtr("Unsupported value: \"konnectID\": supported values: \"konnectNamespacedRef\", \"kic\""),
})
}
{
Expand All @@ -139,9 +141,10 @@ func NewCRDValidationTestCasesGroupCPRefChange[
},
})
ret = append(ret, CRDValidationTestCase[T]{
Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
TestObject: obj,
ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
TestObject: obj,
// TODO: change when konnectID is allowed
ExpectedErrorMessage: lo.ToPtr("Unsupported value: \"konnectID\": supported values: \"konnectNamespacedRef\", \"kic\""),
})
}
{
Expand Down

0 comments on commit 2a289cb

Please sign in to comment.