mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Run go fmt
This commit is contained in:
+15
-6
@@ -12,6 +12,8 @@ import (
|
||||
informers "github.com/stefanprodan/steerer/pkg/client/informers/externalversions"
|
||||
"github.com/stefanprodan/steerer/pkg/controller"
|
||||
"github.com/stefanprodan/steerer/pkg/logging"
|
||||
"github.com/stefanprodan/steerer/pkg/version"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
@@ -19,23 +21,25 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
masterURL string
|
||||
kubeconfig string
|
||||
metricServer string
|
||||
masterURL string
|
||||
kubeconfig string
|
||||
metricServer string
|
||||
rolloutWindow time.Duration
|
||||
logLevel 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", "https://prometheus.istio.weavedx.com", "Prometheus URL")
|
||||
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.")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
logger, err := logging.NewLogger("debug")
|
||||
logger, err := logging.NewLogger(logLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating logger: %v", err)
|
||||
}
|
||||
@@ -70,7 +74,12 @@ func main() {
|
||||
if err != nil {
|
||||
logger.Fatalf("Error calling Kubernetes API: %v", err)
|
||||
}
|
||||
logger.Infof("Kubernetes version %v", ver)
|
||||
|
||||
logger.Infow("Starting steerer",
|
||||
zap.String("version", version.VERSION),
|
||||
zap.String("revision", version.REVISION),
|
||||
zap.String("metrics provider", metricServer),
|
||||
zap.Any("kubernetes version", ver))
|
||||
|
||||
c := controller.NewController(
|
||||
kubeClient,
|
||||
|
||||
@@ -235,12 +235,12 @@ func (c *Controller) handleObject(obj interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func (c *Controller) recordEventInfof(r *rolloutv1.Rollout, template string, args ...interface{}) {
|
||||
func (c *Controller) recordEventInfof(r *rolloutv1.Rollout, template string, args ...interface{}) {
|
||||
c.logger.Infof(template, args...)
|
||||
c.recorder.Event(r, corev1.EventTypeNormal, "Synced", fmt.Sprintf(template, args...))
|
||||
}
|
||||
|
||||
func (c *Controller) recordEventErrorf(r *rolloutv1.Rollout, template string, args ...interface{}) {
|
||||
func (c *Controller) recordEventErrorf(r *rolloutv1.Rollout, template string, args ...interface{}) {
|
||||
c.logger.Errorf(template, args...)
|
||||
c.recorder.Event(r, corev1.EventTypeWarning, "Synced", fmt.Sprintf(template, args...))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (c *Controller) advanceDeploymentRollout(name string, namespace string) {
|
||||
|
||||
// skip HTTP error rate check when no traffic is routed to canary
|
||||
if canaryRoute.Weight == 0 {
|
||||
c.recordEventInfof(r,"Stating rollout for %s.%s", r.Name, r.Namespace)
|
||||
c.recordEventInfof(r, "Stating rollout for %s.%s", r.Name, r.Namespace)
|
||||
} else {
|
||||
if ok := c.checkDeploymentSuccessRate(r); !ok {
|
||||
return
|
||||
@@ -69,20 +69,20 @@ func (c *Controller) advanceDeploymentRollout(name string, namespace string) {
|
||||
|
||||
_, err := c.istioClient.NetworkingV1alpha3().VirtualServices(r.Namespace).Update(vs)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"VirtualService %s.%s update failed: %v", r.Spec.VirtualService.Name, r.Namespace, err)
|
||||
c.recordEventErrorf(r, "VirtualService %s.%s update failed: %v", r.Spec.VirtualService.Name, r.Namespace, err)
|
||||
return
|
||||
} else {
|
||||
c.recordEventInfof(r,"Advance rollout %s.%s weight %v", r.Name, r.Namespace, canaryRoute.Weight)
|
||||
c.recordEventInfof(r, "Advance rollout %s.%s weight %v", r.Name, r.Namespace, canaryRoute.Weight)
|
||||
}
|
||||
|
||||
if canaryRoute.Weight == 100 {
|
||||
c.recordEventInfof(r,"Copying %s.%s template spec to %s.%s",
|
||||
c.recordEventInfof(r, "Copying %s.%s template spec to %s.%s",
|
||||
canary.GetName(), canary.Namespace, primary.GetName(), primary.Namespace)
|
||||
|
||||
primary.Spec.Template.Spec = canary.Spec.Template.Spec
|
||||
_, err = c.kubeClient.AppsV1().Deployments(primary.Namespace).Update(primary)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Deployment %s.%s promotion failed: %v", primary.GetName(), primary.Namespace, err)
|
||||
c.recordEventErrorf(r, "Deployment %s.%s promotion failed: %v", primary.GetName(), primary.Namespace, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -97,10 +97,10 @@ func (c *Controller) advanceDeploymentRollout(name string, namespace string) {
|
||||
vs.Annotations[statusAnnotation] = "finished"
|
||||
_, err := c.istioClient.NetworkingV1alpha3().VirtualServices(r.Namespace).Update(vs)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"VirtualService %s.%s annotations update failed: %v", r.Spec.VirtualService.Name, r.Namespace, err)
|
||||
c.recordEventErrorf(r, "VirtualService %s.%s annotations update failed: %v", r.Spec.VirtualService.Name, r.Namespace, err)
|
||||
return
|
||||
}
|
||||
c.recordEventInfof(r,"%s.%s promotion complete! Scaling down %s.%s",
|
||||
c.recordEventInfof(r, "%s.%s promotion complete! Scaling down %s.%s",
|
||||
r.Name, r.Namespace, canary.GetName(), canary.Namespace)
|
||||
c.scaleToZeroCanary(r)
|
||||
}
|
||||
@@ -109,14 +109,14 @@ func (c *Controller) advanceDeploymentRollout(name string, namespace string) {
|
||||
func (c *Controller) scaleToZeroCanary(r *rolloutv1.Rollout) {
|
||||
canary, err := c.kubeClient.AppsV1().Deployments(r.Namespace).Get(r.Spec.Canary.Name, v1.GetOptions{})
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Deployment %s.%s not found", r.Spec.Canary.Name, r.Namespace)
|
||||
c.recordEventErrorf(r, "Deployment %s.%s not found", r.Spec.Canary.Name, r.Namespace)
|
||||
return
|
||||
}
|
||||
//HPA https://github.com/kubernetes/kubernetes/pull/29212
|
||||
canary.Spec.Replicas = int32p(0)
|
||||
_, err = c.kubeClient.AppsV1().Deployments(canary.Namespace).Update(canary)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Scaling down %s.%s failed: %v", canary.GetName(), canary.Namespace, err)
|
||||
c.recordEventErrorf(r, "Scaling down %s.%s failed: %v", canary.GetName(), canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -124,12 +124,12 @@ func (c *Controller) scaleToZeroCanary(r *rolloutv1.Rollout) {
|
||||
func (c *Controller) checkDeploymentSuccessRate(r *rolloutv1.Rollout) bool {
|
||||
val, err := c.getDeploymentMetric(r.Spec.Canary.Name, r.Namespace, r.Spec.Metric.Name, r.Spec.Metric.Interval)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Metric query error: %v", err)
|
||||
c.recordEventErrorf(r, "Metric query error: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
if float64(r.Spec.Metric.Threshold) > val {
|
||||
c.recordEventErrorf(r,"Halt rollout %s.%s success rate %.2f%% < %v%%",
|
||||
c.recordEventErrorf(r, "Halt rollout %s.%s success rate %.2f%% < %v%%",
|
||||
r.Name, r.Namespace, val, r.Spec.Metric.Threshold)
|
||||
return false
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (c *Controller) updateRolloutAnnotations(r *rolloutv1.Rollout, canaryVersio
|
||||
r.Annotations[statusAnnotation] = "running"
|
||||
r, err = c.rolloutClient.AppsV1beta1().Rollouts(r.Namespace).Update(r)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Rollout %s.%s annotations update failed: %v", r.Name, r.Namespace, err)
|
||||
c.recordEventErrorf(r, "Rollout %s.%s annotations update failed: %v", r.Name, r.Namespace, err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -158,7 +158,7 @@ func (c *Controller) updateRolloutAnnotations(r *rolloutv1.Rollout, canaryVersio
|
||||
r.Annotations[statusAnnotation] = "running"
|
||||
r, err = c.rolloutClient.AppsV1beta1().Rollouts(r.Namespace).Update(r)
|
||||
if err != nil {
|
||||
c.recordEventErrorf(r,"Rollout %s.%s annotations update failed: %v", r.Name, r.Namespace, err)
|
||||
c.recordEventErrorf(r, "Rollout %s.%s annotations update failed: %v", r.Name, r.Namespace, err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"os"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func NewLogger(logLevel string) (*zap.SugaredLogger, error) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package version
|
||||
|
||||
var VERSION = "0.0.1-alpha.1"
|
||||
var VERSION = "unknown"
|
||||
var REVISION = "unknown"
|
||||
|
||||
Reference in New Issue
Block a user