Skip to content

Commit

Permalink
Adds label field to Namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Jul 23, 2021
1 parent ddfa94a commit 4eb32c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/resources/core/v1/namespace/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import (
"github.com/hashicorp/terraform/helper/schema"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/previousnext/terraform-provider-k8s/internal/interfaceutils"
)

// Generate the Namespace.
func Generate(d *schema.ResourceData) (corev1.Namespace, error) {
var name = d.Get(FieldName).(string)
var (
name = d.Get(FieldName).(string)
labels = d.Get(FieldLabels).(map[string]interface{})
)

namespace := corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Name: name,
Labels: interfaceutils.ExpandMap(labels),
},
}

Expand Down
1 change: 1 addition & 0 deletions internal/resources/core/v1/namespace/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Read(d *schema.ResourceData, m interface{}) error {
}

d.Set(FieldName, namespace.ObjectMeta.Name)
d.Set(FieldLabels, namespace.ObjectMeta.Labels)

return nil
}
8 changes: 7 additions & 1 deletion internal/resources/core/v1/namespace/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
const (
// FieldName is a field identifier.
FieldName = "name"
// FieldLabels is a field identifier.
FieldLabels = "labels"
)

// Resource returns this packages Resource and Fields.
Expand All @@ -18,10 +20,14 @@ func Resource() *schema.Resource {
Delete: Delete,

Schema: map[string]*schema.Schema{
FieldName: &schema.Schema{
FieldName: {
Type: schema.TypeString,
Required: true,
},
FieldLabels: {
Type: schema.TypeMap,
Optional: true,
},
},
}
}

0 comments on commit 4eb32c5

Please sign in to comment.