Skip to content

Commit d9be39c

Browse files
authored
fix: set default IngressClass for ControlPlane conversion (#591)
1 parent 98d582f commit d9be39c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

api/gateway-operator/v1beta1/controlplane_conversion.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ func (c *ControlPlane) ConvertTo(dstRaw conversion.Hub) error {
6767

6868
dst.ObjectMeta = c.ObjectMeta
6969

70-
if err := c.Spec.convertTo(&dst.Spec.ControlPlaneOptions, c.Spec.IngressClass); err != nil {
70+
// Setting IngressClass wasn't required in v1beta1, but for v2beta1 it is,
71+
// thus fill with a default value to make it work without hassle.
72+
class := lo.FromPtrOr(c.Spec.IngressClass, "kong")
73+
if err := c.Spec.convertTo(&dst.Spec.ControlPlaneOptions, &class); err != nil {
7174
return err
7275
}
7376
dst.Spec.Extensions = c.Spec.Extensions

test/conversion/gateway-operator.konghq.com/v1beta1/controlplane_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestControlPlane_ConvertTo(t *testing.T) {
2727
name string
2828
spec operatorv1beta1.ControlPlaneSpec
2929
expectsDataPlane bool
30+
expectedIngressClass *string
3031
expectedFeatureGates []operatorv2beta1.ControlPlaneFeatureGate
3132
expectedControllers []operatorv2beta1.ControlPlaneController
3233
expectedError error
@@ -76,9 +77,9 @@ func TestControlPlane_ConvertTo(t *testing.T) {
7677
},
7778
},
7879
},
79-
IngressClass: lo.ToPtr("kong"),
8080
},
81-
expectsDataPlane: true,
81+
expectedIngressClass: lo.ToPtr("kong"),
82+
expectsDataPlane: true,
8283
expectedFeatureGates: []operatorv2beta1.ControlPlaneFeatureGate{
8384
{Name: "GatewayAlpha", State: operatorv2beta1.FeatureGateStateEnabled},
8485
{Name: "ExperimentalFeature", State: operatorv2beta1.FeatureGateStateDisabled},
@@ -190,9 +191,10 @@ func TestControlPlane_ConvertTo(t *testing.T) {
190191
List: []string{"namespace1", "namespace2"},
191192
},
192193
},
193-
IngressClass: lo.ToPtr("kong"),
194+
IngressClass: lo.ToPtr("test"),
194195
},
195-
expectsDataPlane: false,
196+
expectedIngressClass: lo.ToPtr("test"),
197+
expectsDataPlane: false,
196198
},
197199
{
198200
name: "With own namespace watching",
@@ -203,7 +205,8 @@ func TestControlPlane_ConvertTo(t *testing.T) {
203205
},
204206
},
205207
},
206-
expectsDataPlane: false,
208+
expectedIngressClass: lo.ToPtr("kong"),
209+
expectsDataPlane: false,
207210
},
208211
}
209212

@@ -246,7 +249,7 @@ func TestControlPlane_ConvertTo(t *testing.T) {
246249
require.Nil(t, dst.Spec.DataPlane.Ref)
247250
}
248251

249-
require.Equal(t, tc.spec.IngressClass, dst.Spec.IngressClass)
252+
require.Equal(t, tc.expectedIngressClass, dst.Spec.IngressClass)
250253

251254
if tc.spec.WatchNamespaces != nil {
252255
require.NotNil(t, dst.Spec.WatchNamespaces)

0 commit comments

Comments
 (0)