Skip to content

Commit bbed406

Browse files
authored
Merge pull request #77 from banzaicloud/serviceAnnotations
configurable labels and annotations on gateway services
2 parents 1de9c31 + 91c9ed6 commit bbed406

File tree

10 files changed

+148
-50
lines changed

10 files changed

+148
-50
lines changed

config/crds/istio_v1beta1_istio.yaml

+32-9
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,38 @@ spec:
6464
gateways:
6565
description: Gateways configuration options
6666
properties:
67-
maxReplicas:
68-
format: int32
69-
type: integer
70-
minReplicas:
71-
format: int32
72-
type: integer
73-
replicaCount:
74-
format: int32
75-
type: integer
67+
egress:
68+
properties:
69+
maxReplicas:
70+
format: int32
71+
type: integer
72+
minReplicas:
73+
format: int32
74+
type: integer
75+
replicaCount:
76+
format: int32
77+
type: integer
78+
serviceAnnotations:
79+
type: object
80+
serviceLabels:
81+
type: object
82+
type: object
83+
ingress:
84+
properties:
85+
maxReplicas:
86+
format: int32
87+
type: integer
88+
minReplicas:
89+
format: int32
90+
type: integer
91+
replicaCount:
92+
format: int32
93+
type: integer
94+
serviceAnnotations:
95+
type: object
96+
serviceLabels:
97+
type: object
98+
type: object
7699
type: object
77100
includeIPRanges:
78101
description: IncludeIPRanges the range where to capture egress traffic

config/samples/istio_v1beta1_istio.yaml

+20-13
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,34 @@ spec:
1212
- "default"
1313
controlPlaneSecurityEnabled: false
1414
pilot:
15-
image: "istio/pilot:1.0.5"
16-
replicaCount: 1
17-
minReplicas: 1
18-
maxReplicas: 5
15+
image: "istio/pilot:1.0.5"
16+
replicaCount: 1
17+
minReplicas: 1
18+
maxReplicas: 5
1919
citadel:
20-
image: "istio/citadel:1.0.5"
21-
replicaCount: 1
20+
image: "istio/citadel:1.0.5"
21+
replicaCount: 1
2222
galley:
23-
image: "istio/galley:1.0.5"
24-
replicaCount: 1
23+
image: "istio/galley:1.0.5"
24+
replicaCount: 1
2525
gateways:
26+
ingress:
2627
replicaCount: 1
2728
minReplicas: 1
2829
maxReplicas: 5
29-
mixer:
30-
image: "istio/mixer:1.0.5"
30+
serviceAnnotations: {}
31+
egress:
3132
replicaCount: 1
3233
minReplicas: 1
3334
maxReplicas: 5
35+
serviceAnnotations: {}
36+
mixer:
37+
image: "istio/mixer:1.0.5"
38+
replicaCount: 1
39+
minReplicas: 1
40+
maxReplicas: 5
3441
sidecarInjector:
35-
image: "istio/sidecar_injector:1.0.5"
36-
replicaCount: 1
42+
image: "istio/sidecar_injector:1.0.5"
43+
replicaCount: 1
3744
proxy:
38-
image: "istio/proxyv2:1.0.5"
45+
image: "istio/proxyv2:1.0.5"

pkg/apis/istio/v1beta1/istio_types.go

+25-9
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,23 @@ func SetDefaults(config *Istio) {
7070
}
7171

