Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add targetPort field to runtime operator #51

Merged
merged 5 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Changelog
All notable changes to this project will be documented in this file.

## [Unreleased]

- Added optional targetPort field to the CRD ([#51](https://github.com/application-stacks/runtime-component-operator/pull/51))

## [0.4.0]

The initial release of the Runtime Component Operator 🎉


[Unreleased]: https://github.com/application-stacks/runtime-component-operator/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/application-stacks/runtime-component-operator/releases/tag/v0.4.0
[0.4.0]: https://github.com/application-stacks/runtime-component-operator/releases/tag/v0.4.0

3 changes: 3 additions & 0 deletions deploy/crds/app.stacks_runtimecomponents_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,9 @@ spec:
required:
- category
type: object
targetPort:
format: int32
type: integer
type:
description: Service Type string describes ingress methods for a
service
Expand Down
5 changes: 5 additions & 0 deletions deploy/releases/0.4.0/runtime-component-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,11 @@ spec:
maximum: 65536
minimum: 1
type: integer
targetPort:
format: int32
maximum: 65536
minimum: 1
type: integer
portName:
type: string
provides:
Expand Down
5 changes: 5 additions & 0 deletions deploy/releases/daily/runtime-component-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,11 @@ spec:
maximum: 65536
minimum: 1
type: integer
targetPort:
format: int32
maximum: 65536
minimum: 1
type: integer
portName:
type: string
provides:
Expand Down
1 change: 1 addition & 0 deletions doc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Each `RuntimeComponent` CR must at least specify the `applicationImage` paramete
| `sidecarContainers` | The list of `sidecar` containers. These are additional containers to be added to the pods. Note: Sidecar containers should not be named `app`. |
| `architecture` | An array of architectures to be considered for deployment. Their position in the array indicates preference. |
| `service.port` | The port exposed by the container. |
| `service.targetPort` | The port that the operator assigns to containers inside pods. Defaults to the value of `service.port`. |
| `service.portName` | The name for the port exposed by the container. |
| `service.type` | The Kubernetes [Service Type](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types). |
| `service.annotations` | Annotations to be added to the service. |
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/appstacks/v1beta1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type RuntimeComponentService struct {
// +kubebuilder:validation:Maximum=65536
// +kubebuilder:validation:Minimum=1
Port int32 `json:"port,omitempty"`
TargetPort *int32 `json:"targetPort,omitempty"`

PortName string `json:"portName,omitempty"`

Expand Down Expand Up @@ -414,6 +415,15 @@ func (s *RuntimeComponentService) GetPort() int32 {
return s.Port
}

// GetTargetPort returns the internal target port for containers
func (s *RuntimeComponentService) GetTargetPort() *int32 {
if (s.TargetPort == nil) {
return nil
}

return s.TargetPort
}

// GetPortName returns name of service port
func (s *RuntimeComponentService) GetPortName() string {
return s.PortName
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/appstacks/v1beta1/zz_generated.deepcopy.go

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

62 changes: 34 additions & 28 deletions pkg/apis/appstacks/v1beta1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (

func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"./pkg/apis/appstacks/v1beta1.RuntimeComponent": schema_pkg_apis_appstacks_v1beta1_RuntimeComponent(ref),
"./pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentAutoScaling(ref),
"./pkg/apis/appstacks/v1beta1.RuntimeComponentRoute": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentRoute(ref),
"./pkg/apis/appstacks/v1beta1.RuntimeComponentService": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentService(ref),
"./pkg/apis/appstacks/v1beta1.RuntimeComponentSpec": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref),
"./pkg/apis/appstacks/v1beta1.RuntimeComponentStatus": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentStatus(ref),
"./pkg/apis/appstacks/v1beta1.ServiceBindingConsumes": schema_pkg_apis_appstacks_v1beta1_ServiceBindingConsumes(ref),
"./pkg/apis/appstacks/v1beta1.ServiceBindingProvides": schema_pkg_apis_appstacks_v1beta1_ServiceBindingProvides(ref),
"./pkg/apis/appstacks/v1beta1.StatusCondition": schema_pkg_apis_appstacks_v1beta1_StatusCondition(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponent": schema_pkg_apis_appstacks_v1beta1_RuntimeComponent(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentAutoScaling(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentRoute": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentRoute(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentService": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentService(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentSpec": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentStatus": schema_pkg_apis_appstacks_v1beta1_RuntimeComponentStatus(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingConsumes": schema_pkg_apis_appstacks_v1beta1_ServiceBindingConsumes(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingProvides": schema_pkg_apis_appstacks_v1beta1_ServiceBindingProvides(ref),
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.StatusCondition": schema_pkg_apis_appstacks_v1beta1_StatusCondition(ref),
}
}

Expand Down Expand Up @@ -51,19 +51,19 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponent(ref common.ReferenceCall
},
"spec": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentSpec"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentSpec"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentStatus"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentStatus"),
},
},
},
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.RuntimeComponentSpec", "./pkg/apis/appstacks/v1beta1.RuntimeComponentStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentSpec", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentRoute(ref common.Referenc
},
"certificate": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.Certificate"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.Certificate"),
},
},
"certificateSecretRef": {
Expand All @@ -158,7 +158,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentRoute(ref common.Referenc
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.Certificate"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.Certificate"},
}
}

