Skip to content

Commit

Permalink
Adds CRD fields: property and required
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Jul 10, 2023
1 parent 1eb687b commit fe28eb4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/resources/apiextensions/v1beta1/crd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Generate(d *schema.ResourceData) (apiextensionsv1.CustomResourceDefinition,
version = d.Get(FieldVersion).(string)
scope = d.Get(FieldScope).(string)
rawNames = d.Get(FieldNames).([]interface{})
rawProperties = d.Get(FieldProperty).([]interface{})
rawProperties = d.Get(FieldProperty).(*schema.Set).List()
rawRequired = d.Get(FieldRequired).([]interface{})
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func Expand(in []interface{}) map[string]apiextensionsv1.JSONSchemaProps {
prop.Type = val.(string)
}

if val, ok := value[FieldPreserveUnknownFields]; ok {
prop.XPreserveUnknownFields = pointer.Bool(val.(bool))
if val, ok := value[FieldPreserveUnknownFields]; ok && val == true {
prop.XPreserveUnknownFields = pointer.Bool(true)
}

if val, ok := value[FieldName]; ok && val != "" {
Expand All @@ -34,3 +34,4 @@ func Expand(in []interface{}) map[string]apiextensionsv1.JSONSchemaProps {

return vars
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
func Fields() *schema.Schema {
return &schema.Schema{
Description: "Environment variables which can be set for a container",
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
12 changes: 10 additions & 2 deletions internal/resources/apiextensions/v1beta1/crd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia

conn := m.(*config.Client)

crd, err := Generate(d)
c, err := Generate(d)
if err != nil {
return diag.FromErr(err)
}

_, err = conn.APIExtensions().ApiextensionsV1().CustomResourceDefinitions().Update(ctx, &crd, metav1.UpdateOptions{})
crd, err := conn.APIExtensions().ApiextensionsV1().CustomResourceDefinitions().Get(ctx, c.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return diag.FromErr(err)
}

crd.Spec = c.Spec

_, err = conn.APIExtensions().ApiextensionsV1().CustomResourceDefinitions().Update(ctx, crd, metav1.UpdateOptions{})
if err != nil {
return diag.FromErr(err)
}

return diags
}

0 comments on commit fe28eb4

Please sign in to comment.