Skip to content

Commit

Permalink
fix params type in CustomCheckSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusfm committed May 17, 2023
1 parent 41be04e commit d913283
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
30 changes: 20 additions & 10 deletions api/zora/v1alpha1/customcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,38 @@
package v1alpha1

import (
"encoding/json"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

marvin "github.com/undistro/marvin/pkg/types"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CustomCheckSpec defines the desired state of CustomCheck
type CustomCheckSpec struct {
Match Match `json:"match"`
Validations []Validation `json:"validations"`
Params unstructured.Unstructured `json:"params,omitempty"`
Message string `json:"message"`
Category string `json:"category"`
URL string `json:"url,omitempty"`
Match Match `json:"match"`
Validations []Validation `json:"validations"`
Message string `json:"message"`
Category string `json:"category"`
URL string `json:"url,omitempty"`

// Parameters to be used in validations
Params *apiextensionsv1.JSON `json:"params,omitempty"`

//+kubebuilder:validation:Type=string
//+kubebuilder:validation:Enum=Low;Medium;High
Severity string `json:"severity"`
}

func (r *CustomCheck) GetParams() map[string]interface{} {
var values map[string]interface{}
if r.Spec.Params != nil {
_ = json.Unmarshal(r.Spec.Params.Raw, &values)
}
return values
}

type Match marvin.Match

type Validation marvin.Validation
Expand Down Expand Up @@ -75,7 +85,7 @@ func (r *CustomCheck) ToMarvin() *marvin.Check {
ID: r.Name,
Match: marvin.Match(r.Spec.Match),
Validations: mv,
Params: r.Spec.Params.Object,
Params: r.GetParams(),
Severity: marvin.ParseSeverity(r.Spec.Severity),
Message: r.Spec.Message,
Labels: map[string]string{"category": r.Spec.Category, "url": r.Spec.URL},
Expand Down
7 changes: 6 additions & 1 deletion api/zora/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion charts/zora/crds/zora.undistro.io_customchecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ spec:
message:
type: string
params:
type: object
description: Parameters to be used in validations
x-kubernetes-preserve-unknown-fields: true
severity:
enum:
- Low
Expand Down
3 changes: 2 additions & 1 deletion config/crd/bases/zora.undistro.io_customchecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ spec:
message:
type: string
params:
type: object
description: Parameters to be used in validations
x-kubernetes-preserve-unknown-fields: true
severity:
enum:
- Low
Expand Down

0 comments on commit d913283

Please sign in to comment.