Skip to content

Commit

Permalink
fix integer type handling (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabuskey authored Sep 25, 2023
1 parent 7e059df commit f01bc62
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/cnoe-io/cnoe-cli/pkg/models"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -182,7 +182,7 @@ func (c *CRDModule) convert(def string) (any, string, error) {

var resourceName string
if doc.Spec.ClaimNames != nil {
resourceName = doc.Spec.ClaimNames.Kind
resourceName = fmt.Sprintf("%s.%s", doc.Spec.Group, doc.Spec.ClaimNames.Kind)
} else {
resourceName = fmt.Sprintf("%s.%s", doc.Spec.Group, doc.Spec.Names.Kind)
}
Expand Down Expand Up @@ -218,10 +218,14 @@ func (c *CRDModule) convert(def string) (any, string, error) {
"default": fmt.Sprintf("%s/%s", doc.Spec.Group, doc.Spec.Versions[0].Name),
},
"properties", "apiVersion")
kind := doc.Spec.Names.Kind
if doc.Spec.ClaimNames != nil {
kind = doc.Spec.ClaimNames.Kind
}
unstructured.SetNestedMap(obj.Object, map[string]interface{}{
"type": "string",
"description": "Kind for the resource",
"default": doc.Spec.Names.Kind,
"default": kind,
},
"properties", "kind")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/fakes/crd/valid/input/cdn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ spec:
properties:
spec:
properties:
minSize:
type: integer
default: 2
description: Min Size.
resourceConfig:
description: ResourceConfig defines general properties of this AWS
resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spec:
type: string
config:
properties:
minSize:
type: integer
default: 2
description: Min Size.
resourceConfig:
description: ResourceConfig defines general properties of this AWS resource.
properties:
Expand Down Expand Up @@ -50,10 +54,10 @@ spec:
type: object
required:
- resourceConfig
title: awsblueprints.io.XCDN configuration options
title: awsblueprints.io.CDN configuration options
type: object
kind:
default: XCDN
default: CDN
description: Kind for the resource
type: string
name:
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/fakes/crd/valid/output/full-template-oneof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
- dependencies:
resources:
oneOf:
- $yaml: resources/awsblueprints.io.xcdn.yaml
- $yaml: resources/awsblueprints.io.cdn.yaml
- $yaml: resources/sparkoperator.k8s.io.sparkapplication.yaml
description: Select a AWS resource to add to your repository.
properties:
Expand All @@ -23,7 +23,7 @@ spec:
type: string
resources:
enum:
- awsblueprints.io.xcdn
- awsblueprints.io.cdn
- sparkoperator.k8s.io.sparkapplication
type: string
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ properties:
type: string
config:
properties:
minSize:
type: integer
default: 2
description: Min Size.
resourceConfig:
description: ResourceConfig defines general properties of this AWS resource.
properties:
Expand Down Expand Up @@ -40,12 +44,12 @@ properties:
type: object
required:
- resourceConfig
title: awsblueprints.io.XCDN configuration options
title: awsblueprints.io.CDN configuration options
type: object
kind:
default: XCDN
default: CDN
description: Kind for the resource
type: string
resources:
enum:
- awsblueprints.io.xcdn
- awsblueprints.io.cdn

0 comments on commit f01bc62

Please sign in to comment.