Skip to content

Commit

Permalink
Merge pull request #1004 from nkvoll/make-http-service-fully-configur…
Browse files Browse the repository at this point in the history
…able

Make .spec.http.service fully configurable by default
  • Loading branch information
nkvoll authored Jun 6, 2019
2 parents f9f350d + 9140358 commit 93c27ef
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 316 deletions.
75 changes: 12 additions & 63 deletions operators/config/all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down Expand Up @@ -263,29 +246,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down Expand Up @@ -793,29 +759,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down
25 changes: 4 additions & 21 deletions operators/config/crds/apm_v1alpha1_apmserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down
25 changes: 4 additions & 21 deletions operators/config/crds/elasticsearch_v1alpha1_elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down
25 changes: 4 additions & 21 deletions operators/config/crds/kibana_v1alpha1_kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,12 @@ spec:
description: Service is a template for the Kubernetes Service
properties:
metadata:
description: Metadata is metadata for the HTTP Service.
properties:
annotations:
description: 'Annotations is an unstructured key value map
stored with a resource that may be set by external tools
to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
description: ObjectMeta is metadata for the service. The name
and namespace provided here is managed by ECK and will be
ignored.
type: object
spec:
description: Spec contains user-provided settings for the HTTP
Service.
properties:
type:
description: 'Type determines which service type to use
for this workload. The options are: `ClusterIP|LoadBalancer|NodePort`.
Defaults to ClusterIP.'
enum:
- ClusterIP
- LoadBalancer
- NodePort
type: string
description: Spec defines the behavior of the service.
type: object
type: object
tls:
Expand Down
35 changes: 11 additions & 24 deletions operators/pkg/apis/common/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

Expand Down Expand Up @@ -40,7 +42,7 @@ func (s *ObjectSelector) IsDefined() bool {
// HTTPConfig configures a HTTP-based service.
type HTTPConfig struct {
// Service is a template for the Kubernetes Service
Service HTTPService `json:"service,omitempty"`
Service ServiceTemplate `json:"service,omitempty"`
// TLS describe additional options to consider when generating HTTP TLS certificates.
TLS TLSOptions `json:"tls,omitempty"`
}
Expand All @@ -62,29 +64,14 @@ type SubjectAlternativeName struct {
IP string `json:"ip,omitempty"`
}

// HTTPService contains defaults for a HTTP service.
type HTTPService struct {
// Metadata is metadata for the HTTP Service.
Metadata HTTPServiceObjectMeta `json:"metadata,omitempty"`

// Spec contains user-provided settings for the HTTP Service.
Spec HTTPServiceSpec `json:"spec,omitempty"`
}

// HTTPServiceObjectMeta is metadata for HTTP Service.
type HTTPServiceObjectMeta struct {
// Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
// queryable and should be preserved when modifying objects.
// More info: http://kubernetes.io/docs/user-guide/annotations
// ServiceTemplate describes the data a service should have when created from a template
type ServiceTemplate struct {
// ObjectMeta is metadata for the service.
// The name and namespace provided here is managed by ECK and will be ignored.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`

// HTTPServiceSpec contains a subset of overridable settings for the HTTP Service
type HTTPServiceSpec struct {
// Type determines which service type to use for this workload. The
// options are: `ClusterIP|LoadBalancer|NodePort`. Defaults to ClusterIP.
// +kubebuilder:validation:Enum=ClusterIP,LoadBalancer,NodePort
Type string `json:"type,omitempty"`
// Spec defines the behavior of the service.
// +optional
Spec v1.ServiceSpec `json:"spec,omitempty"`
}
75 changes: 18 additions & 57 deletions operators/pkg/apis/common/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 16 additions & 23 deletions operators/pkg/controller/apmserver/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,27 @@
package apmserver

import (
v1alpha1 "github.com/elastic/cloud-on-k8s/operators/pkg/apis/apm/v1alpha1"
"github.com/elastic/cloud-on-k8s/operators/pkg/apis/apm/v1alpha1"
"github.com/elastic/cloud-on-k8s/operators/pkg/controller/common"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewService(as v1alpha1.ApmServer) *corev1.Service {
var svc = corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: as.Namespace,
Name: PseudoNamespacedResourceName(as),
Labels: NewLabels(as.Name),
Annotations: as.Spec.HTTP.Service.Metadata.Annotations,
},
Spec: corev1.ServiceSpec{
Selector: NewLabels(as.Name),
Ports: []corev1.ServicePort{
{
Protocol: corev1.ProtocolTCP,
Port: HTTPPort,
},
},
SessionAffinity: corev1.ServiceAffinityNone,
Type: common.GetServiceType(as.Spec.HTTP.Service.Spec.Type),
},
svc := corev1.Service{
ObjectMeta: as.Spec.HTTP.Service.ObjectMeta,
Spec: as.Spec.HTTP.Service.Spec,
}
if svc.Spec.Type != corev1.ServiceTypeClusterIP {
svc.Spec.ExternalTrafficPolicy = corev1.ServiceExternalTrafficPolicyTypeCluster

svc.ObjectMeta.Namespace = as.Namespace
svc.ObjectMeta.Name = PseudoNamespacedResourceName(as)

labels := NewLabels(as.Name)
ports := []corev1.ServicePort{
{
Protocol: corev1.ProtocolTCP,
Port: HTTPPort,
},
}
return &svc

return common.SetServiceDefaults(&svc, labels, labels, ports)
}
Loading

0 comments on commit 93c27ef

Please sign in to comment.