Skip to content

Commit

Permalink
Replace glog with zap and refactor controller
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Sep 26, 2018
1 parent 3eef986 commit 0a03c8c
Show file tree
Hide file tree
Showing 11 changed files with 699 additions and 1,414 deletions.
14 changes: 12 additions & 2 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ required = [
name = "github.com/knative/pkg"
revision = "c15d7c8f2220a7578b33504df6edefa948c845ae"

[[override]]
name = "github.com/golang/glog"
source = "github.com/istio/glog"

[prune]
go-tests = true
unused-packages = true
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ spec:
weight: 0
```
Primary and canary services should expose a port named http:
```yaml
apiVersion: v1
kind: Service
metadata:
name: podinfo-canary
spec:
type: ClusterIP
selector:
app: podinfo-canary
ports:
- name: http
port: 9898
targetPort: 9898
```
Based on the two deployments, services and virtual service, a rollout can be defined using Steerer's custom resource:
```yaml
Expand Down
14 changes: 6 additions & 8 deletions artifacts/steerer/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ spec:
serviceAccountName: steerer
containers:
- name: steerer
image: stefanprodan/steerer:0.0.1
image: stefanprodan/steerer
imagePullPolicy: Always
ports:
- name: http
containerPort: 8080
command:
- ./steerer
- -level=info
- -prometheus=http://prometheus.istio-system.svc.cluster.local:9090
- -window=10s
- -logtostderr
- -stderrthreshold=ERROR
- -log-level=info
- -control-loop-interval=10s
- -metrics-server=http://prometheus.istio-system.svc.cluster.local:9090
livenessProbe:
exec:
command:
Expand All @@ -42,7 +40,7 @@ spec:
- --tries=1
- --timeout=2
- --spider
- http://localhost:8080/readyz
- http://localhost:8080/healthz
readinessProbe:
exec:
command:
Expand All @@ -51,7 +49,7 @@ spec:
- --tries=1
- --timeout=2
- --spider
- http://localhost:8080/readyz
- http://localhost:8080/healthz
resources:
limits:
memory: "512Mi"
Expand Down
25 changes: 13 additions & 12 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"time"

_ "github.com/istio/glog"
sharedclientset "github.com/knative/pkg/client/clientset/versioned"
"github.com/knative/pkg/signals"
clientset "github.com/stefanprodan/steerer/pkg/client/clientset/versioned"
Expand All @@ -21,20 +22,20 @@ import (
)

var (
masterURL string
kubeconfig string
metricServer string
rolloutWindow time.Duration
logLevel string
port string
masterURL string
kubeconfig string
metricsServer string
controlLoopInterval time.Duration
logLevel string
port string
)

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&metricServer, "prometheus", "http://prometheus:9090", "Prometheus URL")
flag.DurationVar(&rolloutWindow, "window", 10*time.Second, "wait interval between deployment rollouts")
flag.StringVar(&logLevel, "level", "debug", "Log level can be: debug, info, warning, error.")
flag.StringVar(&metricsServer, "metrics-server", "http://prometheus:9090", "Prometheus URL")
flag.DurationVar(&controlLoopInterval, "control-loop-interval", 10*time.Second, "wait interval between rollouts")
flag.StringVar(&logLevel, "log-level", "debug", "Log level can be: debug, info, warning, error.")
flag.StringVar(&port, "port", "8080", "Port to listen on.")
}

Expand Down Expand Up @@ -80,7 +81,7 @@ func main() {
logger.Infow("Starting steerer",
zap.String("version", version.VERSION),
zap.String("revision", version.REVISION),
zap.String("metrics provider", metricServer),
zap.String("metrics provider", metricsServer),
zap.Any("kubernetes version", ver))

// start HTTP server
Expand All @@ -91,8 +92,8 @@ func main() {
sharedClient,
rolloutClient,
rolloutInformer,
rolloutWindow,
metricServer,
controlLoopInterval,
metricsServer,
logger,
)

Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"time"

"github.com/google/go-cmp/cmp"
sharedclientset "github.com/knative/pkg/client/clientset/versioned"
istioclientset "github.com/knative/pkg/client/clientset/versioned"
rolloutv1 "github.com/stefanprodan/steerer/pkg/apis/rollout/v1beta1"
clientset "github.com/stefanprodan/steerer/pkg/client/clientset/versioned"
rolloutscheme "github.com/stefanprodan/steerer/pkg/client/clientset/versioned/scheme"
rolloutInformers "github.com/stefanprodan/steerer/pkg/client/informers/externalversions/rollout/v1beta1"
listers "github.com/stefanprodan/steerer/pkg/client/listers/rollout/v1beta1"
rolloutinformers "github.com/stefanprodan/steerer/pkg/client/informers/externalversions/rollout/v1beta1"
rolloutlisters "github.com/stefanprodan/steerer/pkg/client/listers/rollout/v1beta1"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -30,9 +30,9 @@ const controllerAgentName = "steerer"

type Controller struct {
kubeClient kubernetes.Interface
istioClient sharedclientset.Interface
istioClient istioclientset.Interface
rolloutClient clientset.Interface
rolloutLister listers.RolloutLister
rolloutLister rolloutlisters.RolloutLister
rolloutSynced cache.InformerSynced
rolloutWindow time.Duration
workqueue workqueue.RateLimitingInterface
Expand All @@ -44,9 +44,9 @@ type Controller struct {

func NewController(
kubeClient kubernetes.Interface,
istioClient sharedclientset.Interface,
istioClient istioclientset.Interface,
rolloutClient clientset.Interface,
rolloutInformer rolloutInformers.RolloutInformer,
rolloutInformer rolloutinformers.RolloutInformer,
rolloutWindow time.Duration,
metricServer string,
logger *zap.SugaredLogger,
Expand Down
Loading

0 comments on commit 0a03c8c

Please sign in to comment.