Skip to content

Commit

Permalink
Merge pull request #148 from weaveworks/selectors
Browse files Browse the repository at this point in the history
 Make the pod selector label configurable
  • Loading branch information
stefanprodan authored Apr 16, 2019
2 parents 825d07a + 65f7161 commit bdc3a32
Show file tree
Hide file tree
Showing 19 changed files with 1,169 additions and 662 deletions.
13 changes: 11 additions & 2 deletions cmd/flagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned"
informers "github.com/weaveworks/flagger/pkg/client/informers/externalversions"
"github.com/weaveworks/flagger/pkg/controller"
"github.com/weaveworks/flagger/pkg/logging"
"github.com/weaveworks/flagger/pkg/logger"
"github.com/weaveworks/flagger/pkg/metrics"
"github.com/weaveworks/flagger/pkg/notifier"
"github.com/weaveworks/flagger/pkg/server"
Expand All @@ -18,6 +18,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"log"
"strings"
"time"
)

Expand All @@ -36,6 +37,7 @@ var (
zapEncoding string
namespace string
meshProvider string
selectorLabels string
)

func init() {
Expand All @@ -53,12 +55,13 @@ func init() {
flag.StringVar(&zapEncoding, "zap-encoding", "json", "Zap logger encoding.")
flag.StringVar(&namespace, "namespace", "", "Namespace that flagger would watch canary object")
flag.StringVar(&meshProvider, "mesh-provider", "istio", "Service mesh provider, can be istio or appmesh")
flag.StringVar(&selectorLabels, "selector-labels", "app,name,app.kubernetes.io/name", "List of pod labels that Flagger uses to create pod selectors")
}

func main() {
flag.Parse()

logger, err := logging.NewLoggerWithEncoding(logLevel, zapEncoding)
logger, err := logger.NewLoggerWithEncoding(logLevel, zapEncoding)
if err != nil {
log.Fatalf("Error creating logger: %v", err)
}
Expand Down Expand Up @@ -101,6 +104,11 @@ func main() {
logger.Fatalf("Error calling Kubernetes API: %v", err)
}

labels := strings.Split(selectorLabels, ",")
if len(labels) < 1 {
logger.Fatalf("At least one selector label is required")
}

logger.Infof("Connected to Kubernetes API %s", ver)
if namespace != "" {
logger.Infof("Watching namespace %s", namespace)
Expand Down Expand Up @@ -137,6 +145,7 @@ func main() {
slack,
meshProvider,
version.VERSION,
labels,
)

flaggerInformerFactory.Start(stopCh)
Expand Down
4 changes: 2 additions & 2 deletions cmd/loadtester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"github.com/weaveworks/flagger/pkg/loadtester"
"github.com/weaveworks/flagger/pkg/logging"
"github.com/weaveworks/flagger/pkg/logger"
"github.com/weaveworks/flagger/pkg/signals"
"go.uber.org/zap"
"log"
Expand All @@ -30,7 +30,7 @@ func init() {
func main() {
flag.Parse()

logger, err := logging.NewLoggerWithEncoding(logLevel, zapEncoding)
logger, err := logger.NewLoggerWithEncoding(logLevel, zapEncoding)
if err != nil {
log.Fatalf("Error creating logger: %v", err)
}
Expand Down
3 changes: 3 additions & 0 deletions docs/gitbook/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ spec:
app: podinfo
```

Besides `app` Flagger supports `name` and `app.kubernetes.io/name` selectors. If you use a different
convention you can specify your label with the `-selector-labels` flag.

The target deployment should expose a TCP port that will be used by Flagger to create the ClusterIP Service and
the Istio Virtual Service. The container port from the target deployment should match the `service.port` value.

Expand Down
Loading

0 comments on commit bdc3a32

Please sign in to comment.