Skip to content

Commit

Permalink
test: Support e2e tests and improve robustness on k8s v1.21-v1.23 (ar…
Browse files Browse the repository at this point in the history
…goproj#8431)

Signed-off-by: Yuan Tang <[email protected]>
Co-authored-by: Jesse Suen <[email protected]>
  • Loading branch information
2 people authored and alexmt committed Feb 25, 2022
1 parent c5c25cd commit 3c7d99f
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
k3s-version: [v1.21.2, v1.20.2, v1.19.2, v1.18.9, v1.17.11]
k3s-version: [v1.23.3, v1.22.6, v1.21.2]
needs:
- build-go
env:
Expand Down
34 changes: 19 additions & 15 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
networkingv1beta "k8s.io/api/networking/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -650,7 +650,7 @@ func TestKnownTypesInCRDDiffing(t *testing.T) {
When().
And(func() {
dummyResIf := DynamicClientset.Resource(dummiesGVR).Namespace(DeploymentNamespace())
patchData := []byte(`{"spec":{"requests": {"cpu": "2"}}}`)
patchData := []byte(`{"spec":{"cpu": "2"}}`)
FailOnErr(dummyResIf.Patch(context.Background(), "dummy-crd-instance", types.MergePatchType, patchData, metav1.PatchOptions{}))
}).Refresh(RefreshTypeNormal).
Then().
Expand All @@ -660,7 +660,7 @@ func TestKnownTypesInCRDDiffing(t *testing.T) {
SetResourceOverrides(map[string]ResourceOverride{
"argoproj.io/Dummy": {
KnownTypeFields: []KnownTypeField{{
Field: "spec.requests",
Field: "spec",
Type: "core/v1/ResourceList",
}},
},
Expand Down Expand Up @@ -1278,23 +1278,27 @@ func TestOrphanedResource(t *testing.T) {
func TestNotPermittedResources(t *testing.T) {
ctx := Given(t)

ingress := &networkingv1beta.Ingress{
pathType := networkingv1.PathTypePrefix
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "sample-ingress",
Labels: map[string]string{
common.LabelKeyAppInstance: ctx.GetName(),
},
},
Spec: networkingv1beta.IngressSpec{
Rules: []networkingv1beta.IngressRule{{
IngressRuleValue: networkingv1beta.IngressRuleValue{
HTTP: &networkingv1beta.HTTPIngressRuleValue{
Paths: []networkingv1beta.HTTPIngressPath{{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{{
Path: "/",
Backend: networkingv1beta.IngressBackend{
ServiceName: "guestbook-ui",
ServicePort: intstr.IntOrString{Type: intstr.Int, IntVal: 80},
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "guestbook-ui",
Port: networkingv1.ServiceBackendPort{Number: 80},
},
},
PathType: &pathType,
}},
},
},
Expand All @@ -1303,7 +1307,7 @@ func TestNotPermittedResources(t *testing.T) {
}
defer func() {
log.Infof("Ingress 'sample-ingress' deleted from %s", ArgoCDNamespace)
CheckError(KubeClientset.NetworkingV1beta1().Ingresses(ArgoCDNamespace).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
CheckError(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
}()

svc := &v1.Service{
Expand Down Expand Up @@ -1331,7 +1335,7 @@ func TestNotPermittedResources(t *testing.T) {
{Group: "", Kind: "Service"},
}}).
And(func() {
FailOnErr(KubeClientset.NetworkingV1beta1().Ingresses(ArgoCDNamespace).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Create(context.Background(), svc, metav1.CreateOptions{}))
}).
Path(guestbookPath).
Expand All @@ -1357,7 +1361,7 @@ func TestNotPermittedResources(t *testing.T) {
Expect(DoesNotExist())

// Make sure prohibited resources are not deleted during application deletion
FailOnErr(KubeClientset.NetworkingV1beta1().Ingresses(ArgoCDNamespace).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{}))
}

Expand Down
5 changes: 2 additions & 3 deletions test/e2e/testdata/crd-creation/crd-instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ kind: Dummy
metadata:
name: dummy-crd-instance
spec:
requests:
cpu: 2000m
memory: 32Mi
cpu: 2000m
memory: 32Mi
---
apiVersion: argoproj.io/v1alpha1
kind: Dummy
Expand Down
57 changes: 51 additions & 6 deletions test/e2e/testdata/crd-creation/crd.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,69 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: dummies.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Namespaced
names:
kind: Dummy
listKind: DummyList
plural: dummies
singular: dummy
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
properties:
cpu:
type: string
memory:
type: string
---
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: clusterdummies.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Cluster
names:
kind: ClusterDummy
listKind: ClusterDummyList
plural: clusterdummies
singular: clusterdummy
scope: Cluster
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true
79 changes: 71 additions & 8 deletions test/e2e/testdata/crd-subresource/crd.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,88 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: statussubresources.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Namespaced
names:
kind: StatusSubResource
listKind: StatusSubResourceList
plural: statussubresources
subresources:
status: {}
singular: statussubresource
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true
properties:
foo:
type: string
status:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true
properties:
bar:
type: string

---
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: nonstatussubresources.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Namespaced
names:
kind: NonStatusSubResource
listKind: NonStatusSubResourceList
plural: nonstatussubresources
singular: nonstatussubresource
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true
properties:
foo:
type: string
status:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true
properties:
bar:
type: string
28 changes: 24 additions & 4 deletions test/e2e/testdata/duplicated-resources/duplicates-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: clusterdummies.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Cluster
names:
kind: ClusterDummy
listKind: ClusterDummyList
plural: clusterdummies

singular: clusterdummy
scope: Cluster
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true

---
apiVersion: argoproj.io/v1alpha1
Expand Down
27 changes: 24 additions & 3 deletions test/e2e/testdata/duplicated-resources/duplicates-namespaced.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: dummies.argoproj.io
spec:
conversion:
strategy: None
group: argoproj.io
version: v1alpha1
scope: Namespaced
names:
kind: Dummy
listKind: DummyList
plural: dummies
singular: dummy
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
x-kubernetes-map-type: atomic
x-kubernetes-preserve-unknown-fields: true

---
apiVersion: argoproj.io/v1alpha1
Expand Down
Loading

0 comments on commit 3c7d99f

Please sign in to comment.