Skip to content

Commit 2928bfc

Browse files
committed
put cases together
1 parent a32600a commit 2928bfc

4 files changed

Lines changed: 74 additions & 101 deletions

File tree

test/helpers/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// CheckAllConditionsTrue returns true if all the conditions with given type in `conditionTypes` are set to `True` in the given resource.
1414
// If it returns `false`, the second return value contains a message to tell what conditions are not `True`.
1515
func CheckAllConditionsTrue(resource k8sutils.ConditionsAware, conditionTypes []consts.ConditionType) (bool, string) {
16-
failedConditions := make([]string, 0, len(conditionTypes))
16+
var failedConditions []string
1717
lo.ForEach(conditionTypes, func(conditionType consts.ConditionType, _ int) {
1818
if !k8sutils.HasConditionTrue(conditionType, resource) {
1919
failedConditions = append(failedConditions, string(conditionType))

test/helpers/deploy/deploy_resources.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,32 +1034,6 @@ func KonnectExtension(
10341034
return ke
10351035
}
10361036

1037-
// KonnectExtensionRefencingKonnectGatewayControlPlane deploys a KonnectExtension attached to a Konnect CP represented by the given KonnectGatewayControlPlane.
1038-
func KonnectExtensionRefencingKonnectGatewayControlPlane(
1039-
t *testing.T,
1040-
ctx context.Context,
1041-
cl client.Client,
1042-
cp *konnectv1alpha1.KonnectGatewayControlPlane,
1043-
) *konnectv1alpha1.KonnectExtension {
1044-
return KonnectExtension(
1045-
t, ctx, cl,
1046-
func(obj client.Object) {
1047-
ke, ok := obj.(*konnectv1alpha1.KonnectExtension)
1048-
require.Truef(t, ok, "Expect object %s/%s to be a KonnectExtension, actual type %T",
1049-
obj.GetNamespace(), obj.GetName(), obj)
1050-
ke.Spec.KonnectControlPlane = konnectv1alpha1.KonnectExtensionControlPlane{
1051-
ControlPlaneRef: commonv1alpha1.ControlPlaneRef{
1052-
Type: commonv1alpha1.ControlPlaneRefKonnectNamespacedRef,
1053-
KonnectNamespacedRef: &commonv1alpha1.KonnectNamespacedRef{
1054-
Name: cp.Name,
1055-
Namespace: cp.Namespace,
1056-
},
1057-
},
1058-
}
1059-
},
1060-
)
1061-
}
1062-
10631037
// ObjectSupportingKonnectConfiguration defines the interface of types supporting setting `KonnectConfiguration`.
10641038
type ObjectSupportingKonnectConfiguration interface {
10651039
*konnectv1alpha1.KonnectGatewayControlPlane |
@@ -1083,34 +1057,6 @@ func WithKonnectConfiguration[T ObjectSupportingKonnectConfiguration](
10831057
}
10841058
}
10851059

1086-
// KonnectExtensionWithAPIAuthRefAndCPID deploys a KonnectExtension attaching to control plane
1087-
// by the CP's ID and the API auth configuration to the Konnect server where the CP is in.
1088-
func KonnectExtensionWithAPIAuthRefAndCPID(
1089-
t *testing.T,
1090-
ctx context.Context,
1091-
cl client.Client,
1092-
apiAuth konnectv1alpha1.KonnectAPIAuthConfigurationRef,
1093-
cpID string,
1094-
opts ...ObjOption,
1095-
) *konnectv1alpha1.KonnectExtension {
1096-
opts = append(opts, func(obj client.Object) {
1097-
ke, ok := obj.(*konnectv1alpha1.KonnectExtension)
1098-
require.Truef(t, ok, "Expect object %s/%s to be a KonnectExtension, actual type %T",
1099-
obj.GetNamespace(), obj.GetName(), obj)
1100-
ke.Spec.KonnectConfiguration = &konnectv1alpha1.KonnectConfiguration{
1101-
APIAuthConfigurationRef: apiAuth,
1102-
}
1103-
ke.Spec.KonnectControlPlane.ControlPlaneRef = commonv1alpha1.ControlPlaneRef{
1104-
Type: commonv1alpha1.ControlPlaneRefKonnectID,
1105-
KonnectID: lo.ToPtr(cpID),
1106-
}
1107-
})
1108-
return KonnectExtension(
1109-
t, ctx, cl,
1110-
opts...,
1111-
)
1112-
}
1113-
11141060
func logObjectCreate[
11151061
T interface {
11161062
client.Object

test/integration/test_konnect_extension.go

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/require"
1010
corev1 "k8s.io/api/core/v1"
11-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1211
"k8s.io/apimachinery/pkg/types"
1312
"sigs.k8s.io/controller-runtime/pkg/client"
1413

@@ -22,7 +21,7 @@ import (
2221
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
2322
)
2423

25-
func TestKonnectExtensionKonnectGatewayControlPlaneNamespacedRef(t *testing.T) {
24+
func TestKonnectExtension(t *testing.T) {
2625
ns, _ := helpers.SetupTestEnv(t, GetCtx(), GetEnv())
2726

2827
// Let's generate a unique test ID that we can refer to in Konnect entities.
@@ -58,38 +57,17 @@ func TestKonnectExtensionKonnectGatewayControlPlaneNamespacedRef(t *testing.T) {
5857
assertKonnectEntityProgrammed(t, cp)
5958
}, testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
6059

61-
t.Logf("Creating a KonnectExtension")
62-
ke := deploy.KonnectExtensionRefencingKonnectGatewayControlPlane(
63-
t, ctx,
64-
clientNamespaced,
65-
cp,
66-
)
67-
t.Cleanup(deleteObjectAndWaitForDeletionFn(t, ke.DeepCopy()))
68-
69-
t.Logf("Waiting for KonnectExtension %s/%s to have ControlPlaneRefValid contition set to True", ke.Namespace, ke.Name)
70-
require.EventuallyWithT(t, func(t *assert.CollectT) {
71-
err := GetClients().MgrClient.Get(GetCtx(), types.NamespacedName{Name: ke.Name, Namespace: ke.Namespace}, ke)
72-
require.NoError(t, err)
73-
assert.Truef(t, lo.ContainsBy(
74-
ke.Status.Conditions, func(cond metav1.Condition) bool {
75-
return cond.Type == konnectv1alpha1.ControlPlaneRefValidConditionType &&
76-
cond.Status == metav1.ConditionTrue
77-
},
78-
), "ControlPlaneRefValid has not been set to True, conditions: %+v", ke.Status.Conditions)
79-
}, testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
80-
81-
// TODO: Create a DataPlane using this KonnectExtension:
82-
// https://github.com/Kong/gateway-operator/issues/726
8360
// Create a secret used as dataplane certificate for the KonnectExtension.
8461
s := deploy.Secret(
8562
t, ctx, clientNamespaced,
8663
// TODO: Fill real certificate data here after DP certifcates provisioning is done:
8764
// https://github.com/Kong/gateway-operator/issues/874
8865
map[string][]byte{},
8966
)
90-
// Create a KonnectExtension attaching to the CP by its ID.
91-
t.Logf("Creating a KonnectExtension and waiting for Konnect control plane ref resolved")
92-
ke = deploy.KonnectExtension(
67+
68+
// Tests on KonnectExtension with KonnectID control plane ref.
69+
t.Logf("Creating a KonnectExtension with KonnectID typed control plane ref")
70+
keWithKonnectIDCPRef := deploy.KonnectExtension(
9371
t, ctx, clientNamespaced,
9472
deploy.WithKonnectConfiguration[*konnectv1alpha1.KonnectExtension](konnectv1alpha1.KonnectConfiguration{
9573
APIAuthConfigurationRef: konnectv1alpha1.KonnectAPIAuthConfigurationRef{
@@ -100,30 +78,42 @@ func TestKonnectExtensionKonnectGatewayControlPlaneNamespacedRef(t *testing.T) {
10078
setKonnectExtensionDPCertSecretRef(t, s),
10179
)
10280

103-
t.Cleanup(deleteObjectAndWaitForDeletionFn(t, ke.DeepCopy()))
81+
t.Cleanup(deleteObjectAndWaitForDeletionFn(t, keWithKonnectIDCPRef.DeepCopy()))
10482

105-
t.Logf("Waiting for KonnectExtension %s/%s to have expected conditions set to True", ke.Namespace, ke.Name)
83+
t.Logf("Waiting for KonnectExtension %s/%s to have expected conditions set to True", keWithKonnectIDCPRef.Namespace, keWithKonnectIDCPRef.Name)
10684
require.EventuallyWithT(t, func(t *assert.CollectT) {
107-
ok, msg := checkKonnectExtensionConditions(t, ke)
108-
assert.Truef(t, ok, "condition check failed: %s, conditions: %+v", msg, ke.Status.Conditions)
85+
ok, msg := checkKonnectExtensionConditions(t, keWithKonnectIDCPRef)
86+
assert.Truef(t, ok, "condition check failed: %s, conditions: %+v", msg, keWithKonnectIDCPRef.Status.Conditions)
10987
}, testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
11088

111-
t.Logf("waiting for status.konnect and status.dataPlaneClientAuth to be set for KonnectExtension %s/%s", ke.Namespace, ke.Name)
112-
require.EventuallyWithT(t, func(t *assert.CollectT) {
113-
err := GetClients().MgrClient.Get(GetCtx(), types.NamespacedName{Name: ke.Name, Namespace: ke.Namespace}, ke)
114-
require.NoError(t, err)
115-
// Check Konnect control plane ID
116-
assert.NotNil(t, ke.Status.Konnect, "status.konnect should be present")
117-
assert.Equal(t, cp.GetKonnectID(), ke.Status.Konnect.ControlPlaneID, "Konnect control plane ID should be set in status")
118-
// Check dataplane client auth
119-
assert.NotNil(t, ke.Status.DataPlaneClientAuth, "status.dataPlaneClientAuth should be present")
120-
assert.NotNil(t, ke.Status.DataPlaneClientAuth.CertificateSecretRef, "status.dataPlaneClientAuth.certiifcateSecretRef should be present")
121-
assert.Equal(t, s.Name, ke.Status.DataPlaneClientAuth.CertificateSecretRef.Name,
122-
"status.dataPlaneClientAuth.certiifcateSecretRef should have the expected secret name")
89+
t.Logf("waiting for status.konnect and status.dataPlaneClientAuth to be set for KonnectExtension %s/%s", keWithKonnectIDCPRef.Namespace, keWithKonnectIDCPRef.Name)
90+
require.EventuallyWithT(t,
91+
checkKonnectExtensionStatus(t, keWithKonnectIDCPRef, cp.GetKonnectID(), s.Name),
92+
testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
93+
94+
// Tests on KonnectExtension with KonnectNamespacedRef control plane ref.
95+
// REVIEW: should we separate the KonnectExtensions with different control plane refs to different cases?
96+
t.Logf("Creating a KonnectExtension with KonnectNamespacedRef typed control plane ref")
97+
keWithNamespacedCPRef := deploy.KonnectExtension(
98+
t, ctx,
99+
clientNamespaced,
100+
setKonnectExtesionKonnectNamespacedRefControlPlaneRef(t, cp),
101+
setKonnectExtensionDPCertSecretRef(t, s),
102+
)
103+
t.Cleanup(deleteObjectAndWaitForDeletionFn(t, keWithNamespacedCPRef.DeepCopy()))
123104

105+
t.Logf("Waiting for KonnectExtension %s/%s to have expected conditions set to True", keWithNamespacedCPRef.Namespace, keWithNamespacedCPRef.Name)
106+
require.EventuallyWithT(t, func(t *assert.CollectT) {
107+
ok, msg := checkKonnectExtensionConditions(t, keWithNamespacedCPRef)
108+
assert.Truef(t, ok, "condition check failed: %s, conditions: %+v", msg, keWithNamespacedCPRef.Status.Conditions)
124109
}, testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
125110

126-
// TODO: Create DataPlanes using the KonnectExtension after DP certifcates provisioning is done:
111+
t.Logf("waiting for status.konnect and status.dataPlaneClientAuth to be set for KonnectExtension %s/%s", keWithNamespacedCPRef.Namespace, keWithNamespacedCPRef.Name)
112+
require.EventuallyWithT(t,
113+
checkKonnectExtensionStatus(t, keWithNamespacedCPRef, cp.GetKonnectID(), s.Name),
114+
testutils.ObjectUpdateTimeout, testutils.ObjectUpdateTick)
115+
116+
// TODO: Create DataPlanes using the KonnectExtensions after DP certifcates provisioning is done:
127117
// https://github.com/Kong/gateway-operator/issues/874
128118

129119
}
@@ -141,7 +131,25 @@ func setKonnectExtensionKonnectIDControlPlaneRef(t *testing.T, cpID string) depl
141131
}
142132
}
143133

144-
func setKonnectExtensionDPCertSecretRef(t *testing.T, s *corev1.Secret) func(client.Object) {
134+
func setKonnectExtesionKonnectNamespacedRefControlPlaneRef(
135+
t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane,
136+
) deploy.ObjOption {
137+
return func(obj client.Object) {
138+
ke, ok := obj.(*konnectv1alpha1.KonnectExtension)
139+
require.True(t, ok)
140+
// TODO: use `WithKonnectIDControlPlaneRef` after KonnectExtension support `SetControlPlaneRef`:
141+
// https://github.com/Kong/kubernetes-configuration/issues/328
142+
ke.Spec.KonnectControlPlane.ControlPlaneRef = commonv1alpha1.ControlPlaneRef{
143+
Type: commonv1alpha1.ControlPlaneRefKonnectNamespacedRef,
144+
KonnectNamespacedRef: &commonv1alpha1.KonnectNamespacedRef{
145+
Name: cp.Name,
146+
Namespace: cp.Namespace,
147+
},
148+
}
149+
}
150+
}
151+
152+
func setKonnectExtensionDPCertSecretRef(t *testing.T, s *corev1.Secret) deploy.ObjOption {
145153
return func(obj client.Object) {
146154
ke, ok := obj.(*konnectv1alpha1.KonnectExtension)
147155
require.True(t, ok)
@@ -167,3 +175,22 @@ func checkKonnectExtensionConditions(t *assert.CollectT, ke *konnectv1alpha1.Kon
167175
}
168176
return helpers.CheckAllConditionsTrue(ke, checkConditionTypes)
169177
}
178+
179+
func checkKonnectExtensionStatus(t *testing.T,
180+
ke *konnectv1alpha1.KonnectExtension,
181+
expectedKonnectCPID string,
182+
expectedDPCertificateSecretName string,
183+
) func(t *assert.CollectT) {
184+
return func(t *assert.CollectT) {
185+
err := GetClients().MgrClient.Get(GetCtx(), types.NamespacedName{Name: ke.Name, Namespace: ke.Namespace}, ke)
186+
require.NoError(t, err)
187+
// Check Konnect control plane ID
188+
assert.NotNil(t, ke.Status.Konnect, "status.konnect should be present")
189+
assert.Equal(t, expectedKonnectCPID, ke.Status.Konnect.ControlPlaneID, "Konnect control plane ID should be set in status")
190+
// Check dataplane client auth
191+
assert.NotNil(t, ke.Status.DataPlaneClientAuth, "status.dataPlaneClientAuth should be present")
192+
assert.NotNil(t, ke.Status.DataPlaneClientAuth.CertificateSecretRef, "status.dataPlaneClientAuth.certiifcateSecretRef should be present")
193+
assert.Equal(t, expectedDPCertificateSecretName, ke.Status.DataPlaneClientAuth.CertificateSecretRef.Name,
194+
"status.dataPlaneClientAuth.certiifcateSecretRef should have the expected secret name")
195+
}
196+
}

test/integration/zz_generated.registered_testcases.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)