mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
test: Support e2e tests and improve robustness on k8s v1.21-v1.23 (#8431)
Signed-off-by: Yuan Tang <[email protected]> Co-authored-by: Jesse Suen <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
Jesse Suen
parent
5ba8202377
commit
e1dea67f14
@@ -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:
|
||||
|
||||
@@ -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{}))
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -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
|
||||
|
||||
+51
-6
@@ -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
|
||||
|
||||
+71
-8
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+26
-6
@@ -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
|
||||
- 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
|
||||
|
||||
+26
-6
@@ -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
|
||||
- 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
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user