Skip to content

Commit

Permalink
rpk: change license nag cache and message
Browse files Browse the repository at this point in the history
  • Loading branch information
r-vasquez committed Oct 16, 2024
1 parent 9e810f7 commit 3c30a00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/go/rpk/pkg/adminapi/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func licenseFeatureChecks(ctx context.Context, fs afero.Fs, cl *rpadmin.AdminAPI
// We only do a check if:
// 1. LicenseCheck == nil: never checked before OR last check was in
// violation. (we only save successful responses).
// 2. LicenseStatus was last checked more than 7 days ago.
if p.LicenseCheck == nil || p.LicenseCheck != nil && time.Unix(p.LicenseCheck.LastUpdate, 0).AddDate(0, 0, 7).Before(time.Now()) {
// 2. LicenseStatus was last checked more than 1 hour ago.
if p.LicenseCheck == nil || p.LicenseCheck != nil && time.Unix(p.LicenseCheck.LastUpdate, 0).Add(1*time.Hour).Before(time.Now()) {
resp, err := cl.GetEnterpriseFeatures(ctx)
if err != nil {
zap.L().Sugar().Warnf("unable to check licensed enterprise features in the cluster: %v", err)
Expand All @@ -152,7 +152,7 @@ func licenseFeatureChecks(ctx context.Context, fs afero.Fs, cl *rpadmin.AdminAPI
features = append(features, f.Name)
}
}
msg = fmt.Sprintf("A Redpanda Enterprise Edition license is required to use enterprise features: %v. For more information, see https://docs.redpanda.com/current/get-started/licenses.", features)
msg = fmt.Sprintf("\nWARNING: The following Enterprise features are being used in your Redpanda cluster: %v. These features require a license. To get a license, contact us at https://www.redpanda.com/contact. For more information, see https://docs.redpanda.com/current/get-started/licenses/#redpanda-enterprise-edition\n", features)
} else {
licenseCheck = &config.LicenseStatusCache{
LastUpdate: time.Now().Unix(),
Expand Down
12 changes: 6 additions & 6 deletions src/go/rpk/pkg/adminapi/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_licenseFeatureChecks(t *testing.T) {
},
{
name: "license ok, cache valid",
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().AddDate(0, 0, -1).Unix()}},
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().Add(20 * time.Minute).Unix()}},
checkCache: func(t *testing.T, before int64, after int64) {
// If the cache was valid, last update shouldn't have changed.
require.Equal(t, before, after)
Expand All @@ -39,7 +39,7 @@ func Test_licenseFeatureChecks(t *testing.T) {
},
{
name: "license ok, old cache",
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().AddDate(0, 0, -20).Unix()}}, // Limit is 15 days
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().AddDate(0, 0, -20).Unix()}}, // Limit is 1 hour
checkCache: func(t *testing.T, before int64, after int64) {
// Date should be updated.
afterT := time.Unix(after, 0)
Expand All @@ -52,19 +52,19 @@ func Test_licenseFeatureChecks(t *testing.T) {
name: "inViolation, first time call",
prof: &config.RpkProfile{},
responseCase: "inViolation",
expContain: "A Redpanda Enterprise Edition license is required",
expContain: "These features require a license",
},
{
name: "inViolation, expired last check",
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().AddDate(0, 0, -20).Unix()}},
responseCase: "inViolation",
expContain: "A Redpanda Enterprise Edition license is required t",
expContain: "These features require a license",
},
{
// Edge case when the license expires but the last check was less
// than 15 days ago.
// than 1 hour ago.
name: "inViolation, cache still valid",
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().AddDate(0, 0, -1).Unix()}},
prof: &config.RpkProfile{LicenseCheck: &config.LicenseStatusCache{LastUpdate: time.Now().Add(30 * time.Minute).Unix()}},
responseCase: "inViolation",
// In this case, even if the license is in violation, rpk won't
// reach the Admin API because the last check was under 15 days.
Expand Down

0 comments on commit 3c30a00

Please sign in to comment.