Skip to content

Commit

Permalink
feat: add GroupResource consts; set TypeMeta in Build (#379)
Browse files Browse the repository at this point in the history
## Issue
Resolves #371

## Description
Once plugins implement `ValidationRule`, `Build` will populate
`TypeMeta` properly.

---------

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson authored Aug 9, 2024
1 parent 8fd8c5d commit c05a36e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 23 additions & 3 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,37 @@ limitations under the License.
package v1alpha1

import (
"reflect"

"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "validation.spectrocloud.labs", Version: "v1alpha1"}
// APIVersion is the API version used to reference v1alpha1 objects.
APIVersion = GroupVersion.String()

// Group is the API group used to reference validator objects.
Group = "validation.spectrocloud.labs"

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: Group, Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// ValidatorConfigKind is the kind of the ValidatorConfig object.
ValidatorConfigKind = reflect.TypeOf(ValidatorConfig{}).Name()

// ValidatorConfigGroupResource is the name of the ValidatorConfig resource.
ValidatorConfigGroupResource = schema.GroupResource{Group: Group, Resource: "validatorconfigs"}

// ValidationResultKind is the kind of the ValidationResult object.
ValidationResultKind = reflect.TypeOf(ValidationResult{}).Name()

// ValidationResultGroupResource is the name of the ValidationResult resource.
ValidationResultGroupResource = schema.GroupResource{Group: Group, Resource: "validationresults"}
)
5 changes: 5 additions & 0 deletions pkg/validationresult/validation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ type Patcher interface {
// ValidationRule is an interface for validation rules.
type ValidationRule interface {
client.Object
GetKind() string
PluginCode() string
ResultCount() int
}

// Build creates a new ValidationResult for a specific ValidationRule.
func Build(r ValidationRule) *v1alpha1.ValidationResult {
return &v1alpha1.ValidationResult{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha1.APIVersion,
Kind: r.GetKind(),
},
ObjectMeta: metav1.ObjectMeta{
Name: Name(r),
Namespace: r.GetNamespace(),
Expand Down

0 comments on commit c05a36e

Please sign in to comment.