Skip to content

Commit

Permalink
fix rusi component crd (#51)
Browse files Browse the repository at this point in the history
* fix rusi component crd

* removed comments

* Fixed json uqote

---------

Co-authored-by: fraliv13 <[email protected]>
  • Loading branch information
oncicaradupopovici and fraliv13 authored Feb 4, 2025
1 parent f76fe24 commit fa443ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 41 deletions.
3 changes: 0 additions & 3 deletions helm/crds/rusi.io_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ spec:
- name
type: object
value:
description: DynamicValue is a dynamic value struct for the
component.metadata pair value.
type: object
x-kubernetes-preserve-unknown-fields: true
required:
- name
Expand Down
22 changes: 2 additions & 20 deletions pkg/operator/apis/rusi/v1alpha1/componentTypes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package v1alpha1

import (
"strconv"

v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -39,7 +37,7 @@ type ComponentSpec struct {
type MetadataItem struct {
Name string `json:"name"`
// +optional
Value DynamicValue `json:"value,omitempty"`
Value apiextensionsv1.JSON `json:"value,omitempty"`
// +optional
SecretKeyRef SecretKeyRef `json:"secretKeyRef,omitempty"`
}
Expand All @@ -64,19 +62,3 @@ type ComponentList struct {

Items []Component `json:"items"`
}

// DynamicValue is a dynamic value struct for the component.metadata pair value.
type DynamicValue struct {
v1.JSON `json:",inline"`
}

// String returns the string representation of the raw value.
// If the value is a string, it will be unquoted as the string is guaranteed to be a JSON serialized string.
func (d *DynamicValue) String() string {
s := string(d.Raw)
c, err := strconv.Unquote(s)
if err == nil {
s = c
}
return s
}
17 changes: 0 additions & 17 deletions pkg/operator/apis/rusi/v1alpha1/zz_generated.deepcopy.go

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

13 changes: 12 additions & 1 deletion pkg/operator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"rusi/pkg/custom-resource/components"
rusiv1 "rusi/pkg/operator/apis/rusi/v1alpha1"
operatorv1 "rusi/pkg/proto/operator/v1"
"strconv"
"strings"

"github.com/google/uuid"
jsoniter "github.com/json-iterator/go"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -70,11 +72,20 @@ func convertToComponent(item rusiv1.Component) components.Spec {
func convertMetadataItemsToProperties(items []rusiv1.MetadataItem) map[string]string {
properties := map[string]string{}
for _, c := range items {
val := c.Value.String()
val := JsonToUnquotedString(c.Value)
for strings.Contains(val, "{uuid}") {
val = strings.Replace(val, "{uuid}", uuid.New().String(), 1)
}
properties[c.Name] = val
}
return properties
}

func JsonToUnquotedString(json apiextensionsv1.JSON) string {
s := string(json.Raw)
c, err := strconv.Unquote(s)
if err == nil {
s = c
}
return s
}

0 comments on commit fa443ee

Please sign in to comment.