Skip to content

Commit

Permalink
Package renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed Dec 17, 2019
1 parent 9001680 commit 692cb4e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/licensing-info/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

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")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -322,7 +322,7 @@ func execute() {
os.Exit(1)
}

r := resource.NewLicensingReporter(mgr.GetClient())
r := licensing.NewResourceReporter(mgr.GetClient())
go r.Start(operatorNamespace)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/aggregator.go → pkg/license/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pkg/resource/license.go → pkg/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions pkg/resource/reporter.go → pkg/license/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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)
}

0 comments on commit 692cb4e

Please sign in to comment.