Expand All @@ -181,6 +181,12 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentService(ref common.Refere
Format: "int32",
},
},
"targetPort": {
SchemaProps: spec.SchemaProps{
Type: []string{"integer"},
Format: "int32",
},
},
"portName": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Expand Down Expand Up @@ -212,20 +218,20 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentService(ref common.Refere
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.ServiceBindingConsumes"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingConsumes"),
},
},
},
},
},
"provides": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.ServiceBindingProvides"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingProvides"),
},
},
"certificate": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.Certificate"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.Certificate"),
},
},
"certificateSecretRef": {
Expand All @@ -238,7 +244,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentService(ref common.Refere
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.Certificate", "./pkg/apis/appstacks/v1beta1.ServiceBindingConsumes", "./pkg/apis/appstacks/v1beta1.ServiceBindingProvides"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.Certificate", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingConsumes", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingProvides"},
}
}

Expand Down Expand Up @@ -269,7 +275,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref common.Reference
},
"autoscaling": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling"),
},
},
"pullPolicy": {
Expand Down Expand Up @@ -336,7 +342,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref common.Reference
},
"service": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentService"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentService"),
},
},
"expose": {
Expand Down Expand Up @@ -406,7 +412,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref common.Reference
},
"storage": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentStorage"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentStorage"),
},
},
"createKnativeService": {
Expand All @@ -417,7 +423,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref common.Reference
},
"monitoring": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentMonitoring"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentMonitoring"),
},
},
"createAppDefinition": {
Expand Down Expand Up @@ -470,15 +476,15 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentSpec(ref common.Reference
},
"route": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.RuntimeComponentRoute"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentRoute"),
},
},
},
Required: []string{"applicationImage"},
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling", "./pkg/apis/appstacks/v1beta1.RuntimeComponentMonitoring", "./pkg/apis/appstacks/v1beta1.RuntimeComponentRoute", "./pkg/apis/appstacks/v1beta1.RuntimeComponentService", "./pkg/apis/appstacks/v1beta1.RuntimeComponentStorage", "k8s.io/api/core/v1.Container", "k8s.io/api/core/v1.EnvFromSource", "k8s.io/api/core/v1.EnvVar", "k8s.io/api/core/v1.Probe", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/api/core/v1.Volume", "k8s.io/api/core/v1.VolumeMount"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentAutoScaling", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentMonitoring", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentRoute", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentService", "github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.RuntimeComponentStorage", "k8s.io/api/core/v1.Container", "k8s.io/api/core/v1.EnvFromSource", "k8s.io/api/core/v1.EnvVar", "k8s.io/api/core/v1.Probe", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/api/core/v1.Volume", "k8s.io/api/core/v1.VolumeMount"},
}
}

