Skip to content

Commit c05a36e

Browse files
authored
feat: add GroupResource consts; set TypeMeta in Build (#379)
## Issue Resolves #371 ## Description Once plugins implement `ValidationRule`, `Build` will populate `TypeMeta` properly. --------- Signed-off-by: Tyler Gillson <[email protected]>
1 parent 8fd8c5d commit c05a36e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

api/v1alpha1/groupversion_info.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,37 @@ limitations under the License.
2020
package v1alpha1
2121

2222
import (
23+
"reflect"
24+
2325
"k8s.io/apimachinery/pkg/runtime/schema"
2426
"sigs.k8s.io/controller-runtime/pkg/scheme"
2527
)
2628

2729
var (
28-
// GroupVersion is group version used to register these objects
29-
GroupVersion = schema.GroupVersion{Group: "validation.spectrocloud.labs", Version: "v1alpha1"}
30+
// APIVersion is the API version used to reference v1alpha1 objects.
31+
APIVersion = GroupVersion.String()
32+
33+
// Group is the API group used to reference validator objects.
34+
Group = "validation.spectrocloud.labs"
3035

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
36+
// GroupVersion is group version used to register these objects.
37+
GroupVersion = schema.GroupVersion{Group: Group, Version: "v1alpha1"}
38+
39+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3240
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3341

3442
// AddToScheme adds the types in this group-version to the given scheme.
3543
AddToScheme = SchemeBuilder.AddToScheme
44+
45+
// ValidatorConfigKind is the kind of the ValidatorConfig object.
46+
ValidatorConfigKind = reflect.TypeOf(ValidatorConfig{}).Name()
47+
48+
// ValidatorConfigGroupResource is the name of the ValidatorConfig resource.
49+
ValidatorConfigGroupResource = schema.GroupResource{Group: Group, Resource: "validatorconfigs"}
50+
51+
// ValidationResultKind is the kind of the ValidationResult object.
52+
ValidationResultKind = reflect.TypeOf(ValidationResult{}).Name()
53+
54+
// ValidationResultGroupResource is the name of the ValidationResult resource.
55+
ValidationResultGroupResource = schema.GroupResource{Group: Group, Resource: "validationresults"}
3656
)

pkg/validationresult/validation_result.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ type Patcher interface {
2929
// ValidationRule is an interface for validation rules.
3030
type ValidationRule interface {
3131
client.Object
32+
GetKind() string
3233
PluginCode() string
3334
ResultCount() int
3435
}
3536

3637
// Build creates a new ValidationResult for a specific ValidationRule.
3738
func Build(r ValidationRule) *v1alpha1.ValidationResult {
3839
return &v1alpha1.ValidationResult{
40+
TypeMeta: metav1.TypeMeta{
41+
APIVersion: v1alpha1.APIVersion,
42+
Kind: r.GetKind(),
43+
},
3944
ObjectMeta: metav1.ObjectMeta{
4045
Name: Name(r),
4146
Namespace: r.GetNamespace(),

0 commit comments

Comments
 (0)