From 3c7d99f82c793c1ac59a1633b8c400ec5f27825c Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Tue, 15 Feb 2022 21:01:51 -0500 Subject: [PATCH] test: Support e2e tests and improve robustness on k8s v1.21-v1.23 (#8431) Signed-off-by: Yuan Tang Co-authored-by: Jesse Suen --- .github/workflows/ci-build.yaml | 2 +- test/e2e/app_management_test.go | 34 ++++---- .../testdata/crd-creation/crd-instances.yaml | 5 +- test/e2e/testdata/crd-creation/crd.yaml | 57 +++++++++++-- test/e2e/testdata/crd-subresource/crd.yaml | 79 +++++++++++++++++-- .../duplicates-cluster.yaml | 28 ++++++- .../duplicates-namespaced.yaml | 27 ++++++- test/e2e/testdata/helm-crd/templates/crd.yaml | 32 ++++++-- test/e2e/testdata/helm3-crd/crds/crd.yaml | 32 ++++++-- util/argo/normalizers/diff_normalizer_test.go | 20 ++++- 10 files changed, 260 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index 6c3cd8668e306..3646323dc858f 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -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: diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index 6b2c237eb892f..f7f742db38f3a 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -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" @@ -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(). @@ -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", }}, }, @@ -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, }}, }, }, @@ -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{ @@ -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). @@ -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{})) } diff --git a/test/e2e/testdata/crd-creation/crd-instances.yaml b/test/e2e/testdata/crd-creation/crd-instances.yaml index 29c01a401f46e..59ec50a92b4a7 100644 --- a/test/e2e/testdata/crd-creation/crd-instances.yaml +++ b/test/e2e/testdata/crd-creation/crd-instances.yaml @@ -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 diff --git a/test/e2e/testdata/crd-creation/crd.yaml b/test/e2e/testdata/crd-creation/crd.yaml index 53b1943eac968..2216607cbfb4a 100644 --- a/test/e2e/testdata/crd-creation/crd.yaml +++ b/test/e2e/testdata/crd-creation/crd.yaml @@ -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 diff --git a/test/e2e/testdata/crd-subresource/crd.yaml b/test/e2e/testdata/crd-subresource/crd.yaml index 4d1e37c4398e6..6c59c3e2d2534 100644 --- a/test/e2e/testdata/crd-subresource/crd.yaml +++ b/test/e2e/testdata/crd-subresource/crd.yaml @@ -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 diff --git a/test/e2e/testdata/duplicated-resources/duplicates-cluster.yaml b/test/e2e/testdata/duplicated-resources/duplicates-cluster.yaml index a2e6e9527f6fd..acd0f4025d80e 100644 --- a/test/e2e/testdata/duplicated-resources/duplicates-cluster.yaml +++ b/test/e2e/testdata/duplicated-resources/duplicates-cluster.yaml @@ -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 diff --git a/test/e2e/testdata/duplicated-resources/duplicates-namespaced.yaml b/test/e2e/testdata/duplicated-resources/duplicates-namespaced.yaml index 3f19da75128a2..58458eadb3526 100644 --- a/test/e2e/testdata/duplicated-resources/duplicates-namespaced.yaml +++ b/test/e2e/testdata/duplicated-resources/duplicates-namespaced.yaml @@ -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 diff --git a/test/e2e/testdata/helm-crd/templates/crd.yaml b/test/e2e/testdata/helm-crd/templates/crd.yaml index 9e02aaffb9350..e5b59cc449027 100644 --- a/test/e2e/testdata/helm-crd/templates/crd.yaml +++ b/test/e2e/testdata/helm-crd/templates/crd.yaml @@ -1,14 +1,34 @@ -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: crontabs.stable.example.com spec: + conversion: + strategy: None group: stable.example.com - version: v1 - scope: Namespaced names: - plural: crontabs - singular: crontab kind: CronTab + listKind: CronTabList + plural: crontabs shortNames: - - ct \ No newline at end of file + - ct + singular: crontab + scope: Namespaced + versions: + - name: v1 + 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 diff --git a/test/e2e/testdata/helm3-crd/crds/crd.yaml b/test/e2e/testdata/helm3-crd/crds/crd.yaml index 9e02aaffb9350..e5b59cc449027 100644 --- a/test/e2e/testdata/helm3-crd/crds/crd.yaml +++ b/test/e2e/testdata/helm3-crd/crds/crd.yaml @@ -1,14 +1,34 @@ -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: crontabs.stable.example.com spec: + conversion: + strategy: None group: stable.example.com - version: v1 - scope: Namespaced names: - plural: crontabs - singular: crontab kind: CronTab + listKind: CronTabList + plural: crontabs shortNames: - - ct \ No newline at end of file + - ct + singular: crontab + scope: Namespaced + versions: + - name: v1 + 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 diff --git a/util/argo/normalizers/diff_normalizer_test.go b/util/argo/normalizers/diff_normalizer_test.go index 3cd63966ec5da..f872ca367cc29 100644 --- a/util/argo/normalizers/diff_normalizer_test.go +++ b/util/argo/normalizers/diff_normalizer_test.go @@ -78,22 +78,34 @@ func TestNormalizeMatchedResourceOverrides(t *testing.T) { } const testCRDYAML = ` -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: certificates.cert-manager.io spec: + conversion: + strategy: None group: cert-manager.io names: kind: Certificate listKind: CertificateList plural: certificates shortNames: - - cert - - certs + - cert + - certs singular: certificate scope: Namespaced - version: v1alpha1` + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + json: + x-kubernetes-preserve-unknown-fields: true` func TestNormalizeMissingJsonPointer(t *testing.T) { normalizer, err := NewIgnoreNormalizer([]v1alpha1.ResourceIgnoreDifferences{}, map[string]v1alpha1.ResourceOverride{