7272
// Gateways config
73-
if config.Spec.Gateways.ReplicaCount == 0 {
74-
config.Spec.Gateways.ReplicaCount = defaultReplicaCount
73+
if config.Spec.Gateways.IngressConfig.ReplicaCount == 0 {
74+
config.Spec.Gateways.IngressConfig.ReplicaCount = defaultReplicaCount
7575
}
76-
if config.Spec.Gateways.MinReplicas == 0 {
77-
config.Spec.Gateways.MinReplicas = defaultMinReplicas
76+
if config.Spec.Gateways.IngressConfig.MinReplicas == 0 {
77+
config.Spec.Gateways.IngressConfig.MinReplicas = defaultMinReplicas
7878
}
79-
if config.Spec.Gateways.MaxReplicas == 0 {
80-
config.Spec.Gateways.MaxReplicas = defaultMaxReplicas
79+
if config.Spec.Gateways.IngressConfig.MaxReplicas == 0 {
80+
config.Spec.Gateways.IngressConfig.MaxReplicas = defaultMaxReplicas
81+
}
82+
if config.Spec.Gateways.EgressConfig.ReplicaCount == 0 {
83+
config.Spec.Gateways.EgressConfig.ReplicaCount = defaultReplicaCount
84+
}
85+
if config.Spec.Gateways.EgressConfig.MinReplicas == 0 {
86+
config.Spec.Gateways.EgressConfig.MinReplicas = defaultMinReplicas
87+
}
88+
if config.Spec.Gateways.EgressConfig.MaxReplicas == 0 {
89+
config.Spec.Gateways.EgressConfig.MaxReplicas = defaultMaxReplicas
8190
}
8291

8392
// Mixer config
@@ -130,9 +139,16 @@ type GalleyConfiguration struct {
130139

131140
// GatewaysConfiguration defines config options for Gateways
132141
type GatewaysConfiguration struct {
133-
ReplicaCount int32 `json:"replicaCount,omitempty"`
134-
MinReplicas int32 `json:"minReplicas,omitempty"`
135-
MaxReplicas int32 `json:"maxReplicas,omitempty"`
142+
IngressConfig GatewayConfiguration `json:"ingress,omitempty"`
143+
EgressConfig GatewayConfiguration `json:"egress,omitempty"`
144+
}
145+
146+
type GatewayConfiguration struct {
147+
ReplicaCount int32 `json:"replicaCount,omitempty"`
148+
MinReplicas int32 `json:"minReplicas,omitempty"`
149+
MaxReplicas int32 `json:"maxReplicas,omitempty"`
150+
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
151+
ServiceLabels map[string]string `json:"serviceLabels,omitempty"`
136152
}
137153

138154
// MixerConfiguration defines config options for Mixer

pkg/apis/istio/v1beta1/zz_generated.deepcopy.go

+33-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/remoteistio/remoteistio_controller.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"context"
2121
"reflect"
2222

23-
"github.com/banzaicloud/istio-operator/pkg/util"
24-
2523
"github.com/goph/emperror"
2624
"github.com/pkg/errors"
2725
corev1 "k8s.io/api/core/v1"
@@ -41,6 +39,7 @@ import (
4139
istiov1beta1 "github.com/banzaicloud/istio-operator/pkg/apis/istio/v1beta1"
4240
operatorv1beta1 "github.com/banzaicloud/istio-operator/pkg/apis/istio/v1beta1"
4341
"github.com/banzaicloud/istio-operator/pkg/remoteclusters"
42+
"github.com/banzaicloud/istio-operator/pkg/util"
4443
)
4544

4645
const finalizerID = "remote-istio-operator.finializer.banzaicloud.io"

pkg/resources/gateways/deployment.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ package gateways
1919
import (
2020
"fmt"
2121

22-
"github.com/banzaicloud/istio-operator/pkg/resources/templates"
23-
"github.com/banzaicloud/istio-operator/pkg/util"
2422
appsv1 "k8s.io/api/apps/v1"
2523
apiv1 "k8s.io/api/core/v1"
2624
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
"k8s.io/apimachinery/pkg/runtime"
26+
27+
"github.com/banzaicloud/istio-operator/pkg/resources/templates"
28+
"github.com/banzaicloud/istio-operator/pkg/util"
2829
)
2930

3031
func (r *Reconciler) deployment(gw string) runtime.Object {
32+
gwConfig := r.getGatewayConfig(gw)
3133
return &appsv1.Deployment{
3234
ObjectMeta: templates.ObjectMeta(gatewayName(gw), labelSelector(gw), r.Config),
3335
Spec: appsv1.DeploymentSpec{
34-
Replicas: util.IntPointer(r.Config.Spec.Gateways.ReplicaCount),
36+
Replicas: util.IntPointer(gwConfig.ReplicaCount),
3537
Selector: &metav1.LabelSelector{
3638
MatchLabels: labelSelector(gw),
3739
},
@@ -135,7 +137,7 @@ func (r *Reconciler) deployment(gw string) runtime.Object {
135137

136138
func (r *Reconciler) ports(gw string) []apiv1.ContainerPort {
137139
switch gw {
138-
case "ingressgateway":
140+
case ingress:
139141
return []apiv1.ContainerPort{
140142
{ContainerPort: 80, Protocol: apiv1.ProtocolTCP},
141143
{ContainerPort: 443, Protocol: apiv1.ProtocolTCP},
@@ -147,7 +149,7 @@ func (r *Reconciler) ports(gw string) []apiv1.ContainerPort {
147149
{ContainerPort: 15031, Protocol: apiv1.ProtocolTCP},
148150
{ContainerPort: 15090, Protocol: apiv1.ProtocolTCP, Name: "http-envoy-prom"},
149151
}
150-
case "egressgateway":
152+
case egress:
151153
return []apiv1.ContainerPort{
152154
{ContainerPort: 80, Protocol: apiv1.ProtocolTCP},
153155
{ContainerPort: 443, Protocol: apiv1.ProtocolTCP},

pkg/resources/gateways/gateways.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030

3131
const (
3232
componentName = "gateways"
33+
ingress = "ingressgateway"
34+
egress = "egressgateway"
3335
)
3436

3537
type Reconciler struct {
@@ -58,7 +60,7 @@ func (r *Reconciler) Reconcile(log logr.Logger) error {
5860
r.service,
5961
r.horizontalPodAutoscaler,
6062
}
61-
for _, res := range append(resources.ResolveVariations("ingressgateway", rsv), resources.ResolveVariations("egressgateway", rsv)...) {
63+
for _, res := range append(resources.ResolveVariations(ingress, rsv), resources.ResolveVariations(egress, rsv)...) {
6264
o := res()
6365
err := k8sutil.Reconcile(log, r.Client, o)
6466
if err != nil {
@@ -71,6 +73,16 @@ func (r *Reconciler) Reconcile(log logr.Logger) error {
7173
return nil
7274
}
7375

76+
func (r *Reconciler) getGatewayConfig(gw string) *istiov1beta1.GatewayConfiguration {
77+
switch gw {
78+
case ingress:
79+
return &r.Config.Spec.Gateways.IngressConfig
80+
case egress:
81+
return &r.Config.Spec.Gateways.EgressConfig
82+
}
83+
return nil
84+
}
85+
7486
func serviceAccountName(gw string) string {
7587
return fmt.Sprintf("istio-%s-service-account", gw)
7688
}

pkg/resources/gateways/hpa.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import (
2424
)
2525

2626
func (r *Reconciler) horizontalPodAutoscaler(gw string) runtime.Object {
27+
gwConfig := r.getGatewayConfig(gw)
2728
return &autoscalev2beta1.HorizontalPodAutoscaler{
2829
ObjectMeta: templates.ObjectMeta(hpaName(gw), nil, r.Config),
2930
Spec: autoscalev2beta1.HorizontalPodAutoscalerSpec{
30-
MaxReplicas: r.Config.Spec.Gateways.MaxReplicas,
31-
MinReplicas: util.IntPointer(r.Config.Spec.Gateways.MinReplicas),
31+
MaxReplicas: gwConfig.MaxReplicas,
32+
MinReplicas: util.IntPointer(gwConfig.MinReplicas),
3233
ScaleTargetRef: autoscalev2beta1.CrossVersionObjectReference{
3334
Name: gatewayName(gw),
3435
Kind: "Deployment",

pkg/resources/gateways/service.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ package gateways
1818

1919
import (
2020
"github.com/banzaicloud/istio-operator/pkg/resources/templates"
21+
"github.com/banzaicloud/istio-operator/pkg/util"
2122
apiv1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/runtime"
2324
"k8s.io/apimachinery/pkg/util/intstr"
2425
)
2526

2627
func (r *Reconciler) service(gw string) runtime.Object {
28+
gwConfig := r.getGatewayConfig(gw)
2729
return &apiv1.Service{
28-
ObjectMeta: templates.ObjectMeta(gatewayName(gw), labelSelector(gw), r.Config),
30+
ObjectMeta: templates.ObjectMetaWithAnnotations(gatewayName(gw), util.MergeLabels(labelSelector(gw), gwConfig.ServiceLabels), gwConfig.ServiceAnnotations, r.Config),
2931
Spec: apiv1.ServiceSpec{
3032
Type: serviceType(gw),
3133
Ports: servicePorts(gw),
@@ -36,7 +38,7 @@ func (r *Reconciler) service(gw string) runtime.Object {
3638

3739
func servicePorts(gw string) []apiv1.ServicePort {
3840
switch gw {
39-
case "ingressgateway":
41+
case ingress:
4042
return []apiv1.ServicePort{
4143
{Port: 80, Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(80), Name: "http2", NodePort: 31380},
4244
{Port: 443, Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(443), Name: "https", NodePort: 31390},
@@ -47,7 +49,7 @@ func servicePorts(gw string) []apiv1.ServicePort {
4749
{Port: 15030, Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(15030), Name: "http2-prometheus", NodePort: 31440},
4850
{Port: 15031, Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(15031), Name: "http2-grafana", NodePort: 31450},
4951
}
50-
case "egressgateway":
52+
case egress:
5153
return []apiv1.ServicePort{
5254
{Port: 80, Name: "http2", Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(80)},
5355
{Port: 443, Name: "https", Protocol: apiv1.ProtocolTCP, TargetPort: intstr.FromInt(443)},
@@ -58,9 +60,9 @@ func servicePorts(gw string) []apiv1.ServicePort {
5860

5961
func serviceType(gw string) apiv1.ServiceType {
6062
switch gw {
61-
case "ingressgateway":
63+
case ingress:
6264
return apiv1.ServiceTypeLoadBalancer
63-
case "egressgateway":
65+
case egress:
6466
return apiv1.ServiceTypeClusterIP
6567
}
6668
return ""

pkg/resources/templates/templates.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func ObjectMeta(name string, labels map[string]string, config *istiov1beta1.Istio) metav1.ObjectMeta {
25-
o := metav1.ObjectMeta{
25+
return metav1.ObjectMeta{
2626
Name: name,
2727
Namespace: config.Namespace,
2828
Labels: labels,
@@ -35,11 +35,16 @@ func ObjectMeta(name string, labels map[string]string, config *istiov1beta1.Isti
3535
},
3636
},
3737
}
38+
}
39+
40+
func ObjectMetaWithAnnotations(name string, labels map[string]string, annotations map[string]string, config *istiov1beta1.Istio) metav1.ObjectMeta {
41+
o := ObjectMeta(name, labels, config)
42+
o.Annotations = annotations
3843
return o
3944
}
4045

4146
func ObjectMetaClusterScope(name string, labels map[string]string, config *istiov1beta1.Istio) metav1.ObjectMeta {
42-
o := metav1.ObjectMeta{
47+
return metav1.ObjectMeta{
4348
Name: name,
4449
Labels: labels,
4550
OwnerReferences: []metav1.OwnerReference{
@@ -51,7 +56,6 @@ func ObjectMetaClusterScope(name string, labels map[string]string, config *istio
5156
},
5257
},
5358
}
54-
return o
5559
}
5660

5761
func ControlPlaneAuthPolicy(enabled bool) string {

0 commit comments

Comments
 (0)