-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controlplane): move ControlPlane image validation to CRD CEL rule (
#984) * feat(controlplane): move ControlPlane image validation to CRD CEL rule * tests: add CRD validation tests * chore: use kcfg from main
- Loading branch information
Showing
11 changed files
with
107 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package crdsvalidation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/samber/lo" | ||
"golang.org/x/net/context" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1" | ||
"github.com/kong/gateway-operator/modules/manager/scheme" | ||
"github.com/kong/gateway-operator/test/envtest" | ||
|
||
kcfgcrdsvalidation "github.com/kong/kubernetes-configuration/test/crdsvalidation" | ||
) | ||
|
||
func TestControlPlane(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
cfg, ns := envtest.Setup(t, ctx, scheme.Get()) | ||
|
||
t.Run("spec", func(t *testing.T) { | ||
kcfgcrdsvalidation.TestCasesGroup[*operatorv1beta1.ControlPlane]{ | ||
{ | ||
Name: "not providing image fails", | ||
TestObject: &operatorv1beta1.ControlPlane{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "cp-", | ||
Namespace: ns.Name, | ||
}, | ||
Spec: operatorv1beta1.ControlPlaneSpec{}, | ||
}, | ||
ExpectedErrorMessage: lo.ToPtr("ControlPlane requires an image to be set on controller container"), | ||
}, | ||
{ | ||
Name: "providing image succeeds", | ||
TestObject: &operatorv1beta1.ControlPlane{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "cp-", | ||
Namespace: ns.Name, | ||
}, | ||
Spec: operatorv1beta1.ControlPlaneSpec{ | ||
ControlPlaneOptions: operatorv1beta1.ControlPlaneOptions{ | ||
Deployment: operatorv1beta1.ControlPlaneDeploymentOptions{ | ||
PodTemplateSpec: &corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "controller", | ||
Image: "kong/kubernetes-ingress-controller:3.4.1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}.RunWithConfig(t, cfg, scheme.Get()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters