Add support for naming generated service ports

This commit is contained in:
Trond Nordheim
2019-03-21 12:37:02 +01:00
parent ce79244126
commit f5b97fbb74
2 changed files with 12 additions and 4 deletions
+3 -1
View File
@@ -17,10 +17,11 @@ limitations under the License.
package v1alpha3
import (
"time"
istiov1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3"
hpav1 "k8s.io/api/autoscaling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
)
const (
@@ -111,6 +112,7 @@ type CanaryStatus struct {
// and Istio Virtual Service
type CanaryService struct {
Port int32 `json:"port"`
PortName string `json:"portName,omitempty"`
Match []istiov1alpha3.HTTPMatchRequest `json:"match,omitempty"`
Rewrite *istiov1alpha3.HTTPRewrite `json:"rewrite,omitempty"`
Timeout string `json:"timeout,omitempty"`
+9 -3
View File
@@ -2,6 +2,7 @@ package router
import (
"fmt"
flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3"
clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned"
"go.uber.org/zap"
@@ -24,6 +25,11 @@ type KubernetesRouter struct {
func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
targetName := cd.Spec.TargetRef.Name
primaryName := fmt.Sprintf("%s-primary", targetName)
portName := cd.Spec.Service.PortName
if portName == "" {
portName = "http"
}
canaryService, err := c.kubeClient.CoreV1().Services(cd.Namespace).Get(targetName, metav1.GetOptions{})
if errors.IsNotFound(err) {
canaryService = &corev1.Service{
@@ -43,7 +49,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
Selector: map[string]string{"app": primaryName},
Ports: []corev1.ServicePort{
{
Name: "http",
Name: portName,
Protocol: corev1.ProtocolTCP,
Port: cd.Spec.Service.Port,
TargetPort: intstr.IntOrString{
@@ -82,7 +88,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
Selector: map[string]string{"app": targetName},
Ports: []corev1.ServicePort{
{
Name: "http",
Name: portName,
Protocol: corev1.ProtocolTCP,
Port: cd.Spec.Service.Port,
TargetPort: intstr.IntOrString{
@@ -120,7 +126,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
Selector: map[string]string{"app": primaryName},
Ports: []corev1.ServicePort{
{
Name: "http",
Name: portName,
Protocol: corev1.ProtocolTCP,
Port: cd.Spec.Service.Port,
TargetPort: intstr.IntOrString{