-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds CRD fields: property and required
- Loading branch information
Nick Schuch
committed
Jul 21, 2023
1 parent
0be2e66
commit e833e5d
Showing
10 changed files
with
196 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.19-alpine3.17 as build | ||
|
||
RUN apk add make gcc musl-dev | ||
|
||
WORKDIR /go/src/github.com/previousnext/terraform-provider-k8s | ||
COPY . /go/src/github.com/previousnext/terraform-provider-k8s | ||
|
||
RUN go build -ldflags "-linkmode external -extldflags -static" -o terraform-provider-k8s | ||
|
||
FROM hashicorp/terraform:0.14.8 as run | ||
|
||
RUN apk add bash | ||
|
||
RUN mkdir -p /root/.terraform.d/plugins | ||
|
||
COPY --from=build /go/src/github.com/previousnext/terraform-provider-k8s/terraform-provider-k8s /root/.terraform.d/plugins/registry.terraform.io/previousnext/k8s/99.0.0/linux_amd64/terraform-provider-k8s_v99.0.0 | ||
RUN chmod +x /root/.terraform.d/plugins/registry.terraform.io/*/*/*/linux_amd64/terraform-provider-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
internal/resources/apiextensions/v1beta1/crd/property/expand.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package property | ||
|
||
import ( | ||
"k8s.io/utils/pointer" | ||
|
||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
) | ||
|
||
// Expand will return a structured object. | ||
func Expand(in []interface{}) map[string]apiextensionsv1.JSONSchemaProps { | ||
if len(in) == 0 { | ||
return nil | ||
} | ||
|
||
vars := make(map[string]apiextensionsv1.JSONSchemaProps, len(in)) | ||
|
||
for _, v := range in { | ||
value := v.(map[string]interface{}) | ||
|
||
prop := apiextensionsv1.JSONSchemaProps{} | ||
|
||
if val, ok := value[FieldType]; ok && val != "" { | ||
prop.Type = val.(string) | ||
} | ||
|
||
if val, ok := value[FieldPreserveUnknownFields]; ok && val == true { | ||
prop.XPreserveUnknownFields = pointer.Bool(true) | ||
} | ||
|
||
if val, ok := value[FieldName]; ok && val != "" { | ||
vars[val.(string)] = prop | ||
} | ||
} | ||
|
||
return vars | ||
} | ||
|
39 changes: 39 additions & 0 deletions
39
internal/resources/apiextensions/v1beta1/crd/property/fields.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package property | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
// FieldName is a field identifier. | ||
FieldName = "name" | ||
// FieldType is a field identifier. | ||
FieldType = "type" | ||
// FieldPreserveUnknownFields is a field identifier. | ||
FieldPreserveUnknownFields = "preserve_unknown_fields" | ||
) | ||
|
||
// Fields returns the fields for this package. | ||
func Fields() *schema.Schema { | ||
return &schema.Schema{ | ||
Description: "Environment variables which can be set for a container", | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
FieldName: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldType: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldPreserveUnknownFields: { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
internal/resources/apiextensions/v1beta1/crd/property/flatten.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package property | ||
|
||
import ( | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
) | ||
|
||
// Flatten structured object into unstructured. | ||
func Flatten(in map[string]apiextensionsv1.JSONSchemaProps) []interface{} { | ||
flattened := make([]interface{}, 0) | ||
|
||
for name, value := range in { | ||
row := map[string]interface{}{} | ||
|
||
row[FieldName] = name | ||
|
||
if value.Type != "" { | ||
row[FieldType] = value.Type | ||
} | ||
|
||
if value.XPreserveUnknownFields != nil { | ||
row[FieldPreserveUnknownFields] = *value.XPreserveUnknownFields | ||
} | ||
|
||
flattened = append(flattened, row) | ||
} | ||
|
||
return flattened | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
internal/resources/apiextensions/v1beta1/crd/required/expand.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package required | ||
|
||
// Expand will return a structured object. | ||
func Expand(s []interface{}) []string { | ||
result := make([]string, len(s)) | ||
|
||
for k, v := range s { | ||
result[k] = v.(string) | ||
} | ||
|
||
return result | ||
} |
16 changes: 16 additions & 0 deletions
16
internal/resources/apiextensions/v1beta1/crd/required/fields.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package required | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// Fields returns the fields for this package. | ||
func Fields() *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters