Skip to content

Commit

Permalink
Support old json marshaling (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Oct 12, 2024
1 parent 627173c commit 540a1dd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion apis/config/v1alpha1/setupconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha1

import (
"encoding/json"

cloudv1alpha1 "go.bytebuilders.dev/resource-model/apis/cloud/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -116,11 +118,31 @@ type SelfManagementOptions struct {
// +optional
CreateCAPICluster bool `json:"createCAPICluster"`
// +optional
EnableFeatures map[string]FeatureSetOptions `json:"enableFeatures"`
EnableFeatures EnableFeaturesOptions `json:"enableFeatures"`
// +optional
DisableFeatures []string `json:"disableFeatures"`
}

type EnableFeaturesOptions map[string]FeatureSetOptions

func (opts *EnableFeaturesOptions) UnmarshalJSON(data []byte) error {
var nu map[string]FeatureSetOptions
if err := json.Unmarshal(data, &nu); err != nil {
var old map[string][]string
if err := json.Unmarshal(data, &old); err != nil {
return err
}
for fs, features := range old {
nu[fs] = FeatureSetOptions{
Enabled: true,
Features: features,
}
}
}
*opts = nu
return nil
}

type FeatureSetOptions struct {
Enabled bool `json:"enabled"`
Features []string `json:"features"`
Expand Down
24 changes: 23 additions & 1 deletion apis/config/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 540a1dd

Please sign in to comment.