mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
fix application rollout annotation false issue (#1633)
* fix annotation false issue neat imports * rewrite judge logic * add webhook * add webhook verify annotation * fix test fix bug * modify error message
This commit is contained in:
@@ -102,6 +102,25 @@ var _ = Describe("Test Application Validator", func() {
|
||||
"metadata":{"name":"application-sample"},
|
||||
"spec":{"components":[{"type":"myweb","properties":{"cmd":["sleep","1000"],"image":"busybox"},
|
||||
"traits":[{"type":"scaler","properties":{"replicas":10}}],"type":"worker"}]}}
|
||||
`),
|
||||
},
|
||||
},
|
||||
}
|
||||
resp := handler.Handle(ctx, req)
|
||||
Expect(resp.Allowed).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("Test Application Validator rollout-template annotation [error]", func() {
|
||||
req := admission.Request{
|
||||
AdmissionRequest: admissionv1beta1.AdmissionRequest{
|
||||
Operation: admissionv1beta1.Create,
|
||||
Resource: metav1.GroupVersionResource{Group: "core.oam.dev", Version: "v1alpha2", Resource: "applications"},
|
||||
Object: runtime.RawExtension{
|
||||
Raw: []byte(`
|
||||
{"apiVersion":"core.oam.dev/v1beta1","kind":"Application",
|
||||
"metadata":{"name":"application-sample","annotations":{"app.oam.dev/rollout-template":"false"}},
|
||||
"spec":{"components":[{"type":"worker","properties":{"cmd":["sleep","1000"],"image":"busybox"},
|
||||
"traits":[{"type":"scaler","properties":{"replicas":10}}]}]}}
|
||||
`),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/appfile"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
)
|
||||
|
||||
// ValidateCreate validates the Application on creation
|
||||
@@ -40,7 +41,9 @@ func (h *ValidatingHandler) ValidateCreate(ctx context.Context, app *v1beta1.App
|
||||
if err := appParser.ValidateCUESchematicAppfile(af); err != nil {
|
||||
componentErrs = append(componentErrs, field.Invalid(field.NewPath("schematic"), app, err.Error()))
|
||||
}
|
||||
|
||||
if v := app.GetAnnotations()[oam.AnnotationAppRollout]; len(v) != 0 && v != "true" {
|
||||
componentErrs = append(componentErrs, field.Invalid(field.NewPath("annotation:app.oam.dev/rollout-template"), app, "the annotation value of rollout-template must be true"))
|
||||
}
|
||||
return componentErrs
|
||||
}
|
||||
|
||||
|
||||
@@ -158,4 +158,11 @@ var _ = Describe("Application Normal tests", func() {
|
||||
verifyWorkloadRunningExpected("myweb", 1, "stefanprodan/podinfo:5.0.2")
|
||||
})
|
||||
|
||||
It("Test app have rollout-template false annotation", func() {
|
||||
By("Apply an application")
|
||||
var newApp v1beta1.Application
|
||||
Expect(common.ReadYamlToObject("testdata/app/app5.yaml", &newApp)).Should(BeNil())
|
||||
newApp.Namespace = namespaceName
|
||||
Expect(k8sClient.Create(ctx, &newApp)).ShouldNot(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
annotations:
|
||||
"app.oam.dev/rollout-template": "false"
|
||||
name: app-e2e
|
||||
spec:
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
properties:
|
||||
image: "stefanprodan/podinfo:4.0.3"
|
||||
cmd:
|
||||
- ./podinfo
|
||||
- stress-cpu=1
|
||||
Reference in New Issue
Block a user