Skip to content

Commit

Permalink
Adds annotations to a Service
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Jun 9, 2019
1 parent 6276acc commit c02cd7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/kubernetes/core/v1/service/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ import (
// Generate the Service.
func Generate(d *schema.ResourceData) (corev1.Service, error) {
var (
name = d.Get(FieldName).(string)
namespace = d.Get(FieldNamespace).(string)
rawLabels = d.Get(FieldLabels).(map[string]interface{})
rawType = d.Get(FieldType).(string)
rawPorts = d.Get(FieldPort).([]interface{})
rawSelector = d.Get(FieldSelector).(map[string]interface{})
name = d.Get(FieldName).(string)
namespace = d.Get(FieldNamespace).(string)
rawLabels = d.Get(FieldLabels).(map[string]interface{})
rawAnnotations = d.Get(FieldAnnotations).(map[string]interface{})
rawType = d.Get(FieldType).(string)
rawPorts = d.Get(FieldPort).([]interface{})
rawSelector = d.Get(FieldSelector).(map[string]interface{})
)

service := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: interfaceutils.ExpandMap(rawLabels),
Name: name,
Namespace: namespace,
Labels: interfaceutils.ExpandMap(rawLabels),
Annotations: interfaceutils.ExpandMap(rawAnnotations),
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceType(rawType),
Expand Down
1 change: 1 addition & 0 deletions internal/kubernetes/core/v1/service/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Read(d *schema.ResourceData, m interface{}) error {
d.Set(FieldName, service.ObjectMeta.Name)
d.Set(FieldNamespace, service.ObjectMeta.Namespace)
d.Set(FieldLabels, service.ObjectMeta.Labels)
d.Set(FieldAnnotations, service.ObjectMeta.Annotations)
d.Set(FieldType, service.Spec.Type)
d.Set(FieldPort, port.Flatten(service.Spec.Ports))
d.Set(FieldSelector, service.Spec.Selector)
Expand Down
6 changes: 6 additions & 0 deletions internal/kubernetes/core/v1/service/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
FieldPort = "port"
// FieldLabels is a field identifier.
FieldLabels = "labels"
// FieldAnnotations is a field identifier.
FieldAnnotations = "annotations"
// FieldSelector is a field identifier.
FieldSelector = "selector"
// FieldType is a field identifier.
Expand Down Expand Up @@ -45,6 +47,10 @@ func Resource() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
},
FieldAnnotations: &schema.Schema{
Type: schema.TypeMap,
Optional: true,
},
FieldType: &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down

0 comments on commit c02cd7a

Please sign in to comment.