forked from elastic/cloud-on-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource aggregation for licensing count (elastic#2277)
Start a reporter in a goroutine that repeatedly (every 2 minutes) aggregates the total memory of all Elastic managed components by the operator and reports it in the form of a licensing information in a config map. Example of the content of the config map: > kubectl -n elastic-system get cm elastic-licensing -o json | jq .data { "eck_license_level": "enterprise", "enterprise_resource_units": "1", "timestamp": "2019-12-20T18:18:31+01:00", "total_managed_memory": "12.88GB" } Notes: - "Enterprise resource units" is an Elastic unit calculated with the total memory under management divided by 64GB. - The ECK license level can be basic, trial-enterprise or entreprise.
- Loading branch information
1 parent
9f76d85
commit ea652ce
Showing
17 changed files
with
1,051 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
eckscheme "github.com/elastic/cloud-on-k8s/pkg/controller/common/scheme" | ||
"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" | ||
) | ||
|
||
// Simple program that returns the licensing information, including the total memory of all Elastic managed components by | ||
// the operator and its equivalent in "Enterprise Resource Units". | ||
// | ||
// The main objective of its existence is to show a use of the ResourceReporter and also to propose an alternative to | ||
// immediately retrieve the licensing information. | ||
// | ||
// Example of use: | ||
// | ||
// > go run cmd/licensing-info/main.go | ||
// { | ||
// "timestamp": "2019-12-17T11:56:02+01:00", | ||
// "license_level": "basic", | ||
// "memory": "5.37GB", | ||
// "enterprise_resource_units": "1" | ||
// } | ||
// | ||
|
||
func main() { | ||
licensingInfo, err := license.NewResourceReporter(newK8sClient()).Get() | ||
if err != nil { | ||
log.Fatal(err, "Failed to get licensing info") | ||
} | ||
|
||
bytes, err := json.Marshal(licensingInfo) | ||
if err != nil { | ||
log.Fatal(err, "Failed to marshal licensing info") | ||
} | ||
|
||
fmt.Print(string(bytes)) | ||
} | ||
|
||
func newK8sClient() client.Client { | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
log.Fatal(err, "Failed to get a Kubernetes config") | ||
} | ||
|
||
err = eckscheme.SetupScheme() | ||
if err != nil { | ||
log.Fatal(err, "Failed to set up the ECK scheme") | ||
} | ||
|
||
c, err := client.New(cfg, client.Options{Scheme: scheme.Scheme}) | ||
if err != nil { | ||
log.Fatal(err, "Failed to create a new Kubernetes client") | ||
} | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.