From 692cb4e91081a705e3a417297f828dcd89be3d81 Mon Sep 17 00:00:00 2001 From: Thibault Richard Date: Tue, 17 Dec 2019 18:49:01 +0100 Subject: [PATCH] Package renaming --- cmd/licensing-info/main.go | 4 +-- cmd/manager/main.go | 4 +-- pkg/{resource => license}/aggregator.go | 2 +- pkg/{resource => license}/aggregator_test.go | 2 +- pkg/{resource => license}/license.go | 6 ++--- pkg/{resource => license}/reporter.go | 28 ++++++++++---------- 6 files changed, 23 insertions(+), 23 deletions(-) rename pkg/{resource => license}/aggregator.go (99%) rename pkg/{resource => license}/aggregator_test.go (99%) rename pkg/{resource => license}/license.go (97%) rename pkg/{resource => license}/reporter.go (66%) diff --git a/cmd/licensing-info/main.go b/cmd/licensing-info/main.go index 84a3f114d5d..0dc9e78951e 100644 --- a/cmd/licensing-info/main.go +++ b/cmd/licensing-info/main.go @@ -10,7 +10,7 @@ import ( "log" eckscheme "github.com/elastic/cloud-on-k8s/pkg/controller/common/scheme" - "github.com/elastic/cloud-on-k8s/pkg/resource" + "github.com/elastic/cloud-on-k8s/pkg/license" "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // auth on gke "sigs.k8s.io/controller-runtime/pkg/client" @@ -18,7 +18,7 @@ import ( ) func main() { - licensingInfo, err := resource.NewLicensingReporter(newK8sClient()).Get() + licensingInfo, err := license.NewResourceReporter(newK8sClient()).Get() if err != nil { log.Fatal(err, "Failed to get licensing info") } diff --git a/cmd/manager/main.go b/cmd/manager/main.go index df07db6bbaf..234a16c2ecd 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -40,11 +40,11 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/kibana" kbassn "github.com/elastic/cloud-on-k8s/pkg/controller/kibanaassociation" "github.com/elastic/cloud-on-k8s/pkg/controller/license" + licensing "github.com/elastic/cloud-on-k8s/pkg/license" licensetrial "github.com/elastic/cloud-on-k8s/pkg/controller/license/trial" "github.com/elastic/cloud-on-k8s/pkg/controller/webhook" "github.com/elastic/cloud-on-k8s/pkg/dev" "github.com/elastic/cloud-on-k8s/pkg/dev/portforward" - "github.com/elastic/cloud-on-k8s/pkg/resource" "github.com/elastic/cloud-on-k8s/pkg/utils/net" ) @@ -322,7 +322,7 @@ func execute() { os.Exit(1) } - r := resource.NewLicensingReporter(mgr.GetClient()) + r := licensing.NewResourceReporter(mgr.GetClient()) go r.Start(operatorNamespace) } diff --git a/pkg/resource/aggregator.go b/pkg/license/aggregator.go similarity index 99% rename from pkg/resource/aggregator.go rename to pkg/license/aggregator.go index 5db8db28163..14b211deae2 100644 --- a/pkg/resource/aggregator.go +++ b/pkg/license/aggregator.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package resource +package license import ( "fmt" diff --git a/pkg/resource/aggregator_test.go b/pkg/license/aggregator_test.go similarity index 99% rename from pkg/resource/aggregator_test.go rename to pkg/license/aggregator_test.go index 1a6dabe415a..8a71f800503 100644 --- a/pkg/resource/aggregator_test.go +++ b/pkg/license/aggregator_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package resource +package license import ( "testing" diff --git a/pkg/resource/license.go b/pkg/license/license.go similarity index 97% rename from pkg/resource/license.go rename to pkg/license/license.go index 68d35f03399..875c975bab5 100644 --- a/pkg/resource/license.go +++ b/pkg/license/license.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package resource +package license import ( "encoding/json" @@ -104,9 +104,9 @@ func inGB(q resource.Quantity) string { // inEnterpriseResourceUnits converts a resource.Quantity in Elastic Enterprise resource units func inEnterpriseResourceUnits(q resource.Quantity) string { // divide by the value (in bytes) per 64 billion (64 GB) - eru := float64(q.Value())/64000000000 + eru := float64(q.Value()) / 64000000000 // round to the nearest superior integer - return fmt.Sprintf("%f", math.Round(eru + 0.5)) + return fmt.Sprintf("%f", math.Round(eru+0.5)) } // toMap transforms a LicensingInfo to a map of string, in order to fill in the data of a config map diff --git a/pkg/resource/reporter.go b/pkg/license/reporter.go similarity index 66% rename from pkg/resource/reporter.go rename to pkg/license/reporter.go index 2aa02fad896..75f261b3d44 100644 --- a/pkg/resource/reporter.go +++ b/pkg/license/reporter.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package resource +package license import ( "time" @@ -21,28 +21,28 @@ var ( log = logf.Log.WithName("resource") ) -// LicensingReporter aggregates resources of all Elastic components managed by the operator +// ResourceReporter aggregates resources of all Elastic components managed by the operator // and reports them in a config map in the form of licensing information -type LicensingReporter struct { - aggregator Aggregator - licenseResolver LicensingResolver +type ResourceReporter struct { + aggregator Aggregator + licensingResolver LicensingResolver } -// LicensingReporter returns a new LicensingReporter -func NewLicensingReporter(client client.Client) LicensingReporter { +// NewResourceReporter returns a new ResourceReporter +func NewResourceReporter(client client.Client) ResourceReporter { c := k8s.WrapClient(client) - return LicensingReporter{ + return ResourceReporter{ aggregator: Aggregator{ client: c, }, - licenseResolver: LicensingResolver{ + licensingResolver: LicensingResolver{ client: c, }, } } // Start starts to report the licensing information repeatedly at regular intervals -func (r LicensingReporter) Start(operatorNs string) { +func (r ResourceReporter) Start(operatorNs string) { ticker := time.NewTicker(refreshPeriod) for range ticker.C { err := r.Report(operatorNs) @@ -53,21 +53,21 @@ func (r LicensingReporter) Start(operatorNs string) { } // Report reports the licensing information in a config map -func (r LicensingReporter) Report(operatorNs string) error { +func (r ResourceReporter) Report(operatorNs string) error { licensingInfo, err := r.Get() if err != nil { return err } - return r.licenseResolver.Save(licensingInfo, operatorNs) + return r.licensingResolver.Save(licensingInfo, operatorNs) } // Get aggregates managed resources and returns the licensing information -func (r LicensingReporter) Get() (LicensingInfo, error) { +func (r ResourceReporter) Get() (LicensingInfo, error) { totalMemory, err := r.aggregator.AggregateMemory() if err != nil { return LicensingInfo{}, err } - return r.licenseResolver.ToInfo(totalMemory) + return r.licensingResolver.ToInfo(totalMemory) }