Skip to content

Commit

Permalink
Include license expiry date in licensing config map (#5013)
Browse files Browse the repository at this point in the history
  • Loading branch information
pebrc authored Nov 4, 2021
1 parent 8fcd6b7 commit 107f5f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/operating-eck/licensing.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The operator periodically writes the total amount of Elastic resources under man
> kubectl -n elastic-system get configmap elastic-licensing -o json | jq .data
{
"eck_license_level": "enterprise",
"eck_license_expiry_date": "2022-01-01T00:59:59+01:00",
"enterprise_resource_units": "1",
"max_enterprise_resource_units": "10",
"timestamp": "2020-01-03T23:38:20Z",
Expand Down
15 changes: 15 additions & 0 deletions pkg/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
type LicensingInfo struct {
Timestamp string
EckLicenseLevel string
EckLicenseExpiryDate *time.Time
TotalManagedMemory float64
MaxEnterpriseResourceUnits int64
EnterpriseResourceUnits int64
Expand All @@ -56,6 +57,10 @@ func (li LicensingInfo) toMap() map[string]string {
m["max_enterprise_resource_units"] = strconv.FormatInt(li.MaxEnterpriseResourceUnits, 10)
}

if li.EckLicenseExpiryDate != nil {
m["eck_license_expiry_date"] = li.EckLicenseExpiryDate.Format(time.RFC3339)
}

return m
}

Expand Down Expand Up @@ -85,6 +90,7 @@ func (r LicensingResolver) ToInfo(totalMemory resource.Quantity) (LicensingInfo,
licensingInfo := LicensingInfo{
Timestamp: time.Now().Format(time.RFC3339),
EckLicenseLevel: r.getOperatorLicenseLevel(operatorLicense),
EckLicenseExpiryDate: r.getOperatorLicenseExpiry(operatorLicense),
TotalManagedMemory: inGB(totalMemory),
EnterpriseResourceUnits: inEnterpriseResourceUnits(totalMemory),
}
Expand Down Expand Up @@ -155,6 +161,15 @@ func (r LicensingResolver) getOperatorLicenseLevel(lic *license.EnterpriseLicens
return string(lic.License.Type)
}

// getOperatorLicenseExpiry returns the expiry date of the given Enterprise license or nil.
func (r LicensingResolver) getOperatorLicenseExpiry(lic *license.EnterpriseLicense) *time.Time {
if lic != nil {
t := time.Unix(0, lic.License.ExpiryDateInMillis*int64(time.Millisecond))
return &t
}
return nil
}

// getMaxEnterpriseResourceUnits returns the maximum of enterprise resources units that is allowed for a given license.
// For old style enterprise orchestration licenses which only have max_instances, the maximum of enterprise resources
// units is derived by dividing max_instances by 2.
Expand Down
5 changes: 5 additions & 0 deletions pkg/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ package license

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

commonlicense "github.com/elastic/cloud-on-k8s/pkg/controller/common/license"
)

func TestToMap(t *testing.T) {
dateFixture := time.Date(2021, 11, 03, 0, 0, 0, 0, time.UTC)

t.Run("empty_object", func(t *testing.T) {
i := LicensingInfo{}
have := i.toMap()
Expand All @@ -29,6 +32,7 @@ func TestToMap(t *testing.T) {
i := LicensingInfo{
Timestamp: "2020-05-28T11:15:31Z",
EckLicenseLevel: "enterprise",
EckLicenseExpiryDate: &dateFixture,
TotalManagedMemory: 72.54578,
EnterpriseResourceUnits: 5,
MaxEnterpriseResourceUnits: 10,
Expand All @@ -38,6 +42,7 @@ func TestToMap(t *testing.T) {
want := map[string]string{
"timestamp": "2020-05-28T11:15:31Z",
"eck_license_level": "enterprise",
"eck_license_expiry_date": "2021-11-03T00:00:00Z",
"total_managed_memory": "72.55GB",
"enterprise_resource_units": "5",
"max_enterprise_resource_units": "10",
Expand Down

0 comments on commit 107f5f9

Please sign in to comment.