Files
wangyike 5c33598fe9 modify controller,webhook,api,chart
solve failed test

add compatibility test for old crd

add app ns for cli

modify compatibility test

solve compatibility problem

add testing for  GetDefinition func with cluster scope CRD

generate code for compatibility-test

move testdata generate to makefile

optimize ci pipeline for compatibility-test
2021-03-09 10:10:48 +08:00

37 lines
1.4 KiB
Go

package application
import (
"context"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/pkg/appfile"
"github.com/oam-dev/kubevela/pkg/oam"
)
// ValidateCreate validates the Application on creation
func (h *ValidatingHandler) ValidateCreate(ctx context.Context, app *v1alpha2.Application) field.ErrorList {
var componentErrs field.ErrorList
// try to generate an app file
appParser := appfile.NewApplicationParser(h.Client, h.dm)
if _, err := appParser.GenerateAppFile(ctx, app.Name, app); err != nil {
componentErrs = append(componentErrs, field.Invalid(field.NewPath("spec"), app, err.Error()))
}
return componentErrs
}
// ValidateUpdate validates the Application on update
func (h *ValidatingHandler) ValidateUpdate(ctx context.Context, newApp, oldApp *v1alpha2.Application) field.ErrorList {
// check if the newApp is valid
componentErrs := h.ValidateCreate(ctx, newApp)
// one can't add a rollout annotation to an existing application
if _, exist := oldApp.GetAnnotations()[oam.AnnotationAppRollout]; !exist {
if _, exist := newApp.GetAnnotations()[oam.AnnotationAppRollout]; exist {
componentErrs = append(componentErrs, field.Forbidden(field.NewPath("meta").Child("annotation"),
"cannot add a rollout annotation on an existing application"))
}
}
return componentErrs
}