Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add kongintegration test for KongUpstreamPolicy translation #4957

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ spec:
- message: spec.hashOnFallback.cookiePath must not be set.
rule: 'has(self.spec.hashOnFallback) ? !has(self.spec.hashOnFallback.cookiePath)
: true'
- message: spec.healthchecks.passive.healthy.interval must not be set.
rule: 'has(self.spec.healthchecks) && has(self.spec.healthchecks.passive)
&& has(self.spec.healthchecks.passive.healthy) ? !has(self.spec.healthchecks.passive.healthy.interval)
: true'
- message: spec.healthchecks.passive.unhealthy.interval must not be set.
rule: 'has(self.spec.healthchecks) && has(self.spec.healthchecks.passive)
&& has(self.spec.healthchecks.passive.unhealthy) ? !has(self.spec.healthchecks.passive.unhealthy.interval)
: true'
served: true
storage: true
subresources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ func TestTranslateKongUpstreamPolicy(t *testing.T) {
Passive: &kongv1beta1.KongUpstreamPassiveHealthcheck{
Type: lo.ToPtr("tcp"),
Healthy: &kongv1beta1.KongUpstreamHealthcheckHealthy{
Interval: lo.ToPtr(90),
Successes: lo.ToPtr(100),
},
Unhealthy: &kongv1beta1.KongUpstreamHealthcheckUnhealthy{
TCPFailures: lo.ToPtr(110),
Timeouts: lo.ToPtr(120),
Interval: lo.ToPtr(130),
},
},
Threshold: lo.ToPtr(140),
Expand Down Expand Up @@ -149,13 +147,11 @@ func TestTranslateKongUpstreamPolicy(t *testing.T) {
Passive: &kong.PassiveHealthcheck{
Type: lo.ToPtr("tcp"),
Healthy: &kong.Healthy{
Interval: lo.ToPtr(90),
Successes: lo.ToPtr(100),
},
Unhealthy: &kong.Unhealthy{
TCPFailures: lo.ToPtr(110),
Timeouts: lo.ToPtr(120),
Interval: lo.ToPtr(130),
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/configuration/v1beta1/kongupstreampolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func init() {
// +kubebuilder:validation:XValidation:rule="has(self.spec.hashOn) && has(self.spec.hashOn.cookiePath) ? has(self.spec.hashOn.cookie) : true", message="When spec.hashOn.cookiePath is set, spec.hashOn.cookie is required."
// +kubebuilder:validation:XValidation:rule="has(self.spec.hashOnFallback) ? !has(self.spec.hashOnFallback.cookie) : true", message="spec.hashOnFallback.cookie must not be set."
// +kubebuilder:validation:XValidation:rule="has(self.spec.hashOnFallback) ? !has(self.spec.hashOnFallback.cookiePath) : true", message="spec.hashOnFallback.cookiePath must not be set."
// +kubebuilder:validation:XValidation:rule="has(self.spec.healthchecks) && has(self.spec.healthchecks.passive) && has(self.spec.healthchecks.passive.healthy) ? !has(self.spec.healthchecks.passive.healthy.interval) : true", message="spec.healthchecks.passive.healthy.interval must not be set."
// +kubebuilder:validation:XValidation:rule="has(self.spec.healthchecks) && has(self.spec.healthchecks.passive) && has(self.spec.healthchecks.passive.unhealthy) ? !has(self.spec.healthchecks.passive.unhealthy.interval) : true", message="spec.healthchecks.passive.unhealthy.interval must not be set."
type KongUpstreamPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
30 changes: 30 additions & 0 deletions test/envtest/crds_envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,36 @@ func TestCRDValidations(t *testing.T) {
require.ErrorContains(t, err, "should be greater than or equal to 100")
},
},
{
name: "KongUpstreamPolicy - healthchecks.passive.healthy.interval must not be set",
scenario: func(ctx context.Context, t *testing.T, ns string) {
err := createKongUpstreamPolicy(ctx, ctrlClient, ns, kongv1beta1.KongUpstreamPolicySpec{
Healthchecks: &kongv1beta1.KongUpstreamHealthcheck{
Passive: &kongv1beta1.KongUpstreamPassiveHealthcheck{
Healthy: &kongv1beta1.KongUpstreamHealthcheckHealthy{
Interval: lo.ToPtr(10),
},
},
},
})
require.ErrorContains(t, err, "spec.healthchecks.passive.healthy.interval must not be set.")
},
},
{
name: "KongUpstreamPolicy - healthchecks.passive.unhealthy.interval must not be set",
scenario: func(ctx context.Context, t *testing.T, ns string) {
err := createKongUpstreamPolicy(ctx, ctrlClient, ns, kongv1beta1.KongUpstreamPolicySpec{
Healthchecks: &kongv1beta1.KongUpstreamHealthcheck{
Passive: &kongv1beta1.KongUpstreamPassiveHealthcheck{
Unhealthy: &kongv1beta1.KongUpstreamHealthcheckUnhealthy{
Interval: lo.ToPtr(10),
},
},
},
})
require.ErrorContains(t, err, "spec.healthchecks.passive.unhealthy.interval must not be set.")
},
},
}

for _, tc := range testCases {
Expand Down
Loading