Files
kubevela/pkg/webhook/core.oam.dev/v1alpha2/application/validation.go
Zheng Xi Zhou 2a943c9429 Using Terraform as IaC module in KubeVela (#863)
* Integrate Terraform into KubeVela

Integrated Terrafrom into KubeVela to enable it to deploy
infrastruce resouces by `vela up`

* extend Terraform modules/files as WorkloadDefinition

stop printing terraform log to console

Support one workload consumes two cloud services

Refactor Terraform plugin based on Application Object

add testcase

* refactor code per reviewer's comments

fix rebase issue

* find lost code back

* refactor code to make the modification as little as to that of branch master

* remove blank lines from imports
2021-01-28 18:36:52 +08:00

35 lines
1.3 KiB
Go

package application
import (
"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(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(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(newApp, oldApp *v1alpha2.Application) field.ErrorList {
// check if the newApp is valid
componentErrs := h.ValidateCreate(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
}