Expand All @@ -500,7 +506,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentStatus(ref common.Referen
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.StatusCondition"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.StatusCondition"),
},
},
},
Expand Down Expand Up @@ -537,7 +543,7 @@ func schema_pkg_apis_appstacks_v1beta1_RuntimeComponentStatus(ref common.Referen
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.StatusCondition"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.StatusCondition"},
}
}

Expand Down Expand Up @@ -606,15 +612,15 @@ func schema_pkg_apis_appstacks_v1beta1_ServiceBindingProvides(ref common.Referen
},
"auth": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/appstacks/v1beta1.ServiceBindingAuth"),
Ref: ref("github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingAuth"),
},
},
},
Required: []string{"category"},
},
},
Dependencies: []string{
"./pkg/apis/appstacks/v1beta1.ServiceBindingAuth"},
"github.com/application-stacks/runtime-component-operator/pkg/apis/appstacks/v1beta1.ServiceBindingAuth"},
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type BaseComponentStorage interface {
// BaseComponentService represents basic service configuration
type BaseComponentService interface {
GetPort() int32
GetTargetPort() *int32
GetPortName() string
GetType() *corev1.ServiceType
GetAnnotations() map[string]string
Expand Down
22 changes: 19 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func CustomizeService(svc *corev1.Service, ba common.BaseComponent) {
svc.Spec.Selector = map[string]string{
"app.kubernetes.io/instance": obj.GetName(),
}

if ba.GetService().GetTargetPort() != nil {
svc.Spec.Ports[0].TargetPort = intstr.FromInt(int(*ba.GetService().GetTargetPort()))
}
}

// CustomizeServiceBindingSecret ...
Expand Down Expand Up @@ -222,12 +226,19 @@ func CustomizePodSpec(pts *corev1.PodTemplateSpec, ba common.BaseComponent) {
if len(appContainer.Ports) == 0 {
appContainer.Ports = append(appContainer.Ports, corev1.ContainerPort{})
}
appContainer.Ports[0].ContainerPort = ba.GetService().GetPort()

if ba.GetService().GetTargetPort() != nil {
appContainer.Ports[0].ContainerPort = *ba.GetService().GetTargetPort()
} else {
appContainer.Ports[0].ContainerPort = ba.GetService().GetPort()
}


appContainer.Image = ba.GetStatus().GetImageReference()
if ba.GetService().GetPortName() != "" {
appContainer.Ports[0].Name = ba.GetService().GetPortName()
} else {
appContainer.Ports[0].Name = strconv.Itoa(int(ba.GetService().GetPort())) + "-tcp"
appContainer.Ports[0].Name = strconv.Itoa(int(appContainer.Ports[0].ContainerPort)) + "-tcp"
}
if ba.GetResourceConstraints() != nil {
appContainer.Resources = *ba.GetResourceConstraints()
Expand Down Expand Up @@ -472,7 +483,12 @@ func CustomizeKnativeService(ksvc *servingv1alpha1.Service, ba common.BaseCompon
ksvc.Spec.Template.ObjectMeta.Labels = ba.GetLabels()
ksvc.Spec.Template.ObjectMeta.Annotations = MergeMaps(ksvc.Spec.Template.ObjectMeta.Annotations, ba.GetAnnotations())

ksvc.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = ba.GetService().GetPort()
if ba.GetService().GetTargetPort() != nil {
ksvc.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = *ba.GetService().GetTargetPort()
} else {
ksvc.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = ba.GetService().GetPort()
}

ksvc.Spec.Template.Spec.Containers[0].Image = ba.GetStatus().GetImageReference()
// Knative sets its own resource constraints
//ksvc.Spec.Template.Spec.Containers[0].Resources = *cr.Spec.ResourceConstraints
Expand Down
Loading