diff --git a/README.md b/README.md index 60d5c1999..ca0d4fa80 100644 --- a/README.md +++ b/README.md @@ -86,28 +86,31 @@ Crane is composed of the following components: #### Installing prometheus components with helm chart > Note: -> If you already deployed prometheus, kube-state-metric, prometheus-node-exporter, then you can skip this step. +> If you already deployed prometheus, prometheus-node-exporter, then you can skip this step. -Crane use prometheus to be the default metric provider. Using following command to install prometheus with the release name `[RELEASE_NAME]`. It will also install dependent chart: kube-state-metric. +Export the following env if you want to use default settings, or specify customized value if you want to customize the installation. ```console -helm repo add prometheus-community https://prometheus-community.github.io/helm-charts -helm repo update -helm install [RELEASE_NAME] -n [NAMESPACE] --create-namespace prometheus-community/prometheus +export NAMESPACE=monitoring +export RELEASE_NAME=myprometheus ``` -Using following command to install prometheus-node-exporter with another release name `[NODE_EXPORTER_RELEASE_NAME]`. +Crane use prometheus to be the default metric provider. Using following command to install prometheus components. ```console -helm install [NODE_EXPORTER_RELEASE_NAME] -n [NAMESPACE] --create-namespace prometheus-community/prometheus-node-exporter +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts +helm repo update + +helm install $RELEASE_NAME -n $NAMESPACE --set kubeStateMetrics.enabled=false --set pushgateway.enabled=false --set alertmanager.enabled=false --set server.persistentVolume.enabled=false --create-namespace prometheus-community/prometheus ``` #### Configure Prometheus Address -The following command will configure your prometheus http address for crane, please change `YOUR_PROMETHEUS` to actual Prometheus address. If you're following above guide to install prometheus with helm chart then **YOUR_PROMETHEUS** would be: `http:\/\/[RELEASE_NAME]-prometheus-server.[NAMESPACE].svc.cluster.local` +The following command will configure prometheus http address for crane. Specify `CUSTOMIZE_PROMETHEUS` if you have existing prometheus server. ```console -PROMETHEUS_ADDRESS="YOUR_PROMETHEUS" && sed -i '' "s/PROMETHEUS_ADDRESS/${YOUR_ADDRESS}/" deploy/craned/deployment.yaml +export CUSTOMIZE_PROMETHEUS= +if [ ! $CUSTOMIZE_PROMETHEUS ]; then sed -i '' "s/PROMETHEUS_ADDRESS/http:\/\/${RELEASE_NAME}-server.${NAMESPACE}.svc.cluster.local/" deploy/craned/deployment.yaml ; else sed -i '' "s/PROMETHEUS_ADDRESS/${CUSTOMIZE_PROMETHEUS}/" deploy/craned/deployment.yaml ; fi ``` #### Deploying Crane @@ -119,11 +122,3 @@ kubectl apply -f deploy/manifests kubectl apply -f deploy/craned kubectl apply -f deploy/metric-adapter ``` - -#### Deploying Crane-agent - -If you want to try `QoS Ensurance`, then deploy `Crane-agent` by apply YAML declaration which will create a DaemonSet in your cluster. - -```console -kubectl apply -f deploy/crane-agent -``` diff --git a/cmd/craned/app/manager.go b/cmd/craned/app/manager.go index e1b5f3a07..5fc4afe17 100644 --- a/cmd/craned/app/manager.go +++ b/cmd/craned/app/manager.go @@ -3,7 +3,6 @@ package app import ( "context" "flag" - "fmt" "os" "strings" @@ -33,7 +32,6 @@ import ( "github.com/gocrane/crane/pkg/controller/timeseriesprediction" "github.com/gocrane/crane/pkg/features" "github.com/gocrane/crane/pkg/known" - "github.com/gocrane/crane/pkg/log" "github.com/gocrane/crane/pkg/metrics" "github.com/gocrane/crane/pkg/prediction" "github.com/gocrane/crane/pkg/prediction/dsp" @@ -105,7 +103,7 @@ func Run(ctx context.Context, opts *options.Options) error { } if opts.WebhookConfig.Enabled { - initializationWebhooks(mgr, opts) + initializationWebhooks(mgr) } initializationControllers(ctx, mgr, opts) klog.Info("Starting crane manager") @@ -126,9 +124,7 @@ func initializationMetricCollector(mgr ctrl.Manager) { metrics.CustomCollectorRegister(metrics.NewTspMetricCollector(mgr.GetClient())) } -func initializationWebhooks(mgr ctrl.Manager, opts *options.Options) { - log.Logger().Info(fmt.Sprintf("opts %v", opts)) - +func initializationWebhooks(mgr ctrl.Manager) { if certDir := os.Getenv("WEBHOOK_CERT_DIR"); len(certDir) > 0 { mgr.GetWebhookServer().CertDir = certDir } @@ -144,7 +140,6 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti nodeResource := utilfeature.DefaultFeatureGate.Enabled(features.CraneNodeResource) clusterNodePrediction := utilfeature.DefaultFeatureGate.Enabled(features.CraneClusterNodePrediction) analysis := utilfeature.DefaultMutableFeatureGate.Enabled(features.CraneAnalysis) - // todo: add more features timeseriespredict := utilfeature.DefaultFeatureGate.Enabled(features.CraneTimeSeriesPrediction) discoveryClientSet, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig()) @@ -245,7 +240,6 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti if analysis { if err := (&analytics.Controller{ Client: mgr.GetClient(), - Logger: log.Logger().WithName("analytics-controller"), Scheme: mgr.GetScheme(), RestMapper: mgr.GetRESTMapper(), Recorder: mgr.GetEventRecorderFor("analytics-controller"), diff --git a/deploy/craned/deployment.yaml b/deploy/craned/deployment.yaml index 2cc34fbff..af6fc96dc 100644 --- a/deploy/craned/deployment.yaml +++ b/deploy/craned/deployment.yaml @@ -35,21 +35,28 @@ spec: operator: Exists containers: - name: craned - image: docker.io/gocrane/craned + image: docker.io/gocrane/craned:v0.1.0 imagePullPolicy: IfNotPresent command: - /craned - --prometheus-address=PROMETHEUS_ADDRESS + - --feature-gates=Analysis=true,TimeSeriesPrediction=true,Autoscaling=true + - --recommendation-config-file=/tmp/recommendation-config/config_set.yaml - -v=4 volumeMounts: - mountPath: /tmp/k8s-webhook-server/serving-certs name: cert readOnly: true + - name: config + mountPath: /tmp/recommendation-config volumes: - name: cert secret: defaultMode: 420 secretName: webhook-server-tls + - name: config + configMap: + name: recommendation-config --- apiVersion: v1 data: @@ -60,3 +67,19 @@ metadata: name: webhook-server-tls namespace: crane-system type: kubernetes.io/tls + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: recommendation-config + namespace: crane-system +data: + config_set.yaml: |- + apiVersion: analysis.crane.io/v1alpha1 + kind: ConfigSet + configs: + - targets: [] + properties: + cpu-request-percentile: "0.98" diff --git a/deploy/manifests/analysis.crane.io_configsets.yaml b/deploy/manifests/analysis.crane.io_configsets.yaml deleted file mode 100644 index eb102078e..000000000 --- a/deploy/manifests/analysis.crane.io_configsets.yaml +++ /dev/null @@ -1,66 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.7.0 - creationTimestamp: null - name: configsets.analysis.crane.io -spec: - group: analysis.crane.io - names: - kind: ConfigSet - listKind: ConfigSetList - plural: configsets - shortNames: - - cs - singular: configset - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: ConfigSet represents the configuration set for recommendation. - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - configs: - items: - properties: - properties: - additionalProperties: - type: string - type: object - targets: - items: - properties: - kind: - type: string - name: - type: string - namespace: - type: string - type: object - type: array - type: object - type: array - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - type: object - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/deploy/metric-adapter/deployment.yaml b/deploy/metric-adapter/deployment.yaml index 88a07a185..03bc3f7fb 100644 --- a/deploy/metric-adapter/deployment.yaml +++ b/deploy/metric-adapter/deployment.yaml @@ -27,7 +27,7 @@ spec: serviceAccountName: metric-adapter containers: - name: metric-adapter - image: docker.io/gocrane/metric-adapter + image: docker.io/gocrane/metric-adapter:v0.1.0 imagePullPolicy: IfNotPresent args: - /metric-adapter diff --git a/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.md b/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.md index d976e2a01..dabb93e36 100644 --- a/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.md +++ b/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.md @@ -20,7 +20,7 @@ spec: name: php-apache minReplicas: 1 # MinReplicas is the lower limit replicas to the scale target which the autoscaler can scale down to. maxReplicas: 10 # MaxReplicas is the upper limit replicas to the scale target which the autoscaler can scale up to. - scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Manual". + scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Preview". # Metrics contains the specifications for which to use to calculate the desired replica count. metrics: - type: Resource @@ -45,7 +45,7 @@ spec: * spec.scaleTargetRef defines the reference to the workload that should be scaled. * spec.minReplicas is the lower limit replicas to the scale target which the autoscaler can scale down to. * spec.maxReplicas is the upper limit replicas to the scale target which the autoscaler can scale up to. -* spec.metrics indicate the strategy to scaling target, value can be "Auto" and "Manual". +* spec.metrics indicate the strategy to scaling target, value can be "Auto" and "Preview". * spec.metrics contains the specifications for which to use to calculate the desired replica count. Please refer to the details: * spec.prediction defines configurations for predict resources.If unspecified, defaults don't enable prediction. @@ -138,22 +138,24 @@ We can see significant improvement with EffectiveHorizontalPodAutoscaler: * Fewer replicas changes than HorizontalPodAutoscaler ### ScaleStrategy -EffectiveHorizontalPodAutoscaler provides two strategies for scaling: `Auto` and `Manual`. User can change the strategy at runtime, and it will take effect on the fly. +EffectiveHorizontalPodAutoscaler provides two strategies for scaling: `Auto` and `Preview`. User can change the strategy at runtime, and it will take effect on the fly. #### Auto Auto strategy achieves automatic scaling based on metrics. It is the default strategy. With this strategy, EffectiveHorizontalPodAutoscaler will create and control a HorizontalPodAutoscaler instance in backend. We don't recommend explicit configuration on the underlying HorizontalPodAutoscaler because it will be overridden by EffectiveHPAController. If user delete EffectiveHorizontalPodAutoscaler, HorizontalPodAutoscaler will be cleaned up too. -#### Manual -Manual strategy means user can specify replicas of target. User can switch from default strategy to this one by applying `spec.scaleStrategy` to `Manual`. It will take effect immediately, During the switch, EffectiveHPAController will disable HorizontalPodAutoscaler if exists and scale the target to the value `spec.specificReplicas`, if user not set `spec.specificReplicas`, when ScaleStrategy is change to Manual, it will just stop scaling. +#### Preview +Preview strategy means EffectiveHorizontalPodAutoscaler won't change target's replicas automatically, so you can preview the calculated replicas and control target's replicas by themselves. User can switch from default strategy to this one by applying `spec.scaleStrategy` to `Preview`. It will take effect immediately, During the switch, EffectiveHPAController will disable HorizontalPodAutoscaler if exists and scale the target to the value `spec.specificReplicas`, if user not set `spec.specificReplicas`, when ScaleStrategy is change to Preview, it will just stop scaling. -A sample manual configuration looks like following: +A sample preview configuration looks like following: ```yaml apiVersion: autoscaling.crane.io/v1alpha1 kind: EffectiveHorizontalPodAutoscaler spec: - scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Manual". - specificReplicas: 5 # SpecificReplicas specify the target replicas. - + scaleStrategy: Preview # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Preview". + specificReplicas: 5 # SpecificReplicas specify the target replicas. +status: + expectReplicas: 4 # expectReplicas is the calculated replicas that based on prediction metrics or spec.specificReplicas. + currentReplicas: 4 # currentReplicas is actual replicas from target ``` ### HorizontalPodAutoscaler compatible diff --git a/examples/config_set.yaml b/examples/config_set.yaml new file mode 100644 index 000000000..47316297f --- /dev/null +++ b/examples/config_set.yaml @@ -0,0 +1,6 @@ +apiVersion: analysis.crane.io/v1alpha1 +kind: ConfigSet +configs: + - targets: [] + properties: + cpu-request-percentile: "0.98" \ No newline at end of file diff --git a/go.mod b/go.mod index da8bff139..90d9dbac9 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.17 require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-echarts/go-echarts/v2 v2.2.4 - github.com/go-logr/logr v0.4.0 github.com/gocrane/api v0.0.0-20220101093604-2129a9ce85e3 github.com/google/go-cmp v0.5.6 // indirect github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 @@ -47,6 +46,7 @@ require ( github.com/evanphx/json-patch v4.11.0+incompatible // indirect github.com/felixge/httpsnoop v1.0.1 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/go-logr/logr v0.4.0 // indirect github.com/go-ole/go-ole v1.2.5 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect diff --git a/go.sum b/go.sum index 489d023d6..50066a963 100644 --- a/go.sum +++ b/go.sum @@ -293,6 +293,7 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/cadvisor v0.39.2/go.mod h1:kN93gpdevu+bpS227TyHVZyCU5bbqCzTj5T9drl34MI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -341,9 +342,11 @@ github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORR github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -385,9 +388,11 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -414,6 +419,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= @@ -468,10 +474,13 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= @@ -480,10 +489,12 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -558,15 +569,18 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -604,6 +618,7 @@ github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ= github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= @@ -614,6 +629,7 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= @@ -623,16 +639,21 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v2 v2.305.0 h1:ftQ0nOOHMcbMS3KIaDQ0g5Qcd6bhaBrQT6b89DfwLTs= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= go.etcd.io/etcd/client/v3 v3.5.0 h1:62Eh0XOro+rDwkrypAGDfgmNh5Joq+z+W9HZdlXMzek= go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= +go.etcd.io/etcd/pkg/v3 v3.5.0 h1:ntrg6vvKRW26JRmHTE0iNlDgYK6JX3hg/4cD62X0ixk= go.etcd.io/etcd/pkg/v3 v3.5.0/go.mod h1:UzJGatBQ1lXChBkQF0AuAtkRQMYnHubxAEYIrC3MSsE= +go.etcd.io/etcd/raft/v3 v3.5.0 h1:kw2TmO3yFTgE+F0mdKkG7xMxkit2duBDa2Hu6D/HMlw= go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD00Szc= +go.etcd.io/etcd/server/v3 v3.5.0 h1:jk8D/lwGEDlQU9kZXUFMSANkE22Sg5+mW27ip8xcF9E= go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -653,6 +674,7 @@ go.opentelemetry.io/otel/exporters/otlp v0.20.0 h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85 go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM= go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= +go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/sdk v0.20.0 h1:JsxtGXd06J8jrnya7fdI/U/MR6yXA5DtbZy+qoHQlr8= go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc= @@ -668,6 +690,7 @@ go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0H go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= @@ -718,6 +741,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -908,10 +932,12 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY= gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY= @@ -1039,6 +1065,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= @@ -1051,6 +1078,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXL gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.1/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= diff --git a/pkg/controller/analytics/analytics_controller.go b/pkg/controller/analytics/analytics_controller.go index f376a083e..c79547d83 100644 --- a/pkg/controller/analytics/analytics_controller.go +++ b/pkg/controller/analytics/analytics_controller.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -22,6 +21,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" + "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -34,7 +34,6 @@ import ( type Controller struct { client.Client - Logger logr.Logger Scheme *runtime.Scheme RestMapper meta.RESTMapper Recorder record.EventRecorder @@ -46,7 +45,7 @@ type Controller struct { } func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - c.Logger.V(4).Info("Got an analytics resource.", "analytics", req.NamespacedName) + klog.V(4).InfoS("Got an analytics resource.", "analytics", req.NamespacedName) a := &analysisv1alph1.Analytics{} @@ -59,7 +58,7 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if a.DeletionTimestamp != nil { - c.Logger.Info("Analytics resource is being deleted.", "name", req.NamespacedName) + klog.InfoS("Analytics resource is being deleted.", "name", req.NamespacedName) return ctrl.Result{}, nil } @@ -170,17 +169,17 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu rm[k] = r.DeepCopy() } - if c.Logger.V(6).Enabled() { + if klog.V(6).Enabled() { // Print recommendations for k, r := range rm { - c.Logger.V(6).Info("recommendations", "key", k, "namespace", r.Namespace, "name", r.Name) + klog.V(6).InfoS("recommendations", "key", k, "namespace", r.Namespace, "name", r.Name) } } - if c.Logger.V(6).Enabled() { + if klog.V(6).Enabled() { // Print identities for k, id := range identities { - c.Logger.V(6).Info("identities", "key", k, "apiVersion", id.APIVersion, "kind", id.Kind, "namespace", id.Namespace, "name", id.Name) + klog.V(6).InfoS("identities", "key", k, "apiVersion", id.APIVersion, "kind", id.Kind, "namespace", id.Namespace, "name", id.Name) } } @@ -226,7 +225,7 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if a.Spec.CompletionStrategy.CompletionStrategyType == analysisv1alph1.CompletionStrategyPeriodical { if a.Spec.CompletionStrategy.PeriodSeconds != nil { d := time.Second * time.Duration(*a.Spec.CompletionStrategy.PeriodSeconds) - c.Logger.V(5).Info("Will re-sync", "after", d) + klog.V(4).InfoS("Will re-sync", "after", d) return ctrl.Result{ RequeueAfter: d, }, nil @@ -271,12 +270,12 @@ func (ac *Controller) createRecommendation(ctx context.Context, a *analysisv1alp } if err := ac.Create(ctx, r); err != nil { - ac.Logger.Error(err, "Failed to create Recommendation") + klog.Error(err, "Failed to create Recommendation") return err } if err := ac.Get(ctx, types.NamespacedName{Namespace: r.Namespace, Name: r.Name}, r); err != nil { - ac.Logger.Error(err, "Failed to get Recommendation") + klog.Error(err, "Failed to get Recommendation") return err } *refs = append(*refs, corev1.ObjectReference{ diff --git a/pkg/features/features.go b/pkg/features/features.go index 03539fd33..09e80b714 100644 --- a/pkg/features/features.go +++ b/pkg/features/features.go @@ -20,7 +20,7 @@ const ( CraneClusterNodePrediction featuregate.Feature = "ClusterNodePrediction" // CraneTimeSeriesPrediction enables the time series prediction features. - CraneTimeSeriesPrediction featuregate.Feature = "CraneTimeSeriesPrediction" + CraneTimeSeriesPrediction featuregate.Feature = "TimeSeriesPrediction" ) var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ diff --git a/pkg/log/log.go b/pkg/log/log.go deleted file mode 100644 index 291b1b106..000000000 --- a/pkg/log/log.go +++ /dev/null @@ -1,42 +0,0 @@ -package log - -import ( - "fmt" - "sync" - - "github.com/go-logr/logr" - "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" - ctrl "sigs.k8s.io/controller-runtime" -) - -var ( - once sync.Once - logger logr.Logger -) - -func Logger() logr.Logger { - if logger == nil { - Init("default") - } - return logger -} - -func Init(name string) { - once.Do(func() { - ctrl.SetLogger(klogr.New()) - logger = ctrl.Log.WithName(name) - }) -} - -func NewLogger(name string) logr.Logger { - return ctrl.Log.WithName(name) -} - -func GenerateKey(name string, namespace string) string { - return fmt.Sprintf("%s/%s", namespace, name) -} - -func GenerateObj(obj klog.KMetadata) string { - return klog.KObj(obj).String() -} diff --git a/pkg/providers/mock/provider.go b/pkg/providers/mock/provider.go index 519e7b68e..1e66046cd 100644 --- a/pkg/providers/mock/provider.go +++ b/pkg/providers/mock/provider.go @@ -9,13 +9,12 @@ import ( "strconv" "time" + "k8s.io/klog/v2" + "github.com/gocrane/crane/pkg/common" - "github.com/gocrane/crane/pkg/log" "github.com/gocrane/crane/pkg/providers" ) -var logger = log.Logger() - var _ providers.Interface = &inMemory{} type inMemory struct { @@ -30,12 +29,12 @@ func NewProvider(config *providers.MockConfig) (providers.Interface, error) { } r, err := os.Open(config.SeedFile) if err != nil { - logger.Error(err, "Failed to open seed file", "seedFile", config.SeedFile) + klog.ErrorS(err, "Failed to open seed file", "seedFile", config.SeedFile) return nil, err } buf, err := ioutil.ReadAll(r) if err != nil { - logger.Error(err, "Failed to read seed file", "seedFile", config.SeedFile) + klog.ErrorS(err, "Failed to read seed file", "seedFile", config.SeedFile) return nil, err } reader := csv.NewReader(bytes.NewBuffer(buf)) @@ -76,7 +75,7 @@ func (im inMemory) GetTimeSeries(_ string, _ []common.QueryCondition, start time var samples []common.Sample var i int - logger.Info("GetTimeSeries from imMemory provider", "range", fmt.Sprintf(" [%d, %d]", start.Unix(), end.Unix())) + klog.InfoS("GetTimeSeries from imMemory provider", "range", fmt.Sprintf(" [%d, %d]", start.Unix(), end.Unix())) for i = range im.samples { t := time.Unix(im.samples[i].Timestamp, 0) diff --git a/pkg/providers/prom/prom.go b/pkg/providers/prom/prom.go index ba83cb8c5..63aeacba8 100644 --- a/pkg/providers/prom/prom.go +++ b/pkg/providers/prom/prom.go @@ -9,6 +9,8 @@ import ( "net/url" "time" + "k8s.io/klog/v2" + "github.com/gocrane/crane/pkg/providers" prometheus "github.com/prometheus/client_golang/api" @@ -52,12 +54,12 @@ func (c *context) QueryRangeSync(ctx gocontext.Context, query string, start, end } results, warnings, err := c.api.QueryRange(ctx, query, r) if len(warnings) != 0 { - logger.Info("prom query range warnings", "warnings", warnings) + klog.InfoS("prom query range warnings", "warnings", warnings) } if err != nil { return ts, err } - logger.V(10).Info("prom query range result", "result", results.String(), "resultsType", results.Type()) + klog.V(10).InfoS("prom query range result", "result", results.String(), "resultsType", results.Type()) return c.convertPromResultsToTimeSeries(results) } @@ -66,12 +68,12 @@ func (c *context) QuerySync(ctx gocontext.Context, query string) ([]*common.Time var ts []*common.TimeSeries results, warnings, err := c.api.Query(ctx, query, time.Now()) if len(warnings) != 0 { - logger.Info("prom query warnings", "warnings", warnings) + klog.InfoS("prom query warnings", "warnings", warnings) } if err != nil { return ts, err } - logger.V(10).Info("prom query result", "result", results.String(), "resultsType", results.Type()) + klog.V(10).InfoS("prom query result", "result", results.String(), "resultsType", results.Type()) return c.convertPromResultsToTimeSeries(results) } diff --git a/pkg/providers/prom/provider.go b/pkg/providers/prom/provider.go index 3b5b97be0..0b04aa5dd 100644 --- a/pkg/providers/prom/provider.go +++ b/pkg/providers/prom/provider.go @@ -8,8 +8,9 @@ import ( "strings" "time" + "k8s.io/klog/v2" + "github.com/gocrane/crane/pkg/common" - "github.com/gocrane/crane/pkg/log" "github.com/gocrane/crane/pkg/providers" ) @@ -17,8 +18,6 @@ const ( ClusterContextName = "cluster" ) -var logger = log.Logger() - type prom struct { ctx *context } @@ -44,11 +43,11 @@ func (p *prom) GetTimeSeries(metricName string, conditions []common.QueryConditi } queryExpr := fmt.Sprintf("%s{%s}", metricName, getQueryConditionStr(conditions)) - logger.V(5).Info("GetLatestTimeSeries", "queryExpr", queryExpr) + klog.V(6).InfoS("GetLatestTimeSeries", "queryExpr", queryExpr) timeSeries, err := p.ctx.QueryRangeSync(gocontext.TODO(), queryExpr, startTime, endTime, step) if err != nil { - logger.Error(err, "Failed to QueryTimeSeries") + klog.Error(err, "Failed to QueryTimeSeries") return []*common.TimeSeries{}, err } @@ -61,11 +60,11 @@ func (p *prom) GetLatestTimeSeries(metricName string, conditions []common.QueryC } queryExpr := fmt.Sprintf("%s{%s}", metricName, getQueryConditionStr(conditions)) - logger.V(5).Info("GetLatestTimeSeries", "queryExpr", queryExpr) + klog.V(6).InfoS("GetLatestTimeSeries", "queryExpr", queryExpr) timeSeries, err := p.ctx.QuerySync(gocontext.TODO(), queryExpr) if err != nil { - logger.Error(err, "Failed to QueryTimeSeries") + klog.Error(err, "Failed to QueryTimeSeries") return []*common.TimeSeries{}, err } @@ -75,7 +74,7 @@ func (p *prom) GetLatestTimeSeries(metricName string, conditions []common.QueryC func (p *prom) QueryTimeSeries(queryExpr string, startTime time.Time, endTime time.Time, step time.Duration) ([]*common.TimeSeries, error) { timeSeries, err := p.ctx.QueryRangeSync(gocontext.TODO(), queryExpr, startTime, endTime, step) if err != nil { - logger.Error(err, "Failed to QueryTimeSeries") + klog.Error(err, "Failed to QueryTimeSeries") return nil, err } @@ -89,7 +88,7 @@ func (p *prom) QueryLatestTimeSeries(queryExpr string) ([]*common.TimeSeries, er //start := end.Add(-step * 2) timeSeries, err := p.ctx.QuerySync(gocontext.TODO(), queryExpr) if err != nil { - logger.Error(err, "Failed to QueryLatestTimeSeries") + klog.Error(err, "Failed to QueryLatestTimeSeries") return nil, err } diff --git a/pkg/webhooks/prediction/validating.go b/pkg/webhooks/prediction/validating.go index 7fda64d04..967428cd0 100644 --- a/pkg/webhooks/prediction/validating.go +++ b/pkg/webhooks/prediction/validating.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/sets" predictionapi "github.com/gocrane/api/prediction/v1alpha1" ) diff --git a/pkg/webhooks/webhook.go b/pkg/webhooks/webhook.go index 914ac59c6..5175206ea 100644 --- a/pkg/webhooks/webhook.go +++ b/pkg/webhooks/webhook.go @@ -17,12 +17,12 @@ limitations under the License. package webhooks import ( + "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" analysisapi "github.com/gocrane/api/analysis/v1alpha1" predictionapi "github.com/gocrane/api/prediction/v1alpha1" - "github.com/gocrane/crane/pkg/log" "github.com/gocrane/crane/pkg/webhooks/prediction" "github.com/gocrane/crane/pkg/webhooks/recommendation" ) @@ -34,7 +34,7 @@ func SetupWebhookWithManager(mgr ctrl.Manager) error { WithValidator(&tspValidationAdmission). Complete() if err != nil { - log.Logger().Info("Failed to setup tsp webhook", err) + klog.Errorf("Failed to setup tsp webhook: %v", err) } recomendValidationAdmission := recommendation.ValidationAdmission{} @@ -43,7 +43,7 @@ func SetupWebhookWithManager(mgr ctrl.Manager) error { WithValidator(&recomendValidationAdmission). Complete() if err != nil { - log.Logger().Info("Failed to setup recommendation webhook", err) + klog.Errorf("Failed to setup recommendation webhook: %v", err) } return err