* [API Server] Add Example App for reference use. * Remove Printlns. * Upgrade app-sdk to v0.46.0, update apps to handle breaking changes. * Only start the reconciler for the example app if the v1alpha1 API version is enabled. * Some comment doc updates. * Run make update-workspace * Set codeowner for /apps/example * Run make gofmt and make update-workspace * Run prettier on apps/example/README.md * Add COPY apps/example to Dockerfile * Add an authorizer to the example app. * Fix import ordering. * Update apps/example/kinds/manifest.cue Co-authored-by: Owen Diehl <ow.diehl@gmail.com> * Run make update-workspace * Re-run make gen-go for enterprise import updates * Run make update-workspace --------- Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
29 lines
683 B
Go
29 lines
683 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/grafana/grafana-app-sdk/app"
|
|
"github.com/grafana/grafana-app-sdk/simple"
|
|
)
|
|
|
|
var _ simple.KindValidator = NewValidator()
|
|
|
|
// Validator implements simple.KindValidator
|
|
type Validator struct{}
|
|
|
|
func NewValidator() *Validator {
|
|
return &Validator{}
|
|
}
|
|
|
|
// Validate runs any kind of validation on incoming objects,
|
|
// and returns an error to reject the request.
|
|
// Here, we just reject any Example resource which is named "invalid"
|
|
func (v *Validator) Validate(ctx context.Context, req *app.AdmissionRequest) error {
|
|
if req.Object.GetName() == "invalid" {
|
|
return errors.New("example cannot be named 'invalid'")
|
|
}
|
|
return nil
|
|
}
|